返回介绍

wp_delete_nav_menu()

发布于 2017-09-11 11:50:53 字数 2452 浏览 1045 评论 0 收藏 0

wp_delete_nav_menu( string $menu )

Delete a Navigation Menu.


description


参数

$menu

(string) (Required) Menu ID, slug, or name.


返回值

(bool|WP_Error) True on success, false or WP_Error object on failure.


源代码

File: wp-includes/nav-menu.php

function wp_delete_nav_menu( $menu ) {
	$menu = wp_get_nav_menu_object( $menu );
	if ( ! $menu )
		return false;

	$menu_objects = get_objects_in_term( $menu->term_id, 'nav_menu' );
	if ( ! empty( $menu_objects ) ) {
		foreach ( $menu_objects as $item ) {
			wp_delete_post( $item );
		}
	}

	$result = wp_delete_term( $menu->term_id, 'nav_menu' );

	// Remove this menu from any locations.
	$locations = get_nav_menu_locations();
	foreach ( $locations as $location => $menu_id ) {
		if ( $menu_id == $menu->term_id )
			$locations[ $location ] = 0;
	}
	set_theme_mod( 'nav_menu_locations', $locations );

	if ( $result && !is_wp_error($result) )

		/**
		 * Fires after a navigation menu has been successfully deleted.
		 *
		 * @since 3.0.0
		 *
		 * @param int $term_id ID of the deleted menu.
		 */
		do_action( 'wp_delete_nav_menu', $menu->term_id );

	return $result;
}

更新日志

Versiondescription
3.0.0Introduced.

相关函数

Uses

  • wp-includes/theme.php: set_theme_mod()
  • wp-includes/taxonomy.php: wp_delete_term()
  • wp-includes/taxonomy.php: get_objects_in_term()
  • wp-includes/plugin.php: do_action()
  • wp-includes/post.php: wp_delete_post()
  • wp-includes/nav-menu.php: wp_delete_nav_menu
  • wp-includes/nav-menu.php: wp_get_nav_menu_object()
  • wp-includes/nav-menu.php: get_nav_menu_locations()
  • wp-includes/load.php: is_wp_error()
  • Show 4 more uses Hide more uses

Used By

  • wp-includes/customize/class-wp-customize-nav-menu-setting.php: WP_Customize_Nav_Menu_Setting::update()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文