From 0dbade35e5ccc3c0ee55aa2d748a80ab9bf4c9c9 Mon Sep 17 00:00:00 2001 From: Callum Bridgford-Whittick Date: Wed, 27 Aug 2025 15:54:32 +0100 Subject: [PATCH 1/3] 63836: add error codes to wp_die in post.php --- src/wp-admin/post.php | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/wp-admin/post.php b/src/wp-admin/post.php index 468041c9ead86..ea48009498a9a 100644 --- a/src/wp-admin/post.php +++ b/src/wp-admin/post.php @@ -124,23 +124,23 @@ } if ( ! $post ) { - wp_die( __( 'You attempted to edit an item that does not exist. Perhaps it was deleted?' ) ); + wp_die( __( 'You attempted to edit an item that does not exist. Perhaps it was deleted?' ), 404 ); } if ( ! $post_type_object ) { - wp_die( __( 'Invalid post type.' ) ); + wp_die( __( 'Invalid post type.' ), 400 ); } if ( ! in_array( $typenow, get_post_types( array( 'show_ui' => true ) ), true ) ) { - wp_die( __( 'Sorry, you are not allowed to edit posts in this post type.' ) ); + wp_die( __( 'Sorry, you are not allowed to edit posts in this post type.' ), 403 ); } if ( ! current_user_can( 'edit_post', $post_id ) ) { - wp_die( __( 'Sorry, you are not allowed to edit this item.' ) ); + wp_die( __( 'Sorry, you are not allowed to edit this item.' ), 403 ); } if ( 'trash' === $post->post_status ) { - wp_die( __( 'You cannot edit this item because it is in the Trash. Please restore it and try again.' ) ); + wp_die( __( 'You cannot edit this item because it is in the Trash. Please restore it and try again.' ), 404 ); } if ( ! empty( $_GET['get-post-lock'] ) ) { @@ -239,26 +239,26 @@ check_admin_referer( 'trash-post_' . $post_id ); if ( ! $post ) { - wp_die( __( 'The item you are trying to move to the Trash no longer exists.' ) ); + wp_die( __( 'The item you are trying to move to the Trash no longer exists.' ), 404 ); } if ( ! $post_type_object ) { - wp_die( __( 'Invalid post type.' ) ); + wp_die( __( 'Invalid post type.' ), 400 ); } if ( ! current_user_can( 'delete_post', $post_id ) ) { - wp_die( __( 'Sorry, you are not allowed to move this item to the Trash.' ) ); + wp_die( __( 'Sorry, you are not allowed to move this item to the Trash.' ), 403 ); } $user_id = wp_check_post_lock( $post_id ); if ( $user_id ) { $user = get_userdata( $user_id ); /* translators: %s: User's display name. */ - 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 ), 400 ); } if ( ! wp_trash_post( $post_id ) ) { - wp_die( __( 'Error in moving the item to Trash.' ) ); + wp_die( __( 'Error in moving the item to Trash.' ), 500 ); } wp_redirect( @@ -276,19 +276,19 @@ check_admin_referer( 'untrash-post_' . $post_id ); if ( ! $post ) { - wp_die( __( 'The item you are trying to restore from the Trash no longer exists.' ) ); + wp_die( __( 'The item you are trying to restore from the Trash no longer exists.' ), 404 ); } if ( ! $post_type_object ) { - wp_die( __( 'Invalid post type.' ) ); + wp_die( __( 'Invalid post type.' ), 400 ); } if ( ! current_user_can( 'delete_post', $post_id ) ) { - wp_die( __( 'Sorry, you are not allowed to restore this item from the Trash.' ) ); + wp_die( __( 'Sorry, you are not allowed to restore this item from the Trash.' ), 403 ); } if ( ! wp_untrash_post( $post_id ) ) { - wp_die( __( 'Error in restoring the item from Trash.' ) ); + wp_die( __( 'Error in restoring the item from Trash.' ), 500 ); } $sendback = add_query_arg( @@ -305,25 +305,25 @@ check_admin_referer( 'delete-post_' . $post_id ); if ( ! $post ) { - wp_die( __( 'This item has already been deleted.' ) ); + wp_die( __( 'This item has already been deleted.' ), 404 ); } if ( ! $post_type_object ) { - wp_die( __( 'Invalid post type.' ) ); + wp_die( __( 'Invalid post type.' ), 400 ); } if ( ! current_user_can( 'delete_post', $post_id ) ) { - wp_die( __( 'Sorry, you are not allowed to delete this item.' ) ); + wp_die( __( 'Sorry, you are not allowed to delete this item.' ), 403 ); } if ( 'attachment' === $post->post_type ) { $force = ( ! MEDIA_TRASH ); if ( ! wp_delete_attachment( $post_id, $force ) ) { - wp_die( __( 'Error in deleting the attachment.' ) ); + wp_die( __( 'Error in deleting the attachment.' ), 500 ); } } else { if ( ! wp_delete_post( $post_id, true ) ) { - wp_die( __( 'Error in deleting the item.' ) ); + wp_die( __( 'Error in deleting the item.' ), 500 ); } } From 01150b5c3033a379316896385ba00df55be31415 Mon Sep 17 00:00:00 2001 From: Callum Bridgford-Whittick Date: Tue, 2 Sep 2025 14:32:08 +0100 Subject: [PATCH 2/3] 63836: update 400 error code to 409 instead of 423 --- src/wp-admin/post.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-admin/post.php b/src/wp-admin/post.php index ea48009498a9a..153b105c1b865 100644 --- a/src/wp-admin/post.php +++ b/src/wp-admin/post.php @@ -254,7 +254,7 @@ if ( $user_id ) { $user = get_userdata( $user_id ); /* translators: %s: User's display name. */ - wp_die( sprintf( __( 'You cannot move this item to the Trash. %s is currently editing.' ), $user->display_name ), 400 ); + wp_die( sprintf( __( 'You cannot move this item to the Trash. %s is currently editing.' ), $user->display_name ), 409 ); } if ( ! wp_trash_post( $post_id ) ) { From 729e2fe3e79c27a2686c14a981a1daff201899c2 Mon Sep 17 00:00:00 2001 From: Callum Bridgford-Whittick Date: Fri, 5 Sep 2025 15:17:37 +0100 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Weston Ruter --- src/wp-admin/post.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wp-admin/post.php b/src/wp-admin/post.php index 153b105c1b865..dd7bad1bb3830 100644 --- a/src/wp-admin/post.php +++ b/src/wp-admin/post.php @@ -140,7 +140,7 @@ } if ( 'trash' === $post->post_status ) { - wp_die( __( 'You cannot edit this item because it is in the Trash. Please restore it and try again.' ), 404 ); + wp_die( __( 'You cannot edit this item because it is in the Trash. Please restore it and try again.' ), 409 ); } if ( ! empty( $_GET['get-post-lock'] ) ) { @@ -239,7 +239,7 @@ check_admin_referer( 'trash-post_' . $post_id ); if ( ! $post ) { - wp_die( __( 'The item you are trying to move to the Trash no longer exists.' ), 404 ); + wp_die( __( 'The item you are trying to move to the Trash no longer exists.' ), 410 ); } if ( ! $post_type_object ) { @@ -276,7 +276,7 @@ check_admin_referer( 'untrash-post_' . $post_id ); if ( ! $post ) { - wp_die( __( 'The item you are trying to restore from the Trash no longer exists.' ), 404 ); + wp_die( __( 'The item you are trying to restore from the Trash no longer exists.' ), 410 ); } if ( ! $post_type_object ) { @@ -305,7 +305,7 @@ check_admin_referer( 'delete-post_' . $post_id ); if ( ! $post ) { - wp_die( __( 'This item has already been deleted.' ), 404 ); + wp_die( __( 'This item has already been deleted.' ), 410 ); } if ( ! $post_type_object ) {