Skip to content

Commit a92b25a

Browse files
committed
Interactivity API: Rename data_wp_context() to wp_interactivity_data_wp_context().
Increases clarity about where the function belongs to, bringing it in line with other related functions. Props swissspidy, gziolo, cbravobernal, youknowriad, ankitmaru, westonruter, luisherranz, darerodz. Fixes #60575. git-svn-id: https://develop.svn.wordpress.org/trunk@57742 602fd350-edb4-49c9-b593-d223f7449a82
1 parent f9ab386 commit a92b25a

2 files changed

Lines changed: 23 additions & 23 deletions

File tree

src/wp-includes/interactivity-api/interactivity-api.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ function wp_interactivity_config( string $store_namespace, array $config = array
149149
*
150150
* Example:
151151
*
152-
* <div <?php echo data_wp_context( array( 'isOpen' => true, 'count' => 0 ) ); ?>>
152+
* <div <?php echo wp_interactivity_data_wp_context( array( 'isOpen' => true, 'count' => 0 ) ); ?>>
153153
*
154154
* @since 6.5.0
155155
*
@@ -158,7 +158,7 @@ function wp_interactivity_config( string $store_namespace, array $config = array
158158
* @return string A complete `data-wp-context` directive with a JSON encoded value representing the context array and
159159
* the store namespace if specified.
160160
*/
161-
function data_wp_context( array $context, string $store_namespace = '' ): string {
161+
function wp_interactivity_data_wp_context( array $context, string $store_namespace = '' ): string {
162162
return 'data-wp-context=\'' .
163163
( $store_namespace ? $store_namespace . '::' : '' ) .
164164
( empty( $context ) ? '{}' : wp_json_encode( $context, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP ) ) .

tests/phpunit/tests/interactivity-api/interactivity-api.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -314,18 +314,18 @@ public function test_process_directives_only_process_the_root_interactive_blocks
314314
}
315315

316316
/**
317-
* Tests that data_wp_context function correctly converts different array
317+
* Tests that wp_interactivity_data_wp_context function correctly converts different array
318318
* structures to a JSON string.
319319
*
320320
* @ticket 60356
321321
*
322-
* @covers ::data_wp_context
322+
* @covers ::wp_interactivity_data_wp_context
323323
*/
324-
public function test_data_wp_context_with_different_arrays() {
325-
$this->assertEquals( 'data-wp-context=\'{}\'', data_wp_context( array() ) );
324+
public function test_wp_interactivity_data_wp_context_with_different_arrays() {
325+
$this->assertEquals( 'data-wp-context=\'{}\'', wp_interactivity_data_wp_context( array() ) );
326326
$this->assertEquals(
327327
'data-wp-context=\'{"a":1,"b":"2","c":true}\'',
328-
data_wp_context(
328+
wp_interactivity_data_wp_context(
329329
array(
330330
'a' => 1,
331331
'b' => '2',
@@ -335,27 +335,27 @@ public function test_data_wp_context_with_different_arrays() {
335335
);
336336
$this->assertEquals(
337337
'data-wp-context=\'{"a":[1,2]}\'',
338-
data_wp_context( array( 'a' => array( 1, 2 ) ) )
338+
wp_interactivity_data_wp_context( array( 'a' => array( 1, 2 ) ) )
339339
);
340340
$this->assertEquals(
341341
'data-wp-context=\'[1,2]\'',
342-
data_wp_context( array( 1, 2 ) )
342+
wp_interactivity_data_wp_context( array( 1, 2 ) )
343343
);
344344
}
345345

346346
/**
347-
* Tests that data_wp_context function correctly converts different array
347+
* Tests that wp_interactivity_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 ::data_wp_context
352+
* @covers ::wp_interactivity_data_wp_context
353353
*/
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' ) );
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' ) );
356356
$this->assertEquals(
357357
'data-wp-context=\'myPlugin::{"a":1,"b":"2","c":true}\'',
358-
data_wp_context(
358+
wp_interactivity_data_wp_context(
359359
array(
360360
'a' => 1,
361361
'b' => '2',
@@ -366,28 +366,28 @@ public function test_data_wp_context_with_different_arrays_and_a_namespace() {
366366
);
367367
$this->assertEquals(
368368
'data-wp-context=\'myPlugin::{"a":[1,2]}\'',
369-
data_wp_context( array( 'a' => array( 1, 2 ) ), 'myPlugin' )
369+
wp_interactivity_data_wp_context( array( 'a' => array( 1, 2 ) ), 'myPlugin' )
370370
);
371371
$this->assertEquals(
372372
'data-wp-context=\'myPlugin::[1,2]\'',
373-
data_wp_context( array( 1, 2 ), 'myPlugin' )
373+
wp_interactivity_data_wp_context( array( 1, 2 ), 'myPlugin' )
374374
);
375375
}
376376

377377
/**
378-
* Tests that data_wp_context function correctly applies the JSON encoding
378+
* Tests that wp_interactivity_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
381381
* attacks.
382382
*
383383
* @ticket 60356
384384
*
385-
* @covers ::data_wp_context
385+
* @covers ::wp_interactivity_data_wp_context
386386
*/
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' ) ) );
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' ) ) );
392392
}
393393
}

0 commit comments

Comments
 (0)