Avoid PHP notices when deleting or restoring an item that no longer exists. props johnbillion, ocean90. fixes #24246.
git-svn-id: http://core.svn.wordpress.org/trunk@24201 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
6f2d7d1d3b
commit
6898eba2f2
|
@ -133,19 +133,19 @@ case 'edit':
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( empty($post->ID) )
|
if ( ! $post )
|
||||||
wp_die( __('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?') );
|
wp_die( __( 'You attempted to edit an item that doesn’t exist. Perhaps it was deleted?' ) );
|
||||||
|
|
||||||
if ( null == $post_type_object )
|
if ( ! $post_type_object )
|
||||||
wp_die( __('Unknown post type.') );
|
wp_die( __( 'Unknown post type.' ) );
|
||||||
|
|
||||||
if ( !current_user_can($post_type_object->cap->edit_post, $post_id) )
|
if ( ! current_user_can( $post_type_object->cap->edit_post, $post_id ) )
|
||||||
wp_die( __('You are not allowed to edit this item.') );
|
wp_die( __( 'You are not allowed to edit this item.' ) );
|
||||||
|
|
||||||
if ( 'trash' == $post->post_status )
|
if ( 'trash' == $post->post_status )
|
||||||
wp_die( __('You can’t edit this item because it is in the Trash. Please restore it and try again.') );
|
wp_die( __( 'You can’t edit this item because it is in the Trash. Please restore it and try again.' ) );
|
||||||
|
|
||||||
if ( !empty( $_GET['get-post-lock'] ) ) {
|
if ( ! empty( $_GET['get-post-lock'] ) ) {
|
||||||
wp_set_post_lock( $post_id );
|
wp_set_post_lock( $post_id );
|
||||||
wp_redirect( get_edit_post_link( $post_id, 'url' ) );
|
wp_redirect( get_edit_post_link( $post_id, 'url' ) );
|
||||||
exit();
|
exit();
|
||||||
|
@ -220,16 +220,22 @@ case 'editpost':
|
||||||
case 'trash':
|
case 'trash':
|
||||||
check_admin_referer('trash-post_' . $post_id);
|
check_admin_referer('trash-post_' . $post_id);
|
||||||
|
|
||||||
if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
|
if ( ! $post )
|
||||||
wp_die( __('You are not allowed to move this item to the Trash.') );
|
wp_die( __( 'The item you are trying to move to the Trash no longer exists.' ) );
|
||||||
|
|
||||||
|
if ( ! $post_type_object )
|
||||||
|
wp_die( __( 'Unknown post type.' ) );
|
||||||
|
|
||||||
|
if ( ! current_user_can( $post_type_object->cap->delete_post, $post_id ) )
|
||||||
|
wp_die( __( 'You are not allowed to move this item to the Trash.' ) );
|
||||||
|
|
||||||
if ( $user_id = wp_check_post_lock( $post_id ) ) {
|
if ( $user_id = wp_check_post_lock( $post_id ) ) {
|
||||||
$user = get_userdata( $user_id );
|
$user = get_userdata( $user_id );
|
||||||
wp_die( sprintf( __( 'You cannot move this item to the Trash. %s is currently editing.' ), $user->display_name ) );
|
wp_die( sprintf( __( 'You cannot move this item to the Trash. %s is currently editing.' ), $user->display_name ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! wp_trash_post($post_id) )
|
if ( ! wp_trash_post( $post_id ) )
|
||||||
wp_die( __('Error in moving to Trash.') );
|
wp_die( __( 'Error in moving to Trash.' ) );
|
||||||
|
|
||||||
wp_redirect( add_query_arg( array('trashed' => 1, 'ids' => $post_id), $sendback ) );
|
wp_redirect( add_query_arg( array('trashed' => 1, 'ids' => $post_id), $sendback ) );
|
||||||
exit();
|
exit();
|
||||||
|
@ -238,11 +244,17 @@ case 'trash':
|
||||||
case 'untrash':
|
case 'untrash':
|
||||||
check_admin_referer('untrash-post_' . $post_id);
|
check_admin_referer('untrash-post_' . $post_id);
|
||||||
|
|
||||||
if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
|
if ( ! $post )
|
||||||
wp_die( __('You are not allowed to move this item out of the Trash.') );
|
wp_die( __( 'The item you are trying to restore from the Trash no longer exists.' ) );
|
||||||
|
|
||||||
if ( ! wp_untrash_post($post_id) )
|
if ( ! $post_type_object )
|
||||||
wp_die( __('Error in restoring from Trash.') );
|
wp_die( __( 'Unknown post type.' ) );
|
||||||
|
|
||||||
|
if ( ! current_user_can( $post_type_object->cap->delete_post, $post_id ) )
|
||||||
|
wp_die( __( 'You are not allowed to move this item out of the Trash.' ) );
|
||||||
|
|
||||||
|
if ( ! wp_untrash_post( $post_id ) )
|
||||||
|
wp_die( __( 'Error in restoring from Trash.' ) );
|
||||||
|
|
||||||
wp_redirect( add_query_arg('untrashed', 1, $sendback) );
|
wp_redirect( add_query_arg('untrashed', 1, $sendback) );
|
||||||
exit();
|
exit();
|
||||||
|
@ -251,17 +263,23 @@ case 'untrash':
|
||||||
case 'delete':
|
case 'delete':
|
||||||
check_admin_referer('delete-post_' . $post_id);
|
check_admin_referer('delete-post_' . $post_id);
|
||||||
|
|
||||||
if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
|
if ( ! $post )
|
||||||
wp_die( __('You are not allowed to delete this item.') );
|
wp_die( __( 'This item has already been deleted.' ) );
|
||||||
|
|
||||||
$force = !EMPTY_TRASH_DAYS;
|
if ( ! $post_type_object )
|
||||||
|
wp_die( __( 'Unknown post type.' ) );
|
||||||
|
|
||||||
|
if ( ! current_user_can( $post_type_object->cap->delete_post, $post_id ) )
|
||||||
|
wp_die( __( 'You are not allowed to delete this item.' ) );
|
||||||
|
|
||||||
|
$force = ! EMPTY_TRASH_DAYS;
|
||||||
if ( $post->post_type == 'attachment' ) {
|
if ( $post->post_type == 'attachment' ) {
|
||||||
$force = ( $force || !MEDIA_TRASH );
|
$force = ( $force || ! MEDIA_TRASH );
|
||||||
if ( ! wp_delete_attachment($post_id, $force) )
|
if ( ! wp_delete_attachment( $post_id, $force ) )
|
||||||
wp_die( __('Error in deleting.') );
|
wp_die( __( 'Error in deleting.' ) );
|
||||||
} else {
|
} else {
|
||||||
if ( !wp_delete_post($post_id, $force) )
|
if ( ! wp_delete_post( $post_id, $force ) )
|
||||||
wp_die( __('Error in deleting.') );
|
wp_die( __( 'Error in deleting.' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_redirect( add_query_arg('deleted', 1, $sendback) );
|
wp_redirect( add_query_arg('deleted', 1, $sendback) );
|
||||||
|
|
Loading…
Reference in New Issue