mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-05 18:32:23 +01:00
Add wp_edit_nav_menu_walker filter for specifying a custom edit nav menu walker. Props filosofo. fixes #13342
git-svn-id: http://svn.automattic.com/wordpress/trunk@14645 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d7ff950bb9
commit
25dcb020af
@ -962,21 +962,26 @@ function _wp_nav_menu_meta_box_object( $object = null ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the menu item formatted to edit.
|
* Returns the menu formatted to edit.
|
||||||
*
|
*
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*
|
*
|
||||||
* @param string $menu_item_id The ID of the menu item to format.
|
* @param string $menu_id The ID of the menu to format.
|
||||||
* @return string|WP_Error $output The menu formatted to edit or error object on failure.
|
* @return string|WP_Error $output The menu formatted to edit or error object on failure.
|
||||||
*/
|
*/
|
||||||
function wp_get_nav_menu_to_edit( $menu_item_id = 0 ) {
|
function wp_get_nav_menu_to_edit( $menu_id = 0 ) {
|
||||||
$menu = wp_get_nav_menu_object( $menu_item_id );
|
$menu = wp_get_nav_menu_object( $menu_id );
|
||||||
|
|
||||||
// If the menu exists, get its items.
|
// If the menu exists, get its items.
|
||||||
if ( is_nav_menu( $menu ) ) {
|
if ( is_nav_menu( $menu ) ) {
|
||||||
$menu_items = wp_get_nav_menu_items( $menu->term_id, array('post_status' => 'any') );
|
$menu_items = wp_get_nav_menu_items( $menu->term_id, array('post_status' => 'any') );
|
||||||
|
|
||||||
$walker = new Walker_Nav_Menu_Edit;
|
$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 ) );
|
||||||
|
|
||||||
return walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $menu_items), 0, (object) array('walker' => $walker ) );
|
return walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $menu_items), 0, (object) array('walker' => $walker ) );
|
||||||
} elseif ( is_wp_error( $menu ) ) {
|
} elseif ( is_wp_error( $menu ) ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user