Automattic\WooCommerce\Blocks
BlockTypesController::get_registered_blocks_with_woocommerce_parent()
Get registered blocks that have WooCommerce blocks as their parents. Adds the value to the registered_blocks_with_woocommerce_parents cache if init has been fired.
Method of the class: BlockTypesController{}
No Hooks.
Return
Array
. Registered blocks with WooCommerce blocks as parents.
Usage
$BlockTypesController = new BlockTypesController(); $BlockTypesController->get_registered_blocks_with_woocommerce_parent();
BlockTypesController::get_registered_blocks_with_woocommerce_parent() BlockTypesController::get registered blocks with woocommerce parent code WC 9.4.2
public function get_registered_blocks_with_woocommerce_parent() { // If init has run and the cache is already set, return it. if ( did_action( 'init' ) && ! empty( $this->registered_blocks_with_woocommerce_parents ) ) { return $this->registered_blocks_with_woocommerce_parents; } $registered_blocks = \WP_Block_Type_Registry::get_instance()->get_all_registered(); if ( ! is_array( $registered_blocks ) ) { return array(); } $this->registered_blocks_with_woocommerce_parents = array_filter( $registered_blocks, function ( $block ) { if ( empty( $block->parent ) ) { return false; } if ( ! is_array( $block->parent ) ) { $block->parent = array( $block->parent ); } $woocommerce_blocks = array_filter( $block->parent, function ( $parent_block_name ) { return 'woocommerce' === strtok( $parent_block_name, '/' ); } ); return ! empty( $woocommerce_blocks ); } ); return $this->registered_blocks_with_woocommerce_parents; }