get_all_registered(); foreach ( $block_patterns as $block_pattern ) { if ( ! isset( $block_pattern['categories'] ) ) { continue; } foreach ( $block_pattern['categories'] as $category ) { $categories = wp_list_pluck( WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered(), 'name' ); if ( in_array( $category, $categories ) ) { continue; } register_block_pattern_category( $category, [ 'label' => ucfirst( $category ), ] ); } } } /** * Parses and registers block pattern from PHP file with header comment. * * @since 0.0.8 * * @param string $file * * @return void */ function register_block_pattern_from_file( string $file ): void { $headers = get_file_data( $file, [ 'categories' => 'Categories', 'title' => 'Title', 'slug' => 'Slug', 'block_types' => 'Block Types', ] ); $categories = explode( ',', $headers['categories'] ); ob_start(); include $file; $content = ob_get_clean(); $pattern = [ 'title' => $headers['title'], 'content' => $content, 'categories' => [ ...$categories ], ]; if ( $headers['block_types'] ) { $pattern['blockTypes'] = $headers['block_types']; } foreach ( $categories as $category ) { register_block_pattern_category( $category, [ 'label' => ucwords( $category ), ] ); } register_block_pattern( $headers['slug'], $pattern ); }