-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlock_Patterns.php
More file actions
114 lines (100 loc) · 2.21 KB
/
Block_Patterns.php
File metadata and controls
114 lines (100 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/**
* Patterns Handler.
*
* @author Themeisle
* @package jaxon
* @since 1.0.0
*/
namespace Jaxon;
use WP_Block_Pattern_Categories_Registry;
/**
* Class Block_Patterns
*
* @package jaxon
*/
class Block_Patterns {
/**
* Patterns categories.
*
* @var array
*/
private $categories = array();
/**
* The patterns array.
*
* These use the file names without termination inside the `inc/patterns` directory.
*
* @var array
*/
private $patterns = array();
/**
* Block_Patterns constructor.
*/
public function __construct() {
add_action( 'init', array( $this, 'run' ) );
}
/**
* Run the class functionality.
*
* @return void
*/
public function run() {
$this->setup_properties();
$this->register_categories();
$this->register_patterns();
}
/**
* Setup class properties.
*
* @return void
*/
private function setup_properties() {
$categories = array(
'jaxon' => array( 'label' => __( 'Jaxon Patterns', 'jaxon' ) ),
);
$patterns = array(
'hero-cover-with-title-and-image',
'row-with-logos',
'call-to-action-inverted',
'categories-with-description-and-images',
'two-columns-with-images-and-text',
'features-with-icons',
'three-columns-with-testimonials',
'posts-in-a-three-column-grid',
'two-columns-with-testimonials',
'alternating-layout-with-image-and-description',
'call-to-action-boxed',
'three-columns-with-products',
);
$this->categories = apply_filters( 'jaxon_block_patterns_categories', $categories );
$this->patterns = apply_filters( 'jaxon_block_patterns', $patterns );
}
/**
* Register block patterns categories.
*
* @return void
*/
private function register_categories() {
foreach ( $this->categories as $slug => $args ) {
if ( WP_Block_Pattern_Categories_Registry::get_instance()->is_registered( $slug ) ) {
continue;
}
register_block_pattern_category( $slug, $args );
}
}
/**
* Register Patterns.
*
* @return void
*/
private function register_patterns() {
foreach ( $this->patterns as $pattern ) {
$file = JAXON_DIR . 'inc/patterns/' . $pattern . '.php';
if ( ! is_file( $file ) ) {
continue;
}
register_block_pattern( 'jaxon/' . $pattern, require $file );
}
}
}