Ticket #50328: 50328-skip-assets.diff
| File 50328-skip-assets.diff, 6.3 KB (added by , 5 years ago) |
|---|
-
src/wp-includes/blocks/index.php
56 56 ABSPATH . WPINC . '/blocks/' . $block_folder 57 57 ); 58 58 } 59 60 // TODO: Move this code to unit tests. 61 function register_block_test_block() { 62 wp_register_script( 'my-block-plugin-block-js', null ); 63 wp_add_inline_script( 64 'my-block-plugin-block-js', 65 'console.log( "my-block-plugin-block-js" );' 66 ); 67 wp_register_script( 'my-block-plugin-block-editor-js', null, array( 'wp-blocks' ) ); 68 wp_add_inline_script( 69 'my-block-plugin-block-editor-js', 70 'console.log( "my-block-plugin-block-editor-js" );' . 71 'wp.blocks.registerBlockType( "my-block-plugin/block", { edit() { return "edit my-block-plugin/block"; }, save() { return "content"; } } );' 72 ); 73 wp_register_style( 'my-block-plugin-block-css', null ); 74 wp_add_inline_style( 75 'my-block-plugin-block-css', 76 '.my-block-plugin-block.css { color: red; }' 77 ); 78 wp_register_style( 'my-block-plugin-block-editor-css', null ); 79 wp_add_inline_style( 80 'my-block-plugin-block-editor-css', 81 '.my-block-plugin-block.editor-css { color: red; }' 82 ); 83 register_block_type( 'my-block-plugin/block', [ 84 'title' => 'My Block', 85 'script' => 'my-block-plugin-block-js', 86 'editor_script' => 'my-block-plugin-block-editor-js', 87 'style' => 'my-block-plugin-block-css', 88 'editor_style' => 'my-block-plugin-block-editor-css', 89 ] ); 90 } 91 add_action( 'init', 'register_block_test_block' ); -
src/wp-includes/class-wp-block.php
193 193 */ 194 194 public function render( $options = array() ) { 195 195 global $post; 196 $options = wp_parse_args(196 $options = wp_parse_args( 197 197 $options, 198 198 array( 199 199 'dynamic' => true, 200 200 ) 201 201 ); 202 $block_content = ''; 202 203 203 204 $is_dynamic = $options['dynamic'] && $this->name && null !== $this->block_type && $this->block_type->is_dynamic(); 204 $block_content = '';205 205 206 206 if ( ! $options['dynamic'] || empty( $this->block_type->skip_inner_blocks ) ) { 207 207 $index = 0; … … 218 218 $post = $global_post; 219 219 } 220 220 221 if ( ! empty( $this->block_type->script ) ) {222 wp_enqueue_script( $this->block_type->script );223 }224 225 if ( ! empty( $this->block_type->style ) ) {226 wp_enqueue_style( $this->block_type->style );227 }228 229 221 /** 230 222 * Filters the content of a single block. 231 223 * … … 234 226 * @param string $block_content The block content about to be appended. 235 227 * @param array $block The full block, including name and attributes. 236 228 */ 237 return apply_filters( 'render_block', $block_content, $this->parsed_block ); 229 $block_content = apply_filters( 'render_block', $block_content, $this->parsed_block ); 230 231 $skip_assets = is_admin() || is_feed() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ); 232 233 // Print script when it is set. Note that the scripts is not being 234 // enqueued at the wp_enqueue_script action because this could result 235 // in the script being printed when it would never be used. When 236 // a script is printed in the body it has the additional benefit of 237 // not being render-blocking. When a script is printed the first time, 238 // subsequent calls to wp_print_script() will no-op. 239 if ( ! $skip_assets && ! empty( $this->block_type->script ) ) { 240 ob_start(); 241 wp_print_scripts( $this->block_type->script ); 242 $block_content = trim( ob_get_clean() ) . $block_content; 243 } 244 245 // Print stylesheet when it is set. Note that the stylesheet is not being 246 // enqueued at the wp_enqueue_style action because this could result 247 // in the stylesheet being printed when it would never be used. When 248 // a stylesheet is printed in the body it has the additional benefit of 249 // not being render-blocking. When a stylesheet is printed the first time, 250 // subsequent calls to wp_print_styles() will no-op. 251 if ( ! $skip_assets && ! empty( $this->block_type->style ) ) { 252 ob_start(); 253 wp_print_styles( $this->block_type->style ); 254 $block_content = trim( ob_get_clean() ) . $block_content; 255 } 256 257 return $block_content; 238 258 } 239 259 240 260 } -
src/wp-includes/default-filters.php
507 507 add_action( 'admin_enqueue_scripts', 'wp_localize_jquery_ui_datepicker', 1000 ); 508 508 add_action( 'wp_enqueue_scripts', 'wp_common_block_scripts_and_styles' ); 509 509 add_action( 'admin_enqueue_scripts', 'wp_common_block_scripts_and_styles' ); 510 add_action( 'enqueue_block_assets', 'wp_enqueue_registered_block_scripts_and_styles' );511 510 add_action( 'enqueue_block_editor_assets', 'wp_enqueue_registered_block_scripts_and_styles' ); 512 511 add_action( 'admin_print_scripts-index.php', 'wp_localize_community_events' ); 513 512 add_filter( 'wp_print_scripts', 'wp_just_in_time_script_localization' ); -
src/wp-includes/script-loader.php
2399 2399 global $current_screen; 2400 2400 2401 2401 $is_editor = ( ( $current_screen instanceof WP_Screen ) && $current_screen->is_block_editor() ); 2402 if ( ! $is_editor ) { 2403 return; 2404 } 2402 2405 2403 2406 $block_registry = WP_Block_Type_Registry::get_instance(); 2404 2407 foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) { 2405 // Front-end styles.2408 // Front-end and editor styles. 2406 2409 if ( ! empty( $block_type->style ) ) { 2407 2410 wp_enqueue_style( $block_type->style ); 2408 2411 } 2409 2412 2410 // Front-end script.2413 // Front-end and editor script. 2411 2414 if ( ! empty( $block_type->script ) ) { 2412 2415 wp_enqueue_script( $block_type->script ); 2413 2416 } 2414 2417 2415 2418 // Editor styles. 2416 if ( $is_editor &&! empty( $block_type->editor_style ) ) {2419 if ( ! empty( $block_type->editor_style ) ) { 2417 2420 wp_enqueue_style( $block_type->editor_style ); 2418 2421 } 2419 2422 2420 2423 // Editor script. 2421 if ( $is_editor &&! empty( $block_type->editor_script ) ) {2424 if ( ! empty( $block_type->editor_script ) ) { 2422 2425 wp_enqueue_script( $block_type->editor_script ); 2423 2426 } 2424 2427 }