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

Block Type: Add selectors to block.json schema #3942

Conversation

aaronrobertshaw
Copy link

This PR adds support for the new selectors property. It adds it to the allowed metadata when registering a block type, makes the WP_Block_Type class aware of it, exposes it through the block types REST API, and the get_block_editor_server_block_settings function.

There is a corresponding Gutenberg PR (WordPress/gutenberg#46496) that stabilizes the block.json selectors API and in part depends upon the changes here.

Trac ticket: https://core.trac.wordpress.org/ticket/57585


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions
Copy link

Hi @aaronrobertshaw! 👋

Thank you for your contribution to WordPress! 💖

It looks like this is your first pull request to wordpress-develop. Here are a few things to be aware of that may help you out!

No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description.

Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making.

More information about how GitHub pull requests can be used to contribute to WordPress can be found in this blog post.

Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook.

If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook.

The Developer Hub also documents the various coding standards that are followed:

Thank you,
The WordPress Project

@gziolo
Copy link
Member

gziolo commented Feb 13, 2023

It's nearly ready from my perspective. I left my comments, and deciding on the default value is the only important thing.

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

This is ready to go. We will need to wait with the commit until changes in the Gutenberg plugin land and the release cycle for WordPress 6.2 is finished. Feel free to remind me to to commit it to WordPress core when the time comes 😄

@aaronrobertshaw
Copy link
Author

@gziolo there have been a few changes here. I've added a second property to block types for editor-only selectors. Some background for this change can be found over on the related Gutenberg PR (WordPress/gutenberg#46496 (comment)).

Essentially, we went with the second property to match the existing style / editorStyle block type properties, so we'll offer selectors / editorSelectors.

@aaronrobertshaw aaronrobertshaw force-pushed the add/selectors-to-block-type-schema branch from 39bdd89 to 635ffee Compare March 16, 2023 07:05
@gziolo
Copy link
Member

gziolo commented Mar 16, 2023

Essentially, we went with the second property to match the existing style / editorStyle block type properties, so we'll offer selectors / editorSelectors.

Sounds good, and the code changes look correct. I'm not sure why e2e tests failed on CI but I restarted the job to see if that was only an incident.

@aaronrobertshaw
Copy link
Author

I'm not sure why e2e tests failed on CI but I restarted the job to see if that was only an incident.

Seems like you had the magic touch 🪄

I'd already re-run it twice before rebasing the PR and having it fail again.

@aaronrobertshaw
Copy link
Author

👍 Thanks for the feedback @hellofromtonya. I believe I've addressed all of that now in 82d1762

@aaronrobertshaw
Copy link
Author

There were some concerns raised around introducing support for editor-only selectors on the Gutenberg PR. For the time being, we'll remove that editor-only support so it can be discussed further and added at a future date.

As such, I've reverted the addition of editor selectors to block types here.

@gziolo
Copy link
Member

gziolo commented Apr 18, 2023

@aaronrobertshaw, it's been a while since all the changes landed in the Gutenberg plugin. Do you think it's good to go for WordPress core? The code changes look good.

@aaronrobertshaw
Copy link
Author

Thanks for the nudge @gziolo!

After the removal of the editor-only selectors from this API, it doesn't seem like there is a great appetite yet to see them return. I suspect it might take some time to find solutions to the issues facing editor-only selectors.

Given that, I believe the changes here are stable and as you note the Selectors API landed in Gutenberg 15.5 so they've in the wild for a little while.

There's no objections from my end to see this land in core 🙂

@gziolo
Copy link
Member

gziolo commented Apr 21, 2023

Committed with https://core.trac.wordpress.org/changeset/55673.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants