Ticket #13822: 13822-on-r15218.diff

File 13822-on-r15218.diff, 9.1 KB (added by nacin, 3 years ago)
  • wp-includes/default-filters.php

     
    231231add_action( 'wp_scheduled_delete',        'wp_scheduled_delete'            ); 
    232232 
    233233// Navigation menu actions 
    234 add_action( 'trash_post',                 '_wp_trash_menu_item'            ); 
    235 add_action( 'untrash_post',               '_wp_untrash_menu_item'          ); 
    236234add_action( 'delete_post',                '_wp_delete_post_menu_item'      ); 
    237235add_action( 'delete_term',                '_wp_delete_tax_menu_item'       ); 
    238236add_action( 'transition_post_status', '_wp_auto_add_pages_to_menu',  10, 3 ); 
  • wp-includes/nav-menu-template.php

     
    151151        if ( ! $menu && !$args->theme_location ) { 
    152152                $menus = wp_get_nav_menus(); 
    153153                foreach ( $menus as $menu_maybe ) { 
    154                         if ( $menu_items = wp_get_nav_menu_items($menu_maybe->term_id) ) { 
     154                        if ( $menu_items = wp_get_nav_menu_items($menu_maybe->term_id, array( 'public' => true ) ) ) { 
    155155                                $menu = $menu_maybe; 
    156156                                break; 
    157157                        } 
     
    160160 
    161161        // If the menu exists, get its items. 
    162162        if ( $menu && ! is_wp_error($menu) && !isset($menu_items) ) 
    163                 $menu_items = wp_get_nav_menu_items( $menu->term_id ); 
     163                $menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'public' => true ) ); 
    164164 
    165165        // If no menu was found or if the menu has no items and no location was requested, call the fallback_cb if it exists 
    166166        if ( ( !$menu || is_wp_error($menu) || ( isset($menu_items) && empty($menu_items) && !$args->theme_location ) ) 
  • wp-includes/nav-menu.php

     
    311311                        $original_object = get_post( $args['menu-item-object-id'] ); 
    312312                        $original_parent = (int) $original_object->post_parent; 
    313313                        $original_title = $original_object->post_title; 
    314  
    315                         if ( 'trash' == get_post_status( $args['menu-item-object-id'] ) ) 
    316                                 return new WP_Error('update_nav_menu_item_failed', sprintf(__('The menu item "%1$s" belongs to something that is in the trash, so it cannot be updated.'), $args['menu-item-title'] ) ); 
    317314                } 
    318315 
    319316                if ( empty( $args['menu-item-title'] ) || $args['menu-item-title'] == $original_title ) { 
     
    454451 
    455452        $defaults = array( 'order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item', 
    456453                'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order', 'nopaging' => true, 
    457                 'update_post_term_cache' => false ); 
     454                'update_post_term_cache' => false, 'public' => false ); 
    458455        $args = wp_parse_args( $args, $defaults ); 
     456        $public_consumption = $args['public']; 
     457        unset( $args['public'] ); 
    459458        if ( count( $items ) > 1 ) 
    460459                $args['include'] = implode( ',', $items ); 
    461460        else 
     
    497496                unset($terms); 
    498497        } 
    499498 
    500         $items = array_map( 'wp_setup_nav_menu_item', $items ); 
     499        if ( $public_consumption ) 
     500                $items = array_filter( array_map( 'wp_setup_nav_menu_item_published', $items ) ); 
     501        else 
     502                $items = array_map( 'wp_setup_nav_menu_item', $items ); 
    501503 
    502504        if ( ARRAY_A == $args['output'] ) { 
    503505                $GLOBALS['_menu_item_sort_prop'] = $args['output_key']; 
     
    512514} 
    513515 
    514516/** 
     517 * Callback that wraps wp_setup_nav_menu_item() to ensure only published posts are shown publicly. 
     518 * 
     519 * @uses wp_setup_nav_menu_item() 
     520 * @since 3.0.0 
     521 */ 
     522function wp_setup_nav_menu_item_published( $menu_item ) { 
     523        return wp_setup_nav_menu_item( $menu_item, array( 'post_object_status' => 'publish' ) ); 
     524} 
     525 
     526/** 
    515527 * Decorates a menu item object with the shared navigation menu item properties. 
    516528 * 
    517529 * Properties: 
     
    533545 * @since 3.0.0 
    534546 * 
    535547 * @param object $menu_item The menu item to modify. 
     548 * @param array $args 
    536549 * @return object $menu_item The menu item with standard menu item properties. 
    537550 */ 
    538 function wp_setup_nav_menu_item( $menu_item ) { 
     551function wp_setup_nav_menu_item( $menu_item, $args = array() ) { 
     552        $defaults = array( 'post_object_status' => 'any' ); 
     553        $args = wp_parse_args( $args, $defaults ); 
     554 
    539555        if ( isset( $menu_item->post_type ) ) { 
    540556                if ( 'nav_menu_item' == $menu_item->post_type ) { 
    541557                        $menu_item->db_id = (int) $menu_item->ID; 
     
    545561                        $menu_item->type = empty( $menu_item->type ) ? get_post_meta( $menu_item->ID, '_menu_item_type', true ) : $menu_item->type; 
    546562 
    547563                        if ( 'post_type' == $menu_item->type ) { 
     564                                $original_object = get_post( $menu_item->object_id ); 
     565                                if ( 'publish' == $args['post_object_status'] && $original_object->post_status != 'publish' ) 
     566                                        return null; 
     567 
    548568                                $object = get_post_type_object( $menu_item->object ); 
    549569                                $menu_item->type_label = $object->labels->singular_name; 
    550570                                $menu_item->url = get_permalink( $menu_item->object_id ); 
    551571 
    552                                 $original_object = get_post( $menu_item->object_id ); 
    553572                                $original_title = $original_object->post_title; 
    554573                                $menu_item->title = '' == $menu_item->post_title ? $original_title : $menu_item->post_title; 
    555574 
     
    655674} 
    656675 
    657676/** 
    658  * Callback for handling a menu item when its original object is trashed. 
    659  * 
    660  * @since 3.0.0 
    661  * @access private 
    662  * 
    663  * @param int $object_id The ID of the original object being trashed. 
    664  * 
    665  */ 
    666 function _wp_trash_menu_item( $object_id = 0 ) { 
    667         $object_id = (int) $object_id; 
    668  
    669         $menu_item_ids = wp_get_associated_nav_menu_items( $object_id ); 
    670  
    671         foreach( (array) $menu_item_ids as $menu_item_id ) { 
    672                 $menu_item = get_post( $menu_item_id, ARRAY_A ); 
    673                 $menu_item['post_status'] = 'draft'; 
    674                 wp_insert_post($menu_item); 
    675         } 
    676 } 
    677  
    678 /** 
    679  * Callback for handling a menu item when its original object is un-trashed. 
    680  * 
    681  * @since 3.0.0 
    682  * @access private 
    683  * 
    684  * @param int $object_id The ID of the original object being untrashed. 
    685  * 
    686  */ 
    687 function _wp_untrash_menu_item( $object_id = 0 ) { 
    688         $object_id = (int) $object_id; 
    689  
    690         $menu_item_ids = wp_get_associated_nav_menu_items( $object_id ); 
    691  
    692         foreach( (array) $menu_item_ids as $menu_item_id ) { 
    693                 $menu_item = get_post( $menu_item_id, ARRAY_A ); 
    694                 $menu_item['post_status'] = 'publish'; 
    695                 wp_insert_post($menu_item); 
    696         } 
    697 } 
    698  
    699 /** 
    700677 * Callback for handling a menu item when its original object is deleted. 
    701678 * 
    702679 * @since 3.0.0 
  • wp-admin/includes/nav-menu.php

     
    7171                $title = $item->title; 
    7272 
    7373                if ( isset( $item->post_status ) && 'draft' == $item->post_status ) { 
    74                         $classes[] = 'pending'; 
     74                        $classes[] = 'unsaved'; 
    7575                        /* translators: %s: title of menu item in draft status */ 
    76                         $title = sprintf( __('%s (Pending)'), $item->title ); 
     76                        $title = sprintf( __('%s (Unsaved)'), $item->title ); 
     77                } elseif ( 'post_type' == $item->type && $original_object->post_status != 'publish' ) { 
     78                        $original_status = get_post_status_object( $original_object->post_status ); 
     79                        $classes[] = "unpublished-post post-status-$original_object->post_status"; 
     80                        /* translators: 1: title of menu item in unpublished status, 2: actual post status. */ 
     81                        $title = sprintf( __('%1$s (%2$s)'), $item->title, $original_status->label ); 
    7782                } 
    7883 
    7984                $title = empty( $item->label ) ? $title : $item->label; 
     
    172177                                <div class="menu-item-actions description-wide submitbox"> 
    173178                                        <?php if( 'custom' != $item->type ) : ?> 
    174179                                                <p class="link-to-original"> 
    175                                                         <?php printf( __('Original: %s'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?> 
     180                                                        <?php 
     181                                                        $post_status = get_post_status( $item->object_id ); 
     182                                                        if( 'publish' == $post_status ) { 
     183                                                                printf( __('Original: %s'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>', '' ); 
     184                                                        } else { 
     185                                                                $original_url = $item->url; 
     186                                                                if( 'trash' == $post_status ) { 
     187                                                                        $original_url = add_query_arg( 
     188                                                                                array( 
     189                                                                                        'post_status' => 'trash', 
     190                                                                                        'post_type' => $item->object, 
     191                                                                                ), 
     192                                                                                admin_url( 'edit.php' ) 
     193                                                                        ); 
     194                                                                } 
     195                                                                $post_status_obj = get_post_status_object( $post_status ); 
     196                                                                /* translators: 1: title, 2: post status. */ 
     197                                                                printf( __('Original: %1$s (%2$s)'), '<a href="' . esc_attr( $original_url ) . '">' . esc_html( $original_title ) . '</a>', 
     198                                                                $post_status_obj->label ); 
     199                                                        } 
     200                                                        ?> 
    176201                                                </p> 
    177202                                        <?php endif; ?> 
    178203                                        <a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php 
     
    10841109                } 
    10851110 
    10861111                if ( $some_pending_menu_items ) 
    1087                         $result .= '<div class="updated inline"><p>' . __('Click Save Menu to make pending menu items public.') . '</p></div>'; 
     1112                        $result .= '<div class="updated inline"><p>' . __('Click Save Menu to make unsaved menu items public.') . '</p></div>'; 
    10881113 
    10891114                $result .= '<ul class="menu" id="menu-to-edit"> '; 
    10901115                $result .= walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $menu_items), 0, (object) array('walker' => $walker ) );