Docs: Correct formatting for script module data filter documentation examples.

Follow-up to [58579].

Props jonsurrell.
See #62281.
Built from https://develop.svn.wordpress.org/trunk@59505


git-svn-id: http://core.svn.wordpress.org/trunk@58891 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2024-12-11 15:20:18 +00:00
parent d1058355a5
commit caaf759d21
2 changed files with 21 additions and 18 deletions

View File

@ -407,14 +407,15 @@ class WP_Script_Modules {
* 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 @@ class WP_Script_Modules {
*
* 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
*

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.8-alpha-59504';
$wp_version = '6.8-alpha-59505';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.