| 1 |
<?php |
| 2 |
include BLOCKSPARE_BASE_DIR .'/inc/template-library/init.php'; |
| 3 |
if(!function_exists('blockspare_register_block_pattern')){ |
| 4 |
function blockspare_register_block_pattern() { |
| 5 |
|
| 6 |
//Get all blocks from template library |
| 7 |
$blocks_lists = array(); |
| 8 |
|
| 9 |
$templates_lists = apply_filters( 'blockspare_template_library', $blocks_lists ); |
| 10 |
|
| 11 |
$templates_lists = apply_filters( 'blockspare_template_library', $blocks_lists ); |
| 12 |
$block_pattern_categories =[]; |
| 13 |
foreach($templates_lists as $tl){ |
| 14 |
if($tl['content'] !== 'https://www.blockspare.com/'){ |
| 15 |
array_push($block_pattern_categories,$tl['item']); |
| 16 |
} |
| 17 |
} |
| 18 |
|
| 19 |
foreach($block_pattern_categories as $cat_name){ |
| 20 |
foreach(array_unique($cat_name) as $name){ |
| 21 |
if ( ! WP_Block_Pattern_Categories_Registry::get_instance()->is_registered( $name ) ) { |
| 22 |
register_block_pattern_category( |
| 23 |
$name, |
| 24 |
array( 'label' => $name ) |
| 25 |
); |
| 26 |
} |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
$empty_template_array = []; |
| 31 |
foreach($templates_lists as $template){ |
| 32 |
if($template['content'] !== 'https://www.blockspare.com/'){ |
| 33 |
$new_template_array = []; |
| 34 |
$new_template_array = array( |
| 35 |
'title'=>$template['name'], |
| 36 |
'categories'=>$template['item'], |
| 37 |
'content'=>$template['content'] |
| 38 |
); |
| 39 |
|
| 40 |
array_push($empty_template_array,$new_template_array); |
| 41 |
} |
| 42 |
|
| 43 |
} |
| 44 |
// Register pattern |
| 45 |
if(!empty($empty_template_array)){ |
| 46 |
$i=0; |
| 47 |
foreach($empty_template_array as $new_template){ |
| 48 |
$i++; |
| 49 |
register_block_pattern( |
| 50 |
'blockspare/blockspare-pattern-'.$i, |
| 51 |
$new_template |
| 52 |
|
| 53 |
); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
} |
| 58 |
add_action('init','blockspare_register_block_pattern'); |
| 59 |
} |
| 60 |
|
| 61 |
|