Skip to content

REST API: Restore is_array() check in rest_convert_error_to_response()#11307

Open
nate-allen wants to merge 3 commits intoWordPress:trunkfrom
nate-allen:fix/rest-convert-error-stdclass
Open

REST API: Restore is_array() check in rest_convert_error_to_response()#11307
nate-allen wants to merge 3 commits intoWordPress:trunkfrom
nate-allen:fix/rest-convert-error-stdclass

Conversation

@nate-allen
Copy link

61429 (part of the Code Modernization effort, #63430) replaced the isset() ternary in rest_convert_error_to_response() with a null coalescing operator, removing the is_array() guard. Since WP_Error::get_all_error_data() can return data of any type, this causes a PHP fatal error when error data is a stdClass object.

This PR reverts the line to its original form and adds a test case for stdClass error data.

Trac ticket: https://core.trac.wordpress.org/ticket/64901

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 4.6
Used for: Identifying the regression by diffing 6.9.4 and 7.0-beta5, and writing the test case. The fix itself is a direct revert of the changed line. All code was reviewed by me.


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.

…se()`.

The null coalescing conversion in [61429] removed the `is_array()` guard
when accessing `$error_data['status']`. Since `WP_Error` data can be any
type (including `stdClass`), this causes a PHP fatal error when non-array
data is passed.

This restores the type check while still using null coalescing for the
array case.

Props costdev, westonruter.
Fixes #64901. See #63430.
@github-actions
Copy link

github-actions bot commented Mar 19, 2026

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 nateallen, mukesh27.

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

  • 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.

@nate-allen nate-allen changed the title Fix/rest convert error stdclass REST API: Restore is_array() check in rest_convert_error_to_response() Mar 19, 2026
$error->get_all_error_data(),
static function ( $status, $error_data ) {
return $error_data['status'] ?? $status;
return is_array( $error_data ) && isset( $error_data['status'] ) ? $error_data['status'] : $status;
Copy link
Member

Choose a reason for hiding this comment

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

Better to add a single line comment so in future other can not reintroduce similar changes for Code Modernization

Copy link
Author

Choose a reason for hiding this comment

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

Added an inline comment. The new test case test_error_to_response_with_stdclass_data would also catch any future regression.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants