Changeset 43812
- Timestamp:
- 10/24/2018 12:35:51 AM (6 years ago)
- Location:
- branches/5.0
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.0/src/wp-includes/default-filters.php
r43807 r43812 496 496 add_action( 'wp_enqueue_scripts', 'wp_localize_jquery_ui_datepicker', 1000 ); 497 497 add_action( 'admin_enqueue_scripts', 'wp_localize_jquery_ui_datepicker', 1000 ); 498 add_action( 'wp_enqueue_scripts', 'wp_common_block_scripts_and_styles' ); 499 add_action( 'admin_enqueue_scripts', 'wp_common_block_scripts_and_styles' ); 500 add_action( 'enqueue_block_assets', 'wp_enqueue_registered_block_scripts_and_styles' ); 501 add_action( 'enqueue_block_editor_assets', 'wp_enqueue_registered_block_scripts_and_styles' ); 498 502 add_action( 'admin_print_scripts-index.php', 'wp_localize_community_events' ); 499 503 add_filter( 'wp_print_scripts', 'wp_just_in_time_script_localization' ); -
branches/5.0/src/wp-includes/script-loader.php
r43803 r43812 2179 2179 } 2180 2180 } 2181 2182 /** 2183 * Handles the enqueueing of block scripts and styles that are common to both 2184 * the editor and the front-end. 2185 * 2186 * @since 5.0.0 2187 * 2188 * @global WP_Screen $current_screen 2189 */ 2190 function wp_common_block_scripts_and_styles() { 2191 global $current_screen; 2192 2193 if ( is_admin() && ! $current_screen->is_block_editor() ) { 2194 return; 2195 } 2196 2197 wp_enqueue_style( 'wp-block-library' ); 2198 2199 if ( current_theme_supports( 'wp-block-styles' ) ) { 2200 wp_enqueue_style( 'wp-block-library-theme' ); 2201 } 2202 2203 /** 2204 * Fires after enqueuing block assets for both editor and front-end. 2205 * 2206 * Call `add_action` on any hook before 'wp_enqueue_scripts'. 2207 * 2208 * In the function call you supply, simply use `wp_enqueue_script` and 2209 * `wp_enqueue_style` to add your functionality to the Gutenberg editor. 2210 * 2211 * @since 5.0.0 2212 */ 2213 do_action( 'enqueue_block_assets' ); 2214 } 2215 2216 /** 2217 * Enqueues registered block scripts and styles, depending on current rendered 2218 * context (only enqueuing editor scripts while in context of the editor). 2219 * 2220 * @since 5.0.0 2221 * 2222 * @global WP_Screen $current_screen 2223 */ 2224 function wp_enqueue_registered_block_scripts_and_styles() { 2225 global $current_screen; 2226 2227 $is_editor = ( is_admin() && $current_screen->is_block_editor() ); 2228 2229 $block_registry = WP_Block_Type_Registry::get_instance(); 2230 foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) { 2231 // Front-end styles. 2232 if ( ! empty( $block_type->style ) ) { 2233 wp_enqueue_style( $block_type->style ); 2234 } 2235 2236 // Front-end script. 2237 if ( ! empty( $block_type->script ) ) { 2238 wp_enqueue_script( $block_type->script ); 2239 } 2240 2241 // Editor styles. 2242 if ( $is_editor && ! empty( $block_type->editor_style ) ) { 2243 wp_enqueue_style( $block_type->editor_style ); 2244 } 2245 2246 // Editor script. 2247 if ( $is_editor && ! empty( $block_type->editor_script ) ) { 2248 wp_enqueue_script( $block_type->editor_script ); 2249 } 2250 } 2251 } -
branches/5.0/tests/phpunit/tests/dependencies/styles.php
r36649 r43812 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(); 11 if ( empty( $GLOBALS['wp_styles'] ) ) 12 13 if ( empty( $GLOBALS['wp_styles'] ) ) { 12 14 $GLOBALS['wp_styles'] = null; 15 } 16 13 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 14 25 remove_action( 'wp_default_styles', 'wp_default_styles' ); 15 26 remove_action( 'wp_print_styles', 'print_emoji_styles' ); 27 16 28 $GLOBALS['wp_styles'] = new WP_Styles(); 17 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' ); 18 33 } 19 34 20 35 function tearDown() { 21 36 $GLOBALS['wp_styles'] = $this->old_wp_styles; 37 $GLOBALS['wp_scripts'] = $this->old_wp_scripts; 38 22 39 add_action( 'wp_default_styles', 'wp_default_styles' ); 23 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 24 46 parent::tearDown(); 25 47 } … … 299 321 ); 300 322 } 323 324 /** 325 * Tests that visual block styles are enqueued in the editor even when there is not theme support for 'wp-block-styles'. 326 * 327 * Visual block styles should always be enqueued when editing to avoid the appearance of a broken editor. 328 */ 329 function test_block_styles_for_editing_without_theme_support() { 330 // Confirm we are without theme support by default. 331 $this->assertFalse( current_theme_supports( 'wp-block-styles' ) ); 332 333 wp_default_styles( $GLOBALS['wp_styles'] ); 334 335 $this->assertFalse( wp_style_is( 'wp-block-library-theme' ) ); 336 wp_enqueue_style( 'wp-edit-blocks' ); 337 $this->assertTrue( wp_style_is( 'wp-block-library-theme' ) ); 338 } 339 340 /** 341 * Tests that visual block styles are enqueued when there is theme support for 'wp-block-styles'. 342 * 343 * Visual block styles should always be enqueued when editing to avoid the appearance of a broken editor. 344 */ 345 function test_block_styles_for_editing_with_theme_support() { 346 add_theme_support( 'wp-block-styles' ); 347 348 wp_default_styles( $GLOBALS['wp_styles'] ); 349 350 $this->assertFalse( wp_style_is( 'wp-block-library-theme' ) ); 351 wp_common_block_scripts_and_styles(); 352 $this->assertTrue( wp_style_is( 'wp-block-library-theme' ) ); 353 } 354 355 /** 356 * Tests that visual block styles are not enqueued for viewing when there is no theme support for 'wp-block-styles'. 357 * 358 * Visual block styles should not be enqueued unless a theme opts in. 359 * This way we avoid style conflicts with existing themes. 360 */ 361 function test_no_block_styles_for_viewing_without_theme_support() { 362 // Confirm we are without theme support by default. 363 $this->assertFalse( current_theme_supports( 'wp-block-styles' ) ); 364 365 wp_default_styles( $GLOBALS['wp_styles'] ); 366 367 $this->assertFalse( wp_style_is( 'wp-block-library-theme' ) ); 368 wp_enqueue_style( 'wp-block-library' ); 369 $this->assertFalse( wp_style_is( 'wp-block-library-theme' ) ); 370 } 371 372 /** 373 * Tests that visual block styles are enqueued for viewing when there is theme support for 'wp-block-styles'. 374 * 375 * Visual block styles should be enqueued when a theme opts in. 376 */ 377 function test_block_styles_for_viewing_with_theme_support() { 378 add_theme_support( 'wp-block-styles' ); 379 380 wp_default_styles( $GLOBALS['wp_styles'] ); 381 382 $this->assertFalse( wp_style_is( 'wp-block-library-theme' ) ); 383 wp_common_block_scripts_and_styles(); 384 $this->assertTrue( wp_style_is( 'wp-block-library-theme' ) ); 385 } 301 386 }
Note: See TracChangeset
for help on using the changeset viewer.