Make WordPress Core

Ticket #63836: 63836.audit.2.patch

File 63836.audit.2.patch, 4.4 KB (added by callumbw95, 5 months ago)

Fix accidental removal of elseif from original patch

  • src/wp-admin/post.php

    diff --git a/src/wp-admin/post.php b/src/wp-admin/post.php
    index 468041c9ea..94d84599f5 100644
    a b switch ( $action ) { 
    124124                }
    125125
    126126                if ( ! $post ) {
    127                         wp_die( __( 'You attempted to edit an item that does not exist. Perhaps it was deleted?' ) );
     127                        wp_die( __( 'You attempted to edit an item that does not exist. Perhaps it was deleted?' ), 404);
    128128                }
    129129
    130130                if ( ! $post_type_object ) {
    131                         wp_die( __( 'Invalid post type.' ) );
     131                        wp_die( __( 'Invalid post type.' ), 400 );
    132132                }
    133133
    134134                if ( ! in_array( $typenow, get_post_types( array( 'show_ui' => true ) ), true ) ) {
    135                         wp_die( __( 'Sorry, you are not allowed to edit posts in this post type.' ) );
     135                        wp_die( __( 'Sorry, you are not allowed to edit posts in this post type.' ), 403 );
    136136                }
    137137
    138138                if ( ! current_user_can( 'edit_post', $post_id ) ) {
    139                         wp_die( __( 'Sorry, you are not allowed to edit this item.' ) );
     139                        wp_die( __( 'Sorry, you are not allowed to edit this item.' ), 403 );
    140140                }
    141141
    142142                if ( 'trash' === $post->post_status ) {
    143                         wp_die( __( 'You cannot edit this item because it is in the Trash. Please restore it and try again.' ) );
     143                        wp_die( __( 'You cannot edit this item because it is in the Trash. Please restore it and try again.' ), 404 );
    144144                }
    145145
    146146                if ( ! empty( $_GET['get-post-lock'] ) ) {
    switch ( $action ) { 
    239239                check_admin_referer( 'trash-post_' . $post_id );
    240240
    241241                if ( ! $post ) {
    242                         wp_die( __( 'The item you are trying to move to the Trash no longer exists.' ) );
     242                        wp_die( __( 'The item you are trying to move to the Trash no longer exists.' ), 404 );
    243243                }
    244244
    245245                if ( ! $post_type_object ) {
    246                         wp_die( __( 'Invalid post type.' ) );
     246                        wp_die( __( 'Invalid post type.' ), 400 );
    247247                }
    248248
    249249                if ( ! current_user_can( 'delete_post', $post_id ) ) {
    250                         wp_die( __( 'Sorry, you are not allowed to move this item to the Trash.' ) );
     250                        wp_die( __( 'Sorry, you are not allowed to move this item to the Trash.' ), 403 );
    251251                }
    252252
    253253                $user_id = wp_check_post_lock( $post_id );
    254254                if ( $user_id ) {
    255255                        $user = get_userdata( $user_id );
    256256                        /* translators: %s: User's display name. */
    257                         wp_die( sprintf( __( 'You cannot move this item to the Trash. %s is currently editing.' ), $user->display_name ) );
     257                        wp_die( sprintf( __( 'You cannot move this item to the Trash. %s is currently editing.' ), $user->display_name ), 423 );
    258258                }
    259259
    260260                if ( ! wp_trash_post( $post_id ) ) {
    261                         wp_die( __( 'Error in moving the item to Trash.' ) );
     261                        wp_die( __( 'Error in moving the item to Trash.' ), 500 );
    262262                }
    263263
    264264                wp_redirect(
    switch ( $action ) { 
    276276                check_admin_referer( 'untrash-post_' . $post_id );
    277277
    278278                if ( ! $post ) {
    279                         wp_die( __( 'The item you are trying to restore from the Trash no longer exists.' ) );
     279                        wp_die( __( 'The item you are trying to restore from the Trash no longer exists.' ), 404 );
    280280                }
    281281
    282282                if ( ! $post_type_object ) {
    283                         wp_die( __( 'Invalid post type.' ) );
     283                        wp_die( __( 'Invalid post type.' ), 400 );
    284284                }
    285285
    286286                if ( ! current_user_can( 'delete_post', $post_id ) ) {
    287                         wp_die( __( 'Sorry, you are not allowed to restore this item from the Trash.' ) );
     287                        wp_die( __( 'Sorry, you are not allowed to restore this item from the Trash.' ), 403 );
    288288                }
    289289
    290290                if ( ! wp_untrash_post( $post_id ) ) {
    291                         wp_die( __( 'Error in restoring the item from Trash.' ) );
     291                        wp_die( __( 'Error in restoring the item from Trash.' ), 500 );
    292292                }
    293293
    294294                $sendback = add_query_arg(
    switch ( $action ) { 
    305305                check_admin_referer( 'delete-post_' . $post_id );
    306306
    307307                if ( ! $post ) {
    308                         wp_die( __( 'This item has already been deleted.' ) );
     308                        wp_die( __( 'This item has already been deleted.' ), 404 );
    309309                }
    310310
    311311                if ( ! $post_type_object ) {
    312                         wp_die( __( 'Invalid post type.' ) );
     312                        wp_die( __( 'Invalid post type.' ), 400 );
    313313                }
    314314
    315315                if ( ! current_user_can( 'delete_post', $post_id ) ) {
    316                         wp_die( __( 'Sorry, you are not allowed to delete this item.' ) );
     316                        wp_die( __( 'Sorry, you are not allowed to delete this item.' ), 403 );
    317317                }
    318318
    319319                if ( 'attachment' === $post->post_type ) {
    320320                        $force = ( ! MEDIA_TRASH );
    321321                        if ( ! wp_delete_attachment( $post_id, $force ) ) {
    322                                 wp_die( __( 'Error in deleting the attachment.' ) );
     322                                wp_die( __( 'Error in deleting the attachment.' ), 500 );
    323323                        }
    324324                } else {
    325325                        if ( ! wp_delete_post( $post_id, true ) ) {
    326                                 wp_die( __( 'Error in deleting the item.' ) );
     326                                wp_die( __( 'Error in deleting the item.' ), 500 );
    327327                        }
    328328                }
    329329