-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 editor: pass assets through block_editor_settings_all #35950
Block editor: pass assets through block_editor_settings_all #35950
Conversation
Size Change: -2.6 kB (0%) Total Size: 1.08 MB
ℹ️ View Unchanged
|
Thanks for working on this. How can I best help test this? |
Hey, took a look at this and read through a bit of related context (iframe). I see how this PR is replacing I'm struggling to see how this changes the status quo for the second item mentioned in the description ("Currently it is very hard for themes to add styles to the editor through the WP dependency system."). Is this perhaps something you plan to add in a follow-up? |
No, this is done in this PR. The following is now possible: add_filter(
'block_editor_settings_all',
function( $settings ) {
wp_register_style( 'my-theme-stylesheet', get_stylesheet_uri() );
$settings['assets']['styles'][] = 'my-theme-stylesheet';
return $settings;
}
); |
Still testing but I am seeing: |
Tested in emptytheme: Tested in Twenty Twenty-One where I made the change on top of this PR. |
It's not worth it to test yet, I'm still working on this PR. I'm more wondering if you all agree with the proposal. |
I think the functionality is great and very much needed :) This will make adding styles correctly in the editor much easier. I wonder though whether we can use the ability of what you added here to create a nicer API for it. Something like wp_register_style( 'my-theme-stylesheet', get_stylesheet_uri() );
add_block_editor_style( 'my-theme-stylesheet' ); Which could intern do something like function add_block_editor_style( $handle ) {
add_filter(
'block_editor_settings_all',
function( $settings ) {
$settings['assets']['styles'][] = $handle;
return $settings;
}
);
} I know there are many issues with the example that I provided above and I would also 100% ship this without that syntactical sugar to see how it will actually get used. But I think that in comparison to how enqueueing assets works in the rest of WordPress this manual manipulation of the settings array feels rather crude/low level where you can more easily screw something up. So again I think this is a great and very valuable addition that is much needed :) Thank you for working on it! 🚀 |
4ad5965
to
20d8ed2
Compare
5a5b369
to
6b2a3b6
Compare
9910b2f
to
261e232
Compare
6b2a3b6
to
ffe5cfe
Compare
I agree with @jasmussen, we should have an early version ready for 5.9 to avoid the warnings mentioned in #33212, as there are plugins heavily impacted by these. |
eeb5677
to
1b15d4c
Compare
Description
See #35018 and #33212 for discussions.
This PR attempts to solve two problems:
add_editor_style
only accepts URLs, not WP dependency handles for styles. This makes it impossible to usewp_add_inline_style
. We need a way for themes to be able to add WP dependency handles to the block editor's content (iframe) just like blocks can through registration.The idea: allow anyone (including themes) to add style and script dependencies for the block editor content through the block editor settings.
And if in the future we make themes that are just CSS and JSON, the use case of inline styles for dynamic styling should disappear.
To do: add test with the above example code.To do: load the styles outside iframed editors and prefix the rules.
How has this been tested?
Screenshots
Types of changes
Checklist:
*.native.js
files for terms that need renaming or removal).