[wp-trac] [WordPress Trac] #53099: PHP warnings due to wp_check_term_meta_support_prefilter callback
WordPress Trac
noreply at wordpress.org
Tue Apr 27 15:16:29 UTC 2021
#53099: PHP warnings due to wp_check_term_meta_support_prefilter callback
--------------------------+-----------------------------
Reporter: david.binda | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version: 5.5
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
Following PHP warnings might be triggered in case the callback to
`get_term_metadata` filter (inside the `get_metadata_raw` function)
returns `false`. For instance, as the default
`wp_check_term_meta_support_prefilter` callback does:
{{{
Warning: Invalid argument supplied for foreach() in wp-includes/rest-
api/fields/class-wp-rest-meta-fields.php on line 97
Warning: array_filter() expects parameter 1 to be array, bool given in wp-
includes/rest-api/fields/class-wp-rest-meta-fields.php on line 293
Warning: array_keys() expects parameter 1 to be array, null given in wp-
includes/rest-api/fields/class-wp-rest-meta-fields.php on line 293
Warning: array_map(): Expected parameter 2 to be an array, bool given in
wp-includes/rest-api/fields/class-wp-rest-meta-fields.php on line 317
Warning: array_unique() expects parameter 1 to be array, null given in wp-
includes/rest-api/fields/class-wp-rest-meta-fields.php on line 317
Warning: Invalid argument supplied for foreach() in wp-includes/rest-
api/fields/class-wp-rest-meta-fields.php on line 319.
}}}
While the default callback returns bool (`false`) only on installations
with old DB schema, pre term meta feature (and thus does not really
produce the warnings in default state), the callback with it's `false`
might serve as an example on how to short-circuit the `get_metadata_raw`
function.
Further, the `get_metadata_raw` function, or `get_metadata` which is
calling that one, may also return `false` for other issues.
That said, the boolean value returned by `get_metadata` function call is
something what should, IMHO, be taken into consideration whenever working
with the `get_metadata` function.
However the methods in `WP_REST_Meta_Fields` class do not check the return
value, and expect an array to be returned.
The code, IMHO, should check for the value being an array before using it
as an array in related cases.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/53099>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list