-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Enable customizer legacy widgets only if set #16956
Enable customizer legacy widgets only if set #16956
Conversation
@@ -40,6 +40,9 @@ export function initialize( id, settings ) { | |||
*/ | |||
export function customizerInitialize( id, settings ) { | |||
registerCoreBlocks(); | |||
if ( process.env.GUTENBERG_PHASE === 2 ) { | |||
__experimentalRegisterExperimentalCoreBlocks( settings ); |
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.
Why was this not here before? How was the legacy widget block being registered?
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.
Initially it was being registered in registerCoreBlocks
along with everything else. I moved all the experimental blocks out in my previous PR #16626 so we could enable/disable them more easily.
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.
Got it. Wouldn't that break the screen in the meantime though? If someone loads the Customizer, they won't have the legacy widget block registered right now?
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.
Yup, it's looking a bit broken now unless you have the setting enabled 😅
lib/customizer.php
Outdated
'gutenberg_widget_blocks', | ||
array( 'title' => __( 'Widget Blocks (Experimental)', 'gutenberg' ) ) | ||
); | ||
} | ||
$wp_customize->add_control( |
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.
Shouldn't we bail out of adding anything related to the widget blocks?
Adding the controls and filters without the section might still cause issues.
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.
Good point, I'll move it inside the condition.
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.
It's not just the section and controls though.
There are a lot of filters and actions there that modify legacy widget logic. Are we sure we are not breaking any expectations by leaving them there. Can we not just not load any file related to the customizer in load.php
?
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.
Hmm, that doesn't work. Loading customizer.php
conditionally causes the whole customizer page to crash when the widget experiment is disabled. The absence of add_filter( 'widget_customizer_setting_args', 'filter_widget_customizer_setting_args' );
is what does it, though I have no idea why. Not loading widgets.php
also causes problems when the experiment is disabled: the page loads with a warning that $sidebar_widget_ids
in class-wp-customize-widgets.php
is the wrong type. That one seems to be caused by the absence of add_filter( 'sidebars_widgets', 'Experimental_WP_Widget_Blocks_Manager::swap_out_sidebars_blocks_for_block_widgets' );
🤷♀
In any case, it's better to load customizer.php
by default because even though it's only being used for widget-related stuff now, that might change in the future, so isolating the widget logic within it now will save us work later.
I'd still like to know why not loading these filters causes everything to explode though 😁 . Maybe @jorgefilipecosta can shed some light on that?
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.
It's because the filters work together to change widget areas from storing an array of widgets to store a post ID. That's why I was thinking we should disable loading the entire files. I'm not sure if leaving some of the filters active could cause some weird side effects.
I guess that if we test it well enough and @jorgefilipecosta doesn't see any problems from his side then I'm happy to merge this.
7c2e74e
to
f9836bb
Compare
lib/widgets-page.php
Outdated
@@ -69,12 +69,16 @@ function gutenberg_widgets_init( $hook ) { | |||
); | |||
} | |||
|
|||
$experiments_exist = get_option( 'gutenberg-experiments' ); |
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.
Hi @tellthemachines instead of replicating logic from function gutenberg_experiments_editor_settings here could we just call it on return?
return gutenberg_experiments_editor_settings( $settings );
This would also take care of enabling navigation on the widgets screen, would remove duplicate code.
I followed this approach in #17005.
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.
Done!
8b64255
to
1c3495b
Compare
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.
Everything worked well on my tests 👍
Description
Follow-up from #16626 . Hides the legacy widgets section in the customizer if legacy widgets are not enabled in the experiments settings.
How has this been tested?
Locally, by navigating to "Experiments" under the Gutenberg menu and toggling the "Enable Widgets Screen and Legacy Widget Block" checkbox. "Widget Blocks (Experimental)" section should display in Customizer when setting is enabled and Legacy Widget block should appear in the blocks menu.
Screenshots
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist: