-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Set $name on WP_Block_Editor_Context #39299
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
Conversation
Configures the Gutenberg plugin to set $name on WP_Block_Editor_Context wherever the plugin initializes an editor. This helps plugins identify which editor they are customizing in filters such as 'allowed_block_types_all'. Passing the extra array param is a no-op on versions of WordPress prior to 6.0 which do not have WP_Block_Editor_Context::$name. See WordPress/wordpress-develop#2374.
| $settings = gutenberg_get_block_editor_settings( $settings ); | ||
|
|
||
| $context = new WP_Block_Editor_Context( array( 'name' => 'core/edit-navigation' ) ); | ||
| $settings = get_block_editor_settings( $custom_settings, $context ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the Navigation screen to use get_block_editor_settings which is the more canonical way to do this. Difficult to test though since the Navigation screen is mostly borked 😅
| */ | ||
| public function get_items( $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis | ||
| $editor_context = new WP_Block_Editor_Context(); | ||
| $editor_context = new WP_Block_Editor_Context( array( 'name' => 'core/edit-site' ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is tricky. Technically there's no screen at all since it's just a REST API endpoint. I did some digging and this endpoint is used by the mobile apps for Global Styles (#29063), so I think using core/edit-site makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the same thing as the 'site' entity?
gutenberg/packages/core-data/src/entities.js
Lines 28 to 36 in 5f265e9
| { | |
| label: __( 'Site' ), | |
| name: 'site', | |
| kind: 'root', | |
| baseURL: '/wp/v2/settings', | |
| getTitle: ( record ) => { | |
| return get( record, [ 'title' ], __( 'Site Title' ) ); | |
| }, | |
| }, |
edit: Oh, no, different namespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels like it probably shouldn't have a name, or the name should be passed as a param to the REST request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the same thing as the 'site' entity?
It's not, no. I can't see anywhere where this endpoint is being used but I assume from the issue (#29063) that it's used by the mobile app somehow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels like it probably shouldn't have a
name
Yeah maybe name needs to be optional after all 😕
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@geriux worked on the mobile integration so he might be the best person to share recommendations here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't see anywhere where this endpoint is being used but I assume from the issue (#29063) that it's used by the mobile app somehow.
That's correct, this is currently used on the WordPress mobile app to load the global styles data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In regards to the name, the one that's currently set core/edit-site doesn't affect the response data we need so that works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
talldan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and the wordpress-develop PR (WordPress/wordpress-develop#2374) look good to me 👍
|
Thanks everyone. https://core.trac.wordpress.org/changeset/52942 committed the Core component of this. We may as well get these changes in Gutenberg, though they'll be a no-op if Gutenberg is not running against latest Core trunk. |
What?
Compliments WordPress/wordpress-develop#2374 by configuring the Gutenberg plugin to set
$nameonWP_Block_Editor_Contextwherever the plugin initialises an editor.Why?
It's anticipated that
WP_Block_Editor_Context::$namewill land in WP 6.0. See WordPress/wordpress-develop#2374. It was added so that plugins can identify which editor they are customising when using filters such asallowed_block_types_all. See #28517.How?
Passes
'name'to the constructor ofWP_Block_Editor_Context. This is a safe no-op in versions of WordPress prior to 6.0which won't have
WP_Block_Editor_Context::$name.Testing Instructions
Here's some code you can put into e.g.
wp-content/mu-plugins/allowed-blocks.php:With the above plugin running, activate the plugin and navigate to Appearance → Editor. You should only be allowed to add a Paragraph block.