| @@ -54,12 +54,13 @@ | ||
| 54 | 54 | 'transport' => 'postMessage', |
| 55 | 55 | 'sanitize_callback' => 'gutenberg_customize_sanitize', |
| 56 | 56 | ) |
| 57 | 57 | ); |
| 58 | - if ( gutenberg_is_experiment_enabled( 'gutenberg-widget-experiments' ) ) { | |
| 58 | + | |
| 59 | + if ( gutenberg_use_widgets_block_editor() ) { | |
| 59 | 60 | $wp_customize->add_section( |
| 60 | 61 | 'gutenberg_widget_blocks', |
| 61 | - array( 'title' => __( 'Widget Blocks (Experimental)', 'gutenberg' ) ) | |
| 62 | + array( 'title' => __( 'Widget Blocks', 'gutenberg' ) ) | |
| 62 | 63 | ); |
| 63 | 64 | $wp_customize->add_control( |
| 64 | 65 | new WP_Customize_Widget_Blocks_Control( |
| 65 | 66 | $wp_customize, |
| @@ -74,32 +75,25 @@ | ||
| 74 | 75 | } |
| 75 | 76 | add_action( 'customize_register', 'gutenberg_customize_register' ); |
| 76 | 77 | |
| 77 | 78 | /** |
| 78 | - * Specifies how to save the `gutenberg_widget_blocks` setting. It parses the JSON string and updates the | |
| 79 | - * referenced widget areas with the new content. | |
| 79 | + * Removes the core 'Widgets' panel from the Customizer if block based widgets are enabled. | |
| 80 | 80 | * |
| 81 | - * @param string $value The value that is being published. | |
| 82 | - * @param \WP_Customize_Setting $setting The setting instance. | |
| 81 | + * @param array $components Core Customizer components list. | |
| 82 | + * @return array (Maybe) modified components list. | |
| 83 | 83 | */ |
| 84 | -function gutenberg_customize_update( $value, $setting ) { | |
| 85 | - foreach ( json_decode( $value ) as $sidebar_id => $sidebar_content ) { | |
| 86 | - $id_referenced_in_sidebar = Experimental_WP_Widget_Blocks_Manager::get_post_id_referenced_in_sidebar( $sidebar_id ); | |
| 84 | +function gutenberg_remove_widgets_panel( $components ) { | |
| 85 | + if ( ! gutenberg_use_widgets_block_editor() ) { | |
| 86 | + return $components; | |
| 87 | + } | |
| 87 | 88 | |
| 88 | - $post_id = wp_insert_post( | |
| 89 | - array( | |
| 90 | - 'ID' => $id_referenced_in_sidebar, | |
| 91 | - 'post_content' => $sidebar_content, | |
| 92 | - 'post_type' => 'wp_area', | |
| 93 | - ) | |
| 94 | - ); | |
| 95 | - | |
| 96 | - if ( 0 === $id_referenced_in_sidebar ) { | |
| 97 | - Experimental_WP_Widget_Blocks_Manager::reference_post_id_in_sidebar( $sidebar_id, $post_id ); | |
| 98 | - } | |
| 89 | + $i = array_search( 'widgets', $components, true ); | |
| 90 | + if ( false !== $i ) { | |
| 91 | + unset( $components[ $i ] ); | |
| 99 | 92 | } |
| 93 | + return $components; | |
| 100 | 94 | } |
| 101 | -add_action( 'customize_update_gutenberg_widget_blocks', 'gutenberg_customize_update', 10, 2 ); | |
| 95 | +add_filter( 'customize_loaded_components', 'gutenberg_remove_widgets_panel' ); | |
| 102 | 96 | |
| 103 | 97 | /** |
| 104 | 98 | * Filters the Customizer widget settings arguments. |
| 105 | 99 | * This is needed because the Customizer registers settings for the raw registered widgets, without going through the `sidebars_widgets` filter. |