Advertisements

wp_get_nav_menu_to_edit

Definition:
function wp_get_nav_menu_to_edit( $menu_id = 0 ) {}

Returns the menu formatted to edit.

Parameters

  • string $menu_id: The ID of the menu to format.

Return values

returns:The menu formatted to edit or error object on failure.

Defined filters

  • wp_edit_nav_menu_walker
    apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $menu_id )

Source code

function wp_get_nav_menu_to_edit( $menu_id = 0 ) {

	$menu = wp_get_nav_menu_object( $menu_id );



	// If the menu exists, get its items.

	if ( is_nav_menu( $menu ) ) {

		$menu_items = wp_get_nav_menu_items( $menu->term_id, array('post_status' => 'any') );

		$result = '<div id="menu-instructions" class="post-body-plain';

		$result .= ( ! empty($menu_items) ) ? ' menu-instructions-inactive">' : '">';

		$result .= '<p>' . __('Select menu items (pages, categories, links) from the boxes at left to begin building your custom menu.') . '</p>';

		$result .= '</div>';



		if( empty($menu_items) )

			return $result . ' <ul class="menu" id="menu-to-edit"> </ul>';



		$walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $menu_id );



		if ( class_exists( $walker_class_name ) )

			$walker = new $walker_class_name;

		else

			return new WP_Error( 'menu_walker_not_exist', sprintf( __('The Walker class named <strong>%s</strong> does not exist.'), $walker_class_name ) );



		$some_pending_menu_items = $some_invalid_menu_items = false;

		foreach( (array) $menu_items as $menu_item ) {

			if ( isset( $menu_item->post_status ) && 'draft' == $menu_item->post_status )

				$some_pending_menu_items = true;

			if ( ! empty( $menu_item->_invalid ) )

				$some_invalid_menu_items = true;

		}



		if ( $some_pending_menu_items )

			$result .= '<div class="updated inline"><p>' . __('Click Save Menu to make pending menu items public.') . '</p></div>';



		if ( $some_invalid_menu_items )

			$result .= '<div class="error inline"><p>' . __('There are some invalid menu items. Please check or delete them.') . '</p></div>';



		$result .= '<ul class="menu" id="menu-to-edit"> ';

		$result .= walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $menu_items), 0, (object) array('walker' => $walker ) );

		$result .= ' </ul> ';

		return $result;

	} elseif ( is_wp_error( $menu ) ) {

		return $menu;

	}





}

3719

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: