Make WordPress Core

Changeset 51412 for branches/5.8


Ignore:
Timestamp:
07/13/2021 12:09:11 AM (3 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, SergeyBiryukov.
Merges [51408] to the 5.8 branch.
Fixes #53646.

Location:
branches/5.8
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/5.8

  • branches/5.8/src/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php

    r51385 r51412  
    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'] : '';
  • branches/5.8/tests/phpunit/tests/rest-api/rest-sidebars-controller.php

    r51385 r51412  
    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.