Make WordPress Core

Changeset 14937


Ignore:
Timestamp:
05/26/2010 06:59:14 AM (16 years ago)
Author:
nacin
Message:

Ensure auto-added pages are both published and sent to the end of the menu. Tiny enhancement and optimization to wp_update_nav_menu_item come with it. fixes #13447.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/nav-menu.php

    r14934 r14937  
    269269        }
    270270
    271         $menu_items = (array) wp_get_nav_menu_items( $menu_id );
     271        $menu_items = (array) wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) );
    272272
    273273        $count = count( $menu_items );
     
    287287                'menu-item-classes' => '',
    288288                'menu-item-xfn' => '',
     289                'menu-item-status' => '',
    289290        );
    290291
     
    293294        if ( 0 == (int) $args['menu-item-position'] ) {
    294295                $last_item = array_pop( $menu_items );
    295                 if ( $last_item && isset( $last_item->ID ) ) {
    296                         $last_data = get_post( $last_item->ID );
    297                         if ( ! is_wp_error( $last_data ) && isset( $last_data->menu_order ) ) {
    298                                 $args['menu-item-position'] = 1 + (int) $last_data->menu_order;
    299                         }
    300 
    301                 } else {
    302                         $args['menu-item-position'] = $count;
    303                 }
     296                $args['menu-item-position'] = ( $last_item && isset( $last_item->menu_order ) ) ? 1 + $last_item->menu_order : $count;
    304297        }
    305298
     
    351344        );
    352345
    353         // New menu item
     346        // New menu item. Default is draft status
    354347        if ( 0 == $menu_item_db_id ) {
    355348                $post['ID'] = 0;
    356                 $post['post_status'] = 'draft';
     349                $post['post_status'] = 'publish' == $args['menu-item-status'] ? 'publish' : 'draft';
    357350                $menu_item_db_id = wp_insert_post( $post );
    358351
    359         // Update existing menu item
     352        // Update existing menu item. Default is publish status
    360353        } else {
    361354                $post['ID'] = $menu_item_db_id;
    362                 $post['post_status'] = 'publish';
     355                $post['post_status'] = 'draft' == $args['menu-item-status'] ? 'draft' : 'publish';
    363356                wp_update_post( $post );
    364357        }
     
    763756                'menu-item-object' => $post->post_type,
    764757                'menu-item-type' => 'post_type',
     758                'menu-item-status' => 'publish',
    765759        );
    766760
    767761        foreach ( $auto_add as $menu_id ) {
    768                 $items = wp_get_nav_menu_items( $menu_id );
     762                $items = wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) );
    769763                if ( ! is_array( $items ) )
    770764                        continue;
Note: See TracChangeset for help on using the changeset viewer.