mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 09:07:59 +01:00
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:
parent
d1058355a5
commit
caaf759d21
@ -407,14 +407,15 @@ class WP_Script_Modules {
|
|||||||
* initialization or immediately on page load. It does not replace the REST API or
|
* initialization or immediately on page load. It does not replace the REST API or
|
||||||
* fetching data from the client.
|
* fetching data from the client.
|
||||||
*
|
*
|
||||||
* @example
|
* Example:
|
||||||
* add_filter(
|
*
|
||||||
* 'script_module_data_MyScriptModuleID',
|
* add_filter(
|
||||||
* function ( array $data ): array {
|
* 'script_module_data_MyScriptModuleID',
|
||||||
* $data['script-needs-this-data'] = 'ok';
|
* function ( array $data ): array {
|
||||||
* return $data;
|
* $data['dataForClient'] = 'ok';
|
||||||
* }
|
* return $data;
|
||||||
* );
|
* }
|
||||||
|
* );
|
||||||
*
|
*
|
||||||
* If the filter returns no data (an empty array), nothing will be embedded in the page.
|
* 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:
|
* The data can be read on the client with a pattern like this:
|
||||||
*
|
*
|
||||||
* @example
|
* Example:
|
||||||
* const dataContainer = document.getElementById( 'wp-script-module-data-MyScriptModuleID' );
|
*
|
||||||
* let data = {};
|
* const dataContainer = document.getElementById( 'wp-script-module-data-MyScriptModuleID' );
|
||||||
* if ( dataContainer ) {
|
* let data = {};
|
||||||
* try {
|
* if ( dataContainer ) {
|
||||||
* data = JSON.parse( dataContainer.textContent );
|
* try {
|
||||||
* } catch {}
|
* data = JSON.parse( dataContainer.textContent );
|
||||||
* }
|
* } catch {}
|
||||||
* initMyScriptModuleWithData( data );
|
* }
|
||||||
|
* // data.dataForClient === 'ok';
|
||||||
|
* initMyScriptModuleWithData( data );
|
||||||
*
|
*
|
||||||
* @since 6.7.0
|
* @since 6.7.0
|
||||||
*
|
*
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @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.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user