Make WordPress Core

Changeset 57743


Ignore:
Timestamp:
02/29/2024 02:28:52 PM (3 months ago)
Author:
swissspidy
Message:

Interactivity API: Revert [57742] pending a Gutenberg package update.

This function can only be renamed after updating Gutenberg npm packages, as some of the core blocks already use this function.

See #60575.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/interactivity-api/interactivity-api.php

    r57742 r57743  
    150150 * Example:
    151151 *
    152  *     <div <?php echo wp_interactivity_data_wp_context( array( 'isOpen' => true, 'count' => 0 ) ); ?>>
     152 *     <div <?php echo data_wp_context( array( 'isOpen' => true, 'count' => 0 ) ); ?>>
    153153 *
    154154 * @since 6.5.0
     
    159159 *                the store namespace if specified.
    160160 */
    161 function wp_interactivity_data_wp_context( array $context, string $store_namespace = '' ): string {
     161function data_wp_context( array $context, string $store_namespace = '' ): string {
    162162    return 'data-wp-context=\'' .
    163163        ( $store_namespace ? $store_namespace . '::' : '' ) .
  • trunk/tests/phpunit/tests/interactivity-api/interactivity-api.php

    r57742 r57743  
    315315
    316316    /**
    317      * Tests that wp_interactivity_data_wp_context function correctly converts different array
     317     * Tests that data_wp_context function correctly converts different array
    318318     * structures to a JSON string.
    319319     *
    320320     * @ticket 60356
    321321     *
    322      * @covers ::wp_interactivity_data_wp_context
    323      */
    324     public function test_wp_interactivity_data_wp_context_with_different_arrays() {
    325         $this->assertEquals( 'data-wp-context=\'{}\'', wp_interactivity_data_wp_context( array() ) );
     322     * @covers ::data_wp_context
     323     */
     324    public function test_data_wp_context_with_different_arrays() {
     325        $this->assertEquals( 'data-wp-context=\'{}\'', data_wp_context( array() ) );
    326326        $this->assertEquals(
    327327            'data-wp-context=\'{"a":1,"b":"2","c":true}\'',
    328             wp_interactivity_data_wp_context(
     328            data_wp_context(
    329329                array(
    330330                    'a' => 1,
     
    336336        $this->assertEquals(
    337337            'data-wp-context=\'{"a":[1,2]}\'',
    338             wp_interactivity_data_wp_context( array( 'a' => array( 1, 2 ) ) )
     338            data_wp_context( array( 'a' => array( 1, 2 ) ) )
    339339        );
    340340        $this->assertEquals(
    341341            'data-wp-context=\'[1,2]\'',
    342             wp_interactivity_data_wp_context( array( 1, 2 ) )
    343         );
    344     }
    345 
    346     /**
    347      * Tests that wp_interactivity_data_wp_context function correctly converts different array
     342            data_wp_context( array( 1, 2 ) )
     343        );
     344    }
     345
     346    /**
     347     * Tests that data_wp_context function correctly converts different array
    348348     * structures to a JSON string and adds a namespace.
    349349     *
    350350     * @ticket 60356
    351351     *
    352      * @covers ::wp_interactivity_data_wp_context
    353      */
    354     public function test_wp_interactivity_data_wp_context_with_different_arrays_and_a_namespace() {
    355         $this->assertEquals( 'data-wp-context=\'myPlugin::{}\'', wp_interactivity_data_wp_context( array(), 'myPlugin' ) );
     352     * @covers ::data_wp_context
     353     */
     354    public function test_data_wp_context_with_different_arrays_and_a_namespace() {
     355        $this->assertEquals( 'data-wp-context=\'myPlugin::{}\'', data_wp_context( array(), 'myPlugin' ) );
    356356        $this->assertEquals(
    357357            'data-wp-context=\'myPlugin::{"a":1,"b":"2","c":true}\'',
    358             wp_interactivity_data_wp_context(
     358            data_wp_context(
    359359                array(
    360360                    'a' => 1,
     
    367367        $this->assertEquals(
    368368            'data-wp-context=\'myPlugin::{"a":[1,2]}\'',
    369             wp_interactivity_data_wp_context( array( 'a' => array( 1, 2 ) ), 'myPlugin' )
     369            data_wp_context( array( 'a' => array( 1, 2 ) ), 'myPlugin' )
    370370        );
    371371        $this->assertEquals(
    372372            'data-wp-context=\'myPlugin::[1,2]\'',
    373             wp_interactivity_data_wp_context( array( 1, 2 ), 'myPlugin' )
    374         );
    375     }
    376 
    377     /**
    378      * Tests that wp_interactivity_data_wp_context function correctly applies the JSON encoding
     373            data_wp_context( array( 1, 2 ), 'myPlugin' )
     374        );
     375    }
     376
     377    /**
     378     * Tests that data_wp_context function correctly applies the JSON encoding
    379379     * flags. This ensures that characters like `<`, `>`, `'`, or `&` are
    380380     * properly escaped in the JSON-encoded string to prevent potential XSS
     
    383383     * @ticket 60356
    384384     *
    385      * @covers ::wp_interactivity_data_wp_context
    386      */
    387     public function test_wp_interactivity_data_wp_context_with_json_flags() {
    388         $this->assertEquals( 'data-wp-context=\'{"tag":"\u003Cfoo\u003E"}\'', wp_interactivity_data_wp_context( array( 'tag' => '<foo>' ) ) );
    389         $this->assertEquals( 'data-wp-context=\'{"apos":"\u0027bar\u0027"}\'', wp_interactivity_data_wp_context( array( 'apos' => "'bar'" ) ) );
    390         $this->assertEquals( 'data-wp-context=\'{"quot":"\u0022baz\u0022"}\'', wp_interactivity_data_wp_context( array( 'quot' => '"baz"' ) ) );
    391         $this->assertEquals( 'data-wp-context=\'{"amp":"T\u0026T"}\'', wp_interactivity_data_wp_context( array( 'amp' => 'T&T' ) ) );
     385     * @covers ::data_wp_context
     386     */
     387    public function test_data_wp_context_with_json_flags() {
     388        $this->assertEquals( 'data-wp-context=\'{"tag":"\u003Cfoo\u003E"}\'', data_wp_context( array( 'tag' => '<foo>' ) ) );
     389        $this->assertEquals( 'data-wp-context=\'{"apos":"\u0027bar\u0027"}\'', data_wp_context( array( 'apos' => "'bar'" ) ) );
     390        $this->assertEquals( 'data-wp-context=\'{"quot":"\u0022baz\u0022"}\'', data_wp_context( array( 'quot' => '"baz"' ) ) );
     391        $this->assertEquals( 'data-wp-context=\'{"amp":"T\u0026T"}\'', data_wp_context( array( 'amp' => 'T&T' ) ) );
    392392    }
    393393}
Note: See TracChangeset for help on using the changeset viewer.