Changeset 54155
- Timestamp:
- 09/14/2022 10:50:26 AM (2 years ago)
- Location:
- trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-editor.php
r53419 r54155 325 325 326 326 foreach ( $block_registry->get_all_registered() as $block_type ) { 327 if ( ! empty( $block_type->style ) ) { 328 $style_handles[] = $block_type->style; 329 } 330 331 if ( ! empty( $block_type->editor_style ) ) { 332 $style_handles[] = $block_type->editor_style; 333 } 334 335 if ( ! empty( $block_type->script ) ) { 336 $script_handles[] = $block_type->script; 337 } 327 $style_handles = array_merge( 328 $style_handles, 329 $block_type->style_handles, 330 $block_type->editor_style_handles 331 ); 332 333 $script_handles = array_merge( 334 $script_handles, 335 $block_type->script_handles 336 ); 338 337 } 339 338 -
trunk/src/wp-includes/blocks.php
r54138 r54155 36 36 * 37 37 * @since 5.5.0 38 * @since 6.1.0 Added `$index` parameter. 38 39 * 39 40 * @param string $block_name Name of the block. 40 41 * @param string $field_name Name of the metadata field. 42 * @param int $index Optional. Index of the asset when multiple items passed. 43 * Default 0. 41 44 * @return string Generated asset name for the block's field. 42 45 */ 43 function generate_block_asset_handle( $block_name, $field_name ) {46 function generate_block_asset_handle( $block_name, $field_name, $index = 0 ) { 44 47 if ( 0 === strpos( $block_name, 'core/' ) ) { 45 48 $asset_handle = str_replace( 'core/', 'wp-block-', $block_name ); … … 49 52 if ( 0 === strpos( $field_name, 'view' ) ) { 50 53 $asset_handle .= '-view'; 54 } 55 if ( $index > 0 ) { 56 $asset_handle .= '-' . ( $index + 1 ); 51 57 } 52 58 return $asset_handle; … … 60 66 'style' => 'style', 61 67 ); 62 returnstr_replace( '/', '-', $block_name ) .68 $asset_handle = str_replace( '/', '-', $block_name ) . 63 69 '-' . $field_mappings[ $field_name ]; 70 if ( $index > 0 ) { 71 $asset_handle .= '-' . ( $index + 1 ); 72 } 73 return $asset_handle; 64 74 } 65 75 … … 71 81 * 72 82 * @since 5.5.0 83 * @since 6.1.0 Added `$index` parameter. 73 84 * 74 85 * @param array $metadata Block metadata. 75 86 * @param string $field_name Field name to pick from metadata. 87 * @param int $index Optional. Index of the script to register when multiple items passed. 88 * Default 0. 76 89 * @return string|false Script handle provided directly or created through 77 90 * script's registration, or false on failure. 78 91 */ 79 function register_block_script_handle( $metadata, $field_name ) {92 function register_block_script_handle( $metadata, $field_name, $index = 0 ) { 80 93 if ( empty( $metadata[ $field_name ] ) ) { 81 94 return false; 82 95 } 96 83 97 $script_handle = $metadata[ $field_name ]; 84 $script_path = remove_block_asset_path_prefix( $metadata[ $field_name ] ); 98 if ( is_array( $script_handle ) ) { 99 if ( empty( $script_handle[ $index ] ) ) { 100 return false; 101 } 102 $script_handle = $script_handle[ $index ]; 103 } 104 105 $script_path = remove_block_asset_path_prefix( $script_handle ); 85 106 if ( $script_handle === $script_path ) { 86 107 return $script_handle; 87 108 } 88 109 89 $script_handle = generate_block_asset_handle( $metadata['name'], $field_name );110 $script_handle = generate_block_asset_handle( $metadata['name'], $field_name, $index ); 90 111 $script_asset_path = wp_normalize_path( 91 112 realpath( … … 146 167 * 147 168 * @since 5.5.0 169 * @since 6.1.0 Added `$index` parameter. 148 170 * 149 171 * @param array $metadata Block metadata. 150 172 * @param string $field_name Field name to pick from metadata. 173 * @param int $index Optional. Index of the style to register when multiple items passed. 174 * Default 0. 151 175 * @return string|false Style handle provided directly or created through 152 176 * style's registration, or false on failure. 153 177 */ 154 function register_block_style_handle( $metadata, $field_name ) {178 function register_block_style_handle( $metadata, $field_name, $index = 0 ) { 155 179 if ( empty( $metadata[ $field_name ] ) ) { 156 180 return false; 157 181 } 182 158 183 $wpinc_path_norm = wp_normalize_path( realpath( ABSPATH . WPINC ) ); 159 184 $theme_path_norm = wp_normalize_path( get_theme_file_path() ); 160 185 $is_core_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], $wpinc_path_norm ); 186 // Skip registering individual styles for each core block when a bundled version provided. 161 187 if ( $is_core_block && ! wp_should_load_separate_core_block_assets() ) { 162 188 return false; 163 189 } 164 190 191 $style_handle = $metadata[ $field_name ]; 192 if ( is_array( $style_handle ) ) { 193 if ( empty( $style_handle[ $index ] ) ) { 194 return false; 195 } 196 $style_handle = $style_handle[ $index ]; 197 } 198 199 $style_path = remove_block_asset_path_prefix( $style_handle ); 200 $is_style_handle = $style_handle === $style_path; 201 // Allow only passing style handles for core blocks. 202 if ( $is_core_block && ! $is_style_handle ) { 203 return false; 204 } 205 // Return the style handle unless it's the first item for every core block that requires special treatment. 206 if ( $is_style_handle && ! ( $is_core_block && 0 === $index ) ) { 207 return $style_handle; 208 } 209 165 210 // Check whether styles should have a ".min" suffix or not. 166 $suffix = SCRIPT_DEBUG ? '' : '.min'; 167 168 $style_handle = $metadata[ $field_name ]; 169 $style_path = remove_block_asset_path_prefix( $metadata[ $field_name ] ); 170 171 if ( $style_handle === $style_path && ! $is_core_block ) { 172 return $style_handle; 173 } 174 211 $suffix = SCRIPT_DEBUG ? '' : '.min'; 175 212 $style_uri = plugins_url( $style_path, $metadata['file'] ); 176 213 if ( $is_core_block ) { … … 186 223 } 187 224 188 $style_handle = generate_block_asset_handle( $metadata['name'], $field_name );225 $style_handle = generate_block_asset_handle( $metadata['name'], $field_name, $index ); 189 226 $block_dir = dirname( $metadata['file'] ); 190 $style_file = realpath( "$block_dir/$style_path");227 $style_file = wp_normalize_path( realpath( "$block_dir/$style_path" ) ); 191 228 $has_style_file = false !== $style_file; 192 229 $version = ! $is_core_block && isset( $metadata['version'] ) ? $metadata['version'] : false; … … 312 349 } 313 350 314 if ( ! empty( $metadata['editorScript'] ) ) { 315 $settings['editor_script'] = register_block_script_handle( 316 $metadata, 317 'editorScript' 318 ); 319 } 320 321 if ( ! empty( $metadata['script'] ) ) { 322 $settings['script'] = register_block_script_handle( 323 $metadata, 324 'script' 325 ); 326 } 327 328 if ( ! empty( $metadata['viewScript'] ) ) { 329 $settings['view_script'] = register_block_script_handle( 330 $metadata, 331 'viewScript' 332 ); 333 } 334 335 if ( ! empty( $metadata['editorStyle'] ) ) { 336 $settings['editor_style'] = register_block_style_handle( 337 $metadata, 338 'editorStyle' 339 ); 340 } 341 342 if ( ! empty( $metadata['style'] ) ) { 343 $settings['style'] = register_block_style_handle( 344 $metadata, 345 'style' 346 ); 351 $script_fields = array( 352 'editorScript' => 'editor_script_handles', 353 'script' => 'script_handles', 354 'viewScript' => 'view_script_handles', 355 ); 356 foreach ( $script_fields as $metadata_field_name => $settings_field_name ) { 357 if ( ! empty( $metadata[ $metadata_field_name ] ) ) { 358 $scripts = $metadata[ $metadata_field_name ]; 359 $processed_scripts = array(); 360 if ( is_array( $scripts ) ) { 361 for ( $index = 0; $index < count( $scripts ); $index++ ) { 362 $result = register_block_script_handle( 363 $metadata, 364 $metadata_field_name, 365 $index 366 ); 367 if ( $result ) { 368 $processed_scripts[] = $result; 369 } 370 } 371 } else { 372 $result = register_block_script_handle( 373 $metadata, 374 $metadata_field_name 375 ); 376 if ( $result ) { 377 $processed_scripts[] = $result; 378 } 379 } 380 $settings[ $settings_field_name ] = $processed_scripts; 381 } 382 } 383 384 $style_fields = array( 385 'editorStyle' => 'editor_style_handles', 386 'style' => 'style_handles', 387 ); 388 foreach ( $style_fields as $metadata_field_name => $settings_field_name ) { 389 if ( ! empty( $metadata[ $metadata_field_name ] ) ) { 390 $styles = $metadata[ $metadata_field_name ]; 391 $processed_styles = array(); 392 if ( is_array( $styles ) ) { 393 for ( $index = 0; $index < count( $styles ); $index++ ) { 394 $result = register_block_style_handle( 395 $metadata, 396 $metadata_field_name, 397 $index 398 ); 399 if ( $result ) { 400 $processed_styles[] = $result; 401 } 402 } 403 } else { 404 $result = register_block_style_handle( 405 $metadata, 406 $metadata_field_name 407 ); 408 if ( $result ) { 409 $processed_styles[] = $result; 410 } 411 } 412 $settings[ $settings_field_name ] = $processed_styles; 413 } 347 414 } 348 415 … … 1263 1330 1264 1331 /** 1265 * Allows multiple block styles.1266 *1267 * @since 5.9.01268 *1269 * @param array $metadata Metadata for registering a block type.1270 * @return array Metadata for registering a block type.1271 */1272 function _wp_multiple_block_styles( $metadata ) {1273 foreach ( array( 'style', 'editorStyle' ) as $key ) {1274 if ( ! empty( $metadata[ $key ] ) && is_array( $metadata[ $key ] ) ) {1275 $default_style = array_shift( $metadata[ $key ] );1276 foreach ( $metadata[ $key ] as $handle ) {1277 $args = array( 'handle' => $handle );1278 if ( 0 === strpos( $handle, 'file:' ) && isset( $metadata['file'] ) ) {1279 $style_path = remove_block_asset_path_prefix( $handle );1280 $theme_path_norm = wp_normalize_path( get_theme_file_path() );1281 $style_path_norm = wp_normalize_path( realpath( dirname( $metadata['file'] ) . '/' . $style_path ) );1282 $is_theme_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], $theme_path_norm );1283 1284 $style_uri = plugins_url( $style_path, $metadata['file'] );1285 1286 if ( $is_theme_block ) {1287 $style_uri = get_theme_file_uri( str_replace( $theme_path_norm, '', $style_path_norm ) );1288 }1289 1290 $args = array(1291 'handle' => sanitize_key( "{$metadata['name']}-{$style_path}" ),1292 'src' => $style_uri,1293 );1294 }1295 1296 wp_enqueue_block_style( $metadata['name'], $args );1297 }1298 1299 // Only return the 1st item in the array.1300 $metadata[ $key ] = $default_style;1301 }1302 }1303 return $metadata;1304 }1305 add_filter( 'block_type_metadata', '_wp_multiple_block_styles' );1306 1307 /**1308 1332 * Helper function that constructs a comment query vars array from the passed 1309 1333 * block properties. -
trunk/src/wp-includes/class-wp-block-type.php
r54133 r54155 167 167 168 168 /** 169 * Block type editor only script handle. 170 * 171 * @since 5.0.0 172 * @var string|null 173 */ 174 public $editor_script = null; 175 176 /** 177 * Block type front end and editor script handle. 178 * 179 * @since 5.0.0 180 * @var string|null 181 */ 182 public $script = null; 183 184 /** 185 * Block type front end only script handle. 186 * 187 * @since 5.9.0 188 * @var string|null 189 */ 190 public $view_script = null; 191 192 /** 193 * Block type editor only style handle. 194 * 195 * @since 5.0.0 196 * @var string|null 197 */ 198 public $editor_style = null; 199 200 /** 201 * Block type front end and editor style handle. 202 * 203 * @since 5.0.0 204 * @var string|null 205 */ 206 public $style = null; 169 * Block type editor only script handles. 170 * 171 * @since 6.1.0 172 * @var string[] 173 */ 174 public $editor_script_handles = array(); 175 176 /** 177 * Block type front end and editor script handles. 178 * 179 * @since 6.1.0 180 * @var string[] 181 */ 182 public $script_handles = array(); 183 184 /** 185 * Block type front end only script handles. 186 * 187 * @since 6.1.0 188 * @var string[] 189 */ 190 public $view_script_handles = array(); 191 192 /** 193 * Block type editor only style handles. 194 * 195 * @since 6.1.0 196 * @var string[] 197 */ 198 public $editor_style_handles = array(); 199 200 /** 201 * Block type front end and editor style handles. 202 * 203 * @since 6.1.0 204 * @var string[] 205 */ 206 public $style_handles = array(); 207 208 /** 209 * Deprecated block type properties for script and style handles. 210 * 211 * @since 6.1.0 212 * @var string[] 213 */ 214 private $deprecated_properties = array( 215 'editor_script', 216 'script', 217 'view_script', 218 'editor_style', 219 'style', 220 ); 207 221 208 222 /** … … 229 243 * @since 5.9.0 Added the `view_script` property. 230 244 * @since 6.0.0 Added the `ancestor` property. 245 * @since 6.1.0 Added the `editor_script_handles`, `script_handles`, `view_script_handles, 246 * `editor_style_handles`, and `style_handles` properties. 247 * Deprecated the `editor_script`, `script`, `view_script`, `editor_style`, and `style` properties. 231 248 * 232 249 * @see register_block_type() … … 237 254 * however the ones described below are supported by default. Default empty array. 238 255 * 239 * @type string $api_version Block API version.240 * @type string $title Human-readable block type label.241 * @type string|null $category Block type category classification, used in242 * search interfaces to arrange block types by category.243 * @type string[]|null $parent Setting parent lets a block require that it is only244 * available when nested within the specified blocks.245 * @type string[]|null $ancestor Setting ancestor makes a block available only inside the specified246 * block types at any position of the ancestor's block subtree.247 * @type string|null $icon Block type icon.248 * @type string $description A detailed block type description.249 * @type string[] $keywords Additional keywords to produce block type as250 * result in search interfaces.251 * @type string|null $textdomain The translation textdomain.252 * @type array[] $styles Alternative block styles.253 * @type array[] $variations Block variations.254 * @type array|null $supports Supported features.255 * @type array|null $example Structured data for the block preview.256 * @type callable|null $render_callback Block type render callback.257 * @type array|null $attributes Block type attributes property schemas.258 * @type string[] $uses_context Context values inherited by blocks of this type.259 * @type string[]|null $provides_context Context provided by blocks of this type.260 * @type string |null $editor_script Block type editor only script handle.261 * @type string |null $script Block type front end and editor script handle.262 * @type string |null $view_script Block type front end only script handle.263 * @type string |null $editor_style Block type editor only style handle.264 * @type string |null $style Block type front end and editor style handle.256 * @type string $api_version Block API version. 257 * @type string $title Human-readable block type label. 258 * @type string|null $category Block type category classification, used in 259 * search interfaces to arrange block types by category. 260 * @type string[]|null $parent Setting parent lets a block require that it is only 261 * available when nested within the specified blocks. 262 * @type string[]|null $ancestor Setting ancestor makes a block available only inside the specified 263 * block types at any position of the ancestor's block subtree. 264 * @type string|null $icon Block type icon. 265 * @type string $description A detailed block type description. 266 * @type string[] $keywords Additional keywords to produce block type as 267 * result in search interfaces. 268 * @type string|null $textdomain The translation textdomain. 269 * @type array[] $styles Alternative block styles. 270 * @type array[] $variations Block variations. 271 * @type array|null $supports Supported features. 272 * @type array|null $example Structured data for the block preview. 273 * @type callable|null $render_callback Block type render callback. 274 * @type array|null $attributes Block type attributes property schemas. 275 * @type string[] $uses_context Context values inherited by blocks of this type. 276 * @type string[]|null $provides_context Context provided by blocks of this type. 277 * @type string[] $editor_script_handles Block type editor only script handles. 278 * @type string[] $script_handles Block type front end and editor script handles. 279 * @type string[] $view_script_handles Block type front end only script handles. 280 * @type string[] $editor_style_handles Block type editor only style handles. 281 * @type string[] $style_handles Block type front end and editor style handles. 265 282 * } 266 283 */ … … 269 286 270 287 $this->set_props( $args ); 288 } 289 290 /** 291 * Proxies getting values for deprecated properties for script and style handles for backward compatibility. 292 * Gets the value for the corresponding new property if the first item in the array provided. 293 * 294 * @since 6.1.0 295 * 296 * @param string $name Deprecated property name. 297 * 298 * @return string|null|void The value read from the new property if the first item in the array provided, 299 * null when value not found, or void when unknown property name provided. 300 */ 301 public function __get( $name ) { 302 if ( ! in_array( $name, $this->deprecated_properties ) ) { 303 return; 304 } 305 306 $new_name = $name . '_handles'; 307 return isset( $this->{$new_name }[0] ) ? $this->{$new_name }[0] : null; 308 } 309 310 /** 311 * Proxies checking for deprecated properties for script and style handles for backward compatibility. 312 * Checks whether the corresponding new property has the first item in the array provided. 313 * 314 * @since 6.1.0 315 * 316 * @param string $name Deprecated property name. 317 * 318 * @return boolean Returns true when for the new property the first item in the array exists, 319 * or false otherwise. 320 */ 321 public function __isset( $name ) { 322 if ( ! in_array( $name, $this->deprecated_properties ) ) { 323 return false; 324 } 325 326 $new_name = $name . '_handles'; 327 return isset( $this->{$new_name }[0] ); 328 } 329 330 /** 331 * Proxies setting values for deprecated properties for script and style handles for backward compatibility. 332 * Sets the value for the corresponding new property as the first item in the array. 333 * It also allows setting custom properties for backward compatibility. 334 * 335 * @since 6.1.0 336 * 337 * @param string $name Property name. 338 * @param mixed $value Property value. 339 */ 340 public function __set( $name, $value ) { 341 if ( ! in_array( $name, $this->deprecated_properties ) ) { 342 $this->{$name} = $value; 343 return; 344 } 345 346 if ( ! is_string( $value ) ) { 347 return; 348 } 349 350 $new_name = $name . '_handles'; 351 $this->{$new_name }[0] = $value; 271 352 } 272 353 -
trunk/src/wp-includes/class-wp-block.php
r54133 r54155 261 261 } 262 262 263 if ( ! empty( $this->block_type->script ) ) { 264 wp_enqueue_script( $this->block_type->script ); 265 } 266 267 if ( ! empty( $this->block_type->view_script ) && empty( $this->block_type->render_callback ) ) { 268 wp_enqueue_script( $this->block_type->view_script ); 269 } 270 271 if ( ! empty( $this->block_type->style ) ) { 272 wp_enqueue_style( $this->block_type->style ); 263 if ( ( ! empty( $this->block_type->script_handles ) ) ) { 264 foreach ( $this->block_type->script_handles as $script_handle ) { 265 wp_enqueue_script( $script_handle ); 266 } 267 } 268 269 if ( ! empty( $this->block_type->view_script_handles ) && empty( $this->block_type->render_callback ) ) { 270 foreach ( $this->block_type->view_script_handles as $view_script_handle ) { 271 wp_enqueue_script( $view_script_handle ); 272 } 273 } 274 275 if ( ( ! empty( $this->block_type->style_handles ) ) ) { 276 foreach ( $this->block_type->style_handles as $style_handle ) { 277 wp_enqueue_style( $style_handle ); 278 } 273 279 } 274 280 -
trunk/src/wp-includes/deprecated.php
r53874 r54155 4443 4443 return false; 4444 4444 } 4445 4446 /** 4447 * Allows multiple block styles. 4448 * 4449 * @since 5.9.0 4450 * @deprecated 6.1.0 4451 * 4452 * @param array $metadata Metadata for registering a block type. 4453 * @return array Metadata for registering a block type. 4454 */ 4455 function _wp_multiple_block_styles( $metadata ) { 4456 _deprecated_function( __FUNCTION__, '6.1.0' ); 4457 return $metadata; 4458 } -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php
r53760 r54155 257 257 } 258 258 259 $schema = $this->get_item_schema(); 260 $extra_fields = array( 261 'api_version', 262 'name', 263 'title', 264 'description', 265 'icon', 266 'category', 267 'keywords', 268 'parent', 269 'ancestor', 270 'provides_context', 271 'uses_context', 272 'supports', 273 'styles', 274 'textdomain', 275 'example', 259 $schema = $this->get_item_schema(); 260 // Fields deprecated in WordPress 6.1, but left in the schema for backwards compatibility. 261 $deprecated_fields = array( 276 262 'editor_script', 277 263 'script', … … 279 265 'editor_style', 280 266 'style', 281 'variations', 267 ); 268 $extra_fields = array_merge( 269 array( 270 'api_version', 271 'name', 272 'title', 273 'description', 274 'icon', 275 'category', 276 'keywords', 277 'parent', 278 'ancestor', 279 'provides_context', 280 'uses_context', 281 'supports', 282 'styles', 283 'textdomain', 284 'example', 285 'editor_script_handles', 286 'script_handles', 287 'view_script_handles', 288 'editor_style_handles', 289 'style_handles', 290 'variations', 291 ), 292 $deprecated_fields 282 293 ); 283 294 foreach ( $extra_fields as $extra_field ) { … … 438 449 ); 439 450 440 $ schema = array(451 $this->schema = array( 441 452 '$schema' => 'http://json-schema.org/draft-04/schema#', 442 453 'title' => 'block-type', 443 454 'type' => 'object', 444 455 'properties' => array( 445 'api_version' => array(456 'api_version' => array( 446 457 'description' => __( 'Version of block API.' ), 447 458 'type' => 'integer', … … 450 461 'readonly' => true, 451 462 ), 452 'title' => array(463 'title' => array( 453 464 'description' => __( 'Title of block type.' ), 454 465 'type' => 'string', … … 457 468 'readonly' => true, 458 469 ), 459 'name' => array(470 'name' => array( 460 471 'description' => __( 'Unique name identifying the block type.' ), 461 472 'type' => 'string', … … 464 475 'readonly' => true, 465 476 ), 466 'description' => array(477 'description' => array( 467 478 'description' => __( 'Description of block type.' ), 468 479 'type' => 'string', … … 471 482 'readonly' => true, 472 483 ), 473 'icon' => $icon_definition,474 'attributes' => array(484 'icon' => $icon_definition, 485 'attributes' => array( 475 486 'description' => __( 'Block attributes.' ), 476 487 'type' => array( 'object', 'null' ), … … 483 494 'readonly' => true, 484 495 ), 485 'provides_context' => array(496 'provides_context' => array( 486 497 'description' => __( 'Context provided by blocks of this type.' ), 487 498 'type' => 'object', … … 494 505 'readonly' => true, 495 506 ), 496 'uses_context' => array(507 'uses_context' => array( 497 508 'description' => __( 'Context values inherited by blocks of this type.' ), 498 509 'type' => 'array', … … 504 515 'readonly' => true, 505 516 ), 506 'supports' => array(517 'supports' => array( 507 518 'description' => __( 'Block supports.' ), 508 519 'type' => 'object', … … 512 523 'readonly' => true, 513 524 ), 514 'category' => $category_definition,515 'is_dynamic' => array(525 'category' => $category_definition, 526 'is_dynamic' => array( 516 527 'description' => __( 'Is the block dynamically rendered.' ), 517 528 'type' => 'boolean', … … 520 531 'readonly' => true, 521 532 ), 522 'editor_script' => array( 523 'description' => __( 'Editor script handle.' ), 524 'type' => array( 'string', 'null' ), 525 'default' => null, 526 'context' => array( 'embed', 'view', 'edit' ), 527 'readonly' => true, 528 ), 529 'script' => array( 530 'description' => __( 'Public facing and editor script handle.' ), 531 'type' => array( 'string', 'null' ), 532 'default' => null, 533 'context' => array( 'embed', 'view', 'edit' ), 534 'readonly' => true, 535 ), 536 'view_script' => array( 537 'description' => __( 'Public facing script handle.' ), 538 'type' => array( 'string', 'null' ), 539 'default' => null, 540 'context' => array( 'embed', 'view', 'edit' ), 541 'readonly' => true, 542 ), 543 'editor_style' => array( 544 'description' => __( 'Editor style handle.' ), 545 'type' => array( 'string', 'null' ), 546 'default' => null, 547 'context' => array( 'embed', 'view', 'edit' ), 548 'readonly' => true, 549 ), 550 'style' => array( 551 'description' => __( 'Public facing and editor style handle.' ), 552 'type' => array( 'string', 'null' ), 553 'default' => null, 554 'context' => array( 'embed', 'view', 'edit' ), 555 'readonly' => true, 556 ), 557 'styles' => array( 533 'editor_script_handles' => array( 534 'description' => __( 'Editor script handles.' ), 535 'type' => array( 'array' ), 536 'default' => array(), 537 'items' => array( 538 'type' => 'string', 539 ), 540 'context' => array( 'embed', 'view', 'edit' ), 541 'readonly' => true, 542 ), 543 'script_handles' => array( 544 'description' => __( 'Public facing and editor script handles.' ), 545 'type' => array( 'array' ), 546 'default' => array(), 547 'items' => array( 548 'type' => 'string', 549 ), 550 'context' => array( 'embed', 'view', 'edit' ), 551 'readonly' => true, 552 ), 553 'view_script_handles' => array( 554 'description' => __( 'Public facing script handles.' ), 555 'type' => array( 'array' ), 556 'default' => array(), 557 'items' => array( 558 'type' => 'string', 559 ), 560 'context' => array( 'embed', 'view', 'edit' ), 561 'readonly' => true, 562 ), 563 'editor_style_handles' => array( 564 'description' => __( 'Editor style handles.' ), 565 'type' => array( 'array' ), 566 'default' => array(), 567 'items' => array( 568 'type' => 'string', 569 ), 570 'context' => array( 'embed', 'view', 'edit' ), 571 'readonly' => true, 572 ), 573 'style_handles' => array( 574 'description' => __( 'Public facing and editor style handles.' ), 575 'type' => array( 'array' ), 576 'default' => array(), 577 'items' => array( 578 'type' => 'string', 579 ), 580 'context' => array( 'embed', 'view', 'edit' ), 581 'readonly' => true, 582 ), 583 'styles' => array( 558 584 'description' => __( 'Block style variations.' ), 559 585 'type' => 'array', … … 584 610 'readonly' => true, 585 611 ), 586 'variations' => array(612 'variations' => array( 587 613 'description' => __( 'Block variations.' ), 588 614 'type' => 'array', … … 636 662 'default' => null, 637 663 ), 638 'textdomain' => array(664 'textdomain' => array( 639 665 'description' => __( 'Public text domain.' ), 640 666 'type' => array( 'string', 'null' ), … … 643 669 'readonly' => true, 644 670 ), 645 'parent' => array(671 'parent' => array( 646 672 'description' => __( 'Parent blocks.' ), 647 673 'type' => array( 'array', 'null' ), … … 653 679 'readonly' => true, 654 680 ), 655 'ancestor' => array(681 'ancestor' => array( 656 682 'description' => __( 'Ancestor blocks.' ), 657 683 'type' => array( 'array', 'null' ), … … 668 694 ); 669 695 670 $this->schema = $schema; 696 // Properties deprecated in WordPress 6.1, but left in the schema for backwards compatibility. 697 $deprecated_properties = array( 698 'editor_script' => array( 699 'description' => __( 'Editor script handle. DEPRECATED: Use `editor_script_handles` instead.' ), 700 'type' => array( 'string', 'null' ), 701 'default' => null, 702 'context' => array( 'embed', 'view', 'edit' ), 703 'readonly' => true, 704 ), 705 'script' => array( 706 'description' => __( 'Public facing and editor script handle. DEPRECATED: Use `script_handles` instead.' ), 707 'type' => array( 'string', 'null' ), 708 'default' => null, 709 'context' => array( 'embed', 'view', 'edit' ), 710 'readonly' => true, 711 ), 712 'view_script' => array( 713 'description' => __( 'Public facing script handle. DEPRECATED: Use `view_script_handles` instead.' ), 714 'type' => array( 'string', 'null' ), 715 'default' => null, 716 'context' => array( 'embed', 'view', 'edit' ), 717 'readonly' => true, 718 ), 719 'editor_style' => array( 720 'description' => __( 'Editor style handle. DEPRECATED: Use `editor_style_handles` instead.' ), 721 'type' => array( 'string', 'null' ), 722 'default' => null, 723 'context' => array( 'embed', 'view', 'edit' ), 724 'readonly' => true, 725 ), 726 'style' => array( 727 'description' => __( 'Public facing and editor style handle. DEPRECATED: Use `style_handles` instead.' ), 728 'type' => array( 'string', 'null' ), 729 'default' => null, 730 'context' => array( 'embed', 'view', 'edit' ), 731 'readonly' => true, 732 ), 733 ); 734 $this->schema['properties'] = array_merge( $this->schema['properties'], $deprecated_properties ); 671 735 672 736 return $this->add_additional_fields_schema( $this->schema ); -
trunk/src/wp-includes/script-loader.php
r54118 r54155 2532 2532 } 2533 2533 2534 $load_editor_scripts = is_admin() && wp_should_load_block_editor_scripts_and_styles();2534 $load_editor_scripts_and_styles = is_admin() && wp_should_load_block_editor_scripts_and_styles(); 2535 2535 2536 2536 $block_registry = WP_Block_Type_Registry::get_instance(); 2537 2537 foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) { 2538 // Front-end styles. 2539 if ( ! empty( $block_type->style ) ) { 2540 wp_enqueue_style( $block_type->style ); 2541 } 2542 2543 // Front-end script. 2544 if ( ! empty( $block_type->script ) ) { 2545 wp_enqueue_script( $block_type->script ); 2546 } 2547 2548 // Editor styles. 2549 if ( $load_editor_scripts && ! empty( $block_type->editor_style ) ) { 2550 wp_enqueue_style( $block_type->editor_style ); 2551 } 2552 2553 // Editor script. 2554 if ( $load_editor_scripts && ! empty( $block_type->editor_script ) ) { 2555 wp_enqueue_script( $block_type->editor_script ); 2538 // Front-end and editor styles. 2539 foreach ( $block_type->style_handles as $style_handle ) { 2540 wp_enqueue_style( $style_handle ); 2541 } 2542 2543 // Front-end and editor scripts. 2544 foreach ( $block_type->script_handles as $script_handle ) { 2545 wp_enqueue_script( $script_handle ); 2546 } 2547 2548 if ( $load_editor_scripts_and_styles ) { 2549 // Editor styles. 2550 foreach ( $block_type->editor_style_handles as $editor_style_handle ) { 2551 wp_enqueue_style( $editor_style_handle ); 2552 } 2553 2554 // Editor scripts. 2555 foreach ( $block_type->editor_script_handles as $editor_script_handle ) { 2556 wp_enqueue_script( $editor_script_handle ); 2557 } 2556 2558 } 2557 2559 } -
trunk/tests/phpunit/data/blocks/notice/block.json
r54132 r54155 58 58 "editorScript": "tests-notice-editor-script", 59 59 "script": "tests-notice-script", 60 "viewScript": "tests-notice-view-script",60 "viewScript": [ "tests-notice-view-script", "tests-notice-view-script-2" ], 61 61 "editorStyle": "tests-notice-editor-style", 62 "style": "tests-notice-style",62 "style": [ "tests-notice-style", "tests-notice-style-2" ], 63 63 "render": "file:./render.php" 64 64 } -
trunk/tests/phpunit/tests/blocks/register.php
r54132 r54155 149 149 $this->assertSame( 150 150 'unit-tests-my-block-script', 151 generate_block_asset_handle( $block_name, 'script' )152 ); 153 $this->assertSame( 154 'unit-tests-my-block-view-script ',155 generate_block_asset_handle( $block_name, 'viewScript' )156 ); 157 $this->assertSame( 158 'unit-tests-my-block-editor-style ',159 generate_block_asset_handle( $block_name, 'editorStyle' )151 generate_block_asset_handle( $block_name, 'script', 0 ) 152 ); 153 $this->assertSame( 154 'unit-tests-my-block-view-script-100', 155 generate_block_asset_handle( $block_name, 'viewScript', 99 ) 156 ); 157 $this->assertSame( 158 'unit-tests-my-block-editor-style-2', 159 generate_block_asset_handle( $block_name, 'editorStyle', 1 ) 160 160 ); 161 161 $this->assertSame( … … 177 177 $this->assertSame( 178 178 'wp-block-paragraph', 179 generate_block_asset_handle( $block_name, 'script' )180 ); 181 $this->assertSame( 182 'wp-block-paragraph-view ',183 generate_block_asset_handle( $block_name, 'viewScript' )184 ); 185 $this->assertSame( 186 'wp-block-paragraph-editor ',187 generate_block_asset_handle( $block_name, 'editorStyle' )179 generate_block_asset_handle( $block_name, 'script', 0 ) 180 ); 181 $this->assertSame( 182 'wp-block-paragraph-view-100', 183 generate_block_asset_handle( $block_name, 'viewScript', 99 ) 184 ); 185 $this->assertSame( 186 'wp-block-paragraph-editor-2', 187 generate_block_asset_handle( $block_name, 'editorStyle', 1 ) 188 188 ); 189 189 $this->assertSame( … … 205 205 * @ticket 50263 206 206 */ 207 public function test_empty_ value_register_block_script_handle() {207 public function test_empty_string_value_do_not_register_block_script_handle() { 208 208 $metadata = array( 'script' => '' ); 209 209 $result = register_block_script_handle( $metadata, 'script' ); 210 211 $this->assertFalse( $result ); 212 } 213 214 public function test_empty_array_value_do_not_register_block_script_handle() { 215 $metadata = array( 'script' => array() ); 216 $result = register_block_script_handle( $metadata, 'script' ); 217 218 $this->assertFalse( $result ); 219 } 220 221 public function test_wrong_array_index_do_not_register_block_script_handle() { 222 $metadata = array( 'script' => array( 'test-script-handle' ) ); 223 $result = register_block_script_handle( $metadata, 'script', 1 ); 210 224 211 225 $this->assertFalse( $result ); … … 232 246 public function test_handle_passed_register_block_script_handle() { 233 247 $metadata = array( 234 ' editorScript' => 'test-script-handle',235 ); 236 $result = register_block_script_handle( $metadata, ' editorScript' );248 'script' => 'test-script-handle', 249 ); 250 $result = register_block_script_handle( $metadata, 'script' ); 237 251 238 252 $this->assertSame( 'test-script-handle', $result ); 253 } 254 255 public function test_handles_passed_register_block_script_handles() { 256 $metadata = array( 257 'script' => array( 'test-script-handle', 'test-script-handle-2' ), 258 ); 259 260 $result = register_block_script_handle( $metadata, 'script' ); 261 $this->assertSame( 'test-script-handle', $result ); 262 263 $result = register_block_script_handle( $metadata, 'script', 1 ); 264 $this->assertSame( 'test-script-handle-2', $result, 1 ); 239 265 } 240 266 … … 282 308 * @ticket 50263 283 309 */ 284 public function test_empty_ value_found_register_block_style_handle() {310 public function test_empty_string_value_do_not_register_block_style_handle() { 285 311 $metadata = array( 'style' => '' ); 286 312 $result = register_block_style_handle( $metadata, 'style' ); … … 289 315 } 290 316 317 public function test_empty_array_value_do_not_register_block_style_handle() { 318 $metadata = array( 'style' => array() ); 319 $result = register_block_style_handle( $metadata, 'style' ); 320 321 $this->assertFalse( $result ); 322 } 323 324 public function test_wrong_array_index_do_not_register_block_style_handle() { 325 $metadata = array( 'style' => array( 'test-style-handle' ) ); 326 $result = register_block_style_handle( $metadata, 'style', 1 ); 327 328 $this->assertFalse( $result ); 329 } 330 291 331 /** 292 332 * @ticket 50263 … … 299 339 300 340 $this->assertSame( 'test-style-handle', $result ); 341 } 342 343 public function test_handles_passed_register_block_style_handles() { 344 $metadata = array( 345 'style' => array( 'test-style-handle', 'test-style-handle-2' ), 346 ); 347 348 $result = register_block_style_handle( $metadata, 'style' ); 349 $this->assertSame( 'test-style-handle', $result ); 350 351 $result = register_block_style_handle( $metadata, 'style', 1 ); 352 $this->assertSame( 'test-style-handle-2', $result, 1 ); 301 353 } 302 354 … … 443 495 $result->example 444 496 ); 445 $this->assertSame( 'tests-notice-editor-script', $result->editor_script ); 446 $this->assertSame( 'tests-notice-script', $result->script ); 447 $this->assertSame( 'tests-notice-view-script', $result->view_script ); 448 $this->assertSame( 'tests-notice-editor-style', $result->editor_style ); 449 $this->assertSame( 'tests-notice-style', $result->style ); 497 $this->assertSameSets( 498 array( 'tests-notice-editor-script' ), 499 $result->editor_script_handles 500 ); 501 $this->assertSameSets( 502 array( 'tests-notice-script' ), 503 $result->script_handles 504 ); 505 $this->assertSameSets( 506 array( 'tests-notice-view-script', 'tests-notice-view-script-2' ), 507 $result->view_script_handles 508 ); 509 $this->assertSameSets( 510 array( 'tests-notice-editor-style' ), 511 $result->editor_style_handles 512 ); 513 $this->assertSameSets( 514 array( 'tests-notice-style', 'tests-notice-style-2' ), 515 $result->style_handles 516 ); 450 517 451 518 // @ticket 50328 -
trunk/tests/phpunit/tests/rest-api/rest-block-type-controller.php
r54058 r54155 238 238 $this->assertSame( '1', $data['description'] ); 239 239 $this->assertNull( $data['icon'] ); 240 $this->assert Null( $data['editor_script'] );241 $this->assert Null( $data['script'] );242 $this->assert Null( $data['view_script'] );243 $this->assert Null( $data['editor_style'] );244 $this->assert Null( $data['style'] );240 $this->assertSameSets( array(), $data['editor_script_handles'] ); 241 $this->assertSameSets( array(), $data['script_handles'] ); 242 $this->assertSameSets( array(), $data['view_script_handles'] ); 243 $this->assertSameSets( array(), $data['editor_style_handles'] ); 244 $this->assertSameSets( array(), $data['style_handles'] ); 245 245 $this->assertSameSets( array(), $data['provides_context'] ); 246 246 $this->assertSameSetsWithIndex( … … 261 261 $this->assertFalse( $data['is_dynamic'] ); 262 262 $this->assertSameSets( array( array() ), $data['variations'] ); 263 // Deprecated properties. 264 $this->assertNull( $data['editor_script'] ); 265 $this->assertNull( $data['script'] ); 266 $this->assertNull( $data['view_script'] ); 267 $this->assertNull( $data['editor_style'] ); 268 $this->assertNull( $data['style'] ); 269 263 270 } 264 271 … … 300 307 $this->assertSame( '', $data['description'] ); 301 308 $this->assertNull( $data['icon'] ); 302 $this->assert Null( $data['editor_script'] );303 $this->assert Null( $data['script'] );304 $this->assert Null( $data['view_script'] );305 $this->assert Null( $data['editor_style'] );306 $this->assert Null( $data['style'] );309 $this->assertSameSets( array(), $data['editor_script_handles'] ); 310 $this->assertSameSets( array(), $data['script_handles'] ); 311 $this->assertSameSets( array(), $data['view_script_handles'] ); 312 $this->assertSameSets( array(), $data['editor_style_handles'] ); 313 $this->assertSameSets( array(), $data['style_handles'] ); 307 314 $this->assertSameSetsWithIndex( 308 315 array( … … 324 331 $this->assertFalse( $data['is_dynamic'] ); 325 332 $this->assertSameSets( array(), $data['variations'] ); 333 // Deprecated properties. 334 $this->assertNull( $data['editor_script'] ); 335 $this->assertNull( $data['script'] ); 336 $this->assertNull( $data['view_script'] ); 337 $this->assertNull( $data['editor_style'] ); 338 $this->assertNull( $data['style'] ); 326 339 } 327 340 … … 393 406 $data = $response->get_data(); 394 407 $properties = $data['schema']['properties']; 395 $this->assertCount( 2 3, $properties );408 $this->assertCount( 28, $properties ); 396 409 $this->assertArrayHasKey( 'api_version', $properties ); 397 410 $this->assertArrayHasKey( 'title', $properties ); … … 406 419 $this->assertArrayHasKey( 'category', $properties ); 407 420 $this->assertArrayHasKey( 'is_dynamic', $properties ); 408 $this->assertArrayHasKey( 'editor_script ', $properties );409 $this->assertArrayHasKey( 'script ', $properties );410 $this->assertArrayHasKey( 'view_script ', $properties );411 $this->assertArrayHasKey( 'editor_style ', $properties );412 $this->assertArrayHasKey( 'style ', $properties );421 $this->assertArrayHasKey( 'editor_script_handles', $properties ); 422 $this->assertArrayHasKey( 'script_handles', $properties ); 423 $this->assertArrayHasKey( 'view_script_handles', $properties ); 424 $this->assertArrayHasKey( 'editor_style_handles', $properties ); 425 $this->assertArrayHasKey( 'style_handles', $properties ); 413 426 $this->assertArrayHasKey( 'parent', $properties ); 414 427 $this->assertArrayHasKey( 'example', $properties ); … … 417 430 $this->assertArrayHasKey( 'variations', $properties ); 418 431 $this->assertArrayHasKey( 'ancestor', $properties ); 432 // Deprecated properties. 433 $this->assertArrayHasKey( 'editor_script', $properties ); 434 $this->assertArrayHasKey( 'script', $properties ); 435 $this->assertArrayHasKey( 'view_script', $properties ); 436 $this->assertArrayHasKey( 'editor_style', $properties ); 437 $this->assertArrayHasKey( 'style', $properties ); 438 419 439 } 420 440 … … 519 539 'name', 520 540 'category', 521 'editor_script ',522 'script ',523 'view_script ',524 'editor_style ',525 'style ',541 'editor_script_handles', 542 'script_handles', 543 'view_script_handles', 544 'editor_style_handles', 545 'style_handles', 526 546 'title', 527 547 'icon', … … 535 555 'textdomain', 536 556 'example', 557 // Deprecated fields. 558 'editor_script', 559 'script', 560 'view_script', 561 'editor_style', 562 'style', 537 563 ); 538 564
Note: See TracChangeset
for help on using the changeset viewer.