diff --git a/lib/blocks.php b/lib/blocks.php index 0fe0cb8f1ccf9b..cc3f4c8662254e 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -165,37 +165,15 @@ function gutenberg_reregister_core_block_types() { * @return void */ function gutenberg_register_core_block_assets( $block_name ) { + if ( ! wp_should_load_separate_core_block_assets() ) { + return; + } + $block_name = str_replace( 'core/', '', $block_name ); // When in production, use the plugin's version as the default asset version; // else (for development or test) default to use the current time. $default_version = defined( 'GUTENBERG_VERSION' ) && ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? GUTENBERG_VERSION : time(); - $script_suffix = '.min.js'; - - $view_script_path = "build/block-library/blocks/$block_name/view$script_suffix"; - if ( file_exists( gutenberg_dir_path() . $view_script_path ) ) { - $view_script_handle = "wp-block-{$block_name}-view"; - wp_deregister_script( $view_script_handle ); - - // Replace suffix and extension with `.asset.php` to find the generated dependencies file. - $view_asset_file = substr( $view_script_path, 0, -( strlen( $script_suffix ) ) ) . '.asset.php'; - $view_asset = file_exists( gutenberg_dir_path() . $view_asset_file ) - ? require( gutenberg_dir_path() . $view_asset_file ) - : null; - $view_script_dependencies = isset( $view_asset['dependencies'] ) ? $view_asset['dependencies'] : array(); - $view_script_version = isset( $view_asset['version'] ) ? $view_asset['version'] : $default_version; - - wp_register_script( - $view_script_handle, - gutenberg_url( $view_script_path ), - $view_script_dependencies, - $view_script_version - ); - } - - if ( ! wp_should_load_separate_core_block_assets() ) { - return; - } $style_path = "build/block-library/blocks/$block_name/style.css"; $editor_style_path = "build/block-library/blocks/$block_name/style-editor.css"; diff --git a/lib/client-assets.php b/lib/client-assets.php index f108969b4043ba..0f9704cb39fc4c 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -236,15 +236,14 @@ function gutenberg_register_packages_scripts( $scripts ) { // When in production, use the plugin's version as the default asset version; // else (for development or test) default to use the current time. $default_version = defined( 'GUTENBERG_VERSION' ) && ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? GUTENBERG_VERSION : time(); - $suffix = '.min.js'; - foreach ( glob( gutenberg_dir_path() . "build/*/index$suffix" ) as $path ) { + foreach ( glob( gutenberg_dir_path() . 'build/*/index.min.js' ) as $path ) { // Prefix `wp-` to package directory to get script handle. // For example, `…/build/a11y/index.min.js` becomes `wp-a11y`. $handle = 'wp-' . basename( dirname( $path ) ); - // Replace suffix and extension with `.asset.php` to find the generated dependencies file. - $asset_file = substr( $path, 0, -( strlen( $suffix ) ) ) . '.asset.php'; + // Replace extension with `.asset.php` to find the generated dependencies file. + $asset_file = substr( $path, 0, -( strlen( '.js' ) ) ) . '.asset.php'; $asset = file_exists( $asset_file ) ? require( $asset_file ) : null; diff --git a/lib/compat/wordpress-5.8/blocks.php b/lib/compat/wordpress-5.8/blocks.php new file mode 100644 index 00000000000000..54a9864a270964 --- /dev/null +++ b/lib/compat/wordpress-5.8/blocks.php @@ -0,0 +1,57 @@ +