[wp-trac] [WordPress Trac] #62287: WP_REST_Posts_Controller::prepare_items_query() - Warning $prepared_args can be null
WordPress Trac
noreply at wordpress.org
Wed Oct 23 11:02:16 UTC 2024
#62287: WP_REST_Posts_Controller::prepare_items_query() - Warning $prepared_args
can be null
--------------------------+-----------------------------
Reporter: apermo | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version:
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
In a project I maintain, we are using sentry, and I've received a warning.
`Warning: foreach() argument must be of type array|object, null given`
For:
`/wp/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php in
WP_REST_Posts_Controller::prepare_items_query at line 1124`
This happens for `GET` request on `/wp-json/wp/vs/posts` with the query
parameters `order`, `orderby` and `per_page`
I could not yet figure out, why `null` was given, but I propose to add a
`is_array()` condition around the loop. This will work as intended,
without possibly throwing errors as a type hint in the function header
woul.d
I will prepare a PR on github with a proposed solution, that will ensure,
this warning will not show up.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/62287>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list