WordPress.org

Make WordPress Core

Changeset 51174


Ignore:
Timestamp:
06/17/2021 11:28:55 AM (6 weeks ago)
Author:
SergeyBiryukov
Message:

REST API: Decode HTML entities in widget names and descriptions in widget types controller.

Follow-up to [50995].

Props ramonopoly, noisysocks, spacedmonkey, justinahinon, audrasjb, SergeyBiryukov.
Fixes #53407.

Location:
trunk
Files:
2 edited

Legend:

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

    r51049 r51174  
    211211            $widget_object = $wp_widget_factory->get_widget_object( $parsed_id['id_base'] );
    212212
    213             $widget['id']       = $parsed_id['id_base'];
    214             $widget['is_multi'] = (bool) $widget_object;
     213            $widget['id']          = $parsed_id['id_base'];
     214            $widget['is_multi']    = (bool) $widget_object;
     215
     216            if ( isset( $widget['name'] ) ) {
     217                $widget['name'] = html_entity_decode( $widget['name'] );
     218            }
     219
     220            if ( isset( $widget['description'] ) ) {
     221                $widget['description'] = html_entity_decode( $widget['description'] );
     222            }
    215223
    216224            unset( $widget['callback'] );
  • trunk/tests/phpunit/tests/rest-api/rest-widget-types-controller.php

    r51137 r51174  
    200200
    201201    /**
     202     * @ticket 53407
     203     */
     204    public function test_get_widgets_decodes_html_entities() {
     205        wp_set_current_user( self::$admin_id );
     206        $widget_id = 'archives';
     207        wp_register_sidebar_widget(
     208            $widget_id,
     209            'Legacy ‑ Archive ‑ Widget',
     210            function() {},
     211            array(
     212                'description' => 'A great & interesting archive of your site’s posts!',
     213            )
     214        );
     215        $request  = new WP_REST_Request( 'GET', '/wp/v2/widget-types/archives' );
     216        $response = rest_get_server()->dispatch( $request );
     217        $data     = $response->get_data();
     218        $this->assertSame( 'Legacy ‑ Archive ‑ Widget', $data['name'] );
     219        $this->assertSame( 'A great & interesting archive of your site’s posts!', $data['description'] );
     220    }
     221
     222    /**
    202223     * @ticket 41683
    203224     */
     
    493514    }
    494515
    495 
    496516    /**
    497517     * The test_create_item() method does not exist for widget types.
Note: See TracChangeset for help on using the changeset viewer.