Opened 4 months ago
Last modified 4 months ago
#62287 new defect (bug)
WP_REST_Posts_Controller::prepare_items_query() - Warning $prepared_args can be null
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | REST API | Keywords: | has-patch |
Focuses: | Cc: |
Description
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.
Change History (1)
This ticket was mentioned in PR #7625 on WordPress/wordpress-develop by @apermo.
4 months ago
#1
- Keywords has-patch added
As discribed in the track ticket, it is possible that
prepare_items_query()
can receive a null value as$prepared_args
which results in a warning. This fixes this issue.Trac ticket: https://core.trac.wordpress.org/ticket/62287