Make WordPress Core


Ignore:
Timestamp:
06/14/2010 07:52:30 PM (14 years ago)
Author:
nacin
Message:

Revert [15219], [15250], some of [15249] for 3.0, revisit in 3.0.1. see #13822.

File:
1 edited

Legend:

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

    r15249 r15254  
    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.
     
    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 );
     
    337337        $post['tax_input'] = array( 'nav_menu' => array( intval( $menu->term_id ) ) );
    338338
    339     // New menu item. Default is pending status
     339    // New menu item. Default is draft status
    340340    if ( 0 == $menu_item_db_id ) {
    341341        $post['ID'] = 0;
    342         $post['post_status'] = 'publish' == $args['menu-item-status'] ? 'publish' : 'pending';
     342        $post['post_status'] = 'publish' == $args['menu-item-status'] ? 'publish' : 'draft';
    343343        $menu_item_db_id = wp_insert_post( $post );
    344344
     
    691691
    692692/**
    693  * Modify a navigational menu upon post object status change, if appropos.
     693 * Automatically add newly published page objects to menus with that as an option.
    694694 *
    695695 * @since 3.0.0
     
    701701 * @return void
    702702 */
    703 function _wp_menu_changing_status_observer( $new_status, $old_status, $post ) {
    704     // append new top-level page objects to a menu for which that option is selected
    705     if (
    706         'publish' == $new_status &&
    707         'publish' != $old_status &&
    708         'page' == $post->post_type &&
    709         empty( $post->post_parent )
    710     ) {
    711         $auto_add = get_option( 'nav_menu_options' );
    712         if (
    713             isset( $auto_add['auto_add'] ) &&
    714             is_array( $auto_add['auto_add'] )
    715         ) {
    716             $args = array(
    717                 'menu-item-object-id' => $post->ID,
    718                 'menu-item-object' => $post->post_type,
    719                 'menu-item-type' => 'post_type',
    720                 'menu-item-status' => 'publish',
    721             );
    722 
    723             foreach ( $auto_add['auto_add'] as $menu_id ) {
    724                 $items = wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'draft,pending,publish' ) );
    725                 if ( ! is_array( $items ) )
    726                     continue;
    727                 foreach ( $items as $item ) {
    728                     if ( $post->ID == $item->object_id )
    729                         continue 2;
    730                 }
    731                 wp_update_nav_menu_item( $menu_id, 0, $args );
    732             }
    733         }
    734     }
    735 
    736     // give menu items draft status if their associated post objects change from "publish" to "draft", or vice versa (draft item being re-published)
    737     if (
    738         ( $new_status != $old_status ) &&
    739         ! empty( $post->ID ) && ! empty( $post->post_type ) &&
    740         'nav_menu_item' != $post->post_type &&
    741         ( 'publish' == $old_status || 'publish' == $new_status )
    742     ) {
    743         $menu_items = get_posts(array(
    744             'meta_key' => '_menu_item_object_id',
    745             'meta_value' => $post->ID,
    746             'post_status' => 'any',
    747             'post_type' => 'nav_menu_item',
    748         ));
    749 
    750         foreach( (array) $menu_items as $menu_item ) {
    751             if ( ! empty( $menu_item->ID ) ) {
    752                 $properties = get_object_vars( $menu_item );
    753                 $properties['post_status'] = 'publish' == $new_status ? 'publish' : 'draft';
    754 
    755                 wp_insert_post( $properties );
    756             }
    757         }
     703function _wp_auto_add_pages_to_menu( $new_status, $old_status, $post ) {
     704    if ( 'publish' != $new_status || 'publish' == $old_status || 'page' != $post->post_type )
     705        return;
     706    if ( ! empty( $post->post_parent ) )
     707        return;
     708    $auto_add = get_option( 'nav_menu_options' );
     709    if ( empty( $auto_add ) || ! is_array( $auto_add ) || ! isset( $auto_add['auto_add'] ) )
     710        return;
     711    $auto_add = $auto_add['auto_add'];
     712    if ( empty( $auto_add ) || ! is_array( $auto_add ) )
     713        return;
     714
     715    $args = array(
     716        'menu-item-object-id' => $post->ID,
     717        'menu-item-object' => $post->post_type,
     718        'menu-item-type' => 'post_type',
     719        'menu-item-status' => 'publish',
     720    );
     721
     722    foreach ( $auto_add as $menu_id ) {
     723        $items = wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) );
     724        if ( ! is_array( $items ) )
     725            continue;
     726        foreach ( $items as $item ) {
     727            if ( $post->ID == $item->object_id )
     728                continue 2;
     729        }
     730        wp_update_nav_menu_item( $menu_id, 0, $args );
    758731    }
    759732}
Note: See TracChangeset for help on using the changeset viewer.