Make WordPress Core

Ticket #13822: 13822-reverts-r15219.3.diff

File 13822-reverts-r15219.3.diff, 18.3 KB (added by koopersmith, 15 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'       );
    238 add_action( 'transition_post_status', '_wp_menu_changing_status_observer',  10, 3 );
     236add_action( 'transition_post_status', '_wp_auto_add_pages_to_menu',  10, 3 );
    239237
    240238// Post Thumbnail CSS class filtering
    241239add_action( 'begin_fetch_post_thumbnail_html', '_wp_post_thumbnail_class_filter_add'    );
  • 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

     
    244244 *
    245245 * @since 3.0.0
    246246 *
    247  * @param int $menu_id The ID of the menu. Required. If "0", makes the menu item a pending orphan.
     247 * @param int $menu_id The ID of the menu. Required. If "0", makes the menu item a draft orphan.
    248248 * @param int $menu_item_db_id The ID of the menu item. If "0", creates a new menu item.
    249249 * @param array $menu_item_data The menu item's data.
    250250 * @return int The menu item's database ID or WP_Error object on failure.
     
    262262        if ( ( ! $menu && 0 !== $menu_id ) || is_wp_error( $menu ) )
    263263                return $menu;
    264264
    265         $menu_items = 0 == $menu_id ? array() : (array) wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'draft,pending,publish' ) );
     265        $menu_items = 0 == $menu_id ? array() : (array) wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) );
    266266
    267267        $count = count( $menu_items );
    268268
     
    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 ) {
     
    339336        if ( 0 != $menu_id )
    340337                $post['tax_input'] = array( 'nav_menu' => array( intval( $menu->term_id ) ) );
    341338
    342         // New menu item. Default is pending status
     339        // New menu item. Default is draft status
    343340        if ( 0 == $menu_item_db_id ) {
    344341                $post['ID'] = 0;
    345                 $post['post_status'] = 'publish' == $args['menu-item-status'] ? 'publish' : 'pending';
     342                $post['post_status'] = 'publish' == $args['menu-item-status'] ? 'publish' : 'draft';
    346343                $menu_item_db_id = wp_insert_post( $post );
    347344
    348345        // Update existing menu item. Default is publish status
     
    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'] = 'pending';
    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
     
    735712}
    736713
    737714/**
    738  * Modify a navigational menu upon post object status change, if appropos.
     715 * Automatically add newly published page objects to menus with that as an option.
    739716 *
    740717 * @since 3.0.0
    741718 * @access private
     
    745722 * @param object $post The post object being transitioned from one status to another.
    746723 * @return void
    747724 */
    748 function _wp_menu_changing_status_observer( $new_status, $old_status, $post ) {
    749         // append new top-level page objects to a menu for which that option is selected
    750         if (
    751                 'publish' == $new_status &&
    752                 'publish' != $old_status &&
    753                 'page' == $post->post_type &&
    754                 empty( $post->post_parent )
    755         ) {
    756                 $auto_add = get_option( 'nav_menu_options' );
    757                 if (
    758                         isset( $auto_add['auto_add'] ) &&
    759                         is_array( $auto_add['auto_add'] )
    760                 ) {
    761                         $args = array(
    762                                 'menu-item-object-id' => $post->ID,
    763                                 'menu-item-object' => $post->post_type,
    764                                 'menu-item-type' => 'post_type',
    765                                 'menu-item-status' => 'publish',
    766                         );
     725function _wp_auto_add_pages_to_menu( $new_status, $old_status, $post ) {
     726        if ( 'publish' != $new_status || 'publish' == $old_status || 'page' != $post->post_type )
     727                return;
     728        if ( ! empty( $post->post_parent ) )
     729                return;
     730        $auto_add = get_option( 'nav_menu_options' );
     731        if ( empty( $auto_add ) || ! is_array( $auto_add ) || ! isset( $auto_add['auto_add'] ) )
     732                return;
     733        $auto_add = $auto_add['auto_add'];
     734        if ( empty( $auto_add ) || ! is_array( $auto_add ) )
     735                return;
    767736
    768                         foreach ( $auto_add['auto_add'] as $menu_id ) {
    769                                 $items = wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'draft,pending,publish' ) );
    770                                 if ( ! is_array( $items ) )
    771                                         continue;
    772                                 foreach ( $items as $item ) {
    773                                         if ( $post->ID == $item->object_id )
    774                                                 continue 2;
    775                                 }
    776                                 wp_update_nav_menu_item( $menu_id, 0, $args );
    777                         }
    778                 }
    779         }
     737        $args = array(
     738                'menu-item-object-id' => $post->ID,
     739                'menu-item-object' => $post->post_type,
     740                'menu-item-type' => 'post_type',
     741                'menu-item-status' => 'publish',
     742        );
    780743
    781         // give menu items draft status if their associated post objects change from "publish" to "draft", or vice versa (draft item being re-published)
    782         if (
    783                 ! empty( $post->ID ) &&
    784                 (
    785                         ( 'publish' == $old_status && 'draft' == $new_status ) ||
    786                         ( 'draft' == $old_status && 'publish' == $new_status )
    787                 )
    788         ) {
    789                 $menu_items = get_posts(array(
    790                         'meta_key' => '_menu_item_object_id',
    791                         'meta_value' => $post->ID,
    792                         'post_status' => 'any',
    793                         'post_type' => 'nav_menu_item',
    794                 ));
    795 
    796                 foreach( (array) $menu_items as $menu_item ) {
    797                         if ( ! empty( $menu_item->ID ) ) {
    798                                 $properties = get_object_vars( $menu_item );
    799                                 $properties['post_status'] = $new_status;
    800 
    801                                 wp_insert_post( $properties );
    802                         }
     744        foreach ( $auto_add as $menu_id ) {
     745                $items = wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) );
     746                if ( ! is_array( $items ) )
     747                        continue;
     748                foreach ( $items as $item ) {
     749                        if ( $post->ID == $item->object_id )
     750                                continue 2;
    803751                }
     752                wp_update_nav_menu_item( $menu_id, 0, $args );
    804753        }
    805754}
    806755
  • wp-admin/includes/nav-menu.php

     
    7171                $title = $item->title;
    7272
    7373                if ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
    74                         $classes[] = 'draft';
     74                        $classes[] = 'unsaved';
    7575                        /* translators: %s: title of menu item in draft status */
    76                         $title = sprintf( __('%s (Draft)'), $item->title );
    77                 } elseif ( isset( $item->post_status ) && 'pending' == $item->post_status ) {
    78                         $classes[] = 'pending';
    79                         /* translators: %s: title of menu item in pending status */
    80                         $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 );
    8182                }
    8283
    8384                $title = empty( $item->label ) ? $title : $item->label;
     
    176177                                <div class="menu-item-actions description-wide submitbox">
    177178                                        <?php if( 'custom' != $item->type ) : ?>
    178179                                                <p class="link-to-original">
    179                                                         <?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                                                        ?>
    180201                                                </p>
    181202                                        <?php endif; ?>
    182203                                        <a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php
     
    198219                                <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
    199220                                <input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_item_parent ); ?>" />
    200221                                <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
    201                                 <input class="menu-item-data-status" type="hidden" name="menu-item-status[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_status ); ?>" />
    202222                                <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
    203223                        </div><!-- .menu-item-settings-->
    204224                        <ul class="menu-item-transport"></ul>
     
    952972 *
    953973 * @since 3.0.0
    954974 *
    955  * @param int $menu_id The menu ID for which to save this item. $menu_id of 0 makes a pending, orphaned menu item.
     975 * @param int $menu_id The menu ID for which to save this item. $menu_id of 0 makes a draft, orphaned menu item.
    956976 * @param array $menu_data The unsanitized posted menu item data.
    957977 * @return array The database IDs of the items saved
    958978 */
     
    10841104
    10851105                $some_pending_menu_items = false;
    10861106                foreach( (array) $menu_items as $menu_item ) {
    1087                         if ( isset( $menu_item->post_status ) && 'pending' == $menu_item->post_status )
     1107                        if ( isset( $menu_item->post_status ) && 'draft' == $menu_item->post_status )
    10881108                                $some_pending_menu_items = true;
    10891109                }
    10901110
    10911111                if ( $some_pending_menu_items )
    1092                         $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>';
    10931113
    10941114                $result .= '<ul class="menu" id="menu-to-edit"> ';
    10951115                $result .= walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $menu_items), 0, (object) array('walker' => $walker ) );
     
    11221142}
    11231143
    11241144/**
    1125  * Deletes orphaned pending menu items
     1145 * Deletes orphaned draft menu items
    11261146 *
    11271147 * @access private
    11281148 * @since 3.0.0
    11291149 *
    11301150 */
    1131 function _wp_delete_orphaned_pending_menu_items() {
     1151function _wp_delete_orphaned_draft_menu_items() {
    11321152        global $wpdb;
    11331153        $delete_timestamp = time() - (60*60*24*EMPTY_TRASH_DAYS);
    11341154
    1135         // delete orphaned pending menu items
    1136         $menu_items_to_delete = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS m ON p.ID = m.post_id WHERE post_type = 'nav_menu_item' AND post_status = 'pending' AND meta_key = '_menu_item_orphaned' AND meta_value < '%d'", $delete_timestamp ) );
     1155        // delete orphaned draft menu items
     1156        $menu_items_to_delete = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS m ON p.ID = m.post_id WHERE post_type = 'nav_menu_item' AND post_status = 'draft' AND meta_key = '_menu_item_orphaned' AND meta_value < '%d'", $delete_timestamp ) );
    11371157
    11381158        foreach( (array) $menu_items_to_delete as $menu_item_id )
    11391159                wp_delete_post( $menu_item_id, true );
    11401160}
    11411161
    1142 add_action('admin_head-nav-menus.php', '_wp_delete_orphaned_pending_menu_items');
     1162add_action('admin_head-nav-menus.php', '_wp_delete_orphaned_draft_menu_items');
    11431163
    11441164?>
  • wp-admin/nav-menus.php

     
    327327                        // Update menu items
    328328
    329329                        if ( ! is_wp_error( $_menu_object ) ) {
    330                                 $unsorted_menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID', 'post_status' => 'draft,pending,publish') );
     330                                $unsorted_menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID', 'post_status' => 'draft,publish') );
    331331                                $menu_items = array();
    332332                                // Index menu items by db ID
    333333                                foreach( $unsorted_menu_items as $_item )
    334334                                        $menu_items[$_item->db_id] = $_item;
    335335
    336                                 $post_fields = array( 'menu-item-db-id', 'menu-item-object-id', 'menu-item-object', 'menu-item-parent-id', 'menu-item-position', 'menu-item-type', 'menu-item-title', 'menu-item-url', 'menu-item-description', 'menu-item-attr-title', 'menu-item-status', 'menu-item-target', 'menu-item-classes', 'menu-item-xfn' );
     336                                $post_fields = array( 'menu-item-db-id', 'menu-item-object-id', 'menu-item-object', 'menu-item-parent-id', 'menu-item-position', 'menu-item-type', 'menu-item-title', 'menu-item-url', 'menu-item-description', 'menu-item-attr-title', 'menu-item-target', 'menu-item-classes', 'menu-item-xfn' );
    337337                                wp_defer_term_counting(true);
    338338                                // Loop through all the menu items' POST variables
    339339                                if ( ! empty( $_POST['menu-item-db-id'] ) ) {