Make WordPress Core

Changeset 24201


Ignore:
Timestamp:
05/08/2013 06:56:54 PM (13 years ago)
Author:
SergeyBiryukov
Message:

Avoid PHP notices when deleting or restoring an item that no longer exists. props johnbillion, ocean90. fixes #24246.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/post.php

    r24199 r24201  
    134134        }
    135135
    136         if ( empty($post->ID) )
    137                 wp_die( __('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?') );
    138 
    139         if ( null == $post_type_object )
    140                 wp_die( __('Unknown post type.') );
    141 
    142         if ( !current_user_can($post_type_object->cap->edit_post, $post_id) )
    143                 wp_die( __('You are not allowed to edit this item.') );
     136        if ( ! $post )
     137                wp_die( __( 'You attempted to edit an item that doesn’t exist. Perhaps it was deleted?' ) );
     138
     139        if ( ! $post_type_object )
     140                wp_die( __( 'Unknown post type.' ) );
     141
     142        if ( ! current_user_can( $post_type_object->cap->edit_post, $post_id ) )
     143                wp_die( __( 'You are not allowed to edit this item.' ) );
    144144
    145145        if ( 'trash' == $post->post_status )
    146                 wp_die( __('You can’t edit this item because it is in the Trash. Please restore it and try again.') );
    147 
    148         if ( !empty( $_GET['get-post-lock'] ) ) {
     146                wp_die( __( 'You can’t edit this item because it is in the Trash. Please restore it and try again.' ) );
     147
     148        if ( ! empty( $_GET['get-post-lock'] ) ) {
    149149                wp_set_post_lock( $post_id );
    150150                wp_redirect( get_edit_post_link( $post_id, 'url' ) );
     
    221221        check_admin_referer('trash-post_' . $post_id);
    222222
    223         if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
    224                 wp_die( __('You are not allowed to move this item to the Trash.') );
     223        if ( ! $post )
     224                wp_die( __( 'The item you are trying to move to the Trash no longer exists.' ) );
     225
     226        if ( ! $post_type_object )
     227                wp_die( __( 'Unknown post type.' ) );
     228
     229        if ( ! current_user_can( $post_type_object->cap->delete_post, $post_id ) )
     230                wp_die( __( 'You are not allowed to move this item to the Trash.' ) );
    225231
    226232        if ( $user_id = wp_check_post_lock( $post_id ) ) {
     
    229235        }
    230236
    231         if ( ! wp_trash_post($post_id) )
    232                 wp_die( __('Error in moving to Trash.') );
     237        if ( ! wp_trash_post( $post_id ) )
     238                wp_die( __( 'Error in moving to Trash.' ) );
    233239
    234240        wp_redirect( add_query_arg( array('trashed' => 1, 'ids' => $post_id), $sendback ) );
     
    239245        check_admin_referer('untrash-post_' . $post_id);
    240246
    241         if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
    242                 wp_die( __('You are not allowed to move this item out of the Trash.') );
    243 
    244         if ( ! wp_untrash_post($post_id) )
    245                 wp_die( __('Error in restoring from Trash.') );
     247        if ( ! $post )
     248                wp_die( __( 'The item you are trying to restore from the Trash no longer exists.' ) );
     249
     250        if ( ! $post_type_object )
     251                wp_die( __( 'Unknown post type.' ) );
     252
     253        if ( ! current_user_can( $post_type_object->cap->delete_post, $post_id ) )
     254                wp_die( __( 'You are not allowed to move this item out of the Trash.' ) );
     255
     256        if ( ! wp_untrash_post( $post_id ) )
     257                wp_die( __( 'Error in restoring from Trash.' ) );
    246258
    247259        wp_redirect( add_query_arg('untrashed', 1, $sendback) );
     
    252264        check_admin_referer('delete-post_' . $post_id);
    253265
    254         if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
    255                 wp_die( __('You are not allowed to delete this item.') );
    256 
    257         $force = !EMPTY_TRASH_DAYS;
     266        if ( ! $post )
     267                wp_die( __( 'This item has already been deleted.' ) );
     268
     269        if ( ! $post_type_object )
     270                wp_die( __( 'Unknown post type.' ) );
     271
     272        if ( ! current_user_can( $post_type_object->cap->delete_post, $post_id ) )
     273                wp_die( __( 'You are not allowed to delete this item.' ) );
     274
     275        $force = ! EMPTY_TRASH_DAYS;
    258276        if ( $post->post_type == 'attachment' ) {
    259                 $force = ( $force || !MEDIA_TRASH );
    260                 if ( ! wp_delete_attachment($post_id, $force) )
    261                         wp_die( __('Error in deleting.') );
    262         } else {
    263                 if ( !wp_delete_post($post_id, $force) )
    264                         wp_die( __('Error in deleting.') );
     277                $force = ( $force || ! MEDIA_TRASH );
     278                if ( ! wp_delete_attachment( $post_id, $force ) )
     279                        wp_die( __( 'Error in deleting.' ) );
     280        } else {
     281                if ( ! wp_delete_post( $post_id, $force ) )
     282                        wp_die( __( 'Error in deleting.' ) );
    265283        }
    266284
Note: See TracChangeset for help on using the changeset viewer.