REST API: Restore is_array() check in rest_convert_error_to_response()#11307
REST API: Restore is_array() check in rest_convert_error_to_response()#11307nate-allen wants to merge 3 commits intoWordPress:trunkfrom
is_array() check in rest_convert_error_to_response()#11307Conversation
…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.
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
is_array() check in rest_convert_error_to_response()
| $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; |
There was a problem hiding this comment.
Better to add a single line comment so in future other can not reintroduce similar changes for Code Modernization
There was a problem hiding this comment.
Added an inline comment. The new test case test_error_to_response_with_stdclass_data would also catch any future regression.
61429 (part of the Code Modernization effort, #63430) replaced the
isset()ternary inrest_convert_error_to_response()with a null coalescing operator, removing theis_array()guard. SinceWP_Error::get_all_error_data()can return data of any type, this causes a PHP fatal error when error data is astdClassobject.This PR reverts the line to its original form and adds a test case for
stdClasserror 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.