[wp-trac] [WordPress Trac] #62646: PHP Warning in REST API when post_type doesn't support post-formats, but a post-format filter is applied.

WordPress Trac noreply at wordpress.org
Thu Dec 5 03:38:39 UTC 2024


#62646: PHP Warning in REST API when post_type doesn't support post-formats, but a
post-format filter is applied.
--------------------------+-----------------------------
 Reporter:  dd32          |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  REST API      |    Version:  6.7
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 In #62014 querying for post types via the `?format` query parameter was
 added.

 This has caused some PHP Warnings to be emitted when querying with an
 invalid post-format on a post_type that does not support post formats.

 For example:
 {{{
 GET https://example.org/wp-json/wp/v2/pt-no-post-formats?format=json

 E_WARNING: in_array() expects parameter 2 to be array, string given in wp-
 includes/rest-api/endpoints/class-wp-rest-posts-controller.php:363
 E_WARNING: array_map(): Expected parameter 2 to be an array, string given
 in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:380
 }}}

 This is caused by the "pt-no-post-formats" post_type not supporting post-
 formats, and as such, not having the `format` query param added to the
 endpoints schema.
 https://core.trac.wordpress.org/browser/trunk/src/wp-includes/rest-
 api/endpoints/class-wp-rest-posts-
 controller.php?rev=59453&marks=3050-3060#L3047

 In itself, that's not a concern, but the logic in the endpoint then only
 checks to see if the `format` query parameter is present - not that the
 post_type supports it, and then treating it as an array (As the schema has
 validated that it is one)
 https://core.trac.wordpress.org/browser/trunk/src/wp-includes/rest-
 api/endpoints/class-wp-rest-posts-controller.php?rev=59453&marks=349#L346

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/62646>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list