Changeset 44157
- Timestamp:
- 12/14/2018 03:35:55 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/5.0 merged: 43812
- Property svn:mergeinfo changed
-
trunk/src/wp-includes/default-filters.php
r44118 r44157 508 508 add_action( 'wp_enqueue_scripts', 'wp_localize_jquery_ui_datepicker', 1000 ); 509 509 add_action( 'admin_enqueue_scripts', 'wp_localize_jquery_ui_datepicker', 1000 ); 510 add_action( 'wp_enqueue_scripts', 'wp_common_block_scripts_and_styles' ); 511 add_action( 'admin_enqueue_scripts', 'wp_common_block_scripts_and_styles' ); 512 add_action( 'enqueue_block_assets', 'wp_enqueue_registered_block_scripts_and_styles' ); 513 add_action( 'enqueue_block_editor_assets', 'wp_enqueue_registered_block_scripts_and_styles' ); 510 514 add_action( 'admin_print_scripts-index.php', 'wp_localize_community_events' ); 511 515 add_filter( 'wp_print_scripts', 'wp_just_in_time_script_localization' ); -
trunk/src/wp-includes/script-loader.php
r44143 r44157 2416 2416 } 2417 2417 } 2418 2419 /** 2420 * Handles the enqueueing of block scripts and styles that are common to both 2421 * the editor and the front-end. 2422 * 2423 * @since 5.0.0 2424 * 2425 * @global WP_Screen $current_screen 2426 */ 2427 function wp_common_block_scripts_and_styles() { 2428 global $current_screen; 2429 2430 if ( is_admin() && ! $current_screen->is_block_editor() ) { 2431 return; 2432 } 2433 2434 wp_enqueue_style( 'wp-block-library' ); 2435 2436 if ( current_theme_supports( 'wp-block-styles' ) ) { 2437 wp_enqueue_style( 'wp-block-library-theme' ); 2438 } 2439 2440 /** 2441 * Fires after enqueuing block assets for both editor and front-end. 2442 * 2443 * Call `add_action` on any hook before 'wp_enqueue_scripts'. 2444 * 2445 * In the function call you supply, simply use `wp_enqueue_script` and 2446 * `wp_enqueue_style` to add your functionality to the Gutenberg editor. 2447 * 2448 * @since 5.0.0 2449 */ 2450 do_action( 'enqueue_block_assets' ); 2451 } 2452 2453 /** 2454 * Enqueues registered block scripts and styles, depending on current rendered 2455 * context (only enqueuing editor scripts while in context of the editor). 2456 * 2457 * @since 5.0.0 2458 * 2459 * @global WP_Screen $current_screen 2460 */ 2461 function wp_enqueue_registered_block_scripts_and_styles() { 2462 global $current_screen; 2463 2464 $is_editor = ( is_admin() && $current_screen->is_block_editor() ); 2465 2466 $block_registry = WP_Block_Type_Registry::get_instance(); 2467 foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) { 2468 // Front-end styles. 2469 if ( ! empty( $block_type->style ) ) { 2470 wp_enqueue_style( $block_type->style ); 2471 } 2472 2473 // Front-end script. 2474 if ( ! empty( $block_type->script ) ) { 2475 wp_enqueue_script( $block_type->script ); 2476 } 2477 2478 // Editor styles. 2479 if ( $is_editor && ! empty( $block_type->editor_style ) ) { 2480 wp_enqueue_style( $block_type->editor_style ); 2481 } 2482 2483 // Editor script. 2484 if ( $is_editor && ! empty( $block_type->editor_script ) ) { 2485 wp_enqueue_script( $block_type->editor_script ); 2486 } 2487 } 2488 } -
trunk/tests/phpunit/tests/dependencies/styles.php
r42343 r44157 5 5 */ 6 6 class Tests_Dependencies_Styles extends WP_UnitTestCase { 7 var $old_wp_styles; 7 private $old_wp_styles; 8 private $old_wp_scripts; 8 9 9 10 function setUp() { 10 11 parent::setUp(); 12 11 13 if ( empty( $GLOBALS['wp_styles'] ) ) { 12 14 $GLOBALS['wp_styles'] = null; 13 15 } 16 14 17 $this->old_wp_styles = $GLOBALS['wp_styles']; 18 19 if ( empty( $GLOBALS['wp_scripts'] ) ) { 20 $GLOBALS['wp_scripts'] = null; 21 } 22 23 $this->old_wp_styles = $GLOBALS['wp_scripts']; 24 15 25 remove_action( 'wp_default_styles', 'wp_default_styles' ); 16 26 remove_action( 'wp_print_styles', 'print_emoji_styles' ); 27 17 28 $GLOBALS['wp_styles'] = new WP_Styles(); 18 29 $GLOBALS['wp_styles']->default_version = get_bloginfo( 'version' ); 30 31 $GLOBALS['wp_scripts'] = new WP_Scripts(); 32 $GLOBALS['wp_scripts']->default_version = get_bloginfo( 'version' ); 19 33 } 20 34 21 35 function tearDown() { 22 $GLOBALS['wp_styles'] = $this->old_wp_styles; 36 $GLOBALS['wp_styles'] = $this->old_wp_styles; 37 $GLOBALS['wp_scripts'] = $this->old_wp_scripts; 38 23 39 add_action( 'wp_default_styles', 'wp_default_styles' ); 24 40 add_action( 'wp_print_styles', 'print_emoji_styles' ); 41 42 if ( current_theme_supports( 'wp-block-styles' ) ) { 43 remove_theme_support( 'wp-block-styles' ); 44 } 45 25 46 parent::tearDown(); 26 47 } … … 306 327 ); 307 328 } 329 330 /** 331 * Tests that visual block styles are enqueued in the editor even when there is not theme support for 'wp-block-styles'. 332 * 333 * Visual block styles should always be enqueued when editing to avoid the appearance of a broken editor. 334 */ 335 function test_block_styles_for_editing_without_theme_support() { 336 // Confirm we are without theme support by default. 337 $this->assertFalse( current_theme_supports( 'wp-block-styles' ) ); 338 339 wp_default_styles( $GLOBALS['wp_styles'] ); 340 341 $this->assertFalse( wp_style_is( 'wp-block-library-theme' ) ); 342 wp_enqueue_style( 'wp-edit-blocks' ); 343 $this->assertTrue( wp_style_is( 'wp-block-library-theme' ) ); 344 } 345 346 /** 347 * Tests that visual block styles are enqueued when there is theme support for 'wp-block-styles'. 348 * 349 * Visual block styles should always be enqueued when editing to avoid the appearance of a broken editor. 350 */ 351 function test_block_styles_for_editing_with_theme_support() { 352 add_theme_support( 'wp-block-styles' ); 353 354 wp_default_styles( $GLOBALS['wp_styles'] ); 355 356 $this->assertFalse( wp_style_is( 'wp-block-library-theme' ) ); 357 wp_common_block_scripts_and_styles(); 358 $this->assertTrue( wp_style_is( 'wp-block-library-theme' ) ); 359 } 360 361 /** 362 * Tests that visual block styles are not enqueued for viewing when there is no theme support for 'wp-block-styles'. 363 * 364 * Visual block styles should not be enqueued unless a theme opts in. 365 * This way we avoid style conflicts with existing themes. 366 */ 367 function test_no_block_styles_for_viewing_without_theme_support() { 368 // Confirm we are without theme support by default. 369 $this->assertFalse( current_theme_supports( 'wp-block-styles' ) ); 370 371 wp_default_styles( $GLOBALS['wp_styles'] ); 372 373 $this->assertFalse( wp_style_is( 'wp-block-library-theme' ) ); 374 wp_enqueue_style( 'wp-block-library' ); 375 $this->assertFalse( wp_style_is( 'wp-block-library-theme' ) ); 376 } 377 378 /** 379 * Tests that visual block styles are enqueued for viewing when there is theme support for 'wp-block-styles'. 380 * 381 * Visual block styles should be enqueued when a theme opts in. 382 */ 383 function test_block_styles_for_viewing_with_theme_support() { 384 add_theme_support( 'wp-block-styles' ); 385 386 wp_default_styles( $GLOBALS['wp_styles'] ); 387 388 $this->assertFalse( wp_style_is( 'wp-block-library-theme' ) ); 389 wp_common_block_scripts_and_styles(); 390 $this->assertTrue( wp_style_is( 'wp-block-library-theme' ) ); 391 } 308 392 }
Note: See TracChangeset
for help on using the changeset viewer.