Skip to content

Conversation

@CallumBW95
Copy link

@CallumBW95 CallumBW95 commented Sep 23, 2025

Update wp_die() to include status codes where appropriate within files related to the REST API component

Trac ticket: #64032


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions
Copy link

github-actions bot commented Sep 23, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props callumbw95, mindctrl.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@CallumBW95 CallumBW95 changed the title Update wp_die() to include status codes where appropriate within file… Oct 3, 2025
@mindctrl
Copy link

mindctrl commented Oct 7, 2025

Just noting that I've eyeballed these changes, but I'm setting up to test to ensure no ajax calls are broken with the new response codes. I probably won't have this completed until tomorrow.

Copy link

@mindctrl mindctrl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging this first pass of results as we work through them together in Zoom.


if ( ! current_user_can( 'delete_term', $tag_id ) ) {
wp_die( -1 );
wp_die( -1, 403 );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed this works.


if ( wp_delete_term( $tag_id, $taxonomy ) ) {
wp_die( 1 );
wp_die( 1, 200 );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed this works.


if ( ! $wp_list_table->ajax_user_can() ) {
wp_die( -1 );
wp_die( -1, 403 );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed this works in the Comments list as expected.

I see references to the fetch-list action in WP_Themes_List_Table and WP_Theme_Install_List_Table, but I don't see any AJAX calls being made to these classes, but maybe I'm missing it?

function wp_ajax_wp_compression_test() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( -1 );
wp_die( -1, 403 );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ works as expected

update_option( 'can_compress_scripts', 0, true );
}
wp_die( 0 );
wp_die( 0, 200 );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ works as expected

$post_id = (int) $_GET['postid'];
if ( empty( $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) {
wp_die( -1 );
wp_die( -1, 403 );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ works as expected


if ( ! stream_preview_image( $post_id ) ) {
wp_die( -1 );
wp_die( -1, 403 );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ works as expected

}

wp_die();
wp_die( '', 200 );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ works as expected


if ( ! empty( $_POST['add_new'] ) ) {
wp_die();
wp_die( '', 400 );

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks adding a widget to a widget area. It results in a spinning save icon.


wp_set_sidebars_widgets( $sidebars );
wp_die( 1 );
wp_die( 1, 400 );

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes console errors when sorting widgets in a widget area.

function wp_ajax_menu_locations_save() {
if ( ! current_user_can( 'edit_theme_options' ) ) {
wp_die( -1 );
wp_die( -1, 403 );

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unable to test this manually, because I don't see where WP core uses this for anything.

I see the JS tries to work on elements nested within #nav-menu-theme-locations, but I don't see that ID anywhere in WP, or any other element/item with that value. I also looked for elements that might have been constructed in JS, but was unable to find any there either. It seems like old code.

Note: when grabbing the URL to the nav-menu.js code referenced in the previous paragraph, I noticed a code comment, from two weeks ago about #nav-menu-theme-locations no longer existing and that it was possibly removed here in June 2015.

With that in mind, I'll skip the changes in this function. Maybe we need another ticket to remove the old code, or figure out if that change introduced a bug of some kind because the JS wasn't updated - though I didn't notice anything while looking all through Appearance > Menus.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants