Changeset 59505
- Timestamp:
- 12/11/2024 03:18:43 PM (2 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-script-modules.php
r59089 r59505 408 408 * fetching data from the client. 409 409 * 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 * ); 418 419 * 419 420 * If the filter returns no data (an empty array), nothing will be embedded in the page. … … 424 425 * The data can be read on the client with a pattern like this: 425 426 * 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 ); 435 438 * 436 439 * @since 6.7.0
Note: See TracChangeset
for help on using the changeset viewer.