Make WordPress Core

Changeset 60713

Timestamp:
09/06/2025 06:47:54 AM (5 weeks ago)
Author:
westonruter
Message:

Posts, Post Types: Use relevant HTTP status codes for wp_die() calls in wp-admin/post.php.

The status code is now explicitly set in each wp_die() call so that the default 500 status code is not sent unless it is the most appropriate.

Props callumbw95, kkmuffme, mindctrl, westonruter.
Fixes #63836.

File:
1 edited

Legend:

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

    r60344 r60713  
    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.' ), 409 );
    144144        }
    145145
     
    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.' ), 410 );
    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
     
    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 ), 409 );
    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
     
    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.' ), 410 );
    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
     
    306306
    307307        if ( ! $post ) {
    308             wp_die( __( 'This item has already been deleted.' ) );
     308            wp_die( __( 'This item has already been deleted.' ), 410 );
    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
     
    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        }
Note: See TracChangeset for help on using the changeset viewer.