Make WordPress Core

Changeset 60279


Ignore:
Timestamp:
06/05/2025 08:43:08 AM (5 months ago)
Author:
audrasjb
Message:

Customize: Prevent errors occuring with Classic Theme without Widgets.

This changeset prevents the customizer from displaying a warning when a classic theme has no widget area.

Props ArtZ91, SirLouen, audrasjb, dilipbheda.
Fixes #63151.

Location:
trunk
Files:
2 edited

Legend:

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

    r59676 r60279  
    922922                <h3>
    923923                    <span class="customize-action">
    924                     <?php
     924                        <?php
     925                        $panel       = $this->manager->get_panel( 'widgets' );
     926                        $panel_title = $panel && isset( $panel->title ) ? $panel->title : __( 'Widgets' );
    925927                        /* translators: &#9656; is the unicode right-pointing triangle. %s: Section title in the Customizer. */
    926                         printf( __( 'Customizing &#9656; %s' ), esc_html( $this->manager->get_panel( 'widgets' )->title ) );
    927                     ?>
     928                        printf( __( 'Customizing &#9656; %s' ), esc_html( $panel_title ) );
     929                        ?>
    928930                    </span>
    929931                    <?php _e( 'Add a Widget' ); ?>
  • trunk/tests/phpunit/tests/customize/widgets.php

    r60253 r60279  
    873873        $this->manager->widgets->remove_prepreview_filters();
    874874    }
     875
     876    /**
     877     * Test that output_widget_control_templates() works without sidebars.
     878     * This test verifies that the fix for accessing panel title works correctly
     879     * when no sidebars are registered or the widgets panel doesn't exist.
     880     *
     881     * @ticket 63151
     882     *
     883     * @covers WP_Customize_Widgets::output_widget_control_templates
     884     */
     885    public function test_output_widget_control_templates_without_sidebars() {
     886        global $wp_registered_sidebars;
     887
     888        $original_sidebars      = $wp_registered_sidebars;
     889        $wp_registered_sidebars = array();
     890        $manager                = new WP_Customize_Manager();
     891        $widgets                = new WP_Customize_Widgets( $manager );
     892
     893        if ( $manager->get_panel( 'widgets' ) ) {
     894            $manager->remove_panel( 'widgets' );
     895        }
     896
     897        ob_start();
     898
     899        $widgets->output_widget_control_templates();
     900
     901        $output                 = ob_get_clean();
     902        $wp_registered_sidebars = $original_sidebars;
     903
     904        $this->assertStringNotContainsString( 'Warning', $output, 'Failed asserting that the output does not contain "Warning".' );
     905        $this->assertStringNotContainsString( 'Notice', $output, 'Failed asserting that the output does not contain "Notice".' );
     906        $this->assertStringNotContainsString( 'Error', $output, 'Failed asserting that the output does not contain "Error".' );
     907
     908        // Check that the output contains expected widget controls HTML.
     909        $this->assertStringContainsString( 'id="widgets-left"', $output, 'Failed asserting that the output contains "id=widgets-left".' );
     910        $this->assertStringContainsString( 'id="available-widgets"', $output, 'Failed asserting that the output contains "id=available-widgets".' );
     911        $this->assertStringNotContainsString( 'id="accordion-panel-widgets"', $output, 'Failed asserting that the output does not contain "id=accordion-panel-widgets".' );
     912    }
    875913}
Note: See TracChangeset for help on using the changeset viewer.