Skip to content

Conversation

@CallumBW95
Copy link

@CallumBW95 CallumBW95 commented Sep 22, 2025

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

Trac ticket: 64025


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 22, 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.


if ( ! $tax ) {
wp_die( __( 'Invalid taxonomy.' ) );
wp_die( __( 'Invalid taxonomy.' ), 400 );

Choose a reason for hiding this comment

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

I wonder if this should be 404. 🤷‍♂️ Also, there's an instance of wp_die() below that's in your list on Trac but not the PR. (Line 23)

Copy link
Author

Choose a reason for hiding this comment

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

Thanks I have put line 23 in to the PR now 😄

My reasoning for a 400 is because of how we are obtaining the taxonomy through the request params in src/wp-admin/admin.php
on line 149:
$taxnow = $_REQUEST['taxonomy'];

However I can see an argument for both 400 and 404 as I am not sure if this is just a case of "doing it wrong" or a missing taxonomy?

Copy link

Choose a reason for hiding this comment

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

I think either is fine and definitely better than the default 500.


if ( ! $term instanceof WP_Term ) {
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?' ), 403 );

Choose a reason for hiding this comment

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

Is this a 403, 404, or 400 situation? The request for a non-existent term, coupled with the "does not exist" message, makes me think 404. (Edit: 404 would also match what you used below on line 180)

CallumBW95 and others added 3 commits September 25, 2025 12:18
$post_type = $_GET['post_type'];
} else {
wp_die( __( 'Invalid post type.' ) );
wp_die( __( 'Invalid post type.' ), 400 );
Copy link
Member

Choose a reason for hiding this comment

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

This text is confusing

Essentially is the same as this other one
https://github.com/WordPress/wordpress-develop/pull/9997/files#diff-e16824dc0b95c8da5a7b198cac7bf89280d06180cefaf6da296ccf211671af77R22
Missing in the array search when calling get_*

Or both are 400 or both are 403.

Copy link

Choose a reason for hiding this comment

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

I think the text is fine for what's happening here. Even still, text changes would be out of scope for this ticket.

Not sure what you mean by array search @SirLouen. There's an in_array check above that compares to post types with show_ui set to true. Can you elaborate?

Copy link
Member

Choose a reason for hiding this comment

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

I'm checking this better now, and I'm noticing that I reviewed this out of context.

@CallumBW95 CallumBW95 changed the title Update wp_die() to include status codes where appropriate within file… Oct 3, 2025
$post_type = $_GET['post_type'];
} else {
wp_die( __( 'Invalid post type.' ) );
wp_die( __( 'Invalid post type.' ), 400 );
Copy link
Member

Choose a reason for hiding this comment

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

I'm checking this better now, and I'm noticing that I reviewed this out of context.

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

Labels

None yet

3 participants