Surface "Move to Trash" link for posts/pages immediately after first autosave fires. Props cross country flight. fixes #10344

git-svn-id: http://svn.automattic.com/wordpress/trunk@11986 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
markjaquith 2009-10-01 11:44:18 +00:00
parent 4e20ae5719
commit 9109450809
6 changed files with 13 additions and 14 deletions

View File

@ -968,13 +968,9 @@ case 'autosave' : // The name of this action is hardcoded in edit_post()
case 'autosave-generate-nonces' : case 'autosave-generate-nonces' :
check_ajax_referer( 'autosave', 'autosavenonce' ); check_ajax_referer( 'autosave', 'autosavenonce' );
$ID = (int) $_POST['post_ID']; $ID = (int) $_POST['post_ID'];
if ( $_POST['post_type'] == 'post' ) { $post_type = ( 'page' == $_POST['post_type'] ) ? 'page' : 'post';
if ( current_user_can('edit_post', $ID) ) if ( current_user_can( "edit_{$post_type}", $ID ) )
die(wp_create_nonce('update-post_' . $ID)); die( json_encode( array( 'updateNonce' => wp_create_nonce( "update-{$post_type}_{$ID}" ), 'deleteURL' => str_replace( '&', '&', wp_nonce_url( admin_url( $post_type . '.php?action=trash&post=' . $ID ), "trash-{$post_type}_{$ID}" ) ) ) ) );
} elseif ( $_POST['post_type'] == 'page' ) {
if ( current_user_can('edit_page', $ID) )
die(wp_create_nonce('update-page_' . $ID));
}
do_action('autosave_generate_nonces'); do_action('autosave_generate_nonces');
die('0'); die('0');
break; break;

View File

@ -183,9 +183,9 @@ if ( $can_publish ) : // Contributors don't get to choose the date of publish ?>
<?php do_action('post_submitbox_start'); ?> <?php do_action('post_submitbox_start'); ?>
<div id="delete-action"> <div id="delete-action">
<?php <?php
if ( ( 'edit' == $action ) && current_user_can("delete_${post_type}", $post->ID) ) { ?> if ( current_user_can("delete_${post_type}", $post->ID) ) { ?>
<?php $delete_url = add_query_arg( array('action'=>'trash', 'post'=>$post->ID) ); ?> <?php $delete_url = add_query_arg( array('action'=>'trash', 'post'=>$post->ID) ); ?>
<a class="submitdelete deletion" href="<?php echo wp_nonce_url($delete_url, "trash-${post_type}_" . $post->ID); ?>"><?php _e('Move to Trash'); ?></a> <a class="submitdelete deletion<?php if ( 'edit' != $action ) { echo " hidden"; } ?>" href="<?php echo wp_nonce_url($delete_url, "trash-${post_type}_" . $post->ID); ?>"><?php _e('Move to Trash'); ?></a>
<?php } ?> <?php } ?>
</div> </div>

View File

@ -155,7 +155,7 @@ case 'trash':
wp_die( __('Error in moving to trash...') ); wp_die( __('Error in moving to trash...') );
$sendback = wp_get_referer(); $sendback = wp_get_referer();
if ( strpos($sendback, 'page.php') !== false ) if ( strpos($sendback, 'page.php') !== false || strpos($sendback, 'page-new.php') !== false )
$sendback = admin_url('edit-pages.php?trashed=1'); $sendback = admin_url('edit-pages.php?trashed=1');
else else
$sendback = add_query_arg('trashed', 1, $sendback); $sendback = add_query_arg('trashed', 1, $sendback);

View File

@ -195,7 +195,7 @@ case 'trash':
wp_die( __('Error in moving to trash...') ); wp_die( __('Error in moving to trash...') );
$sendback = wp_get_referer(); $sendback = wp_get_referer();
if ( strpos($sendback, 'post.php') !== false ) if ( strpos($sendback, 'post.php') !== false || strpos($sendback, 'post-new.php') !== false )
$sendback = admin_url('edit.php?trashed=1'); $sendback = admin_url('edit.php?trashed=1');
else else
$sendback = add_query_arg('trashed', 1, $sendback); $sendback = add_query_arg('trashed', 1, $sendback);

View File

@ -152,9 +152,12 @@ function autosave_update_post_ID( postID ) {
autosavenonce: jQuery('#autosavenonce').val(), autosavenonce: jQuery('#autosavenonce').val(),
post_type: jQuery('#post_type').val() post_type: jQuery('#post_type').val()
}, function(html) { }, function(html) {
jQuery('#_wpnonce').val(html); jQuery('#_wpnonce').val(html.updateNonce);
jQuery('#delete-action a.submitdelete').attr('href', html.deleteURL);
autosave_enable_buttons(); // re-enable disabled form buttons autosave_enable_buttons(); // re-enable disabled form buttons
}); jQuery('#delete-action a.submitdelete').fadeIn();
},
'json');
jQuery('#hiddenaction').val('editpost'); jQuery('#hiddenaction').val('editpost');
} }
} }

File diff suppressed because one or more lines are too long