Opened 11 months ago
Last modified 3 weeks ago
#62742 new defect (bug)
Add Missing REST API Filters to WP_REST_Global_Styles_Revisions_Controller
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Future Release | Priority: | normal |
| Severity: | normal | Version: | 6.7 |
| Component: | REST API | Keywords: | has-patch has-unit-tests |
| Focuses: | rest-api | Cc: |
Description
This ticket is created in response to a Gutenberg GitHub issue raised by anton-vlasenko and confirmed by ramonjd here https://github.com/WordPress/gutenberg/issues/68327
The issue highlights that the WP_REST_Global_Styles_Revisions_Controller class is missing standard WordPress REST API filters, such as rest_revision_query and rest_prepare_revision. According to ramonjd, the omission was intentional initially, as the endpoint was new and evolving, and public APIs were not introduced prematurely.
However, now that https://github.com/WordPress/wordpress-develop/pull/5699 has been completed, it makes sense to add these filters to align with WordPress REST API conventions and ensure consistency.
Proposed Solution:
Add the missing filters to the WP_REST_Global_Styles_Revisions_Controller class.
Use unique filter names, such as rest_global_styles_query and rest_prepare_global_styles_revision.
Backport these changes to WordPress Core for parity with Gutenberg and to provide developers with consistent, extensible APIs.
This update will enhance developer experience and maintain consistency with other REST controllers across the WordPress ecosystem.
Change History (9)
This ticket was mentioned in PR #8062 on WordPress/wordpress-develop by @vipulpatil.
11 months ago
#1
- Keywords has-patch added; needs-patch removed
@vipulpatil commented on PR #8062:
11 months ago
#2
@Mamaduka Can you take a look at this PR 🙇
@vipulpatil commented on PR #8062:
9 months ago
#3
@anton-vlasenko Can you look at this PR.
#4
@
7 months ago
- Milestone changed from Awaiting Review to 6.9
- Type changed from enhancement to defect (bug)
This ticket was mentioned in PR #9615 on WordPress/wordpress-develop by @vidugupta.
3 months ago
#5
- Keywords has-unit-tests added
Adds missing REST API filters to the WP_REST_Global_Styles_Revisions_Controller class for consistency with other REST controllers.
Changes Introduced
Adds rest_global_styles_query filter for customizing global styles revision queries.
Adds rest_prepare_global_styles_revision filter for modifying prepared revision data before the response.
References
Trac ticket: #62742
This ticket was mentioned in Slack in #core by vidugupta. View the logs.
3 months ago
#7
@
3 months ago
Tested the filters locally and confirmed both are working correctly:
Test command (in browser console while logged in to wp-admin):
fetch('/wp-json/wp/v2/global-styles/<id>/revisions', { headers: { 'X-WP-Nonce': wpApiSettings.nonce } }) .then(r => r.json()) .then(data => console.log(data));
Tested filters
add_filter( 'rest_global_styles_revision_query', function( $args, $request ) {
$args['posts_per_page'] = 1; // Modify query to return only one revision.
return $args;
}, 10, 2 );
add_filter( 'rest_prepare_global_styles_revision', function( $response, $post, $request ) {
$response->data['_test_filter_applied'] = true; // Modify response by adding a test field.
return $response;
}, 10, 3 );
Both filters trigger correctly and can modify query parameters and response data.
## Summary
This PR adds two standard WordPress REST API filters to the Global Styles Revisions controller:
rest_global_styles_revision_queryandrest_prepare_global_styles_revision.Currently, WP_REST_Global_Styles_Revisions_Controller lacks the standard WordPress REST filters, likely an oversight since other revision controllers include them.
### Changes Proposed
rest_global_styles_revision_queryfilter for query modificationrest_prepare_global_styles_revisionfilter for response data modificationTrac ticket: https://core.trac.wordpress.org/ticket/62742