From 9104190b6d36c2959f652e0b65bf5bb7af42ffcc Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 11 Dec 2024 15:18:43 +0000 Subject: [PATCH] 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 --- src/wp-includes/class-wp-script-modules.php | 37 +++++++++++---------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/wp-includes/class-wp-script-modules.php b/src/wp-includes/class-wp-script-modules.php index 384bf9ef2f59b..dbfa038f8cbe2 100644 --- a/src/wp-includes/class-wp-script-modules.php +++ b/src/wp-includes/class-wp-script-modules.php @@ -407,14 +407,15 @@ public function print_script_module_data(): void { * initialization or immediately on page load. It does not replace the REST API or * fetching data from the client. * - * @example - * add_filter( - * 'script_module_data_MyScriptModuleID', - * function ( array $data ): array { - * $data['script-needs-this-data'] = 'ok'; - * return $data; - * } - * ); + * Example: + * + * add_filter( + * 'script_module_data_MyScriptModuleID', + * function ( array $data ): array { + * $data['dataForClient'] = 'ok'; + * return $data; + * } + * ); * * If the filter returns no data (an empty array), nothing will be embedded in the page. * @@ -423,15 +424,17 @@ public function print_script_module_data(): void { * * The data can be read on the client with a pattern like this: * - * @example - * const dataContainer = document.getElementById( 'wp-script-module-data-MyScriptModuleID' ); - * let data = {}; - * if ( dataContainer ) { - * try { - * data = JSON.parse( dataContainer.textContent ); - * } catch {} - * } - * initMyScriptModuleWithData( data ); + * Example: + * + * const dataContainer = document.getElementById( 'wp-script-module-data-MyScriptModuleID' ); + * let data = {}; + * if ( dataContainer ) { + * try { + * data = JSON.parse( dataContainer.textContent ); + * } catch {} + * } + * // data.dataForClient === 'ok'; + * initMyScriptModuleWithData( data ); * * @since 6.7.0 *