Skip to content

Commit a316966

Browse files
committed
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. git-svn-id: https://develop.svn.wordpress.org/trunk@60713 602fd350-edb4-49c9-b593-d223f7449a82
1 parent f294326 commit a316966

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/wp-admin/post.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -124,23 +124,23 @@
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.' ), 409 );
144144
}
145145

146146
if ( ! empty( $_GET['get-post-lock'] ) ) {
@@ -239,26 +239,26 @@
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.' ), 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

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 ), 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

264264
wp_redirect(
@@ -276,19 +276,19 @@
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.' ), 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

294294
$sendback = add_query_arg(
@@ -305,25 +305,25 @@
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.' ), 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

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

0 commit comments

Comments
 (0)