Bazujące na WordPress narzędzie wyszukiwania dla deweloperów i twórców motywów.



wp_delete_nav_menu ›

Od3.0.0
Przestarzałyn/a
wp_delete_nav_menu ( $menu )
Parametry:
  • (int|string|WP_Term) $menu Menu ID, slug, name, or object.
    Wymagane: Tak
Powrót:
  • (bool|WP_Error) True on success, false or WP_Error object on failure.
Zdefiniowane na:
Codex:

Delete a Navigation Menu.



Źródło

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;
}