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

git-svn-id: http://svn.automattic.com/wordpress/trunk@15254 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2010-06-14 19:52:30 +00:00
parent c735965594
commit 48bc4e220c
4 changed files with 46 additions and 99 deletions

View File

@ -71,14 +71,9 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
$title = $item->title;
if ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
$original_status = get_post_status_object( $original_object->post_status );
$classes[] = "draft post-status-$original_object->post_status";
/* translators: 1: title of menu item in draft status, 2: actual post status. */
$title = sprintf( __('%1$s (%2$s)'), $item->title, $original_status->label );
} elseif ( isset( $item->post_status ) && 'pending' == $item->post_status ) {
$classes[] = 'unsaved';
/* translators: %s: title of menu item in pending status */
$title = sprintf( __('%s (Unsaved)'), $item->title );
$classes[] = 'pending';
/* translators: %s: title of menu item in draft status */
$title = sprintf( __('%s (Pending)'), $item->title );
}
$title = empty( $item->label ) ? $title : $item->label;
@ -177,27 +172,7 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
<div class="menu-item-actions description-wide submitbox">
<?php if( 'custom' != $item->type ) : ?>
<p class="link-to-original">
<?php
$post_status = get_post_status( $item->object_id );
if( 'publish' == $post_status ) {
printf( __('Original: %s'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>', '' );
} else {
$original_url = $item->url;
if( 'trash' == $post_status ) {
$original_url = add_query_arg(
array(
'post_status' => 'trash',
'post_type' => $item->object,
),
admin_url( 'edit.php' )
);
}
$post_status_obj = get_post_status_object( $post_status );
/* translators: 1: title, 2: post status. */
printf( __('Original: %1$s (%2$s)'), '<a href="' . esc_attr( $original_url ) . '">' . esc_html( $original_title ) . '</a>',
$post_status_obj->label );
}
?>
<?php printf( __('Original: %s'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
</p>
<?php endif; ?>
<a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php
@ -219,7 +194,6 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
<input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
<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 ); ?>" />
<input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
<input class="menu-item-data-status" type="hidden" name="menu-item-status[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_status ); ?>" />
<input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
</div><!-- .menu-item-settings-->
<ul class="menu-item-transport"></ul>
@ -973,7 +947,7 @@ function wp_nav_menu_item_taxonomy_meta_box( $object, $taxonomy ) {
*
* @since 3.0.0
*
* @param int $menu_id The menu ID for which to save this item. $menu_id of 0 makes a pending, orphaned menu item.
* @param int $menu_id The menu ID for which to save this item. $menu_id of 0 makes a draft, orphaned menu item.
* @param array $menu_data The unsanitized posted menu item data.
* @return array The database IDs of the items saved
*/
@ -1105,12 +1079,12 @@ function wp_get_nav_menu_to_edit( $menu_id = 0 ) {
$some_pending_menu_items = false;
foreach( (array) $menu_items as $menu_item ) {
if ( isset( $menu_item->post_status ) && 'pending' == $menu_item->post_status )
if ( isset( $menu_item->post_status ) && 'draft' == $menu_item->post_status )
$some_pending_menu_items = true;
}
if ( $some_pending_menu_items )
$result .= '<div class="updated inline"><p>' . __('Click Save Menu to make unsaved menu items public.') . '</p></div>';
$result .= '<div class="updated inline"><p>' . __('Click Save Menu to make pending menu items public.') . '</p></div>';
$result .= '<ul class="menu" id="menu-to-edit"> ';
$result .= walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $menu_items), 0, (object) array('walker' => $walker ) );
@ -1143,23 +1117,23 @@ function wp_nav_menu_manage_columns() {
}
/**
* Deletes orphaned pending menu items
* Deletes orphaned draft menu items
*
* @access private
* @since 3.0.0
*
*/
function _wp_delete_orphaned_pending_menu_items() {
function _wp_delete_orphaned_draft_menu_items() {
global $wpdb;
$delete_timestamp = time() - (60*60*24*EMPTY_TRASH_DAYS);
// delete orphaned pending menu items
$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 ) );
// delete orphaned draft menu items
$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 ) );
foreach( (array) $menu_items_to_delete as $menu_item_id )
wp_delete_post( $menu_item_id, true );
}
add_action('admin_head-nav-menus.php', '_wp_delete_orphaned_pending_menu_items');
add_action('admin_head-nav-menus.php', '_wp_delete_orphaned_draft_menu_items');
?>

View File

@ -327,13 +327,13 @@ switch ( $action ) {
// Update menu items
if ( ! is_wp_error( $_menu_object ) ) {
$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') );
$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') );
$menu_items = array();
// Index menu items by db ID
foreach( $unsorted_menu_items as $_item )
$menu_items[$_item->db_id] = $_item;
$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' );
$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' );
wp_defer_term_counting(true);
// Loop through all the menu items' POST variables
if ( ! empty( $_POST['menu-item-db-id'] ) ) {

View File

@ -233,7 +233,7 @@ add_action( 'wp_scheduled_delete', 'wp_scheduled_delete' );
// Navigation menu actions
add_action( 'delete_post', '_wp_delete_post_menu_item' );
add_action( 'delete_term', '_wp_delete_tax_menu_item' );
add_action( 'transition_post_status', '_wp_menu_changing_status_observer', 10, 3 );
add_action( 'transition_post_status', '_wp_auto_add_pages_to_menu', 10, 3 );
// Post Thumbnail CSS class filtering
add_action( 'begin_fetch_post_thumbnail_html', '_wp_post_thumbnail_class_filter_add' );

View File

@ -244,7 +244,7 @@ function wp_update_nav_menu_object( $menu_id = 0, $menu_data = array() ) {
*
* @since 3.0.0
*
* @param int $menu_id The ID of the menu. Required. If "0", makes the menu item a pending orphan.
* @param int $menu_id The ID of the menu. Required. If "0", makes the menu item a draft orphan.
* @param int $menu_item_db_id The ID of the menu item. If "0", creates a new menu item.
* @param array $menu_item_data The menu item's data.
* @return int The menu item's database ID or WP_Error object on failure.
@ -262,7 +262,7 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item
if ( ( ! $menu && 0 !== $menu_id ) || is_wp_error( $menu ) )
return $menu;
$menu_items = 0 == $menu_id ? array() : (array) wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'draft,pending,publish' ) );
$menu_items = 0 == $menu_id ? array() : (array) wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) );
$count = count( $menu_items );
@ -336,10 +336,10 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item
if ( 0 != $menu_id )
$post['tax_input'] = array( 'nav_menu' => array( intval( $menu->term_id ) ) );
// New menu item. Default is pending status
// New menu item. Default is draft status
if ( 0 == $menu_item_db_id ) {
$post['ID'] = 0;
$post['post_status'] = 'publish' == $args['menu-item-status'] ? 'publish' : 'pending';
$post['post_status'] = 'publish' == $args['menu-item-status'] ? 'publish' : 'draft';
$menu_item_db_id = wp_insert_post( $post );
// Update existing menu item. Default is publish status
@ -690,7 +690,7 @@ function _wp_delete_tax_menu_item( $object_id = 0 ) {
}
/**
* Modify a navigational menu upon post object status change, if appropos.
* Automatically add newly published page objects to menus with that as an option.
*
* @since 3.0.0
* @access private
@ -700,61 +700,34 @@ function _wp_delete_tax_menu_item( $object_id = 0 ) {
* @param object $post The post object being transitioned from one status to another.
* @return void
*/
function _wp_menu_changing_status_observer( $new_status, $old_status, $post ) {
// append new top-level page objects to a menu for which that option is selected
if (
'publish' == $new_status &&
'publish' != $old_status &&
'page' == $post->post_type &&
empty( $post->post_parent )
) {
$auto_add = get_option( 'nav_menu_options' );
if (
isset( $auto_add['auto_add'] ) &&
is_array( $auto_add['auto_add'] )
) {
$args = array(
'menu-item-object-id' => $post->ID,
'menu-item-object' => $post->post_type,
'menu-item-type' => 'post_type',
'menu-item-status' => 'publish',
);
function _wp_auto_add_pages_to_menu( $new_status, $old_status, $post ) {
if ( 'publish' != $new_status || 'publish' == $old_status || 'page' != $post->post_type )
return;
if ( ! empty( $post->post_parent ) )
return;
$auto_add = get_option( 'nav_menu_options' );
if ( empty( $auto_add ) || ! is_array( $auto_add ) || ! isset( $auto_add['auto_add'] ) )
return;
$auto_add = $auto_add['auto_add'];
if ( empty( $auto_add ) || ! is_array( $auto_add ) )
return;
foreach ( $auto_add['auto_add'] as $menu_id ) {
$items = wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'draft,pending,publish' ) );
if ( ! is_array( $items ) )
continue;
foreach ( $items as $item ) {
if ( $post->ID == $item->object_id )
continue 2;
}
wp_update_nav_menu_item( $menu_id, 0, $args );
}
}
}
// give menu items draft status if their associated post objects change from "publish" to "draft", or vice versa (draft item being re-published)
if (
( $new_status != $old_status ) &&
! empty( $post->ID ) && ! empty( $post->post_type ) &&
'nav_menu_item' != $post->post_type &&
( 'publish' == $old_status || 'publish' == $new_status )
) {
$menu_items = get_posts(array(
'meta_key' => '_menu_item_object_id',
'meta_value' => $post->ID,
'post_status' => 'any',
'post_type' => 'nav_menu_item',
));
foreach( (array) $menu_items as $menu_item ) {
if ( ! empty( $menu_item->ID ) ) {
$properties = get_object_vars( $menu_item );
$properties['post_status'] = 'publish' == $new_status ? 'publish' : 'draft';
wp_insert_post( $properties );
}
$args = array(
'menu-item-object-id' => $post->ID,
'menu-item-object' => $post->post_type,
'menu-item-type' => 'post_type',
'menu-item-status' => 'publish',
);
foreach ( $auto_add as $menu_id ) {
$items = wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) );
if ( ! is_array( $items ) )
continue;
foreach ( $items as $item ) {
if ( $post->ID == $item->object_id )
continue 2;
}
wp_update_nav_menu_item( $menu_id, 0, $args );
}
}