Nav menus: Apply the wp_get_nav_menu_items filter also on an empty list of menu items.

props westonruter.
fixes #32631.
Built from https://develop.svn.wordpress.org/trunk@32748


git-svn-id: http://core.svn.wordpress.org/trunk@32719 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dominik Schilling 2015-06-13 14:38:25 +00:00
parent 144a28a5c2
commit 792295d077
2 changed files with 14 additions and 11 deletions

View File

@ -560,25 +560,27 @@ function _is_valid_nav_menu_item( $item ) {
function wp_get_nav_menu_items( $menu, $args = array() ) { function wp_get_nav_menu_items( $menu, $args = array() ) {
$menu = wp_get_nav_menu_object( $menu ); $menu = wp_get_nav_menu_object( $menu );
if ( ! $menu ) if ( ! $menu ) {
return false; return false;
}
static $fetched = array(); static $fetched = array();
$items = get_objects_in_term( $menu->term_id, 'nav_menu' ); $items = get_objects_in_term( $menu->term_id, 'nav_menu' );
if ( is_wp_error( $items ) ) {
if ( empty( $items ) ) return false;
return $items; }
$defaults = array( 'order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item', $defaults = array( 'order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item',
'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order', 'nopaging' => true ); 'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order', 'nopaging' => true );
$args = wp_parse_args( $args, $defaults ); $args = wp_parse_args( $args, $defaults );
$args['include'] = $items; $args['include'] = $items;
$items = get_posts( $args ); if ( ! empty( $items ) ) {
$items = get_posts( $args );
if ( is_wp_error( $items ) || ! is_array( $items ) ) } else {
return false; $items = array();
}
// Get all posts and terms at once to prime the caches // Get all posts and terms at once to prime the caches
if ( empty( $fetched[$menu->term_id] ) || wp_using_ext_object_cache() ) { if ( empty( $fetched[$menu->term_id] ) || wp_using_ext_object_cache() ) {
@ -616,8 +618,9 @@ function wp_get_nav_menu_items( $menu, $args = array() ) {
$items = array_map( 'wp_setup_nav_menu_item', $items ); $items = array_map( 'wp_setup_nav_menu_item', $items );
if ( ! is_admin() ) // Remove invalid items only in frontend if ( ! is_admin() ) { // Remove invalid items only in frontend
$items = array_filter( $items, '_is_valid_nav_menu_item' ); $items = array_filter( $items, '_is_valid_nav_menu_item' );
}
if ( ARRAY_A == $args['output'] ) { if ( ARRAY_A == $args['output'] ) {
$GLOBALS['_menu_item_sort_prop'] = $args['output_key']; $GLOBALS['_menu_item_sort_prop'] = $args['output_key'];
@ -637,7 +640,7 @@ function wp_get_nav_menu_items( $menu, $args = array() ) {
* @param object $menu The menu object. * @param object $menu The menu object.
* @param array $args An array of arguments used to retrieve menu item objects. * @param array $args An array of arguments used to retrieve menu item objects.
*/ */
return apply_filters( 'wp_get_nav_menu_items', $items, $menu, $args ); return apply_filters( 'wp_get_nav_menu_items', $items, $menu, $args );
} }
/** /**

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.3-alpha-32747'; $wp_version = '4.3-alpha-32748';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.