[wp-trac] [WordPress Trac] #52640: The rest_prepare_attachment filter runs twice during REST request
WordPress Trac
noreply at wordpress.org
Wed Feb 24 14:41:39 UTC 2021
#52640: The rest_prepare_attachment filter runs twice during REST request
--------------------------+-----------------------------
Reporter: chrisl27 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version: trunk
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
Hi,
For each `/wp/v2/media` call the `rest_prepare_attachment` filter is being
run twice. Once by `WP_REST_Posts_Controller` and then a second time by
`WP_REST_Attachments_Controller`.
This is due to `WP_REST_Attachments_Controller::prepare_item_for_response`
calling its class parent method, which calls apply_filters on
`"rest_prepare_{$this->post_type}"`
This may cause issues with code that expects the attachment to only be
prepared once, particularly where the response payload is different
between the two filter callbacks (eg doesn't include media sizes the first
time).
--
Ticket URL: <https://core.trac.wordpress.org/ticket/52640>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list