diff -r 3d4e9c994f10 -r a86126ab1dd4 wp/wp-admin/includes/nav-menu.php --- a/wp/wp-admin/includes/nav-menu.php Tue Oct 22 16:11:46 2019 +0200 +++ b/wp/wp-admin/includes/nav-menu.php Tue Dec 15 13:49:49 2020 +0100 @@ -8,10 +8,10 @@ */ /** Walker_Nav_Menu_Edit class */ -require_once( ABSPATH . 'wp-admin/includes/class-walker-nav-menu-edit.php' ); +require_once ABSPATH . 'wp-admin/includes/class-walker-nav-menu-edit.php'; /** Walker_Nav_Menu_Checklist class */ -require_once( ABSPATH . 'wp-admin/includes/class-walker-nav-menu-checklist.php' ); +require_once ABSPATH . 'wp-admin/includes/class-walker-nav-menu-checklist.php'; /** * Prints the appropriate response to a menu quick search. @@ -25,19 +25,23 @@ $type = isset( $request['type'] ) ? $request['type'] : ''; $object_type = isset( $request['object_type'] ) ? $request['object_type'] : ''; $query = isset( $request['q'] ) ? $request['q'] : ''; - $response_format = isset( $request['response-format'] ) && in_array( $request['response-format'], array( 'json', 'markup' ) ) ? $request['response-format'] : 'json'; + $response_format = isset( $request['response-format'] ) ? $request['response-format'] : ''; - if ( 'markup' == $response_format ) { + if ( ! $response_format || ! in_array( $response_format, array( 'json', 'markup' ), true ) ) { + $response_format = 'json'; + } + + if ( 'markup' === $response_format ) { $args['walker'] = new Walker_Nav_Menu_Checklist; } - if ( 'get-post-item' == $type ) { + if ( 'get-post-item' === $type ) { if ( post_type_exists( $object_type ) ) { if ( isset( $request['ID'] ) ) { $object_id = (int) $request['ID']; - if ( 'markup' == $response_format ) { + if ( 'markup' === $response_format ) { echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_post( $object_id ) ) ), 0, (object) $args ); - } elseif ( 'json' == $response_format ) { + } elseif ( 'json' === $response_format ) { echo wp_json_encode( array( 'ID' => $object_id, @@ -51,9 +55,9 @@ } elseif ( taxonomy_exists( $object_type ) ) { if ( isset( $request['ID'] ) ) { $object_id = (int) $request['ID']; - if ( 'markup' == $response_format ) { + if ( 'markup' === $response_format ) { echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_term( $object_id, $object_type ) ) ), 0, (object) $args ); - } elseif ( 'json' == $response_format ) { + } elseif ( 'json' === $response_format ) { $post_obj = get_term( $object_id, $object_type ); echo wp_json_encode( array( @@ -67,7 +71,7 @@ } } } elseif ( preg_match( '/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*\b)/', $type, $matches ) ) { - if ( 'posttype' == $matches[1] && get_post_type_object( $matches[2] ) ) { + if ( 'posttype' === $matches[1] && get_post_type_object( $matches[2] ) ) { $post_type_obj = _wp_nav_menu_meta_box_object( get_post_type_object( $matches[2] ) ); $args = array_merge( $args, @@ -89,10 +93,10 @@ } while ( $search_results_query->have_posts() ) { $post = $search_results_query->next_post(); - if ( 'markup' == $response_format ) { + if ( 'markup' === $response_format ) { $var_by_ref = $post->ID; echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_post( $var_by_ref ) ) ), 0, (object) $args ); - } elseif ( 'json' == $response_format ) { + } elseif ( 'json' === $response_format ) { echo wp_json_encode( array( 'ID' => $post->ID, @@ -103,21 +107,22 @@ echo "\n"; } } - } elseif ( 'taxonomy' == $matches[1] ) { + } elseif ( 'taxonomy' === $matches[1] ) { $terms = get_terms( array( 'taxonomy' => $matches[2], 'name__like' => $query, 'number' => 10, + 'hide_empty' => false, ) ); if ( empty( $terms ) || is_wp_error( $terms ) ) { return; } foreach ( (array) $terms as $term ) { - if ( 'markup' == $response_format ) { + if ( 'markup' === $response_format ) { echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( $term ) ), 0, (object) $args ); - } elseif ( 'json' == $response_format ) { + } elseif ( 'json' === $response_format ) { echo wp_json_encode( array( 'ID' => $term->term_id, @@ -138,12 +143,12 @@ * @since 3.0.0 */ function wp_nav_menu_setup() { - // Register meta boxes + // Register meta boxes. wp_nav_menu_post_type_meta_boxes(); add_meta_box( 'add-custom-links', __( 'Custom Links' ), 'wp_nav_menu_item_link_meta_box', 'nav-menus', 'side', 'default' ); wp_nav_menu_taxonomy_meta_boxes(); - // Register advanced menu items (columns) + // Register advanced menu items (columns). add_filter( 'manage_nav-menus_columns', 'wp_nav_menu_manage_columns' ); // If first time editing, disable advanced items by default. @@ -184,7 +189,7 @@ foreach ( array_keys( $wp_meta_boxes['nav-menus'] ) as $context ) { foreach ( array_keys( $wp_meta_boxes['nav-menus'][ $context ] ) as $priority ) { foreach ( $wp_meta_boxes['nav-menus'][ $context ][ $priority ] as $box ) { - if ( in_array( $box['id'], $initial_meta_boxes ) ) { + if ( in_array( $box['id'], $initial_meta_boxes, true ) ) { unset( $box['id'] ); } else { $hidden_meta_boxes[] = $box['id']; @@ -219,14 +224,14 @@ * * @since 3.0.0 * - * @param object $meta_box_object The current object to add a menu items - * meta box for. + * @param WP_Post_Type|false $post_type The current object to add a menu items + * meta box for. */ $post_type = apply_filters( 'nav_menu_meta_box_object', $post_type ); if ( $post_type ) { $id = $post_type->name; // Give pages a higher priority. - $priority = ( 'page' == $post_type->name ? 'core' : 'default' ); + $priority = ( 'page' === $post_type->name ? 'core' : 'default' ); add_meta_box( "add-post-type-{$id}", $post_type->labels->name, 'wp_nav_menu_item_post_type_meta_box', 'nav-menus', 'side', $priority, $post_type ); } } @@ -255,23 +260,25 @@ } /** - * Check whether to disable the Menu Locations meta box submit button + * Check whether to disable the Menu Locations meta box submit button and inputs. * * @since 3.6.0 + * @since 5.3.1 The `$echo` parameter was added. * * @global bool $one_theme_location_no_menus to determine if no menus exist * - * @param int|string $nav_menu_selected_id (id, name or slug) of the currently-selected menu - * @return string Disabled attribute if at least one menu exists, false if not + * @param int|string $nav_menu_selected_id ID, name, or slug of the currently selected menu. + * @param bool $echo Whether to echo or just return the string. + * @return string|false Disabled attribute if at least one menu exists, false if not. */ -function wp_nav_menu_disabled_check( $nav_menu_selected_id ) { +function wp_nav_menu_disabled_check( $nav_menu_selected_id, $echo = true ) { global $one_theme_location_no_menus; if ( $one_theme_location_no_menus ) { return false; } - return disabled( $nav_menu_selected_id, 0 ); + return disabled( $nav_menu_selected_id, 0, $echo ); } /** @@ -292,12 +299,12 @@
' . __( 'No items.' ) . '
'; - return; + if ( ! empty( $suppress_page_ids ) ) { + unset( $args['post__not_in'] ); + $get_posts = new WP_Query; + $posts = $get_posts->query( $args ); + } else { + echo '' . __( 'No items.' ) . '
'; + return; + } + } elseif ( ! empty( $important_pages ) ) { + $posts = array_merge( $important_pages, $posts ); } $num_pages = $get_posts->max_num_pages; @@ -368,10 +453,10 @@ array( 'base' => add_query_arg( array( - $post_type_name . '-tab' => 'all', - 'paged' => '%#%', - 'item-type' => 'post_type', - 'item-object' => $post_type_name, + $tab_name => 'all', + 'paged' => '%#%', + 'item-type' => 'post_type', + 'item-object' => $post_type_name, ) ), 'format' => '', @@ -394,8 +479,9 @@ $walker = new Walker_Nav_Menu_Checklist( $db_fields ); $current_tab = 'most-recent'; - if ( isset( $_REQUEST[ $post_type_name . '-tab' ] ) && in_array( $_REQUEST[ $post_type_name . '-tab' ], array( 'all', 'search' ) ) ) { - $current_tab = $_REQUEST[ $post_type_name . '-tab' ]; + + if ( isset( $_REQUEST[ $tab_name ] ) && in_array( $_REQUEST[ $tab_name ], array( 'all', 'search' ), true ) ) { + $current_tab = $_REQUEST[ $tab_name ]; } if ( ! empty( $_REQUEST[ 'quick-search-posttype-' . $post_type_name ] ) ) { @@ -411,33 +497,35 @@ '_wpnonce', ); - $most_recent_url = $view_all_url = $search_url = ''; + $most_recent_url = ''; + $view_all_url = ''; + $search_url = ''; if ( $nav_menu_selected_id ) { - $most_recent_url = esc_url( add_query_arg( $post_type_name . '-tab', 'most-recent', remove_query_arg( $removed_args ) ) ); - $view_all_url = esc_url( add_query_arg( $post_type_name . '-tab', 'all', remove_query_arg( $removed_args ) ) ); - $search_url = esc_url( add_query_arg( $post_type_name . '-tab', 'search', remove_query_arg( $removed_args ) ) ); + $most_recent_url = esc_url( add_query_arg( $tab_name, 'most-recent', remove_query_arg( $removed_args ) ) ); + $view_all_url = esc_url( add_query_arg( $tab_name, 'all', remove_query_arg( $removed_args ) ) ); + $search_url = esc_url( add_query_arg( $tab_name, 'search', remove_query_arg( $removed_args ) ) ); } ?>- + class="quick-search" value="" name="quick-search-posttype-" id="quick-search-posttype-" /> 'submit-quick-search-posttype-' . $post_type_name ) ); ?>
@@ -510,7 +598,7 @@