Skip to content

Commit

Permalink
Merge branch 'trunk' into html-api/add-css-selector-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Dec 11, 2024
2 parents abb4d25 + 9104190 commit 1c1e29a
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions src/wp-includes/class-wp-script-modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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
*
Expand Down

0 comments on commit 1c1e29a

Please sign in to comment.