Skip to content

Commit 9104190

Browse files
Docs: Correct formatting for script module data filter documentation examples.
Follow-up to [58579]. Props jonsurrell. See #62281. git-svn-id: https://develop.svn.wordpress.org/trunk@59505 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 32880ec commit 9104190

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/wp-includes/class-wp-script-modules.php

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -407,14 +407,15 @@ public function print_script_module_data(): void {
407407
* initialization or immediately on page load. It does not replace the REST API or
408408
* fetching data from the client.
409409
*
410-
* @example
411-
* add_filter(
412-
* 'script_module_data_MyScriptModuleID',
413-
* function ( array $data ): array {
414-
* $data['script-needs-this-data'] = 'ok';
415-
* return $data;
416-
* }
417-
* );
410+
* Example:
411+
*
412+
* add_filter(
413+
* 'script_module_data_MyScriptModuleID',
414+
* function ( array $data ): array {
415+
* $data['dataForClient'] = 'ok';
416+
* return $data;
417+
* }
418+
* );
418419
*
419420
* If the filter returns no data (an empty array), nothing will be embedded in the page.
420421
*
@@ -423,15 +424,17 @@ public function print_script_module_data(): void {
423424
*
424425
* The data can be read on the client with a pattern like this:
425426
*
426-
* @example
427-
* const dataContainer = document.getElementById( 'wp-script-module-data-MyScriptModuleID' );
428-
* let data = {};
429-
* if ( dataContainer ) {
430-
* try {
431-
* data = JSON.parse( dataContainer.textContent );
432-
* } catch {}
433-
* }
434-
* initMyScriptModuleWithData( data );
427+
* Example:
428+
*
429+
* const dataContainer = document.getElementById( 'wp-script-module-data-MyScriptModuleID' );
430+
* let data = {};
431+
* if ( dataContainer ) {
432+
* try {
433+
* data = JSON.parse( dataContainer.textContent );
434+
* } catch {}
435+
* }
436+
* // data.dataForClient === 'ok';
437+
* initMyScriptModuleWithData( data );
435438
*
436439
* @since 6.7.0
437440
*

0 commit comments

Comments
 (0)