| 1 |
<?php |
| 2 |
class CTBPattern{ |
| 3 |
public function __construct(){ |
| 4 |
add_action('plugins_loaded', [$this, 'onPluginsLoaded']); |
| 5 |
} |
| 6 |
|
| 7 |
function onPluginsLoaded(){ |
| 8 |
$patterns = wp_json_file_decode( __DIR__ . '/pattern.json', [ 'associative' => true ] ); |
| 9 |
$patterns = ctbIsPremium() ? $patterns : array_filter( $patterns, function( $item ) { |
| 10 |
return !isset($item['pro']) || !$item['pro']; |
| 11 |
} ); |
| 12 |
|
| 13 |
// Register Pattern Category |
| 14 |
if ( function_exists( 'register_block_pattern_category' ) ) { |
| 15 |
register_block_pattern_category( 'ctbPattern', [ 'label' => __( 'Countdown Time', 'countdown-time' ) ] ); |
| 16 |
} |
| 17 |
|
| 18 |
// Register Pattern |
| 19 |
if ( !empty( $patterns ) ) { |
| 20 |
foreach ( $patterns as $pattern ) { |
| 21 |
if ( function_exists( 'register_block_pattern' ) ) { |
| 22 |
register_block_pattern( $pattern['name'], [ |
| 23 |
'title' => $pattern['title'], |
| 24 |
'content' => $pattern['content'], |
| 25 |
'description' => $pattern['description'], |
| 26 |
'categories' => [ 'ctbPattern' ], |
| 27 |
'keywords' => $pattern['keywords'], |
| 28 |
'blockTypes' => $pattern['blockTypes'], |
| 29 |
'viewportWidth' => 1200 |
| 30 |
] ); |
| 31 |
} |
| 32 |
} |
| 33 |
} |
| 34 |
} |
| 35 |
} |
| 36 |
new CTBPattern(); |