Changeset 50838
- Timestamp:
- 05/11/2021 04:26:28 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/script-loader.php
r50837 r50838 1366 1366 1367 1367 /** 1368 * Checks whether separate assets should be loaded for core blocks.1369 *1370 * @since 5.81371 *1372 * @return bool1373 */1374 function should_load_separate_core_block_assets() {1375 if ( is_admin() || is_feed() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) {1376 return false;1377 }1378 /**1379 * Determine if separate styles & scripts will be loaded for blocks on-render or not.1380 *1381 * @since 5.8.01382 *1383 * @param bool $load_separate_styles Whether separate styles will be loaded or not.1384 *1385 * @return bool Whether separate styles will be loaded or not.1386 */1387 return apply_filters( 'separate_core_block_assets', false );1388 }1389 1390 /**1391 1368 * Assign default styles to $styles object. 1392 1369 * … … 2277 2254 * @since 5.6.0 2278 2255 * 2279 * @return bool 2256 * @return bool Whether scripts and styles should be enqueued. 2280 2257 */ 2281 2258 function wp_should_load_block_editor_scripts_and_styles() { … … 2285 2262 2286 2263 /** 2287 * Filters the flag that decides whether or not block editor scripts and 2288 * stylesare going to be enqueued on the current screen.2264 * Filters the flag that decides whether or not block editor scripts and styles 2265 * are going to be enqueued on the current screen. 2289 2266 * 2290 2267 * @since 5.6.0 … … 2293 2270 */ 2294 2271 return apply_filters( 'should_load_block_editor_scripts_and_styles', $is_block_editor_screen ); 2272 } 2273 2274 /** 2275 * Checks whether separate assets should be loaded for core blocks on-render. 2276 * 2277 * @since 5.8.0 2278 * 2279 * @return bool Whether separate assets will be loaded or not. 2280 */ 2281 function should_load_separate_core_block_assets() { 2282 if ( is_admin() || is_feed() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) { 2283 return false; 2284 } 2285 2286 /** 2287 * Filters the flag that decides whether or not separate scripts and styles 2288 * will be loaded for core blocks on-render or not. 2289 * 2290 * @since 5.8.0 2291 * 2292 * @param bool $load_separate_assets Whether separate assets will be loaded or not. 2293 * Default false. 2294 */ 2295 return apply_filters( 'separate_core_block_assets', false ); 2295 2296 } 2296 2297 … … 2530 2531 2531 2532 /** 2532 * Allow small styles to be inlined. 2533 * This improves performance and sustainability, and is opt-in. 2534 * 2535 * Stylesheets can opt-in by adding `path` data using `wp_style_add_data`, and defining the file's absolute path. 2536 * wp_style_add_data( $style_handle, 'path', $file_path ); 2533 * Allows small styles to be inlined. 2534 * 2535 * This improves performance and sustainability, and is opt-in. Stylesheets can opt in 2536 * by adding `path` data using `wp_style_add_data`, and defining the file's absolute path: 2537 * 2538 * wp_style_add_data( $style_handle, 'path', $file_path ); 2537 2539 * 2538 2540 * @since 5.8.0 2539 2541 * 2540 * @ return void2542 * @global WP_Styles $wp_styles 2541 2543 */ 2542 2544 function wp_maybe_inline_styles() { 2545 global $wp_styles; 2543 2546 2544 2547 $total_inline_limit = 20000; … … 2547 2550 * 2548 2551 * @param int $total_inline_limit The file-size threshold, in bytes. Defaults to 20000. 2549 * @return int The file-size threshold, in bytes.2550 2552 */ 2551 2553 $total_inline_limit = apply_filters( 'styles_inline_size_limit', $total_inline_limit ); 2552 2554 2553 global $wp_styles;2554 2555 $styles = array(); 2555 2556 … … 2574 2575 ); 2575 2576 2576 /* *2577 /* 2577 2578 * The total inlined size. 2578 2579 * -
trunk/tests/phpunit/tests/blocks/register.php
r50836 r50838 260 260 /** 261 261 * @ticket 50263 262 * @ticket 50328 262 263 */ 263 264 function test_success_register_block_style_handle() { … … 308 309 * 309 310 * @ticket 50263 311 * @ticket 50328 310 312 */ 311 313 function test_block_registers_with_metadata_fixture() { -
trunk/tests/phpunit/tests/dependencies/styles.php
r50836 r50838 423 423 424 424 /** 425 * Tests that the main "style.css" file gets enqueued when the site doesn't opt -in to separate_core_block_assets.425 * Tests that the main "style.css" file gets enqueued when the site doesn't opt in to separate core block assets. 426 426 * 427 427 * @ticket 50263 428 */ 429 function test_common_block_styles_for_viewing_without_split_styles() { 428 * 429 * @covers ::wp_default_styles 430 */ 431 function test_block_styles_for_viewing_without_split_styles() { 430 432 add_filter( 'separate_core_block_assets', '__return_false' ); 431 433 wp_default_styles( $GLOBALS['wp_styles'] ); 432 434 433 435 $this->assertSame( 434 $GLOBALS['wp_styles']->registered['wp-block-library']->src,435 '/' . WPINC . '/css/dist/block-library/style.css'436 '/' . WPINC . '/css/dist/block-library/style.css', 437 $GLOBALS['wp_styles']->registered['wp-block-library']->src 436 438 ); 437 439 } 438 440 439 441 /** 440 * Tests that the "common.css" file gets enqueued when the site opts -in to separate_core_block_assets.442 * Tests that the "common.css" file gets enqueued when the site opts in to separate core block assets. 441 443 * 442 444 * @ticket 50263 443 */ 444 function test_common_block_styles_for_viewing_with_split_styles() { 445 add_filter( 'separate_core_block_assets', '__return_false' ); 446 wp_default_styles( $GLOBALS['wp_styles'] ); 447 448 $this->assertSame( 449 $GLOBALS['wp_styles']->registered['wp-block-library']->src, 450 '/' . WPINC . '/css/dist/block-library/style.css' 451 ); 452 } 453 445 * 446 * @covers ::wp_default_styles 447 */ 454 448 function test_block_styles_for_viewing_with_split_styles() { 455 449 add_filter( 'separate_core_block_assets', '__return_true' ); … … 457 451 458 452 $this->assertSame( 459 $GLOBALS['wp_styles']->registered['wp-block-library']->src,460 '/' . WPINC . '/css/dist/block-library/common.css'453 '/' . WPINC . '/css/dist/block-library/common.css', 454 $GLOBALS['wp_styles']->registered['wp-block-library']->src 461 455 ); 462 456 }
Note: See TracChangeset
for help on using the changeset viewer.