Skip to content

Commit

Permalink
Temporarily restore gutenberg_initialize_editor() until reliance remo…
Browse files Browse the repository at this point in the history
…ved (#602)

* Temporarily restore gutenberg_initialize_editor() until reliance removed.
* Update yoast/phpunit-polyfills to v1.1
  • Loading branch information
dd32 authored Aug 24, 2023
1 parent 11bccb6 commit d3c6c36
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 8 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"wp-phpunit/wp-phpunit": "^5.4",
"phpunit/phpunit": "^7.5.20",
"rmccue/requests": "^1.8.1",
"yoast/phpunit-polyfills": "^1.0"
"yoast/phpunit-polyfills": "^1.1"
},
"scripts": {
"format": "phpcbf -p",
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions public_html/wp-content/plugins/pattern-creator/pattern-creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,61 @@ function set_theme_twentytwentythree() {
return 'core/twentytwentythree';
}
}

/**
* Temporarily restore gutenberg_initialize_editor() for compat with Gutenberg 16.5.0
*
* @see https://github.com/WordPress/pattern-directory/issues/601
*/
function gutenberg_initialize_editor( $editor_name, $editor_script_handle, $settings ) {

$defaults = array(
'preload_paths' => array(),
'initializer_name' => 'initialize',
'editor_settings' => array(),
);

$settings = wp_parse_args( $settings, $defaults );

/**
* Preload common data by specifying an array of REST API paths that will be preloaded.
*
* Filters the array of paths that will be preloaded.
*
* @param string[] $preload_paths Array of paths to preload.
*/
$preload_paths = apply_filters( "{$editor_name}_preload_paths", $settings['preload_paths'] );

$preload_data = array_reduce(
$preload_paths,
'rest_preload_api_request',
array()
);

wp_add_inline_script(
'wp-api-fetch',
sprintf(
'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );',
wp_json_encode( $preload_data )
),
'after'
);
wp_add_inline_script(
"wp-{$editor_script_handle}",
sprintf(
'wp.domReady( function() {
wp.%s.%s( "%s", %s );
} );',
lcfirst( str_replace( '-', '', ucwords( $editor_script_handle, '-' ) ) ),
$settings['initializer_name'],
str_replace( '_', '-', $editor_name ),
wp_json_encode( $settings['editor_settings'] )
)
);

// Preload server-registered block schemas.
wp_add_inline_script(
'wp-blocks',
'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');'
);
}

0 comments on commit d3c6c36

Please sign in to comment.