Make WordPress Core

Ticket #13822: 13822-reverts-r15219.diff

File 13822-reverts-r15219.diff, 14.8 KB (added by nacin, 15 years ago)

Would revert [15219].

  • wp-includes/default-filters.php

     
    235235add_action( 'untrash_post',               '_wp_untrash_menu_item'          );
    236236add_action( 'delete_post',                '_wp_delete_post_menu_item'      );
    237237add_action( 'delete_term',                '_wp_delete_tax_menu_item'       );
    238 add_action( 'transition_post_status', '_wp_menu_changing_status_observer',  10, 3 );
     238add_action( 'transition_post_status', '_wp_auto_add_pages_to_menu',  10, 3 );
    239239
    240240// Post Thumbnail CSS class filtering
    241241add_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
     
    339339        if ( 0 != $menu_id )
    340340                $post['tax_input'] = array( 'nav_menu' => array( intval( $menu->term_id ) ) );
    341341
    342         // New menu item. Default is pending status
     342        // New menu item. Default is draft status
    343343        if ( 0 == $menu_item_db_id ) {
    344344                $post['ID'] = 0;
    345                 $post['post_status'] = 'publish' == $args['menu-item-status'] ? 'publish' : 'pending';
     345                $post['post_status'] = 'publish' == $args['menu-item-status'] ? 'publish' : 'draft';
    346346                $menu_item_db_id = wp_insert_post( $post );
    347347
    348348        // Update existing menu item. Default is publish status
     
    454454
    455455        $defaults = array( 'order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item',
    456456                'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order', 'nopaging' => true,
    457                 'update_post_term_cache' => false );
     457                'update_post_term_cache' => false, 'public' => false );
    458458        $args = wp_parse_args( $args, $defaults );
     459        $public_consumption = $args['public'];
     460        unset( $args['public'] );
    459461        if ( count( $items ) > 1 )
    460462                $args['include'] = implode( ',', $items );
    461463        else
     
    497499                unset($terms);
    498500        }
    499501
    500         $items = array_map( 'wp_setup_nav_menu_item', $items );
     502        if ( $public_consumption )
     503                $items = array_filter( array_map( 'wp_setup_nav_menu_item_published', $items ) );
     504        else
     505                $items = array_map( 'wp_setup_nav_menu_item', $items );
    501506
    502507        if ( ARRAY_A == $args['output'] ) {
    503508                $GLOBALS['_menu_item_sort_prop'] = $args['output_key'];
     
    512517}
    513518
    514519/**
     520 * Callback that wraps wp_setup_nav_menu_item() to ensure only published posts are shown publicly.
     521 *
     522 * @uses wp_setup_nav_menu_item()
     523 * @since 3.0.0
     524 */
     525function wp_setup_nav_menu_item_published( $menu_item ) {
     526        return wp_setup_nav_menu_item( $menu_item, array( 'post_object_status' => 'publish' ) );
     527}
     528
     529/**
    515530 * Decorates a menu item object with the shared navigation menu item properties.
    516531 *
    517532 * Properties:
     
    533548 * @since 3.0.0
    534549 *
    535550 * @param object $menu_item The menu item to modify.
     551 * @param array $args
    536552 * @return object $menu_item The menu item with standard menu item properties.
    537553 */
    538 function wp_setup_nav_menu_item( $menu_item ) {
     554function wp_setup_nav_menu_item( $menu_item, $args = array() ) {
     555        $defaults = array( 'post_object_status' => 'any' );
     556        $args = wp_parse_args( $args, $defaults );
     557
    539558        if ( isset( $menu_item->post_type ) ) {
    540559                if ( 'nav_menu_item' == $menu_item->post_type ) {
    541560                        $menu_item->db_id = (int) $menu_item->ID;
     
    545564                        $menu_item->type = empty( $menu_item->type ) ? get_post_meta( $menu_item->ID, '_menu_item_type', true ) : $menu_item->type;
    546565
    547566                        if ( 'post_type' == $menu_item->type ) {
     567                                $original_object = get_post( $menu_item->object_id );
     568                                if ( 'publish' == $args['post_object_status'] && $original_object->post_status != 'publish' )
     569                                        return null;
     570
    548571                                $object = get_post_type_object( $menu_item->object );
    549572                                $menu_item->type_label = $object->labels->singular_name;
    550573                                $menu_item->url = get_permalink( $menu_item->object_id );
    551574
    552                                 $original_object = get_post( $menu_item->object_id );
    553575                                $original_title = $original_object->post_title;
    554576                                $menu_item->title = '' == $menu_item->post_title ? $original_title : $menu_item->post_title;
    555577
     
    670692
    671693        foreach( (array) $menu_item_ids as $menu_item_id ) {
    672694                $menu_item = get_post( $menu_item_id, ARRAY_A );
    673                 $menu_item['post_status'] = 'pending';
     695                $menu_item['post_status'] = 'draft';
    674696                wp_insert_post($menu_item);
    675697        }
    676698}
     
    735757}
    736758
    737759/**
    738  * Modify a navigational menu upon post object status change, if appropos.
     760 * Automatically add newly published page objects to menus with that as an option.
    739761 *
    740762 * @since 3.0.0
    741763 * @access private
     
    745767 * @param object $post The post object being transitioned from one status to another.
    746768 * @return void
    747769 */
    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                         );
     770function _wp_auto_add_pages_to_menu( $new_status, $old_status, $post ) {
     771        if ( 'publish' != $new_status || 'publish' == $old_status || 'page' != $post->post_type )
     772                return;
     773        if ( ! empty( $post->post_parent ) )
     774                return;
     775        $auto_add = get_option( 'nav_menu_options' );
     776        if ( empty( $auto_add ) || ! is_array( $auto_add ) || ! isset( $auto_add['auto_add'] ) )
     777                return;
     778        $auto_add = $auto_add['auto_add'];
     779        if ( empty( $auto_add ) || ! is_array( $auto_add ) )
     780                return;
    767781
    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         }
     782        $args = array(
     783                'menu-item-object-id' => $post->ID,
     784                'menu-item-object' => $post->post_type,
     785                'menu-item-type' => 'post_type',
     786                'menu-item-status' => 'publish',
     787        );
    780788
    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                         }
     789        foreach ( $auto_add as $menu_id ) {
     790                $items = wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) );
     791                if ( ! is_array( $items ) )
     792                        continue;
     793                foreach ( $items as $item ) {
     794                        if ( $post->ID == $item->object_id )
     795                                continue 2;
    803796                }
     797                wp_update_nav_menu_item( $menu_id, 0, $args );
    804798        }
    805799}
    806800
  • 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                        $classes[] = 'unpublished-post';
     79                        $original_status = get_post_status_object( $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;
     
    198199                                <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
    199200                                <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 ); ?>" />
    200201                                <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 ); ?>" />
    202202                                <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
    203203                        </div><!-- .menu-item-settings-->
    204204                        <ul class="menu-item-transport"></ul>
     
    952952 *
    953953 * @since 3.0.0
    954954 *
    955  * @param int $menu_id The menu ID for which to save this item. $menu_id of 0 makes a pending, orphaned menu item.
     955 * @param int $menu_id The menu ID for which to save this item. $menu_id of 0 makes a draft, orphaned menu item.
    956956 * @param array $menu_data The unsanitized posted menu item data.
    957957 * @return array The database IDs of the items saved
    958958 */
     
    10841084
    10851085                $some_pending_menu_items = false;
    10861086                foreach( (array) $menu_items as $menu_item ) {
    1087                         if ( isset( $menu_item->post_status ) && 'pending' == $menu_item->post_status )
     1087                        if ( isset( $menu_item->post_status ) && 'draft' == $menu_item->post_status )
    10881088                                $some_pending_menu_items = true;
    10891089                }
    10901090
     
    11221122}
    11231123
    11241124/**
    1125  * Deletes orphaned pending menu items
     1125 * Deletes orphaned draft menu items
    11261126 *
    11271127 * @access private
    11281128 * @since 3.0.0
    11291129 *
    11301130 */
    1131 function _wp_delete_orphaned_pending_menu_items() {
     1131function _wp_delete_orphaned_draft_menu_items() {
    11321132        global $wpdb;
    11331133        $delete_timestamp = time() - (60*60*24*EMPTY_TRASH_DAYS);
    11341134
    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 ) );
     1135        // delete orphaned draft 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 = 'draft' AND meta_key = '_menu_item_orphaned' AND meta_value < '%d'", $delete_timestamp ) );
    11371137
    11381138        foreach( (array) $menu_items_to_delete as $menu_item_id )
    11391139                wp_delete_post( $menu_item_id, true );
    11401140}
    11411141
    1142 add_action('admin_head-nav-menus.php', '_wp_delete_orphaned_pending_menu_items');
     1142add_action('admin_head-nav-menus.php', '_wp_delete_orphaned_draft_menu_items');
    11431143
    11441144?>
  • 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'] ) ) {