Changeset 55955 for trunk/src/wp-includes/block-editor.php
- Timestamp:
- 06/21/2023 04:21:04 AM (3 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/block-editor.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-editor.php
r55438 r55955 360 360 'scripts' => $scripts, 361 361 ); 362 } 363 364 /** 365 * Finds the first occurrence of a specific block in an array of blocks. 366 * 367 * @since 6.3.0 368 * 369 * @param array $blocks Array of blocks. 370 * @param string $block_name Name of the block to find. 371 * @return array Found block, or empty array if none found. 372 */ 373 function wp_get_first_block( $blocks, $block_name ) { 374 foreach ( $blocks as $block ) { 375 if ( $block_name === $block['blockName'] ) { 376 return $block; 377 } 378 if ( ! empty( $block['innerBlocks'] ) ) { 379 $found_block = wp_get_first_block( $block['innerBlocks'], $block_name ); 380 381 if ( ! empty( $found_block ) ) { 382 return $found_block; 383 } 384 } 385 } 386 387 return array(); 388 } 389 390 /** 391 * Retrieves Post Content block attributes from the current post template. 392 * 393 * @since 6.3.0 394 * @access private 395 * 396 * @global int $post_ID 397 * 398 * @return array Post Content block attributes or empty array if they don't exist. 399 */ 400 function wp_get_post_content_block_attributes() { 401 global $post_ID; 402 403 $is_block_theme = wp_is_block_theme(); 404 405 if ( ! $is_block_theme || ! $post_ID ) { 406 return array(); 407 } 408 409 $template_slug = get_page_template_slug( $post_ID ); 410 411 if ( ! $template_slug ) { 412 $post_slug = 'singular'; 413 $page_slug = 'singular'; 414 $template_types = get_block_templates(); 415 416 foreach ( $template_types as $template_type ) { 417 if ( 'page' === $template_type->slug ) { 418 $page_slug = 'page'; 419 } 420 if ( 'single' === $template_type->slug ) { 421 $post_slug = 'single'; 422 } 423 } 424 425 $what_post_type = get_post_type( $post_ID ); 426 switch ( $what_post_type ) { 427 case 'page': 428 $template_slug = $page_slug; 429 break; 430 default: 431 $template_slug = $post_slug; 432 break; 433 } 434 } 435 436 $current_template = get_block_templates( array( 'slug__in' => array( $template_slug ) ) ); 437 438 if ( ! empty( $current_template ) ) { 439 $template_blocks = parse_blocks( $current_template[0]->content ); 440 $post_content_block = wp_get_first_block( $template_blocks, 'core/post-content' ); 441 442 if ( ! empty( $post_content_block['attrs'] ) ) { 443 return $post_content_block['attrs']; 444 } 445 } 446 447 return array(); 362 448 } 363 449 … … 529 615 ), 530 616 ); 617 618 $post_content_block_attributes = wp_get_post_content_block_attributes(); 619 620 if ( ! empty( $post_content_block_attributes ) ) { 621 $editor_settings['postContentAttributes'] = $post_content_block_attributes; 622 } 531 623 532 624 /**
Note: See TracChangeset
for help on using the changeset viewer.