Make WordPress Core

Changeset 51228


Ignore:
Timestamp:
06/24/2021 07:19:57 PM (5 years ago)
Author:
desrosj
Message:

Widgets: Add missing label and description to Customizer controls.

This fixes a bug where the “Move To” dialogue was empty when a theme has multiple widget areas.

Props kevin940726, noisysocks, hellofromTonya.
Fixes #53487.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-widgets.php

    r51149 r51228  
    481481                                                        $setting_id,
    482482                                                        array(
    483                                                                 'section'    => $section_id,
    484                                                                 'sidebar_id' => $sidebar_id,
     483                                                                'section'     => $section_id,
     484                                                                'sidebar_id'  => $sidebar_id,
     485                                                                'label'       => $section_args['title'],
     486                                                                'description' => $section_args['description'],
    485487                                                        )
    486488                                                );
  • trunk/tests/phpunit/tests/customize/widgets.php

    r51088 r51228  
    143143                $this->manager->widgets->customize_register();
    144144                $this->assertSame( array_fill_keys( array( 'wp_inactive_widgets', $sidebar_id ), array() ), wp_get_sidebars_widgets() );
     145        }
     146
     147        /**
     148         * Tests the label and description controls when registering sidebars with Customizer.
     149         *
     150         * @ticket       53487
     151         * @dataProvider data_customize_register_control_label_and_description
     152         * @covers       WP_Customize_Widgets::customize_register
     153         */
     154        public function test_customize_register_control_label_and_description( $sidebars, $use_classic_widgets, $expected ) {
     155                if ( $use_classic_widgets ) {
     156                        add_filter( 'use_widgets_block_editor', '__return_false' );
     157                }
     158
     159                foreach ( $sidebars as $args ) {
     160                        register_sidebar( $args );
     161                }
     162
     163                $this->manager->widgets->customize_register();
     164
     165                $label       = array();
     166                $description = array();
     167                foreach ( array_keys( $sidebars ) as $sidebar_id ) {
     168                        $control_id    = "sidebars_widgets[{$sidebar_id}]";
     169                        $control       = $this->manager->get_control( $control_id );
     170                        $label[]       = $control->label;
     171                        $description[] = $control->description;
     172                }
     173
     174                $this->assertSame( $expected['label'], $label );
     175                $this->assertSame( $expected['description'], $description );
     176        }
     177
     178        public function data_customize_register_control_label_and_description() {
     179                return array(
     180                        'with widgets block editor' => array(
     181                                'sidebars'            => array(
     182                                        'footer-1' => array(
     183                                                'id'          => 'footer-1',
     184                                                'name'        => 'Footer 1',
     185                                                'description' => 'This is the Footer 1 sidebar.',
     186                                        ),
     187                                        'footer-2' => array(
     188                                                'id'          => 'footer-2',
     189                                                'name'        => 'Footer 2',
     190                                                'description' => 'This is the Footer 2 sidebar.',
     191                                        ),
     192                                ),
     193                                'use_classic_widgets' => false,
     194                                'expected'            => array(
     195                                        'label'       => array( 'Footer 1', 'Footer 2' ),
     196                                        'description' => array( '', '' ),
     197                                ),
     198                        ),
     199                        'with classic widgets'      => array(
     200                                'sidebars'            => array(
     201                                        'classic-1' => array(
     202                                                'id'          => 'classic-1',
     203                                                'name'        => 'Classic 1',
     204                                                'description' => 'This is the Classic 1 sidebar.',
     205                                        ),
     206                                        'classic-2' => array(
     207                                                'id'          => 'classic-2',
     208                                                'name'        => 'Classic 2',
     209                                                'description' => 'This is the Classic 2 sidebar.',
     210                                        ),
     211                                        'classic-3' => array(
     212                                                'id'          => 'classic-3',
     213                                                'name'        => 'Classic 3',
     214                                                'description' => 'This is the Classic 3 sidebar.',
     215                                        ),
     216                                ),
     217                                'use_classic_widgets' => true,
     218                                'expected'            => array(
     219                                        'label'       => array( '', '', '' ),
     220                                        'description' => array( '', '', '' ),
     221                                ),
     222                        ),
     223                );
    145224        }
    146225
Note: See TracChangeset for help on using the changeset viewer.