Changeset 12356 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-block-plugin-checker.php
- Timestamp:
- 01/04/2023 06:31:00 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-block-plugin-checker.php
r11675 r12356 453 453 'data' => $data, 454 454 ); 455 } 456 457 /** 458 * Determine whether a block is top-level or a child block. 459 * 460 * @param object $block The block in question. 461 * 462 * @return bool True if the block is top-level; false if it is a child block that can only be used within other blocks in the plugin. 463 */ 464 public function is_top_level_block( $block ) { 465 $ancestors = $block->parent ?? []; 466 $ancestors = array_merge( $ancestors, $block->ancestor ?? [] ); 467 468 // If it has no parent or ancestor blocks, it's top-level. 469 if ( empty( $ancestors ) ) { 470 return true; 471 } 472 473 foreach ( $ancestors as $ancestor_block_name ) { 474 // If it has an ancestor outside of this plugin, like `core/column`, then it's also top-level. 475 if ( ! isset( $this->blocks[ $ancestor_block_name ] ) ) { 476 return true; 477 } 478 } 479 480 return false; 455 481 } 456 482 … … 792 818 $top_level_blocks = array_filter( 793 819 $this->blocks, 794 function( $block ) { 795 return ! isset( $block->parent ) || is_null( $block->parent ); 796 } 820 array( $this, 'is_top_level_block' ) 797 821 ); 798 822
Note: See TracChangeset
for help on using the changeset viewer.