| @@ -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,78 @@ | ||
| 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 | + /* | |
| 81 | + * `WP_Dependencies::set_translations` will fall over on itself if setting | |
| 82 | + * translations on the `wp-i18n` handle, since it internally adds `wp-i18n` | |
| 83 | + * as a dependency of itself, exhausting memory. The same applies for the | |
| 84 | + * polyfill and hooks scripts, which are dependencies _of_ `wp-i18n`. | |
| 85 | + * | |
| 86 | + * See: https://core.trac.wordpress.org/ticket/46089 | |
| 87 | + */ | |
| 88 | + if ( ! in_array( $handle, array( 'wp-i18n', 'wp-polyfill', 'wp-hooks' ), true ) ) { | |
| 89 | + $scripts->set_translations( $handle, 'default' ); | |
| 90 | + } | |
| 91 | + | |
| 92 | + /* | |
| 93 | + * Wp-editor module is exposed as window.wp.editor. | |
| 94 | + * Problem: there is quite some code expecting window.wp.oldEditor object available under window.wp.editor. | |
| 95 | + * Solution: fuse the two objects together to maintain backward compatibility. | |
| 96 | + * For more context, see https://github.com/WordPress/gutenberg/issues/33203 | |
| 97 | + */ | |
| 98 | + if ( 'wp-editor' === $handle ) { | |
| 99 | + $scripts->add_inline_script( | |
| 100 | + 'wp-editor', | |
| 101 | + 'Object.assign( window.wp.editor, window.wp.oldEditor );', | |
| 102 | + 'after' | |
| 103 | + ); | |
| 104 | + } | |
| 105 | +} | |
| 106 | + | |
| 107 | +/** | |
| 38 | 108 | * Filters the default translation file load behavior to load the Gutenberg |
| 39 | 109 | * plugin translation file, if available. |
| 40 | 110 | * |
| 41 | 111 | * @param string|false $file Path to the translation file to load. False if |
| @@ -55,10 +125,10 @@ | ||
| 55 | 125 | if ( ! str_starts_with( $handle, 'wp-' ) ) { |
| 56 | 126 | return $file; |
| 57 | 127 | } |
| 58 | 128 | |
| 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'; | |
| 129 | + // Ignore scripts that are not found in the expected `build/` location. | |
| 130 | + $script_path = gutenberg_dir_path() . 'build/' . substr( $handle, 3 ) . '/index.min.js'; | |
| 61 | 131 | if ( ! file_exists( $script_path ) ) { |
| 62 | 132 | return $file; |
| 63 | 133 | } |
| 64 | 134 | |
| @@ -86,38 +156,95 @@ | ||
| 86 | 156 | } |
| 87 | 157 | add_filter( 'load_script_translation_file', 'gutenberg_override_translation_file', 10, 2 ); |
| 88 | 158 | |
| 89 | 159 | /** |
| 90 | - * Adds the 'editor' dependency to wp-block-library, required by the Classic block. | |
| 160 | + * Registers a style according to `wp_register_style`. Honors this request by | |
| 161 | + * deregistering any style by the same handler before registration. | |
| 91 | 162 | * |
| 92 | - * @param WP_Scripts $scripts WP_Scripts instance. | |
| 163 | + * @since 4.1.0 | |
| 164 | + * | |
| 165 | + * @param WP_Styles $styles WP_Styles instance. | |
| 166 | + * @param string $handle Name of the stylesheet. Should be unique. | |
| 167 | + * @param string $src Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory. | |
| 168 | + * @param array $deps Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array. | |
| 169 | + * @param string|bool|null $ver Optional. String specifying stylesheet version number, if it has one, which is added to the URL | |
| 170 | + * as a query string for cache busting purposes. If version is set to false, a version | |
| 171 | + * number is automatically added equal to current installed WordPress version. | |
| 172 | + * If set to null, no version is added. | |
| 173 | + * @param string $media Optional. The media for which this stylesheet has been defined. | |
| 174 | + * Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like | |
| 175 | + * '(orientation: portrait)' and '(max-width: 640px)'. | |
| 93 | 176 | */ |
| 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'; | |
| 177 | +function gutenberg_override_style( $styles, $handle, $src, $deps = array(), $ver = false, $media = 'all' ) { | |
| 178 | + $style = $styles->query( $handle, 'registered' ); | |
| 179 | + if ( $style ) { | |
| 180 | + $styles->remove( $handle ); | |
| 99 | 181 | } |
| 182 | + $styles->add( $handle, $src, $deps, $ver, $media ); | |
| 100 | 183 | } |
| 101 | -add_action( 'wp_default_scripts', 'gutenberg_register_block_library_script_special_case', 11 ); | |
| 102 | 184 | |
| 103 | 185 | /** |
| 104 | - * Registers WordPress package styles with complex requirements. | |
| 186 | + * Registers all the WordPress packages scripts that are in the standardized | |
| 187 | + * `build/` location. | |
| 105 | 188 | * |
| 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 | |
| 189 | + * @since 4.5.0 | |
| 113 | 190 | * |
| 114 | - * These override calls will replace the auto-registered versions as needed. | |
| 191 | + * @param WP_Scripts $scripts WP_Scripts instance. | |
| 192 | + */ | |
| 193 | +function gutenberg_register_packages_scripts( $scripts ) { | |
| 194 | + // When in production, use the plugin's version as the default asset version; | |
| 195 | + // else (for development or test) default to use the current time. | |
| 196 | + $default_version = defined( 'GUTENBERG_VERSION' ) && ! SCRIPT_DEBUG ? GUTENBERG_VERSION : time(); | |
| 197 | + | |
| 198 | + foreach ( glob( gutenberg_dir_path() . 'build/*/index.min.js' ) as $path ) { | |
| 199 | + // Prefix `wp-` to package directory to get script handle. | |
| 200 | + // For example, `…/build/a11y/index.min.js` becomes `wp-a11y`. | |
| 201 | + $handle = 'wp-' . basename( dirname( $path ) ); | |
| 202 | + | |
| 203 | + // Replace extension with `.asset.php` to find the generated dependencies file. | |
| 204 | + $asset_file = substr( $path, 0, -( strlen( '.js' ) ) ) . '.asset.php'; | |
| 205 | + $asset = file_exists( $asset_file ) | |
| 206 | + ? require $asset_file | |
| 207 | + : null; | |
| 208 | + $dependencies = isset( $asset['dependencies'] ) ? $asset['dependencies'] : array(); | |
| 209 | + $version = isset( $asset['version'] ) ? $asset['version'] : $default_version; | |
| 210 | + | |
| 211 | + // Add dependencies that cannot be detected and generated by build tools. | |
| 212 | + switch ( $handle ) { | |
| 213 | + case 'wp-block-library': | |
| 214 | + array_push( $dependencies, 'editor' ); | |
| 215 | + break; | |
| 216 | + | |
| 217 | + case 'wp-edit-post': | |
| 218 | + array_push( $dependencies, 'media-models', 'media-views', 'postbox' ); | |
| 219 | + break; | |
| 220 | + | |
| 221 | + case 'wp-edit-site': | |
| 222 | + array_push( $dependencies, 'wp-dom-ready' ); | |
| 223 | + break; | |
| 224 | + } | |
| 225 | + | |
| 226 | + // Get the path from Gutenberg directory as expected by `gutenberg_url`. | |
| 227 | + $gutenberg_path = substr( $path, strlen( gutenberg_dir_path() ) ); | |
| 228 | + | |
| 229 | + gutenberg_override_script( | |
| 230 | + $scripts, | |
| 231 | + $handle, | |
| 232 | + gutenberg_url( $gutenberg_path ), | |
| 233 | + $dependencies, | |
| 234 | + $version, | |
| 235 | + true | |
| 236 | + ); | |
| 237 | + } | |
| 238 | +} | |
| 239 | +add_action( 'wp_default_scripts', 'gutenberg_register_packages_scripts' ); | |
| 240 | + | |
| 241 | +/** | |
| 242 | + * Registers all the WordPress packages styles that are in the standardized | |
| 243 | + * `build/` location. | |
| 115 | 244 | * |
| 116 | 245 | * @since 6.7.0 |
| 117 | - * | |
| 118 | - * @global array $editor_styles | |
| 119 | - * | |
| 246 | + | |
| 120 | 247 | * @param WP_Styles $styles WP_Styles instance. |
| 121 | 248 | */ |
| 122 | 249 | function gutenberg_register_packages_styles( $styles ) { |
| 123 | 250 | // When in production, use the plugin's version as the asset version; |
| @@ -122,64 +249,75 @@ | ||
| 122 | 249 | function gutenberg_register_packages_styles( $styles ) { |
| 123 | 250 | // When in production, use the plugin's version as the asset version; |
| 124 | 251 | // else (for development or test) default to use the current time. |
| 125 | 252 | $version = defined( 'GUTENBERG_VERSION' ) && ! SCRIPT_DEBUG ? GUTENBERG_VERSION : time(); |
| 126 | - $suffix = SCRIPT_DEBUG ? '' : '.min'; | |
| 127 | 253 | |
| 128 | - // wp-components: add dashicons (icon font dependency) | |
| 129 | - $styles->query( 'wp-components', 'registered' )->deps[] = 'dashicons'; | |
| 254 | + gutenberg_override_style( | |
| 255 | + $styles, | |
| 256 | + 'wp-block-editor-content', | |
| 257 | + gutenberg_url( 'build/block-editor/content.css' ), | |
| 258 | + array(), | |
| 259 | + $version | |
| 260 | + ); | |
| 261 | + $styles->add_data( 'wp-block-editor-content', 'rtl', 'replace' ); | |
| 130 | 262 | |
| 131 | - // wp-edit-post: add wp-edit-blocks (custom handle not auto-inferred) | |
| 132 | - $styles->query( 'wp-edit-post', 'registered' )->deps[] = 'wp-edit-blocks'; | |
| 263 | + // Editor Styles. | |
| 264 | + gutenberg_override_style( | |
| 265 | + $styles, | |
| 266 | + 'wp-block-editor', | |
| 267 | + gutenberg_url( 'build/block-editor/style.css' ), | |
| 268 | + array( 'wp-components' ), | |
| 269 | + $version | |
| 270 | + ); | |
| 271 | + $styles->add_data( 'wp-block-editor', 'rtl', 'replace' ); | |
| 133 | 272 | |
| 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'; | |
| 273 | + gutenberg_override_style( | |
| 274 | + $styles, | |
| 275 | + 'wp-editor', | |
| 276 | + gutenberg_url( 'build/editor/style.css' ), | |
| 277 | + array( 'wp-components', 'wp-block-editor', 'wp-nux', 'wp-reusable-blocks' ), | |
| 278 | + $version | |
| 279 | + ); | |
| 280 | + $styles->add_data( 'wp-editor', 'rtl', 'replace' ); | |
| 139 | 281 | |
| 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-base-styles and add it to the already registered wp-admin stylesheet | |
| 147 | 282 | gutenberg_override_style( |
| 148 | 283 | $styles, |
| 149 | - 'wp-base-styles', | |
| 150 | - gutenberg_url( 'build/styles/base-styles/admin-schemes' . $suffix . '.css' ), | |
| 151 | - array(), | |
| 284 | + 'wp-edit-post', | |
| 285 | + gutenberg_url( 'build/edit-post/style.css' ), | |
| 286 | + array( 'wp-components', 'wp-block-editor', 'wp-editor', 'wp-edit-blocks', 'wp-block-library', 'wp-nux' ), | |
| 152 | 287 | $version |
| 153 | 288 | ); |
| 154 | - $styles->add_data( 'wp-base-styles', 'rtl', 'replace' ); | |
| 155 | - $styles->add_data( 'wp-base-styles', 'suffix', $suffix ); | |
| 156 | - $styles->add_data( 'wp-base-styles', 'path', gutenberg_dir_path() . 'build/styles/base-styles/admin-schemes' . $suffix . '.css' ); | |
| 157 | - $styles->query( 'wp-admin', 'registered' )->deps[] = 'wp-base-styles'; | |
| 289 | + $styles->add_data( 'wp-edit-post', 'rtl', 'replace' ); | |
| 158 | 290 | |
| 159 | 291 | gutenberg_override_style( |
| 160 | 292 | $styles, |
| 161 | - 'wp-block-editor-content', | |
| 162 | - gutenberg_url( 'build/styles/block-editor/content' . $suffix . '.css' ), | |
| 163 | - array( 'wp-components' ), | |
| 293 | + 'wp-components', | |
| 294 | + gutenberg_url( 'build/components/style.css' ), | |
| 295 | + array( 'dashicons' ), | |
| 164 | 296 | $version |
| 165 | 297 | ); |
| 166 | - $styles->add_data( 'wp-block-editor-content', 'rtl', 'replace' ); | |
| 167 | - $styles->add_data( 'wp-block-editor-content', 'suffix', $suffix ); | |
| 298 | + $styles->add_data( 'wp-components', 'rtl', 'replace' ); | |
| 168 | 299 | |
| 169 | 300 | $block_library_filename = wp_should_load_separate_core_block_assets() ? 'common' : 'style'; |
| 170 | 301 | gutenberg_override_style( |
| 171 | 302 | $styles, |
| 172 | 303 | 'wp-block-library', |
| 173 | - gutenberg_url( 'build/styles/block-library/' . $block_library_filename . $suffix . '.css' ), | |
| 304 | + gutenberg_url( 'build/block-library/' . $block_library_filename . '.css' ), | |
| 174 | 305 | array(), |
| 175 | 306 | $version |
| 176 | 307 | ); |
| 177 | 308 | $styles->add_data( 'wp-block-library', 'rtl', 'replace' ); |
| 178 | - $styles->add_data( 'wp-block-library', 'suffix', $suffix ); | |
| 179 | - $styles->add_data( 'wp-block-library', 'path', gutenberg_dir_path() . 'build/styles/block-library/' . $block_library_filename . $suffix . '.css' ); | |
| 309 | + $styles->add_data( 'wp-block-library', 'path', gutenberg_dir_path() . 'build/block-library/' . $block_library_filename . '.css' ); | |
| 180 | 310 | |
| 181 | - // Only add CONTENT styles here that should be enqueued in the iframe! | |
| 311 | + gutenberg_override_style( | |
| 312 | + $styles, | |
| 313 | + 'wp-format-library', | |
| 314 | + gutenberg_url( 'build/format-library/style.css' ), | |
| 315 | + array( 'wp-block-editor', 'wp-components' ), | |
| 316 | + $version | |
| 317 | + ); | |
| 318 | + $styles->add_data( 'wp-format-library', 'rtl', 'replace' ); | |
| 319 | + | |
| 182 | 320 | $wp_edit_blocks_dependencies = array( |
| 183 | 321 | 'wp-components', |
| 184 | 322 | // This need to be added before the block library styles, |
| 185 | 323 | // The block library styles override the "reset" styles. |
| @@ -184,12 +322,12 @@ | ||
| 184 | 322 | // This need to be added before the block library styles, |
| 185 | 323 | // The block library styles override the "reset" styles. |
| 186 | 324 | 'wp-reset-editor-styles', |
| 187 | 325 | 'wp-block-library', |
| 326 | + 'wp-reusable-blocks', | |
| 188 | 327 | // Until #37466, we can't specifically add them as editor styles yet, |
| 189 | 328 | // so we must hard-code it here as a dependency. |
| 190 | 329 | 'wp-block-editor-content', |
| 191 | - 'wp-base-styles', | |
| 192 | 330 | ); |
| 193 | 331 | |
| 194 | 332 | // Only load the default layout and margin styles for themes without theme.json file. |
| 195 | 333 | if ( ! wp_theme_has_theme_json() ) { |
| @@ -204,67 +342,122 @@ | ||
| 204 | 342 | |
| 205 | 343 | gutenberg_override_style( |
| 206 | 344 | $styles, |
| 207 | 345 | 'wp-reset-editor-styles', |
| 208 | - gutenberg_url( 'build/styles/block-library/reset' . $suffix . '.css' ), | |
| 346 | + gutenberg_url( 'build/block-library/reset.css' ), | |
| 209 | 347 | array( 'common', 'forms' ), // Make sure the reset is loaded after the default WP Admin styles. |
| 210 | 348 | $version |
| 211 | 349 | ); |
| 212 | 350 | $styles->add_data( 'wp-reset-editor-styles', 'rtl', 'replace' ); |
| 213 | - $styles->add_data( 'wp-reset-editor-styles', 'suffix', $suffix ); | |
| 214 | 351 | |
| 215 | 352 | gutenberg_override_style( |
| 216 | 353 | $styles, |
| 217 | 354 | 'wp-editor-classic-layout-styles', |
| 218 | - gutenberg_url( 'build/styles/edit-post/classic' . $suffix . '.css' ), | |
| 355 | + gutenberg_url( 'build/edit-post/classic.css' ), | |
| 219 | 356 | array(), |
| 220 | 357 | $version |
| 221 | 358 | ); |
| 222 | 359 | $styles->add_data( 'wp-editor-classic-layout-styles', 'rtl', 'replace' ); |
| 223 | - $styles->add_data( 'wp-editor-classic-layout-styles', 'suffix', $suffix ); | |
| 224 | 360 | |
| 225 | 361 | gutenberg_override_style( |
| 226 | 362 | $styles, |
| 227 | - 'wp-block-library-editor', | |
| 228 | - gutenberg_url( 'build/styles/block-library/editor' . $suffix . '.css' ), | |
| 229 | - array(), | |
| 363 | + 'wp-edit-blocks', | |
| 364 | + gutenberg_url( 'build/block-library/editor.css' ), | |
| 365 | + $wp_edit_blocks_dependencies, | |
| 230 | 366 | $version |
| 231 | 367 | ); |
| 232 | - $styles->add_data( 'wp-block-library-editor', 'rtl', 'replace' ); | |
| 233 | - $styles->add_data( 'wp-block-library-editor', 'suffix', $suffix ); | |
| 368 | + $styles->add_data( 'wp-edit-blocks', 'rtl', 'replace' ); | |
| 234 | 369 | |
| 235 | 370 | gutenberg_override_style( |
| 236 | 371 | $styles, |
| 237 | - 'wp-edit-blocks', | |
| 238 | - gutenberg_url( 'build/styles/block-library/editor' . $suffix . '.css' ), | |
| 239 | - $wp_edit_blocks_dependencies, | |
| 372 | + 'wp-nux', | |
| 373 | + gutenberg_url( 'build/nux/style.css' ), | |
| 374 | + array( 'wp-components' ), | |
| 240 | 375 | $version |
| 241 | 376 | ); |
| 242 | - $styles->add_data( 'wp-edit-blocks', 'rtl', 'replace' ); | |
| 243 | - $styles->add_data( 'wp-edit-blocks', 'suffix', $suffix ); | |
| 377 | + $styles->add_data( 'wp-nux', 'rtl', 'replace' ); | |
| 244 | 378 | |
| 245 | 379 | gutenberg_override_style( |
| 246 | 380 | $styles, |
| 247 | 381 | 'wp-block-library-theme', |
| 248 | - gutenberg_url( 'build/styles/block-library/theme' . $suffix . '.css' ), | |
| 382 | + gutenberg_url( 'build/block-library/theme.css' ), | |
| 249 | 383 | array(), |
| 250 | 384 | $version |
| 251 | 385 | ); |
| 252 | 386 | $styles->add_data( 'wp-block-library-theme', 'rtl', 'replace' ); |
| 253 | - $styles->add_data( 'wp-block-library-theme', 'suffix', $suffix ); | |
| 254 | 387 | |
| 255 | 388 | gutenberg_override_style( |
| 256 | 389 | $styles, |
| 257 | - 'classic-theme-styles', | |
| 258 | - gutenberg_url( 'build/styles/block-library/classic' . $suffix . '.css' ), | |
| 259 | - array(), | |
| 390 | + 'wp-list-reusable-blocks', | |
| 391 | + gutenberg_url( 'build/list-reusable-blocks/style.css' ), | |
| 392 | + array( 'wp-components' ), | |
| 260 | 393 | $version |
| 261 | 394 | ); |
| 262 | - $styles->add_data( 'classic-theme-styles', 'rtl', 'replace' ); | |
| 263 | - $styles->add_data( 'classic-theme-styles', 'suffix', $suffix ); | |
| 264 | - $styles->add_data( 'classic-theme-styles', 'path', gutenberg_dir_path() . 'build/styles/block-library/classic' . $suffix . '.css' ); | |
| 395 | + $styles->add_data( 'wp-list-reusable-block', 'rtl', 'replace' ); | |
| 396 | + | |
| 397 | + gutenberg_override_style( | |
| 398 | + $styles, | |
| 399 | + 'wp-edit-navigation', | |
| 400 | + gutenberg_url( 'build/edit-navigation/style.css' ), | |
| 401 | + array( 'wp-components', 'wp-block-editor', 'wp-editor', 'wp-edit-blocks' ), | |
| 402 | + $version | |
| 403 | + ); | |
| 404 | + $styles->add_data( 'wp-edit-navigation', 'rtl', 'replace' ); | |
| 405 | + | |
| 406 | + gutenberg_override_style( | |
| 407 | + $styles, | |
| 408 | + 'wp-edit-site', | |
| 409 | + gutenberg_url( 'build/edit-site/style.css' ), | |
| 410 | + array( 'wp-components', 'wp-block-editor', 'wp-editor', 'wp-edit-blocks' ), | |
| 411 | + $version | |
| 412 | + ); | |
| 413 | + $styles->add_data( 'wp-edit-site', 'rtl', 'replace' ); | |
| 414 | + | |
| 415 | + gutenberg_override_style( | |
| 416 | + $styles, | |
| 417 | + 'wp-edit-widgets', | |
| 418 | + gutenberg_url( 'build/edit-widgets/style.css' ), | |
| 419 | + array( 'wp-components', 'wp-block-editor', 'wp-editor', 'wp-edit-blocks', 'wp-reusable-blocks', 'wp-widgets' ), | |
| 420 | + $version | |
| 421 | + ); | |
| 422 | + $styles->add_data( 'wp-edit-widgets', 'rtl', 'replace' ); | |
| 423 | + | |
| 424 | + gutenberg_override_style( | |
| 425 | + $styles, | |
| 426 | + 'wp-block-directory', | |
| 427 | + gutenberg_url( 'build/block-directory/style.css' ), | |
| 428 | + array( 'wp-block-editor', 'wp-components' ), | |
| 429 | + $version | |
| 430 | + ); | |
| 431 | + $styles->add_data( 'wp-block-directory', 'rtl', 'replace' ); | |
| 432 | + | |
| 433 | + gutenberg_override_style( | |
| 434 | + $styles, | |
| 435 | + 'wp-customize-widgets', | |
| 436 | + gutenberg_url( 'build/customize-widgets/style.css' ), | |
| 437 | + array( 'wp-components', 'wp-block-editor', 'wp-editor', 'wp-edit-blocks', 'wp-widgets' ), | |
| 438 | + $version | |
| 439 | + ); | |
| 440 | + $styles->add_data( 'wp-customize-widgets', 'rtl', 'replace' ); | |
| 441 | + | |
| 442 | + gutenberg_override_style( | |
| 443 | + $styles, | |
| 444 | + 'wp-reusable-blocks', | |
| 445 | + gutenberg_url( 'build/reusable-blocks/style.css' ), | |
| 446 | + array( 'wp-components' ), | |
| 447 | + $version | |
| 448 | + ); | |
| 449 | + $styles->add_data( 'wp-reusable-block', 'rtl', 'replace' ); | |
| 450 | + | |
| 451 | + gutenberg_override_style( | |
| 452 | + $styles, | |
| 453 | + 'wp-widgets', | |
| 454 | + gutenberg_url( 'build/widgets/style.css' ), | |
| 455 | + array( 'wp-components' ) | |
| 456 | + ); | |
| 457 | + $styles->add_data( 'wp-widgets', 'rtl', 'replace' ); | |
| 265 | 458 | } |
| 266 | -add_action( 'wp_default_styles', 'gutenberg_register_packages_styles', 15 ); | |
| 459 | +add_action( 'wp_default_styles', 'gutenberg_register_packages_styles' ); | |
| 267 | 460 | |
| 268 | 461 | /** |
| 269 | 462 | * Fetches, processes and compiles stored core styles, then combines and renders them to the page. |
| 270 | 463 | * Styles are stored via the Style Engine API. |
| @@ -271,12 +464,10 @@ | ||
| 271 | 464 | * |
| 272 | 465 | * This hook also exists, and should be backported to Core in future versions. |
| 273 | 466 | * However, it is envisaged that Gutenberg will continue to use the Style Engine's `gutenberg_*` functions and `_Gutenberg` classes to aid continuous development. |
| 274 | 467 | * |
| 275 | - * @since 6.1 | |
| 468 | + * See: https://developer.wordpress.org/block-editor/reference-guides/packages/packages-style-engine/ | |
| 276 | 469 | * |
| 277 | - * @link https://developer.wordpress.org/block-editor/reference-guides/packages/packages-style-engine/ | |
| 278 | - * | |
| 279 | 470 | * @param array $options { |
| 280 | 471 | * Optional. An array of options to pass to gutenberg_style_engine_get_stylesheet_from_context(). Default empty array. |
| 281 | 472 | * |
| 282 | 473 | * @type bool $optimize Whether to optimize the CSS output, e.g., combine rules. Default is `false`. |
| @@ -282,8 +473,10 @@ | ||
| 282 | 473 | * @type bool $optimize Whether to optimize the CSS output, e.g., combine rules. Default is `false`. |
| 283 | 474 | * @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. |
| 284 | 475 | * } |
| 285 | 476 | * |
| 477 | + * @since 6.1 | |
| 478 | + * | |
| 286 | 479 | * @return void |
| 287 | 480 | */ |
| 288 | 481 | function gutenberg_enqueue_stored_styles( $options = array() ) { |
| 289 | 482 | $is_block_theme = wp_is_block_theme(); |
| @@ -315,9 +508,9 @@ | ||
| 315 | 508 | } |
| 316 | 509 | |
| 317 | 510 | // Combines Core styles. |
| 318 | 511 | if ( ! empty( $compiled_core_stylesheet ) ) { |
| 319 | - wp_register_style( $style_tag_id, false, array(), true ); | |
| 512 | + wp_register_style( $style_tag_id, false, array(), true, true ); | |
| 320 | 513 | wp_add_inline_style( $style_tag_id, $compiled_core_stylesheet ); |
| 321 | 514 | wp_enqueue_style( $style_tag_id ); |
| 322 | 515 | } |
| 323 | 516 | |
| @@ -338,9 +531,9 @@ | ||
| 338 | 531 | } |
| 339 | 532 | $styles = gutenberg_style_engine_get_stylesheet_from_context( $store_name, $options ); |
| 340 | 533 | if ( ! empty( $styles ) ) { |
| 341 | 534 | $key = "wp-style-engine-$store_name"; |
| 342 | - wp_register_style( $key, false, array(), true ); | |
| 535 | + wp_register_style( $key, false, array(), true, true ); | |
| 343 | 536 | wp_add_inline_style( $key, $styles ); |
| 344 | 537 | wp_enqueue_style( $key ); |
| 345 | 538 | } |
| 346 | 539 | } |
| @@ -345,83 +538,9 @@ | ||
| 345 | 538 | } |
| 346 | 539 | } |
| 347 | 540 | } |
| 348 | 541 | |
| 349 | -/** | |
| 350 | - * Registers vendor JavaScript files to be used as dependencies of the editor | |
| 351 | - * and plugins. | |
| 352 | - * | |
| 353 | - * This function is called from a script during the plugin build process, so it | |
| 354 | - * should not call any WordPress PHP functions. | |
| 355 | - * | |
| 356 | - * @since 13.0 | |
| 357 | - * | |
| 358 | - * @param WP_Scripts $scripts WP_Scripts instance. | |
| 359 | - */ | |
| 360 | -function gutenberg_register_vendor_scripts( $scripts ) { | |
| 361 | - $extension = SCRIPT_DEBUG ? '.js' : '.min.js'; | |
| 362 | - $vendors_dir = gutenberg_dir_path() . 'build/scripts/vendors/'; | |
| 363 | - | |
| 364 | - // When the React 19 experiment is enabled, register React 19 vendor | |
| 365 | - // scripts under the `react`, `react-dom`, and `react-jsx-runtime` handles. | |
| 366 | - $use_react_19 = gutenberg_is_experiment_enabled( 'gutenberg-react-19' ); | |
| 367 | - | |
| 368 | - $vendor_handles = array( 'react', 'react-dom', 'react-jsx-runtime' ); | |
| 369 | - | |
| 370 | - foreach ( $vendor_handles as $handle ) { | |
| 371 | - $source = $use_react_19 ? $handle . '-19' : $handle; | |
| 372 | - $asset_file = $vendors_dir . $source . '.min.asset.php'; | |
| 373 | - $asset = file_exists( $asset_file ) ? require $asset_file : array(); | |
| 374 | - $dependencies = $asset['dependencies'] ?? array(); | |
| 375 | - $version = $asset['version'] ?? '0'; | |
| 376 | - | |
| 377 | - gutenberg_override_script( | |
| 378 | - $scripts, | |
| 379 | - $handle, | |
| 380 | - gutenberg_url( 'build/scripts/vendors/' . $source . $extension ), | |
| 381 | - $dependencies, | |
| 382 | - $version | |
| 383 | - ); | |
| 384 | - } | |
| 385 | - | |
| 386 | - // WordPress Core in `wp_register_development_scripts` sets `wp-react-refresh-entry` | |
| 387 | - // as a dependency to `react` when `SCRIPT_DEBUG` is true. Preserve that here. | |
| 388 | - if ( SCRIPT_DEBUG ) { | |
| 389 | - $react = $scripts->query( 'react', 'registered' ); | |
| 390 | - if ( $react && ! in_array( 'wp-react-refresh-entry', $react->deps, true ) ) { | |
| 391 | - $react->deps[] = 'wp-react-refresh-entry'; | |
| 392 | - } | |
| 393 | - } | |
| 394 | -} | |
| 395 | -add_action( 'wp_default_scripts', 'gutenberg_register_vendor_scripts' ); | |
| 396 | - | |
| 397 | -/** | |
| 398 | - * Registers or re-registers Gutenberg Script Modules. | |
| 399 | - * | |
| 400 | - * Script modules that are registered by Core will be re-registered by Gutenberg. | |
| 401 | - * | |
| 402 | - * @since 19.3.0 | |
| 403 | - */ | |
| 404 | -function gutenberg_define_interactivity_modules_support() { | |
| 405 | - // Load the auto-generated module registry. | |
| 406 | - $modules_registry_file = gutenberg_dir_path() . 'build/modules/index.php'; | |
| 407 | - if ( ! file_exists( $modules_registry_file ) ) { | |
| 408 | - return; | |
| 409 | - } | |
| 410 | - | |
| 411 | - $modules = require $modules_registry_file; | |
| 412 | - | |
| 413 | - // Add client navigation support to block library modules. | |
| 414 | - foreach ( $modules as $module ) { | |
| 415 | - if ( str_starts_with( $module['id'], '@wordpress/block-library' ) && method_exists( 'WP_Interactivity_API', 'add_client_navigation_support_to_script_module' ) ) { | |
| 416 | - wp_interactivity()->add_client_navigation_support_to_script_module( $module['id'] ); | |
| 417 | - } | |
| 418 | - } | |
| 419 | -} | |
| 420 | -remove_action( 'wp_default_scripts', 'wp_define_interactivity_modules_support' ); | |
| 421 | -add_action( 'wp_default_scripts', 'gutenberg_define_interactivity_modules_support' ); | |
| 422 | - | |
| 423 | -/** | |
| 542 | +/* | |
| 424 | 543 | * Always remove the Core action hook while gutenberg_enqueue_stored_styles() exists to avoid styles being printed twice. |
| 425 | 544 | * This is also because gutenberg_enqueue_stored_styles uses the Style Engine's `gutenberg_*` functions and `_Gutenberg` classes, |
| 426 | 545 | * which are in continuous development and generally ahead of Core. |
| 427 | 546 | */ |
| @@ -430,28 +549,4 @@ | ||
| 430 | 549 | |
| 431 | 550 | // Enqueue stored styles. |
| 432 | 551 | add_action( 'wp_enqueue_scripts', 'gutenberg_enqueue_stored_styles' ); |
| 433 | 552 | add_action( 'wp_footer', 'gutenberg_enqueue_stored_styles', 1 ); |
| 434 | - | |
| 435 | -add_action( 'enqueue_block_editor_assets', 'gutenberg_enqueue_latex_to_mathml_loader' ); | |
| 436 | -function gutenberg_enqueue_latex_to_mathml_loader() { | |
| 437 | - wp_enqueue_script_module( '@wordpress/latex-to-mathml/loader' ); | |
| 438 | -} | |
| 439 | - | |
| 440 | -/** | |
| 441 | - * Enqueue the vips loader script module in the block editor. | |
| 442 | - * | |
| 443 | - * This registers @wordpress/vips/worker as a dynamic dependency in the import map, | |
| 444 | - * enabling on-demand loading of the ~3.8MB WASM-based image processing module | |
| 445 | - * when client-side media processing is triggered via @wordpress/upload-media. | |
| 446 | - * | |
| 447 | - * @see packages/vips/src/loader.ts | |
| 448 | - */ | |
| 449 | -add_action( 'enqueue_block_editor_assets', 'gutenberg_enqueue_vips_loader' ); | |
| 450 | -function gutenberg_enqueue_vips_loader() { | |
| 451 | - wp_enqueue_script_module( '@wordpress/vips/loader' ); | |
| 452 | -} | |
| 453 | - | |
| 454 | -add_action( 'admin_enqueue_scripts', 'gutenberg_enqueue_core_abilities' ); | |
| 455 | -function gutenberg_enqueue_core_abilities() { | |
| 456 | - wp_enqueue_script_module( '@wordpress/core-abilities' ); | |
| 457 | -} | |