| 1 |
<?php |
| 2 |
/** |
| 3 |
* Bootstrapping the Gutenberg widgets editor in the customizer. |
| 4 |
* |
| 5 |
* @package gutenberg |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Gutenberg's Customize Register. |
| 10 |
* |
| 11 |
* Adds a section to the Customizer for editing widgets with Gutenberg. |
| 12 |
* |
| 13 |
* @param \WP_Customize_Manager $manager An instance of the class that controls most of the Theme Customization API for WordPress 3.4 and newer. |
| 14 |
*/ |
| 15 |
function gutenberg_widgets_customize_register( $manager ) { |
| 16 |
global $wp_registered_sidebars; |
| 17 |
|
| 18 |
if ( ! gutenberg_use_widgets_block_editor() ) { |
| 19 |
return; |
| 20 |
} |
| 21 |
|
| 22 |
require_once __DIR__ . '/class-wp-sidebar-block-editor-control.php'; |
| 23 |
|
| 24 |
foreach ( $manager->sections() as $section ) { |
| 25 |
if ( $section instanceof WP_Customize_Sidebar_Section ) { |
| 26 |
$section->description = ''; |
| 27 |
} |
| 28 |
} |
| 29 |
foreach ( $manager->controls() as $control ) { |
| 30 |
if ( |
| 31 |
$control instanceof WP_Widget_Area_Customize_Control || |
| 32 |
$control instanceof WP_Widget_Form_Customize_Control |
| 33 |
) { |
| 34 |
$manager->remove_control( $control->id ); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
foreach ( $wp_registered_sidebars as $sidebar_id => $sidebar ) { |
| 39 |
$manager->add_setting( |
| 40 |
"sidebars_widgets[$sidebar_id]", |
| 41 |
array( |
| 42 |
'capability' => 'edit_theme_options', |
| 43 |
'transport' => 'postMessage', |
| 44 |
) |
| 45 |
); |
| 46 |
|
| 47 |
$manager->add_control( |
| 48 |
new WP_Sidebar_Block_Editor_Control( |
| 49 |
$manager, |
| 50 |
"sidebars_widgets[$sidebar_id]", |
| 51 |
array( |
| 52 |
'section' => "sidebar-widgets-$sidebar_id", |
| 53 |
'settings' => "sidebars_widgets[$sidebar_id]", |
| 54 |
'sidebar_id' => $sidebar_id, |
| 55 |
) |
| 56 |
) |
| 57 |
); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
if ( gutenberg_is_experiment_enabled( 'gutenberg-widgets-in-customizer' ) ) { |
| 62 |
add_action( 'customize_register', 'gutenberg_widgets_customize_register' ); |
| 63 |
} |
| 64 |
|