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