Make WordPress Core

Changeset 51408 for trunk


Ignore:
Timestamp:
07/12/2021 07:02:53 PM (5 years ago)
Author:
desrosj
Message:

Widgets: Use wp_sidebar_description() to retrieve a sidebar’s description.

This switches WP_REST_Sidebars_Controller to use wp_sidebar_description() for retrieving the description of a given sidebar instead of referencing the value in the $wp_registered_sidebars global variable directly.

wp_sidebar_description() uses wp_kses() to only allow the default list of $allowed_tags to be present in a sidebar’s description.

Props timothyblynjacobs, desrosj.
Fixes #53646.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php

    r51377 r51408  
    282282                        $sidebar['status']        = 'active';
    283283                        $sidebar['name']          = isset( $registered_sidebar['name'] ) ? $registered_sidebar['name'] : '';
    284                         $sidebar['description']   = isset( $registered_sidebar['description'] ) ? $registered_sidebar['description'] : '';
     284                        $sidebar['description']   = isset( $registered_sidebar['description'] ) ? wp_sidebar_description( $id ) : '';
    285285                        $sidebar['class']         = isset( $registered_sidebar['class'] ) ? $registered_sidebar['class'] : '';
    286286                        $sidebar['before_widget'] = isset( $registered_sidebar['before_widget'] ) ? $registered_sidebar['before_widget'] : '';
  • trunk/tests/phpunit/tests/rest-api/rest-sidebars-controller.php

    r51377 r51408  
    314314
    315315        /**
     316         * @ticket 53646
     317         */
     318        public function test_get_items_when_descriptions_have_markup() {
     319                register_sidebar(
     320                        array(
     321                                'name'          => 'New Sidebar',
     322                                'id'            => 'new-sidebar',
     323                                'description'   => '<iframe></iframe>This is a <b>description</b> with some <a href="#">markup</a>.<script></script>',
     324                                'before_widget' => '',
     325                                'after_widget'  => '',
     326                                'before_title'  => '',
     327                                'after_title'   => '',
     328                        )
     329                );
     330
     331                $request  = new WP_REST_Request( 'GET', '/wp/v2/sidebars' );
     332                $response = rest_get_server()->dispatch( $request );
     333                $data     = $response->get_data();
     334                $data     = $this->remove_links( $data );
     335                $this->assertSame(
     336                        array(
     337                                array(
     338                                        'id'            => 'wp_inactive_widgets',
     339                                        'name'          => 'Inactive widgets',
     340                                        'description'   => '',
     341                                        'class'         => '',
     342                                        'before_widget' => '',
     343                                        'after_widget'  => '',
     344                                        'before_title'  => '',
     345                                        'after_title'   => '',
     346                                        'status'        => 'inactive',
     347                                        'widgets'       => array(),
     348                                ),
     349                                array(
     350                                        'id'            => 'new-sidebar',
     351                                        'name'          => 'New Sidebar',
     352                                        'description'   => 'This is a <b>description</b> with some <a href="#">markup</a>.',
     353                                        'class'         => '',
     354                                        'before_widget' => '',
     355                                        'after_widget'  => '',
     356                                        'before_title'  => '',
     357                                        'after_title'   => '',
     358                                        'status'        => 'active',
     359                                        'widgets'       => array(),
     360                                ),
     361                        ),
     362                        $data
     363                );
     364        }
     365
     366        /**
    316367         * @ticket 41683
    317368         */
Note: See TracChangeset for help on using the changeset viewer.