From 3dc566ba89d35168d506d370eb37348d9c72b2cf Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Thu, 24 Jun 2021 19:19:57 +0000 Subject: [PATCH] Widgets: Add missing `label` and `description` to Customizer controls. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes a bug where the “Move To” dialogue was empty when a theme has multiple widget areas. Props kevin940726, noisysocks, hellofromTonya. Fixes #53487. git-svn-id: https://develop.svn.wordpress.org/trunk@51228 602fd350-edb4-49c9-b593-d223f7449a82 --- .../class-wp-customize-widgets.php | 6 +- tests/phpunit/tests/customize/widgets.php | 79 +++++++++++++++++++ 2 files changed, 83 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/class-wp-customize-widgets.php b/src/wp-includes/class-wp-customize-widgets.php index 03a3109680..7f1be455a3 100644 --- a/src/wp-includes/class-wp-customize-widgets.php +++ b/src/wp-includes/class-wp-customize-widgets.php @@ -480,8 +480,10 @@ final class WP_Customize_Widgets { $this->manager, $setting_id, array( - 'section' => $section_id, - 'sidebar_id' => $sidebar_id, + 'section' => $section_id, + 'sidebar_id' => $sidebar_id, + 'label' => $section_args['title'], + 'description' => $section_args['description'], ) ); } else { diff --git a/tests/phpunit/tests/customize/widgets.php b/tests/phpunit/tests/customize/widgets.php index 432a183255..f872ff12ee 100644 --- a/tests/phpunit/tests/customize/widgets.php +++ b/tests/phpunit/tests/customize/widgets.php @@ -144,6 +144,85 @@ class Tests_WP_Customize_Widgets extends WP_UnitTestCase { $this->assertSame( array_fill_keys( array( 'wp_inactive_widgets', $sidebar_id ), array() ), wp_get_sidebars_widgets() ); } + /** + * Tests the label and description controls when registering sidebars with Customizer. + * + * @ticket 53487 + * @dataProvider data_customize_register_control_label_and_description + * @covers WP_Customize_Widgets::customize_register + */ + public function test_customize_register_control_label_and_description( $sidebars, $use_classic_widgets, $expected ) { + if ( $use_classic_widgets ) { + add_filter( 'use_widgets_block_editor', '__return_false' ); + } + + foreach ( $sidebars as $args ) { + register_sidebar( $args ); + } + + $this->manager->widgets->customize_register(); + + $label = array(); + $description = array(); + foreach ( array_keys( $sidebars ) as $sidebar_id ) { + $control_id = "sidebars_widgets[{$sidebar_id}]"; + $control = $this->manager->get_control( $control_id ); + $label[] = $control->label; + $description[] = $control->description; + } + + $this->assertSame( $expected['label'], $label ); + $this->assertSame( $expected['description'], $description ); + } + + public function data_customize_register_control_label_and_description() { + return array( + 'with widgets block editor' => array( + 'sidebars' => array( + 'footer-1' => array( + 'id' => 'footer-1', + 'name' => 'Footer 1', + 'description' => 'This is the Footer 1 sidebar.', + ), + 'footer-2' => array( + 'id' => 'footer-2', + 'name' => 'Footer 2', + 'description' => 'This is the Footer 2 sidebar.', + ), + ), + 'use_classic_widgets' => false, + 'expected' => array( + 'label' => array( 'Footer 1', 'Footer 2' ), + 'description' => array( '', '' ), + ), + ), + 'with classic widgets' => array( + 'sidebars' => array( + 'classic-1' => array( + 'id' => 'classic-1', + 'name' => 'Classic 1', + 'description' => 'This is the Classic 1 sidebar.', + ), + 'classic-2' => array( + 'id' => 'classic-2', + 'name' => 'Classic 2', + 'description' => 'This is the Classic 2 sidebar.', + ), + 'classic-3' => array( + 'id' => 'classic-3', + 'name' => 'Classic 3', + 'description' => 'This is the Classic 3 sidebar.', + ), + ), + 'use_classic_widgets' => true, + 'expected' => array( + 'label' => array( '', '', '' ), + 'description' => array( '', '', '' ), + ), + ), + ); + } + /** * Tests WP_Customize_Widgets::get_selective_refreshable_widgets(). *