Ticket #22189: 22189.2.diff

File 22189.2.diff, 1.7 KB (added by nacin, 7 months ago)

When printing nav checklists, we avoid meta and term caches. WP_Post's magic get/set will trigger a metadata_exists() check. Using property_exists() and some cleaner code can prevent the meta cache from firing.

  • wp-admin/includes/nav-menu.php

     
    247247                $output .= $indent . '<li>'; 
    248248                $output .= '<label class="menu-item-title">'; 
    249249                $output .= '<input type="checkbox" class="menu-item-checkbox'; 
    250                 if ( ! empty( $item->_add_to_top ) ) { 
     250                if ( property_exists( $item, 'front_or_home' ) && $item->front_or_home ) { 
     251                        $title = sprintf( _x( 'Home: %s', 'nav menu front page title' ), $item->post_title ); 
    251252                        $output .= ' add-to-top'; 
    252253                } 
    253254                $output .= '" name="menu-item[' . $possible_object_id . '][menu-item-object-id]" value="'. esc_attr( $item->object_id ) .'" /> '; 
    254                 $output .= empty( $item->label ) ? esc_html( $item->title ) : esc_html( $item->label ); 
     255                $output .= isset( $title ) ? esc_html( $item->title ) : esc_html( $title ); 
    255256                $output .= '</label>'; 
    256257 
    257258                // Menu item hidden fields 
     
    727728                                        $front_page = 'page' == get_option('show_on_front') ? (int) get_option( 'page_on_front' ) : 0; 
    728729                                        if ( ! empty( $front_page ) ) { 
    729730                                                $front_page_obj = get_post( $front_page ); 
    730                                                 $front_page_obj->_add_to_top = true; 
    731                                                 $front_page_obj->label = sprintf( _x('Home: %s', 'nav menu front page title'), $front_page_obj->post_title ); 
     731                                                $front_page_obj->front_or_home = true; 
    732732                                                array_unshift( $posts, $front_page_obj ); 
    733733                                        } else { 
    734734                                                $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1; 
    735735                                                array_unshift( $posts, (object) array( 
    736                                                         '_add_to_top' => true, 
     736                                                        'front_or_home' => true, 
    737737                                                        'ID' => 0, 
    738738                                                        'object_id' => $_nav_menu_placeholder, 
    739739                                                        'post_content' => '',