PluginProbe
Countdown Timer Block – build urgency for events and launches / trunk
Countdown Timer Block – build urgency for events and launches vtrunk
1.3.3 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 All 32 releases
countdown-time / includes / Patterns.php

Patterns.php in Countdown Timer Block – build urgency for events and launches trunk, at includes/Patterns.php

53 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace CTB;
3
4 if ( !defined( 'ABSPATH' ) ) { exit; }
5
6 /**
7 * Class Patterns
8 *
9 * Handles Gutenberg block patterns registration from pattern.json file.
10 *
11 * @package CTB
12 */
13 class Patterns{
14 /**
15 * Constructor. Sets up action hook for plugin init.
16 */
17 public function __construct(){
18 add_action('init', [$this, 'onPluginsLoaded']);
19 }
20
21 /**
22 * Decode pattern.json, filter Pro patterns if using the free version,
23 * register block pattern category and individual block patterns.
24 *
25 * @return void
26 */
27 function onPluginsLoaded(){
28 $patterns = wp_json_file_decode( __DIR__ . '/pattern.json', [ 'associative' => true ] );
29
30 // Register Pattern Category
31 if ( function_exists( 'register_block_pattern_category' ) ) {
32 register_block_pattern_category( 'ctbPattern', [ 'label' => __( 'Countdown Time', 'countdown-time' ) ] );
33 }
34
35 // Register Pattern
36 if ( !empty( $patterns ) ) {
37 foreach ( $patterns as $pattern ) {
38 if ( function_exists( 'register_block_pattern' ) ) {
39 register_block_pattern( $pattern['name'], [
40 'title' => $pattern['title'],
41 'content' => $pattern['content'],
42 'description' => $pattern['description'],
43 'categories' => [ 'ctbPattern' ],
44 'keywords' => $pattern['keywords'],
45 'blockTypes' => $pattern['blockTypes'],
46 'viewportWidth' => 1200
47 ] );
48 }
49 }
50 }
51 }
52 }
53 new Patterns();