Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect fields param for global styles REST API requests. #36206

Merged
merged 2 commits into from
Nov 8, 2021

Conversation

spacedmonkey
Copy link
Member

Description

The global styles endpoint, does not respect fields param passed a query string.

This fix, addresses that issue.

This PR also fixes protected titles.

How has this been tested?

Screenshots

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

@spacedmonkey spacedmonkey added Core REST API Task Task for Core REST API efforts REST API Interaction Related to REST API labels Nov 4, 2021
@spacedmonkey spacedmonkey self-assigned this Nov 4, 2021
@spacedmonkey
Copy link
Member Author

Fixes originally from #36076

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Supporting the _fields might be good here, we don't need it ourselves but it doesn't hurt I guess.

I'll defer to you all REST API folks.

$data['id'] = $post->ID;
}

if ( rest_is_field_included( 'title', $fields ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we include both raw and rendered here as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is what is happening in the line below 😄

$data['title']['raw'] = $post->post_title;
}
if ( rest_is_field_included( 'title.rendered', $fields ) ) {
add_filter( 'protected_title_format', array( $this, 'protected_title_format' ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

protected style variations is not something that is meaningful for the global styles IMO, so I'd rather remove all these "protected" handling.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how core handles protected titles. We can't do much about it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Global styles posts won't be password protected, so I'm not sure we need to handle it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better safe than sorry?

@spacedmonkey spacedmonkey merged commit 0a0e0ca into trunk Nov 8, 2021
@spacedmonkey spacedmonkey deleted the fix/fields branch November 8, 2021 21:46
@github-actions github-actions bot added this to the Gutenberg 12.0 milestone Nov 8, 2021
@spacedmonkey spacedmonkey added the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Nov 8, 2021
@andrewserong andrewserong mentioned this pull request Nov 9, 2021
28 tasks
@noisysocks noisysocks removed the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Nov 10, 2021
noisysocks pushed a commit that referenced this pull request Nov 10, 2021
* Respect fields param for REST API requests.

* Fix lint
andrewserong pushed a commit that referenced this pull request Nov 10, 2021
* Respect fields param for REST API requests.

* Fix lint
@andrewserong
Copy link
Contributor

Cherry picked into the Gutenberg 11.9 release in: b147195

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core REST API Task Task for Core REST API efforts REST API Interaction Related to REST API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants