| @@ -12,11 +12,11 @@ | ||
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * Retrieves the root plugin path. |
| 15 | 15 | * |
| 16 | + * @return string Root path to the gutenberg plugin. | |
| 17 | + * | |
| 16 | 18 | * @since 0.1.0 |
| 17 | - * | |
| 18 | - * @return string Root path to the gutenberg plugin. | |
| 19 | 19 | */ |
| 20 | 20 | function gutenberg_dir_path() { |
| 21 | 21 | return plugin_dir_path( __DIR__ ); |
| 22 | 22 | } |
| @@ -23,13 +23,13 @@ | ||
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * Retrieves a URL to a file in the gutenberg plugin. |
| 26 | 26 | * |
| 27 | - * @since 0.1.0 | |
| 28 | - * | |
| 29 | 27 | * @param string $path Relative path of the desired file. |
| 30 | 28 | * |
| 31 | 29 | * @return string Fully qualified URL pointing to the desired file. |
| 30 | + * | |
| 31 | + * @since 0.1.0 | |
| 32 | 32 | */ |
| 33 | 33 | function gutenberg_url( $path ) { |
| 34 | 34 | return plugins_url( $path, __DIR__ ); |
| 35 | 35 | } |
| @@ -34,8 +34,70 @@ | ||
| 34 | 34 | return plugins_url( $path, __DIR__ ); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | + * Registers a script according to `wp_register_script`. Honors this request by | |
| 39 | + * reassigning internal dependency properties of any script handle already | |
| 40 | + * registered by that name. It does not deregister the original script, to | |
| 41 | + * avoid losing inline scripts which may have been attached. | |
| 42 | + * | |
| 43 | + * @since 4.1.0 | |
| 44 | + * | |
| 45 | + * @param WP_Scripts $scripts WP_Scripts instance. | |
| 46 | + * @param string $handle Name of the script. Should be unique. | |
| 47 | + * @param string $src Full URL of the script, or path of the script relative to the WordPress root directory. | |
| 48 | + * @param array $deps Optional. An array of registered script handles this script depends on. Default empty array. | |
| 49 | + * @param string|bool|null $ver Optional. String specifying script version number, if it has one, which is added to the URL | |
| 50 | + * as a query string for cache busting purposes. If version is set to false, a version | |
| 51 | + * number is automatically added equal to current installed WordPress version. | |
| 52 | + * If set to null, no version is added. | |
| 53 | + * @param bool $in_footer Optional. Whether to enqueue the script before </body> instead of in the <head>. | |
| 54 | + * Default 'false'. | |
| 55 | + */ | |
| 56 | +function gutenberg_override_script( $scripts, $handle, $src, $deps = array(), $ver = false, $in_footer = false ) { | |
| 57 | + /* | |
| 58 | + * Force `wp-i18n` script to be registered in the <head> as a | |
| 59 | + * temporary workaround for https://meta.trac.wordpress.org/ticket/6195. | |
| 60 | + */ | |
| 61 | + $in_footer = 'wp-i18n' === $handle ? false : $in_footer; | |
| 62 | + | |
| 63 | + $script = $scripts->query( $handle, 'registered' ); | |
| 64 | + if ( $script ) { | |
| 65 | + /* | |
| 66 | + * In many ways, this is a reimplementation of `wp_register_script` but | |
| 67 | + * bypassing consideration of whether a script by the given handle had | |
| 68 | + * already been registered. | |
| 69 | + */ | |
| 70 | + | |
| 71 | + // See: `_WP_Dependency::__construct` . | |
| 72 | + $script->src = $src; | |
| 73 | + $script->deps = $deps; | |
| 74 | + $script->ver = $ver; | |
| 75 | + $script->args = $in_footer ? 1 : null; | |
| 76 | + } else { | |
| 77 | + $scripts->add( $handle, $src, $deps, $ver, ( $in_footer ? 1 : null ) ); | |
| 78 | + } | |
| 79 | + | |
| 80 | + if ( in_array( 'wp-i18n', $deps, true ) ) { | |
| 81 | + $scripts->set_translations( $handle ); | |
| 82 | + } | |
| 83 | + | |
| 84 | + /* | |
| 85 | + * Wp-editor module is exposed as window.wp.editor. | |
| 86 | + * Problem: there is quite some code expecting window.wp.oldEditor object available under window.wp.editor. | |
| 87 | + * Solution: fuse the two objects together to maintain backward compatibility. | |
| 88 | + * For more context, see https://github.com/WordPress/gutenberg/issues/33203 | |
| 89 | + */ | |
| 90 | + if ( 'wp-editor' === $handle ) { | |
| 91 | + $scripts->add_inline_script( | |
| 92 | + 'wp-editor', | |
| 93 | + 'Object.assign( window.wp.editor, window.wp.oldEditor );', | |
| 94 | + 'after' | |
| 95 | + ); | |
| 96 | + } | |
| 97 | +} | |
| 98 | + | |
| 99 | +/** | |
| 38 | 100 | * Filters the default translation file load behavior to load the Gutenberg |
| 39 | 101 | * plugin translation file, if available. |
| 40 | 102 | * |
| 41 | 103 | * @param string|false $file Path to the translation file to load. False if |
| @@ -55,10 +117,10 @@ | ||
| 55 | 117 | if ( ! str_starts_with( $handle, 'wp-' ) ) { |
| 56 | 118 | return $file; |
| 57 | 119 | } |
| 58 | 120 | |
| 59 | - // Ignore scripts that are not found in the expected `build/scripts/` location. | |
| 60 | - $script_path = gutenberg_dir_path() . 'build/scripts/' . substr( $handle, 3 ) . '/index.min.js'; | |
| 121 | + // Ignore scripts that are not found in the expected `build/` location. | |
| 122 | + $script_path = gutenberg_dir_path() . 'build/' . substr( $handle, 3 ) . '/index.min.js'; | |
| 61 | 123 | if ( ! file_exists( $script_path ) ) { |
| 62 | 124 | return $file; |
| 63 | 125 | } |
| 64 | 126 | |
| @@ -86,38 +148,104 @@ | ||
| 86 | 148 | } |
| 87 | 149 | add_filter( 'load_script_translation_file', 'gutenberg_override_translation_file', 10, 2 ); |
| 88 | 150 | |
| 89 | 151 | /** |
| 90 | - * Adds the 'editor' dependency to wp-block-library, required by the Classic block. | |
| 152 | + * Registers a style according to `wp_register_style`. Honors this request by | |
| 153 | + * deregistering any style by the same handler before registration. | |
| 91 | 154 | * |
| 92 | - * @param WP_Scripts $scripts WP_Scripts instance. | |
| 155 | + * @since 4.1.0 | |
| 156 | + * | |
| 157 | + * @param WP_Styles $styles WP_Styles instance. | |
| 158 | + * @param string $handle Name of the stylesheet. Should be unique. | |
| 159 | + * @param string $src Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory. | |
| 160 | + * @param array $deps Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array. | |
| 161 | + * @param string|bool|null $ver Optional. String specifying stylesheet version number, if it has one, which is added to the URL | |
| 162 | + * as a query string for cache busting purposes. If version is set to false, a version | |
| 163 | + * number is automatically added equal to current installed WordPress version. | |
| 164 | + * If set to null, no version is added. | |
| 165 | + * @param string $media Optional. The media for which this stylesheet has been defined. | |
| 166 | + * Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like | |
| 167 | + * '(orientation: portrait)' and '(max-width: 640px)'. | |
| 93 | 168 | */ |
| 94 | -function gutenberg_register_block_library_script_special_case( $scripts ) { | |
| 95 | - $handle = 'wp-block-library'; | |
| 96 | - $script = $scripts->query( $handle, 'registered' ); | |
| 97 | - if ( ! in_array( 'editor', $script->deps, true ) ) { | |
| 98 | - $script->deps[] = 'editor'; | |
| 169 | +function gutenberg_override_style( $styles, $handle, $src, $deps = array(), $ver = false, $media = 'all' ) { | |
| 170 | + $style = $styles->query( $handle, 'registered' ); | |
| 171 | + if ( $style ) { | |
| 172 | + $styles->remove( $handle ); | |
| 99 | 173 | } |
| 174 | + $styles->add( $handle, $src, $deps, $ver, $media ); | |
| 100 | 175 | } |
| 101 | -add_action( 'wp_default_scripts', 'gutenberg_register_block_library_script_special_case', 11 ); | |
| 102 | 176 | |
| 103 | 177 | /** |
| 104 | - * Registers WordPress package styles with complex requirements. | |
| 178 | + * Registers all the WordPress packages scripts that are in the standardized | |
| 179 | + * `build/` location. | |
| 105 | 180 | * |
| 106 | - * Simple styles (main style.css with inferred dependencies) are auto-registered | |
| 107 | - * via build/styles.php at default priority (10). This function runs at priority 15 to handle: | |
| 108 | - * - Multiple style files per package (content.css, classic.css, etc.) | |
| 109 | - * - Non-WordPress dependencies (dashicons, common, forms) | |
| 110 | - * - Custom handles that don't match wp-{package} pattern | |
| 111 | - * - Conditional dependencies based on theme/settings | |
| 112 | - * - Dynamic filename logic | |
| 181 | + * @since 4.5.0 | |
| 113 | 182 | * |
| 114 | - * These override calls will replace the auto-registered versions as needed. | |
| 183 | + * @param WP_Scripts $scripts WP_Scripts instance. | |
| 184 | + */ | |
| 185 | +function gutenberg_register_packages_scripts( $scripts ) { | |
| 186 | + // When in production, use the plugin's version as the default asset version; | |
| 187 | + // else (for development or test) default to use the current time. | |
| 188 | + $default_version = defined( 'GUTENBERG_VERSION' ) && ! SCRIPT_DEBUG ? GUTENBERG_VERSION : time(); | |
| 189 | + | |
| 190 | + foreach ( glob( gutenberg_dir_path() . 'build/*/index.min.js' ) as $path ) { | |
| 191 | + // Prefix `wp-` to package directory to get script handle. | |
| 192 | + // For example, `…/build/a11y/index.min.js` becomes `wp-a11y`. | |
| 193 | + $handle = 'wp-' . basename( dirname( $path ) ); | |
| 194 | + | |
| 195 | + // Replace extension with `.asset.php` to find the generated dependencies file. | |
| 196 | + $asset_file = substr( $path, 0, -( strlen( '.js' ) ) ) . '.asset.php'; | |
| 197 | + $asset = file_exists( $asset_file ) | |
| 198 | + ? require $asset_file | |
| 199 | + : null; | |
| 200 | + $dependencies = isset( $asset['dependencies'] ) ? $asset['dependencies'] : array(); | |
| 201 | + $version = isset( $asset['version'] ) ? $asset['version'] : $default_version; | |
| 202 | + | |
| 203 | + // Add dependencies that cannot be detected and generated by build tools. | |
| 204 | + switch ( $handle ) { | |
| 205 | + case 'wp-block-library': | |
| 206 | + if ( | |
| 207 | + ! gutenberg_is_experiment_enabled( 'gutenberg-no-tinymce' ) || | |
| 208 | + ! empty( $_GET['requiresTinymce'] ) || | |
| 209 | + gutenberg_post_being_edited_requires_classic_block() | |
| 210 | + ) { | |
| 211 | + array_push( $dependencies, 'editor' ); | |
| 212 | + } | |
| 213 | + break; | |
| 214 | + | |
| 215 | + case 'wp-edit-post': | |
| 216 | + array_push( $dependencies, 'media-models', 'media-views', 'postbox' ); | |
| 217 | + break; | |
| 218 | + | |
| 219 | + case 'wp-edit-site': | |
| 220 | + array_push( $dependencies, 'wp-dom-ready' ); | |
| 221 | + break; | |
| 222 | + case 'wp-preferences': | |
| 223 | + array_push( $dependencies, 'wp-preferences-persistence' ); | |
| 224 | + break; | |
| 225 | + } | |
| 226 | + | |
| 227 | + // Get the path from Gutenberg directory as expected by `gutenberg_url`. | |
| 228 | + $gutenberg_path = substr( $path, strlen( gutenberg_dir_path() ) ); | |
| 229 | + | |
| 230 | + gutenberg_override_script( | |
| 231 | + $scripts, | |
| 232 | + $handle, | |
| 233 | + gutenberg_url( $gutenberg_path ), | |
| 234 | + $dependencies, | |
| 235 | + $version, | |
| 236 | + true | |
| 237 | + ); | |
| 238 | + } | |
| 239 | +} | |
| 240 | +add_action( 'wp_default_scripts', 'gutenberg_register_packages_scripts' ); | |
| 241 | + | |
| 242 | +/** | |
| 243 | + * Registers all the WordPress packages styles that are in the standardized | |
| 244 | + * `build/` location. | |
| 115 | 245 | * |
| 116 | 246 | * @since 6.7.0 |
| 117 | - * | |
| 118 | - * @global array $editor_styles | |
| 119 | - * | |
| 247 | + | |
| 120 | 248 | * @param WP_Styles $styles WP_Styles instance. |
| 121 | 249 | */ |
| 122 | 250 | function gutenberg_register_packages_styles( $styles ) { |
| 123 | 251 | // When in production, use the plugin's version as the asset version; |
| @@ -122,93 +250,85 @@ | ||
| 122 | 250 | function gutenberg_register_packages_styles( $styles ) { |
| 123 | 251 | // When in production, use the plugin's version as the asset version; |
| 124 | 252 | // else (for development or test) default to use the current time. |
| 125 | 253 | $version = defined( 'GUTENBERG_VERSION' ) && ! SCRIPT_DEBUG ? GUTENBERG_VERSION : time(); |
| 126 | - $suffix = SCRIPT_DEBUG ? '' : '.min'; | |
| 127 | 254 | |
| 128 | - // wp-components: add dashicons (icon font dependency) | |
| 129 | - $styles->query( 'wp-components', 'registered' )->deps[] = 'dashicons'; | |
| 255 | + gutenberg_override_style( | |
| 256 | + $styles, | |
| 257 | + 'wp-block-editor-content', | |
| 258 | + gutenberg_url( 'build/block-editor/content.css' ), | |
| 259 | + array( 'wp-components' ), | |
| 260 | + $version | |
| 261 | + ); | |
| 262 | + $styles->add_data( 'wp-block-editor-content', 'rtl', 'replace' ); | |
| 130 | 263 | |
| 131 | - // wp-edit-post: add wp-edit-blocks (custom handle not auto-inferred) | |
| 132 | - $styles->query( 'wp-edit-post', 'registered' )->deps[] = 'wp-edit-blocks'; | |
| 264 | + // Editor Styles. | |
| 265 | + gutenberg_override_style( | |
| 266 | + $styles, | |
| 267 | + 'wp-block-editor', | |
| 268 | + gutenberg_url( 'build/block-editor/style.css' ), | |
| 269 | + array( 'wp-components' ), | |
| 270 | + $version | |
| 271 | + ); | |
| 272 | + $styles->add_data( 'wp-block-editor', 'rtl', 'replace' ); | |
| 133 | 273 | |
| 134 | - // wp-edit-site: add core WP styles and custom handles | |
| 135 | - $edit_site_style = $styles->query( 'wp-edit-site', 'registered' ); | |
| 136 | - $edit_site_style->deps[] = 'common'; | |
| 137 | - $edit_site_style->deps[] = 'forms'; | |
| 138 | - $edit_site_style->deps[] = 'wp-block-library-editor'; | |
| 139 | - | |
| 140 | - // wp-edit-widgets: add wp-edit-blocks (custom handle not auto-inferred) | |
| 141 | - $styles->query( 'wp-edit-widgets', 'registered' )->deps[] = 'wp-edit-blocks'; | |
| 142 | - | |
| 143 | - // wp-customize-widgets: add wp-edit-blocks (custom handle not auto-inferred) | |
| 144 | - $styles->query( 'wp-customize-widgets', 'registered' )->deps[] = 'wp-edit-blocks'; | |
| 145 | - | |
| 146 | - // Register wp-theme (Design System tokens from @wordpress/theme) as a | |
| 147 | - // dependency of wp-base-styles so its `:root` token block loads | |
| 148 | - // everywhere wp-base-styles does, including the editor iframe via | |
| 149 | - // $wp_edit_blocks_dependencies below. | |
| 150 | 274 | gutenberg_override_style( |
| 151 | 275 | $styles, |
| 152 | - 'wp-theme', | |
| 153 | - gutenberg_url( 'build/styles/theme/design-tokens' . $suffix . '.css' ), | |
| 154 | - array(), | |
| 276 | + 'wp-editor', | |
| 277 | + gutenberg_url( 'build/editor/style.css' ), | |
| 278 | + array( 'wp-components', 'wp-block-editor', 'wp-reusable-blocks' ), | |
| 155 | 279 | $version |
| 156 | 280 | ); |
| 157 | - $styles->add_data( 'wp-theme', 'rtl', 'replace' ); | |
| 158 | - $styles->add_data( 'wp-theme', 'suffix', $suffix ); | |
| 159 | - $styles->add_data( 'wp-theme', 'path', gutenberg_dir_path() . 'build/styles/theme/design-tokens' . $suffix . '.css' ); | |
| 281 | + $styles->add_data( 'wp-editor', 'rtl', 'replace' ); | |
| 160 | 282 | |
| 161 | - // Register wp-base-styles and add it to the already registered wp-admin stylesheet | |
| 162 | 283 | gutenberg_override_style( |
| 163 | 284 | $styles, |
| 164 | - 'wp-base-styles', | |
| 165 | - gutenberg_url( 'build/styles/base-styles/admin-schemes' . $suffix . '.css' ), | |
| 166 | - array( 'wp-theme' ), | |
| 285 | + 'wp-edit-post', | |
| 286 | + gutenberg_url( 'build/edit-post/style.css' ), | |
| 287 | + array( 'wp-components', 'wp-block-editor', 'wp-editor', 'wp-edit-blocks', 'wp-block-library', 'wp-commands' ), | |
| 167 | 288 | $version |
| 168 | 289 | ); |
| 169 | - $styles->add_data( 'wp-base-styles', 'rtl', 'replace' ); | |
| 170 | - $styles->add_data( 'wp-base-styles', 'suffix', $suffix ); | |
| 171 | - $styles->add_data( 'wp-base-styles', 'path', gutenberg_dir_path() . 'build/styles/base-styles/admin-schemes' . $suffix . '.css' ); | |
| 172 | - $styles->query( 'wp-admin', 'registered' )->deps[] = 'wp-base-styles'; | |
| 290 | + $styles->add_data( 'wp-edit-post', 'rtl', 'replace' ); | |
| 173 | 291 | |
| 174 | 292 | gutenberg_override_style( |
| 175 | 293 | $styles, |
| 176 | - 'wp-block-editor-content', | |
| 177 | - gutenberg_url( 'build/styles/block-editor/content' . $suffix . '.css' ), | |
| 178 | - array( 'wp-components' ), | |
| 294 | + 'wp-components', | |
| 295 | + gutenberg_url( 'build/components/style.css' ), | |
| 296 | + array( 'dashicons' ), | |
| 179 | 297 | $version |
| 180 | 298 | ); |
| 181 | - $styles->add_data( 'wp-block-editor-content', 'rtl', 'replace' ); | |
| 182 | - $styles->add_data( 'wp-block-editor-content', 'suffix', $suffix ); | |
| 299 | + $styles->add_data( 'wp-components', 'rtl', 'replace' ); | |
| 183 | 300 | |
| 184 | 301 | $block_library_filename = wp_should_load_separate_core_block_assets() ? 'common' : 'style'; |
| 185 | 302 | gutenberg_override_style( |
| 186 | 303 | $styles, |
| 187 | 304 | 'wp-block-library', |
| 188 | - gutenberg_url( 'build/styles/block-library/' . $block_library_filename . $suffix . '.css' ), | |
| 305 | + gutenberg_url( 'build/block-library/' . $block_library_filename . '.css' ), | |
| 189 | 306 | array(), |
| 190 | 307 | $version |
| 191 | 308 | ); |
| 192 | 309 | $styles->add_data( 'wp-block-library', 'rtl', 'replace' ); |
| 193 | - $styles->add_data( 'wp-block-library', 'suffix', $suffix ); | |
| 194 | - $styles->add_data( 'wp-block-library', 'path', gutenberg_dir_path() . 'build/styles/block-library/' . $block_library_filename . $suffix . '.css' ); | |
| 310 | + $styles->add_data( 'wp-block-library', 'path', gutenberg_dir_path() . 'build/block-library/' . $block_library_filename . '.css' ); | |
| 195 | 311 | |
| 196 | - // Only add CONTENT styles here that should be enqueued in the iframe! | |
| 312 | + gutenberg_override_style( | |
| 313 | + $styles, | |
| 314 | + 'wp-format-library', | |
| 315 | + gutenberg_url( 'build/format-library/style.css' ), | |
| 316 | + array( 'wp-block-editor', 'wp-components' ), | |
| 317 | + $version | |
| 318 | + ); | |
| 319 | + $styles->add_data( 'wp-format-library', 'rtl', 'replace' ); | |
| 320 | + | |
| 197 | 321 | $wp_edit_blocks_dependencies = array( |
| 198 | - // Design System tokens load first so the `:root` CSS custom | |
| 199 | - // properties are defined before any consuming stylesheet reads | |
| 200 | - // them inside the editor iframe. | |
| 201 | - 'wp-theme', | |
| 202 | 322 | 'wp-components', |
| 203 | 323 | // This need to be added before the block library styles, |
| 204 | 324 | // The block library styles override the "reset" styles. |
| 205 | 325 | 'wp-reset-editor-styles', |
| 206 | 326 | 'wp-block-library', |
| 327 | + 'wp-reusable-blocks', | |
| 207 | 328 | // Until #37466, we can't specifically add them as editor styles yet, |
| 208 | 329 | // so we must hard-code it here as a dependency. |
| 209 | 330 | 'wp-block-editor-content', |
| 210 | - 'wp-base-styles', | |
| 211 | 331 | ); |
| 212 | 332 | |
| 213 | 333 | // Only load the default layout and margin styles for themes without theme.json file. |
| 214 | 334 | if ( ! wp_theme_has_theme_json() ) { |
| @@ -223,67 +343,113 @@ | ||
| 223 | 343 | |
| 224 | 344 | gutenberg_override_style( |
| 225 | 345 | $styles, |
| 226 | 346 | 'wp-reset-editor-styles', |
| 227 | - gutenberg_url( 'build/styles/block-library/reset' . $suffix . '.css' ), | |
| 347 | + gutenberg_url( 'build/block-library/reset.css' ), | |
| 228 | 348 | array( 'common', 'forms' ), // Make sure the reset is loaded after the default WP Admin styles. |
| 229 | 349 | $version |
| 230 | 350 | ); |
| 231 | 351 | $styles->add_data( 'wp-reset-editor-styles', 'rtl', 'replace' ); |
| 232 | - $styles->add_data( 'wp-reset-editor-styles', 'suffix', $suffix ); | |
| 233 | 352 | |
| 234 | 353 | gutenberg_override_style( |
| 235 | 354 | $styles, |
| 236 | 355 | 'wp-editor-classic-layout-styles', |
| 237 | - gutenberg_url( 'build/styles/edit-post/classic' . $suffix . '.css' ), | |
| 356 | + gutenberg_url( 'build/edit-post/classic.css' ), | |
| 238 | 357 | array(), |
| 239 | 358 | $version |
| 240 | 359 | ); |
| 241 | 360 | $styles->add_data( 'wp-editor-classic-layout-styles', 'rtl', 'replace' ); |
| 242 | - $styles->add_data( 'wp-editor-classic-layout-styles', 'suffix', $suffix ); | |
| 243 | 361 | |
| 244 | 362 | gutenberg_override_style( |
| 245 | 363 | $styles, |
| 246 | - 'wp-block-library-editor', | |
| 247 | - gutenberg_url( 'build/styles/block-library/editor' . $suffix . '.css' ), | |
| 364 | + 'wp-edit-blocks', | |
| 365 | + gutenberg_url( 'build/block-library/editor.css' ), | |
| 366 | + $wp_edit_blocks_dependencies, | |
| 367 | + $version | |
| 368 | + ); | |
| 369 | + $styles->add_data( 'wp-edit-blocks', 'rtl', 'replace' ); | |
| 370 | + | |
| 371 | + gutenberg_override_style( | |
| 372 | + $styles, | |
| 373 | + 'wp-block-library-theme', | |
| 374 | + gutenberg_url( 'build/block-library/theme.css' ), | |
| 248 | 375 | array(), |
| 249 | 376 | $version |
| 250 | 377 | ); |
| 251 | - $styles->add_data( 'wp-block-library-editor', 'rtl', 'replace' ); | |
| 252 | - $styles->add_data( 'wp-block-library-editor', 'suffix', $suffix ); | |
| 378 | + $styles->add_data( 'wp-block-library-theme', 'rtl', 'replace' ); | |
| 253 | 379 | |
| 254 | 380 | gutenberg_override_style( |
| 255 | 381 | $styles, |
| 256 | - 'wp-edit-blocks', | |
| 257 | - gutenberg_url( 'build/styles/block-library/editor' . $suffix . '.css' ), | |
| 258 | - $wp_edit_blocks_dependencies, | |
| 382 | + 'wp-list-reusable-blocks', | |
| 383 | + gutenberg_url( 'build/list-reusable-blocks/style.css' ), | |
| 384 | + array( 'wp-components' ), | |
| 259 | 385 | $version |
| 260 | 386 | ); |
| 261 | - $styles->add_data( 'wp-edit-blocks', 'rtl', 'replace' ); | |
| 262 | - $styles->add_data( 'wp-edit-blocks', 'suffix', $suffix ); | |
| 387 | + $styles->add_data( 'wp-list-reusable-block', 'rtl', 'replace' ); | |
| 263 | 388 | |
| 264 | 389 | gutenberg_override_style( |
| 265 | 390 | $styles, |
| 266 | - 'wp-block-library-theme', | |
| 267 | - gutenberg_url( 'build/styles/block-library/theme' . $suffix . '.css' ), | |
| 268 | - array(), | |
| 391 | + 'wp-commands', | |
| 392 | + gutenberg_url( 'build/commands/style.css' ), | |
| 393 | + array( 'wp-components' ), | |
| 269 | 394 | $version |
| 270 | 395 | ); |
| 271 | - $styles->add_data( 'wp-block-library-theme', 'rtl', 'replace' ); | |
| 272 | - $styles->add_data( 'wp-block-library-theme', 'suffix', $suffix ); | |
| 396 | + $styles->add_data( 'wp-commands', 'rtl', 'replace' ); | |
| 273 | 397 | |
| 274 | 398 | gutenberg_override_style( |
| 275 | 399 | $styles, |
| 276 | - 'classic-theme-styles', | |
| 277 | - gutenberg_url( 'build/styles/block-library/classic' . $suffix . '.css' ), | |
| 278 | - array(), | |
| 400 | + 'wp-edit-site', | |
| 401 | + gutenberg_url( 'build/edit-site/style.css' ), | |
| 402 | + array( 'wp-components', 'wp-block-editor', 'wp-editor', 'wp-edit-blocks', 'wp-commands' ), | |
| 279 | 403 | $version |
| 280 | 404 | ); |
| 281 | - $styles->add_data( 'classic-theme-styles', 'rtl', 'replace' ); | |
| 282 | - $styles->add_data( 'classic-theme-styles', 'suffix', $suffix ); | |
| 283 | - $styles->add_data( 'classic-theme-styles', 'path', gutenberg_dir_path() . 'build/styles/block-library/classic' . $suffix . '.css' ); | |
| 405 | + $styles->add_data( 'wp-edit-site', 'rtl', 'replace' ); | |
| 406 | + | |
| 407 | + gutenberg_override_style( | |
| 408 | + $styles, | |
| 409 | + 'wp-edit-widgets', | |
| 410 | + gutenberg_url( 'build/edit-widgets/style.css' ), | |
| 411 | + array( 'wp-components', 'wp-block-editor', 'wp-editor', 'wp-edit-blocks', 'wp-reusable-blocks', 'wp-widgets' ), | |
| 412 | + $version | |
| 413 | + ); | |
| 414 | + $styles->add_data( 'wp-edit-widgets', 'rtl', 'replace' ); | |
| 415 | + | |
| 416 | + gutenberg_override_style( | |
| 417 | + $styles, | |
| 418 | + 'wp-block-directory', | |
| 419 | + gutenberg_url( 'build/block-directory/style.css' ), | |
| 420 | + array( 'wp-block-editor', 'wp-components' ), | |
| 421 | + $version | |
| 422 | + ); | |
| 423 | + $styles->add_data( 'wp-block-directory', 'rtl', 'replace' ); | |
| 424 | + | |
| 425 | + gutenberg_override_style( | |
| 426 | + $styles, | |
| 427 | + 'wp-customize-widgets', | |
| 428 | + gutenberg_url( 'build/customize-widgets/style.css' ), | |
| 429 | + array( 'wp-components', 'wp-block-editor', 'wp-editor', 'wp-edit-blocks', 'wp-widgets' ), | |
| 430 | + $version | |
| 431 | + ); | |
| 432 | + $styles->add_data( 'wp-customize-widgets', 'rtl', 'replace' ); | |
| 433 | + | |
| 434 | + gutenberg_override_style( | |
| 435 | + $styles, | |
| 436 | + 'wp-reusable-blocks', | |
| 437 | + gutenberg_url( 'build/reusable-blocks/style.css' ), | |
| 438 | + array( 'wp-components' ), | |
| 439 | + $version | |
| 440 | + ); | |
| 441 | + $styles->add_data( 'wp-reusable-blocks', 'rtl', 'replace' ); | |
| 442 | + | |
| 443 | + gutenberg_override_style( | |
| 444 | + $styles, | |
| 445 | + 'wp-widgets', | |
| 446 | + gutenberg_url( 'build/widgets/style.css' ), | |
| 447 | + array( 'wp-components' ) | |
| 448 | + ); | |
| 449 | + $styles->add_data( 'wp-widgets', 'rtl', 'replace' ); | |
| 284 | 450 | } |
| 285 | -add_action( 'wp_default_styles', 'gutenberg_register_packages_styles', 15 ); | |
| 451 | +add_action( 'wp_default_styles', 'gutenberg_register_packages_styles' ); | |
| 286 | 452 | |
| 287 | 453 | /** |
| 288 | 454 | * Fetches, processes and compiles stored core styles, then combines and renders them to the page. |
| 289 | 455 | * Styles are stored via the Style Engine API. |
| @@ -290,12 +456,10 @@ | ||
| 290 | 456 | * |
| 291 | 457 | * This hook also exists, and should be backported to Core in future versions. |
| 292 | 458 | * However, it is envisaged that Gutenberg will continue to use the Style Engine's `gutenberg_*` functions and `_Gutenberg` classes to aid continuous development. |
| 293 | 459 | * |
| 294 | - * @since 6.1 | |
| 460 | + * See: https://developer.wordpress.org/block-editor/reference-guides/packages/packages-style-engine/ | |
| 295 | 461 | * |
| 296 | - * @link https://developer.wordpress.org/block-editor/reference-guides/packages/packages-style-engine/ | |
| 297 | - * | |
| 298 | 462 | * @param array $options { |
| 299 | 463 | * Optional. An array of options to pass to gutenberg_style_engine_get_stylesheet_from_context(). Default empty array. |
| 300 | 464 | * |
| 301 | 465 | * @type bool $optimize Whether to optimize the CSS output, e.g., combine rules. Default is `false`. |
| @@ -301,8 +465,10 @@ | ||
| 301 | 465 | * @type bool $optimize Whether to optimize the CSS output, e.g., combine rules. Default is `false`. |
| 302 | 466 | * @type bool $prettify Whether to add new lines and indents to output. Default is the test of whether the global constant `SCRIPT_DEBUG` is defined. |
| 303 | 467 | * } |
| 304 | 468 | * |
| 469 | + * @since 6.1 | |
| 470 | + * | |
| 305 | 471 | * @return void |
| 306 | 472 | */ |
| 307 | 473 | function gutenberg_enqueue_stored_styles( $options = array() ) { |
| 308 | 474 | $is_block_theme = wp_is_block_theme(); |
| @@ -334,9 +500,9 @@ | ||
| 334 | 500 | } |
| 335 | 501 | |
| 336 | 502 | // Combines Core styles. |
| 337 | 503 | if ( ! empty( $compiled_core_stylesheet ) ) { |
| 338 | - wp_register_style( $style_tag_id, false, array(), true ); | |
| 504 | + wp_register_style( $style_tag_id, false, array(), true, true ); | |
| 339 | 505 | wp_add_inline_style( $style_tag_id, $compiled_core_stylesheet ); |
| 340 | 506 | wp_enqueue_style( $style_tag_id ); |
| 341 | 507 | } |
| 342 | 508 | |
| @@ -357,9 +523,9 @@ | ||
| 357 | 523 | } |
| 358 | 524 | $styles = gutenberg_style_engine_get_stylesheet_from_context( $store_name, $options ); |
| 359 | 525 | if ( ! empty( $styles ) ) { |
| 360 | 526 | $key = "wp-style-engine-$store_name"; |
| 361 | - wp_register_style( $key, false, array(), true ); | |
| 527 | + wp_register_style( $key, false, array(), true, true ); | |
| 362 | 528 | wp_add_inline_style( $key, $styles ); |
| 363 | 529 | wp_enqueue_style( $key ); |
| 364 | 530 | } |
| 365 | 531 | } |
| @@ -376,71 +542,30 @@ | ||
| 376 | 542 | * |
| 377 | 543 | * @param WP_Scripts $scripts WP_Scripts instance. |
| 378 | 544 | */ |
| 379 | 545 | function gutenberg_register_vendor_scripts( $scripts ) { |
| 380 | - $extension = SCRIPT_DEBUG ? '.js' : '.min.js'; | |
| 381 | - $vendors_dir = gutenberg_dir_path() . 'build/scripts/vendors/'; | |
| 546 | + $extension = SCRIPT_DEBUG ? '.js' : '.min.js'; | |
| 382 | 547 | |
| 383 | - // When the React 19 experiment is enabled, register React 19 vendor | |
| 384 | - // scripts under the `react`, `react-dom`, and `react-jsx-runtime` handles. | |
| 385 | - $use_react_19 = gutenberg_is_experiment_enabled( 'gutenberg-react-19' ); | |
| 386 | - | |
| 387 | - $vendor_handles = array( 'react', 'react-dom', 'react-jsx-runtime' ); | |
| 388 | - | |
| 389 | - foreach ( $vendor_handles as $handle ) { | |
| 390 | - $source = $use_react_19 ? $handle . '-19' : $handle; | |
| 391 | - $asset_file = $vendors_dir . $source . '.min.asset.php'; | |
| 392 | - $asset = file_exists( $asset_file ) ? require $asset_file : array(); | |
| 393 | - $dependencies = $asset['dependencies'] ?? array(); | |
| 394 | - $version = $asset['version'] ?? '0'; | |
| 395 | - | |
| 396 | - gutenberg_override_script( | |
| 397 | - $scripts, | |
| 398 | - $handle, | |
| 399 | - gutenberg_url( 'build/scripts/vendors/' . $source . $extension ), | |
| 400 | - $dependencies, | |
| 401 | - $version | |
| 402 | - ); | |
| 403 | - } | |
| 404 | - | |
| 405 | - // WordPress Core in `wp_register_development_scripts` sets `wp-react-refresh-entry` | |
| 406 | - // as a dependency to `react` when `SCRIPT_DEBUG` is true. Preserve that here. | |
| 407 | - if ( SCRIPT_DEBUG ) { | |
| 408 | - $react = $scripts->query( 'react', 'registered' ); | |
| 409 | - if ( $react && ! in_array( 'wp-react-refresh-entry', $react->deps, true ) ) { | |
| 410 | - $react->deps[] = 'wp-react-refresh-entry'; | |
| 411 | - } | |
| 412 | - } | |
| 548 | + gutenberg_override_script( | |
| 549 | + $scripts, | |
| 550 | + 'react', | |
| 551 | + gutenberg_url( 'build/vendors/react' . $extension ), | |
| 552 | + // See https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/main/docs/TROUBLESHOOTING.md#externalising-react. | |
| 553 | + SCRIPT_DEBUG ? array( 'wp-react-refresh-entry', 'wp-polyfill' ) : array( 'wp-polyfill' ), | |
| 554 | + '18' | |
| 555 | + ); | |
| 556 | + gutenberg_override_script( | |
| 557 | + $scripts, | |
| 558 | + 'react-dom', | |
| 559 | + gutenberg_url( 'build/vendors/react-dom' . $extension ), | |
| 560 | + array( 'react' ), | |
| 561 | + '18' | |
| 562 | + ); | |
| 413 | 563 | } |
| 414 | 564 | add_action( 'wp_default_scripts', 'gutenberg_register_vendor_scripts' ); |
| 415 | 565 | |
| 416 | -/** | |
| 417 | - * Registers or re-registers Gutenberg Script Modules. | |
| 418 | - * | |
| 419 | - * Script modules that are registered by Core will be re-registered by Gutenberg. | |
| 420 | - * | |
| 421 | - * @since 19.3.0 | |
| 422 | - */ | |
| 423 | -function gutenberg_define_interactivity_modules_support() { | |
| 424 | - // Load the auto-generated module registry. | |
| 425 | - $modules_registry_file = gutenberg_dir_path() . 'build/modules/index.php'; | |
| 426 | - if ( ! file_exists( $modules_registry_file ) ) { | |
| 427 | - return; | |
| 428 | - } | |
| 429 | 566 | |
| 430 | - $modules = require $modules_registry_file; | |
| 431 | - | |
| 432 | - // Add client navigation support to block library modules. | |
| 433 | - foreach ( $modules as $module ) { | |
| 434 | - if ( str_starts_with( $module['id'], '@wordpress/block-library' ) && method_exists( 'WP_Interactivity_API', 'add_client_navigation_support_to_script_module' ) ) { | |
| 435 | - wp_interactivity()->add_client_navigation_support_to_script_module( $module['id'] ); | |
| 436 | - } | |
| 437 | - } | |
| 438 | -} | |
| 439 | -remove_action( 'wp_default_scripts', 'wp_define_interactivity_modules_support' ); | |
| 440 | -add_action( 'wp_default_scripts', 'gutenberg_define_interactivity_modules_support' ); | |
| 441 | - | |
| 442 | -/** | |
| 567 | +/* | |
| 443 | 568 | * Always remove the Core action hook while gutenberg_enqueue_stored_styles() exists to avoid styles being printed twice. |
| 444 | 569 | * This is also because gutenberg_enqueue_stored_styles uses the Style Engine's `gutenberg_*` functions and `_Gutenberg` classes, |
| 445 | 570 | * which are in continuous development and generally ahead of Core. |
| 446 | 571 | */ |
| @@ -449,43 +574,4 @@ | ||
| 449 | 574 | |
| 450 | 575 | // Enqueue stored styles. |
| 451 | 576 | add_action( 'wp_enqueue_scripts', 'gutenberg_enqueue_stored_styles' ); |
| 452 | 577 | add_action( 'wp_footer', 'gutenberg_enqueue_stored_styles', 1 ); |
| 453 | - | |
| 454 | -/** | |
| 455 | - * Enqueues the LaTeX to MathML loader script module in the block editor. | |
| 456 | - */ | |
| 457 | -add_action( 'enqueue_block_editor_assets', 'gutenberg_enqueue_latex_to_mathml_loader' ); | |
| 458 | -function gutenberg_enqueue_latex_to_mathml_loader() { | |
| 459 | - wp_enqueue_script_module( '@wordpress/latex-to-mathml/loader' ); | |
| 460 | -} | |
| 461 | - | |
| 462 | -/** | |
| 463 | - * Enqueue the vips loader script module in the block editor. | |
| 464 | - * | |
| 465 | - * This registers @wordpress/vips/worker as a dynamic dependency in the import map, | |
| 466 | - * enabling on-demand loading of the ~3.8MB WASM-based image processing module | |
| 467 | - * when client-side media processing is triggered via @wordpress/upload-media. | |
| 468 | - * | |
| 469 | - * @see packages/vips/src/loader.ts | |
| 470 | - */ | |
| 471 | -add_action( 'enqueue_block_editor_assets', 'gutenberg_enqueue_vips_loader' ); | |
| 472 | -function gutenberg_enqueue_vips_loader() { | |
| 473 | - wp_enqueue_script_module( '@wordpress/vips/loader' ); | |
| 474 | -} | |
| 475 | - | |
| 476 | -/** | |
| 477 | - * Enqueue the video-conversion loader script module in the block editor. | |
| 478 | - * | |
| 479 | - * This registers @wordpress/video-conversion/worker as a dynamic dependency | |
| 480 | - * in the import map, enabling on-demand loading of the WebCodecs-based | |
| 481 | - * GIF-to-video processing module when animated GIF conversion is triggered | |
| 482 | - * via @wordpress/upload-media. | |
| 483 | - * | |
| 484 | - * @see packages/video-conversion/src/loader.ts | |
| 485 | - */ | |
| 486 | -if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) { | |
| 487 | - add_action( 'enqueue_block_editor_assets', 'gutenberg_enqueue_video_conversion_loader' ); | |
| 488 | -} | |
| 489 | -function gutenberg_enqueue_video_conversion_loader() { | |
| 490 | - wp_enqueue_script_module( '@wordpress/video-conversion/loader' ); | |
| 491 | -} | |