generator-chisel 2.1.2 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/404.php +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/archive.php +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/author.php +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/composer.json +7 -6
- package/lib/commands/create/creators/app/chisel-starter-theme/footer.php +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/functions.php +3 -3
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Controllers/AjaxController.php +20 -15
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Enums/AcfOptionsPageType.php +8 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Enums/BlocksType.php +17 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Factories/RegisterAcfOptionsPage.php +78 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Factory → Factories}/RegisterBlocks.php +41 -30
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Factory → Factories}/RegisterCustomPostType.php +44 -32
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Factory → Factories}/RegisterCustomTaxonomy.php +39 -27
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Helper → Helpers}/AcfHelpers.php +12 -12
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helpers/AjaxHelpers.php +36 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Helper → Helpers}/AssetsHelpers.php +3 -3
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Helper → Helpers}/BlocksHelpers.php +22 -18
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helpers/CacheHelpers.php +43 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Helper → Helpers}/CommentsHelpers.php +8 -6
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Helper → Helpers}/DataHelpers.php +5 -5
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Helper → Helpers}/GravityFormsHelpers.php +13 -13
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Helper → Helpers}/ImageHelpers.php +30 -15
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Helper → Helpers}/ThemeHelpers.php +29 -25
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Helper → Helpers}/WoocommerceHelpers.php +15 -9
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Helper → Helpers}/YoastHelpers.php +6 -6
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Interfaces/HooksInterface.php +3 -3
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Interfaces/InstanceInterface.php +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Plugin → Plugins}/GravityForms.php +13 -15
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Plugin → Plugins}/Woocommerce.php +14 -14
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Plugin → Plugins}/Yoast.php +6 -6
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Traits/PageBlocks.php +14 -14
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Traits/Singleton.php +28 -7
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/Acf.php +16 -15
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/AcfBlocks.php +19 -19
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/{AjaxEnpoints.php → AjaxEndpoints.php} +13 -13
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/Assets.php +42 -68
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/Blocks.php +23 -23
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/Cache.php +10 -11
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/ChiselImage.php +3 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/ChiselPost.php +13 -7
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/ChiselProduct.php +11 -10
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/ChiselProductCategory.php +10 -10
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/Comments.php +27 -35
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/Components.php +44 -61
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/CustomPostTypes.php +12 -13
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/CustomTaxonomies.php +12 -13
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/Sidebars.php +6 -6
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/Site.php +7 -8
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/Theme.php +22 -22
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/Twig.php +53 -48
- package/lib/commands/create/creators/app/chisel-starter-theme/index.php +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/page.php +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/search.php +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/single.php +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/src/scripts/editor/blocks-styles.js +3 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/src/styles/vendor/_breadcrumbs.scss +6 -3
- package/lib/commands/create/creators/app/chisel-starter-theme/style.chisel-tpl.css +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/woocommerce.php +3 -3
- package/lib/commands/create/packages-versions.js +1 -1
- package/package.json +2 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Factory/RegisterAcfOptionsPage.php +0 -62
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helper/AjaxHelpers.php +0 -33
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helper/CacheHelpers.php +0 -41
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
<?php
|
|
2
2
|
|
|
3
|
-
namespace Chisel\
|
|
3
|
+
namespace Chisel\Factories;
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Custom post types wrapper class.
|
|
7
7
|
*
|
|
8
8
|
* @package Chisel
|
|
9
9
|
*/
|
|
10
|
-
class RegisterCustomPostType {
|
|
10
|
+
final class RegisterCustomPostType {
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Post type.
|
|
14
14
|
*
|
|
15
|
-
* @var
|
|
15
|
+
* @var string
|
|
16
16
|
*/
|
|
17
|
-
private $post_type;
|
|
17
|
+
private string $post_type;
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Arguments.
|
|
21
21
|
*
|
|
22
22
|
* @var array
|
|
23
23
|
*/
|
|
24
|
-
private $args;
|
|
24
|
+
private array $args;
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Default arguments.
|
|
28
28
|
*
|
|
29
29
|
* @var array
|
|
30
30
|
*/
|
|
31
|
-
private $defaults;
|
|
31
|
+
private array $defaults;
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* Class constructor.
|
|
@@ -37,7 +37,7 @@ class RegisterCustomPostType {
|
|
|
37
37
|
* @param array $args Arguments.
|
|
38
38
|
* @param array $defaults Default arguments.
|
|
39
39
|
*/
|
|
40
|
-
public function __construct( $post_type, $args, $defaults = array() ) {
|
|
40
|
+
public function __construct( string $post_type, array $args, array $defaults = array() ) {
|
|
41
41
|
$this->post_type = $post_type;
|
|
42
42
|
$this->args = $args;
|
|
43
43
|
$this->defaults = $defaults;
|
|
@@ -46,42 +46,46 @@ class RegisterCustomPostType {
|
|
|
46
46
|
/**
|
|
47
47
|
* Register custom post type.
|
|
48
48
|
*/
|
|
49
|
-
public function register_post_type() {
|
|
49
|
+
public function register_post_type(): void {
|
|
50
50
|
$post_type = $this->post_type;
|
|
51
51
|
$post_type_args = $this->args;
|
|
52
52
|
$defaults = $this->defaults;
|
|
53
53
|
|
|
54
|
-
$default_supports = isset( $defaults['supports'] )
|
|
55
|
-
|
|
54
|
+
$default_supports = isset( $defaults['supports'] )
|
|
55
|
+
? (array) apply_filters( 'chisel_default_post_type_supports_' . $post_type, $defaults['supports'] )
|
|
56
|
+
: array();
|
|
57
|
+
$default_rewrite = isset( $defaults['rewrite_args'] )
|
|
58
|
+
? (array) apply_filters( 'chisel_default_post_type_rewrite_args_' . $post_type, $defaults['rewrite_args'] )
|
|
59
|
+
: array();
|
|
56
60
|
|
|
57
61
|
$labels = $this->get_post_type_labels();
|
|
58
62
|
|
|
59
63
|
$default_rewrite['slug'] = $post_type;
|
|
60
64
|
|
|
61
|
-
$description =
|
|
62
|
-
$public =
|
|
63
|
-
$hierarchical =
|
|
64
|
-
$exclude_from_search =
|
|
65
|
-
$publicly_queryable =
|
|
66
|
-
$show_ui =
|
|
67
|
-
$show_in_menu =
|
|
68
|
-
$show_in_nav_menus =
|
|
69
|
-
$show_in_admin_bar =
|
|
70
|
-
$show_in_rest =
|
|
71
|
-
$menu_position =
|
|
72
|
-
$menu_icon =
|
|
73
|
-
$capability_type =
|
|
74
|
-
$capabilities =
|
|
75
|
-
$supports = isset( $post_type_args['supports'] ) ? wp_parse_args( $post_type_args['supports'], $default_supports ) : $default_supports;
|
|
76
|
-
$has_archive =
|
|
77
|
-
$rewrite = isset( $post_type_args['rewrite'] ) ? wp_parse_args( $post_type_args['rewrite'], $default_rewrite ) : $default_rewrite;
|
|
78
|
-
$query_var =
|
|
79
|
-
$can_export =
|
|
65
|
+
$description = $post_type_args['description'] ?? '';
|
|
66
|
+
$public = (bool) ( $post_type_args['public'] ?? true );
|
|
67
|
+
$hierarchical = (bool) ( $post_type_args['hierarchical'] ?? false ); // true for pages like post type.
|
|
68
|
+
$exclude_from_search = (bool) ( $post_type_args['exclude_from_search'] ?? ! $public );
|
|
69
|
+
$publicly_queryable = (bool) ( $post_type_args['publicly_queryable'] ?? $public );
|
|
70
|
+
$show_ui = (bool) ( $post_type_args['show_ui'] ?? $public ); // show in admin.
|
|
71
|
+
$show_in_menu = $post_type_args['show_in_menu'] ?? $public; // bool|string. If or where to show in admin menu - show_ui must be true. If a string of an existing top level menu ('tools.php' or 'edit.php?post_type=page', for example), the post type will be placed as a sub-menu of that.
|
|
72
|
+
$show_in_nav_menus = (bool) ( $post_type_args['show_in_nav_menus'] ?? $public );
|
|
73
|
+
$show_in_admin_bar = (bool) ( $post_type_args['show_in_admin_bar'] ?? $show_in_menu );
|
|
74
|
+
$show_in_rest = (bool) ( $post_type_args['show_in_rest'] ?? true ); // set to false to disable block editor. Supports array must also include 'editor'.
|
|
75
|
+
$menu_position = $post_type_args['menu_position'] ?? null; // int|null are valid.
|
|
76
|
+
$menu_icon = (string) ( $post_type_args['menu_icon'] ?? 'dashicons-admin-post' );
|
|
77
|
+
$capability_type = $post_type_args['capability_type'] ?? 'post';
|
|
78
|
+
$capabilities = (array) ( $post_type_args['capabilities'] ?? array() );
|
|
79
|
+
$supports = isset( $post_type_args['supports'] ) ? wp_parse_args( (array) $post_type_args['supports'], $default_supports ) : $default_supports;
|
|
80
|
+
$has_archive = (bool) ( $post_type_args['has_archive'] ?? true );
|
|
81
|
+
$rewrite = isset( $post_type_args['rewrite'] ) ? wp_parse_args( (array) $post_type_args['rewrite'], $default_rewrite ) : $default_rewrite;
|
|
82
|
+
$query_var = $post_type_args['query_var'] ?? $post_type;
|
|
83
|
+
$can_export = (bool) ( $post_type_args['can_export'] ?? true );
|
|
80
84
|
|
|
81
85
|
if ( in_array( 'thumbnail', $supports, true ) ) {
|
|
82
86
|
add_filter(
|
|
83
87
|
'chisel_post_thumbnails_post_types',
|
|
84
|
-
function ( $pts ) use ( $post_type ) {
|
|
88
|
+
function ( array $pts ) use ( $post_type ): array {
|
|
85
89
|
$pts[] = $post_type;
|
|
86
90
|
return $pts;
|
|
87
91
|
}
|
|
@@ -140,9 +144,17 @@ class RegisterCustomPostType {
|
|
|
140
144
|
*
|
|
141
145
|
* @return array
|
|
142
146
|
*/
|
|
143
|
-
private function get_post_type_labels() {
|
|
147
|
+
private function get_post_type_labels(): array {
|
|
144
148
|
$post_type_args = $this->args;
|
|
145
149
|
|
|
150
|
+
if ( empty( $post_type_args['plural'] ) ) {
|
|
151
|
+
$post_type_args['plural'] = __( 'Items', 'chisel' );
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if ( empty( $post_type_args['singular'] ) ) {
|
|
155
|
+
$post_type_args['singular'] = __( 'Item', 'chisel' );
|
|
156
|
+
}
|
|
157
|
+
|
|
146
158
|
$labels = array(
|
|
147
159
|
'name' => $post_type_args['plural'],
|
|
148
160
|
'singular_name' => $post_type_args['singular'],
|
|
@@ -204,7 +216,7 @@ class RegisterCustomPostType {
|
|
|
204
216
|
'item_link_description' => sprintf( __( 'A link to a %s', 'chisel' ), $post_type_args['singular'] ),
|
|
205
217
|
);
|
|
206
218
|
|
|
207
|
-
$custom_labels = isset( $post_type_args['labels'] ) ? $post_type_args['labels'] : array();
|
|
219
|
+
$custom_labels = isset( $post_type_args['labels'] ) && is_array( $post_type_args['labels'] ) ? $post_type_args['labels'] : array();
|
|
208
220
|
|
|
209
221
|
return wp_parse_args( $custom_labels, $labels );
|
|
210
222
|
}
|
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
<?php
|
|
2
2
|
|
|
3
|
-
namespace Chisel\
|
|
3
|
+
namespace Chisel\Factories;
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Custom axonomies wrapper class.
|
|
7
7
|
*
|
|
8
8
|
* @package Chisel
|
|
9
9
|
*/
|
|
10
|
-
class RegisterCustomTaxonomy {
|
|
10
|
+
final class RegisterCustomTaxonomy {
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Taxonomy.
|
|
14
14
|
*
|
|
15
|
-
* @var
|
|
15
|
+
* @var string
|
|
16
16
|
*/
|
|
17
|
-
private $taxonomy;
|
|
17
|
+
private string $taxonomy;
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Arguments.
|
|
21
21
|
*
|
|
22
22
|
* @var array
|
|
23
23
|
*/
|
|
24
|
-
private $args;
|
|
24
|
+
private array $args;
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Default arguments.
|
|
28
28
|
*
|
|
29
29
|
* @var array
|
|
30
30
|
*/
|
|
31
|
-
private $defaults;
|
|
31
|
+
private array $defaults;
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* Class constructor.
|
|
@@ -37,7 +37,7 @@ class RegisterCustomTaxonomy {
|
|
|
37
37
|
* @param array $args Arguments.
|
|
38
38
|
* @param array $defaults Default arguments.
|
|
39
39
|
*/
|
|
40
|
-
public function __construct( $taxonomy, $args, $defaults = array() ) {
|
|
40
|
+
public function __construct( string $taxonomy, array $args, array $defaults = array() ) {
|
|
41
41
|
$this->taxonomy = $taxonomy;
|
|
42
42
|
$this->args = $args;
|
|
43
43
|
$this->defaults = $defaults;
|
|
@@ -46,33 +46,37 @@ class RegisterCustomTaxonomy {
|
|
|
46
46
|
/**
|
|
47
47
|
* Register custom taxonomy.
|
|
48
48
|
*/
|
|
49
|
-
public function register_taxonomy() {
|
|
49
|
+
public function register_taxonomy(): void {
|
|
50
50
|
$taxonomy = $this->taxonomy;
|
|
51
51
|
$taxonomy_args = $this->args;
|
|
52
52
|
$defaults = $this->defaults;
|
|
53
53
|
|
|
54
|
-
$default_capabilities = isset( $defaults['capabilities'] )
|
|
55
|
-
|
|
54
|
+
$default_capabilities = isset( $defaults['capabilities'] )
|
|
55
|
+
? (array) apply_filters( 'chisel_default_taxonomy_capabilities_' . $taxonomy, $defaults['capabilities'] )
|
|
56
|
+
: array();
|
|
57
|
+
$default_rewrite = isset( $defaults['rewrite_args'] )
|
|
58
|
+
? (array) apply_filters( 'chisel_default_taxonomy_rewrite_args_' . $taxonomy, $defaults['rewrite_args'] )
|
|
59
|
+
: array();
|
|
56
60
|
|
|
57
61
|
$labels = $this->get_taxonomy_labels();
|
|
58
62
|
|
|
59
63
|
$default_rewrite['slug'] = $taxonomy;
|
|
60
64
|
|
|
61
|
-
$description =
|
|
62
|
-
$public =
|
|
63
|
-
$publicly_queryable =
|
|
64
|
-
$hierarchical =
|
|
65
|
-
$show_ui =
|
|
66
|
-
$show_in_menu =
|
|
67
|
-
$show_in_nav_menus =
|
|
68
|
-
$show_in_rest =
|
|
69
|
-
$show_tagcloud =
|
|
70
|
-
$show_in_quick_edit =
|
|
71
|
-
$show_admin_column =
|
|
72
|
-
$capabilities = isset( $taxonomy_args['capabilities'] ) ? wp_parse_args( $taxonomy_args['capabilities'], $default_capabilities ) : $default_capabilities;
|
|
73
|
-
$rewrite = isset( $taxonomy_args['rewrite'] ) ? wp_parse_args( $taxonomy_args['rewrite'], $default_rewrite ) : $default_rewrite;
|
|
74
|
-
$query_var =
|
|
75
|
-
$rest_base =
|
|
65
|
+
$description = $taxonomy_args['description'] ?? '';
|
|
66
|
+
$public = (bool) ( $taxonomy_args['public'] ?? true );
|
|
67
|
+
$publicly_queryable = (bool) ( $taxonomy_args['publicly_queryable'] ?? $public );
|
|
68
|
+
$hierarchical = (bool) ( $taxonomy_args['hierarchical'] ?? false ); // true for a taxonomy like categories.
|
|
69
|
+
$show_ui = (bool) ( $taxonomy_args['show_ui'] ?? $public ); // show in admin.
|
|
70
|
+
$show_in_menu = $taxonomy_args['show_in_menu'] ?? $show_ui; // Show in admin menu (as a submenu of post type) - bool|string (submenu parent).
|
|
71
|
+
$show_in_nav_menus = (bool) ( $taxonomy_args['show_in_nav_menus'] ?? $public );
|
|
72
|
+
$show_in_rest = (bool) ( $taxonomy_args['show_in_rest'] ?? true ); // set to false to hide in block editor.
|
|
73
|
+
$show_tagcloud = (bool) ( $taxonomy_args['show_tagcloud'] ?? $show_ui );
|
|
74
|
+
$show_in_quick_edit = (bool) ( $taxonomy_args['show_in_quick_edit'] ?? $show_ui );
|
|
75
|
+
$show_admin_column = (bool) ( $taxonomy_args['show_admin_column'] ?? $public );
|
|
76
|
+
$capabilities = isset( $taxonomy_args['capabilities'] ) ? wp_parse_args( (array) $taxonomy_args['capabilities'], $default_capabilities ) : $default_capabilities;
|
|
77
|
+
$rewrite = isset( $taxonomy_args['rewrite'] ) ? wp_parse_args( (array) $taxonomy_args['rewrite'], $default_rewrite ) : $default_rewrite;
|
|
78
|
+
$query_var = $taxonomy_args['query_var'] ?? $taxonomy;
|
|
79
|
+
$rest_base = $taxonomy_args['rest_base'] ?? $taxonomy;
|
|
76
80
|
|
|
77
81
|
$args = array(
|
|
78
82
|
'labels' => $labels,
|
|
@@ -109,7 +113,7 @@ class RegisterCustomTaxonomy {
|
|
|
109
113
|
}
|
|
110
114
|
}
|
|
111
115
|
|
|
112
|
-
register_taxonomy( $taxonomy, $taxonomy_args['post_types'], $args );
|
|
116
|
+
register_taxonomy( $taxonomy, (array) $taxonomy_args['post_types'], $args );
|
|
113
117
|
}
|
|
114
118
|
|
|
115
119
|
/**
|
|
@@ -117,9 +121,17 @@ class RegisterCustomTaxonomy {
|
|
|
117
121
|
*
|
|
118
122
|
* @return array
|
|
119
123
|
*/
|
|
120
|
-
private function get_taxonomy_labels() {
|
|
124
|
+
private function get_taxonomy_labels(): array {
|
|
121
125
|
$taxonomy_args = $this->args;
|
|
122
126
|
|
|
127
|
+
if ( empty( $taxonomy_args['plural'] ) ) {
|
|
128
|
+
$taxonomy_args['plural'] = __( 'Items', 'chisel' );
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if ( empty( $taxonomy_args['singular'] ) ) {
|
|
132
|
+
$taxonomy_args['singular'] = __( 'Item', 'chisel' );
|
|
133
|
+
}
|
|
134
|
+
|
|
123
135
|
$labels = array(
|
|
124
136
|
'name' => $taxonomy_args['plural'],
|
|
125
137
|
'singular_name' => $taxonomy_args['singular'],
|
package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Helper → Helpers}/AcfHelpers.php
RENAMED
|
@@ -1,42 +1,42 @@
|
|
|
1
1
|
<?php
|
|
2
2
|
|
|
3
|
-
namespace Chisel\
|
|
3
|
+
namespace Chisel\Helpers;
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Helper functions.
|
|
7
7
|
*
|
|
8
8
|
* @package Chisel
|
|
9
9
|
*/
|
|
10
|
-
class AcfHelpers {
|
|
10
|
+
final class AcfHelpers {
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Get the acf field value. Acf get_field() wrapper. If ACF plugin is not active, returns false.
|
|
14
14
|
*
|
|
15
|
-
* @param string
|
|
16
|
-
* @param
|
|
17
|
-
* @param bool
|
|
18
|
-
* @param bool
|
|
15
|
+
* @param string $selector
|
|
16
|
+
* @param mixed $post_id
|
|
17
|
+
* @param bool $format_value
|
|
18
|
+
* @param bool $escape_html
|
|
19
19
|
*
|
|
20
20
|
* @return mixed
|
|
21
21
|
*/
|
|
22
|
-
public static function get_field( $selector, $post_id = false, $format_value = true, $escape_html = false ) {
|
|
22
|
+
public static function get_field( string $selector, mixed $post_id = false, bool $format_value = true, bool $escape_html = false ) {
|
|
23
23
|
if ( function_exists( 'get_field' ) ) {
|
|
24
24
|
return get_field( $selector, $post_id, $format_value, $escape_html );
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
return
|
|
27
|
+
return null;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Update the acf field value. Acf update_field() wrapper. If ACF plugin is not active, returns false.
|
|
32
32
|
*
|
|
33
|
-
* @param string
|
|
34
|
-
* @param mixed
|
|
35
|
-
* @param
|
|
33
|
+
* @param string $selector
|
|
34
|
+
* @param mixed $value
|
|
35
|
+
* @param mixed $post_id
|
|
36
36
|
*
|
|
37
37
|
* @return int|bool
|
|
38
38
|
*/
|
|
39
|
-
public static function update_field( $selector, $value, $post_id = false ) {
|
|
39
|
+
public static function update_field( string $selector, mixed $value, mixed $post_id = false ) {
|
|
40
40
|
if ( function_exists( 'update_field' ) ) {
|
|
41
41
|
return update_field( $selector, $value, $post_id );
|
|
42
42
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Chisel\Helpers;
|
|
4
|
+
|
|
5
|
+
use Chisel\Controllers\AjaxController;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Helper functions.
|
|
9
|
+
*
|
|
10
|
+
* @package Chisel
|
|
11
|
+
*/
|
|
12
|
+
final class AjaxHelpers {
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Get custom ajax endpint
|
|
16
|
+
*
|
|
17
|
+
* @return string
|
|
18
|
+
*/
|
|
19
|
+
public static function get_ajax_endpoint_url(): string {
|
|
20
|
+
return sprintf( '%s/wp-json/%s/%s', rtrim( get_bloginfo( 'url' ), '/' ), AjaxController::ROUTE_NAMESPACE, AjaxController::ROUTE_BASE );
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Decode json string from ajax request safely
|
|
25
|
+
*
|
|
26
|
+
* @param string $value
|
|
27
|
+
*
|
|
28
|
+
* @return array
|
|
29
|
+
*/
|
|
30
|
+
public static function ajax_json_decode( string $value ): array {
|
|
31
|
+
$raw = stripslashes( $value );
|
|
32
|
+
$decoded = json_decode( $raw, true, 512, JSON_THROW_ON_ERROR );
|
|
33
|
+
|
|
34
|
+
return is_array( $decoded ) ? $decoded : array();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
<?php
|
|
2
2
|
|
|
3
|
-
namespace Chisel\
|
|
3
|
+
namespace Chisel\Helpers;
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Helper functions.
|
|
7
7
|
*
|
|
8
8
|
* @package Chisel
|
|
9
9
|
*/
|
|
10
|
-
class AssetsHelpers {
|
|
10
|
+
final class AssetsHelpers {
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Get the final handle for the asset.
|
|
@@ -16,7 +16,7 @@ class AssetsHelpers {
|
|
|
16
16
|
*
|
|
17
17
|
* @return string
|
|
18
18
|
*/
|
|
19
|
-
public static function get_final_handle( $handle ) {
|
|
19
|
+
public static function get_final_handle( string $handle ): string {
|
|
20
20
|
$handle = 'chisel-' . $handle;
|
|
21
21
|
|
|
22
22
|
if ( ThemeHelpers::is_fast_refresh() ) {
|
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
<?php
|
|
2
2
|
|
|
3
|
-
namespace Chisel\
|
|
3
|
+
namespace Chisel\Helpers;
|
|
4
4
|
|
|
5
5
|
use Timber\Timber;
|
|
6
6
|
use Chisel\WP\AcfBlocks;
|
|
7
|
-
use Chisel\
|
|
7
|
+
use Chisel\Helpers\CacheHelpers;
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Helper functions.
|
|
11
11
|
*
|
|
12
12
|
* @package Chisel
|
|
13
13
|
*/
|
|
14
|
-
class BlocksHelpers {
|
|
14
|
+
final class BlocksHelpers {
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Get block object classnames
|
|
18
18
|
*
|
|
19
|
-
* @param string $block_name
|
|
19
|
+
* @param ?string $block_name
|
|
20
20
|
*
|
|
21
21
|
* @return string
|
|
22
22
|
*/
|
|
23
|
-
public static function get_block_object_classnames( $block_name ) {
|
|
24
|
-
if (
|
|
23
|
+
public static function get_block_object_classnames( ?string $block_name ): string {
|
|
24
|
+
if ( empty( $block_name ) ) {
|
|
25
25
|
return '';
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
$
|
|
28
|
+
$parts = explode( '/', $block_name );
|
|
29
29
|
|
|
30
|
-
if (
|
|
30
|
+
if ( count( $parts ) < 2 ) {
|
|
31
31
|
return '';
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
return 'c-block c-block--' . $
|
|
34
|
+
return 'c-block c-block--' . $parts[0] . ' c-block--' . $parts[1];
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
/**
|
|
@@ -42,11 +42,11 @@ class BlocksHelpers {
|
|
|
42
42
|
*
|
|
43
43
|
* @return void
|
|
44
44
|
*/
|
|
45
|
-
public static function render_twig_file( $block_name, $context ) {
|
|
46
|
-
$
|
|
47
|
-
$block_name = end( $
|
|
45
|
+
public static function render_twig_file( string $block_name, array $context ): void {
|
|
46
|
+
$parts = explode( '/', $block_name );
|
|
47
|
+
$block_name = end( $parts ) ?: $block_name;
|
|
48
48
|
|
|
49
|
-
$twig_file =
|
|
49
|
+
$twig_file = Blocks::get_instance()->blocks_twig_base_path . $block_name . '/render.twig';
|
|
50
50
|
Timber::render( $twig_file, $context );
|
|
51
51
|
}
|
|
52
52
|
|
|
@@ -60,7 +60,11 @@ class BlocksHelpers {
|
|
|
60
60
|
*
|
|
61
61
|
* @return void
|
|
62
62
|
*/
|
|
63
|
-
public static function acf_block_render( $block, $content = '', $is_preview = false, $post_id = 0 ) {
|
|
63
|
+
public static function acf_block_render( array $block, string $content = '', bool $is_preview = false, int $post_id = 0 ): void {
|
|
64
|
+
if ( empty( $block['name'] ) ) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
64
68
|
$context = Timber::context();
|
|
65
69
|
|
|
66
70
|
$block_slug = str_replace( 'chisel/', '', $block['name'] );
|
|
@@ -70,7 +74,7 @@ class BlocksHelpers {
|
|
|
70
74
|
$context['post_id'] = $post_id;
|
|
71
75
|
$context['slug'] = $slug;
|
|
72
76
|
$context['is_preview'] = $is_preview;
|
|
73
|
-
$context['fields'] = get_fields();
|
|
77
|
+
$context['fields'] = function_exists( 'get_fields' ) ? get_fields() : array();
|
|
74
78
|
$classes = array_merge(
|
|
75
79
|
array( $slug ),
|
|
76
80
|
isset( $block['className'] ) ? array( $block['className'] ) : array(),
|
|
@@ -79,7 +83,7 @@ class BlocksHelpers {
|
|
|
79
83
|
);
|
|
80
84
|
|
|
81
85
|
$context['block']['class_names'] = $classes;
|
|
82
|
-
$context['block']['block_id'] =
|
|
86
|
+
$context['block']['block_id'] = $block['anchor'] ?? ( $block['id'] ?? '' );
|
|
83
87
|
|
|
84
88
|
// allow to use filters to manipulate the output.
|
|
85
89
|
$context = apply_filters( 'chisel_timber_acf_blocks_data', $context );
|
|
@@ -104,8 +108,8 @@ class BlocksHelpers {
|
|
|
104
108
|
*
|
|
105
109
|
* @return string
|
|
106
110
|
*/
|
|
107
|
-
public static function get_block_inline_css( $blocks_url, $block_name ) {
|
|
108
|
-
$css_url = $blocks_url . '/' . $block_name . '/script.css';
|
|
111
|
+
public static function get_block_inline_css( string $blocks_url, string $block_name ): string {
|
|
112
|
+
$css_url = rtrim( $blocks_url, '/' ) . '/' . $block_name . '/script.css';
|
|
109
113
|
$response = wp_remote_get( $css_url );
|
|
110
114
|
$css = '';
|
|
111
115
|
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Chisel\Helpers;
|
|
4
|
+
|
|
5
|
+
use Timber\Timber;
|
|
6
|
+
use Timber\Loader;
|
|
7
|
+
|
|
8
|
+
use Chisel\WP\Cache;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Image Helper functions.
|
|
12
|
+
*
|
|
13
|
+
* @package Chisel
|
|
14
|
+
*/
|
|
15
|
+
final class CacheHelpers {
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Get the cache expiry time.
|
|
19
|
+
*
|
|
20
|
+
* @param ?int $custom_expiry The custom expiry time.
|
|
21
|
+
*
|
|
22
|
+
* @return ?int
|
|
23
|
+
*/
|
|
24
|
+
public static function expiry( ?int $custom_expiry = null ): int {
|
|
25
|
+
$cache = Cache::get_instance();
|
|
26
|
+
|
|
27
|
+
if ( ! $cache->cache_everything ) {
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return $custom_expiry ?? (int) $cache->cache_expiry;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Clear twig environment cache.
|
|
36
|
+
*
|
|
37
|
+
* @return void
|
|
38
|
+
*/
|
|
39
|
+
public static function clear_environment_cache(): void {
|
|
40
|
+
$loader = new Loader();
|
|
41
|
+
$loader->clear_cache_twig();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
<?php
|
|
2
2
|
|
|
3
|
-
namespace Chisel\
|
|
3
|
+
namespace Chisel\Helpers;
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Helper functions.
|
|
7
7
|
*
|
|
8
8
|
* @package Chisel
|
|
9
9
|
*/
|
|
10
|
-
class CommentsHelpers {
|
|
10
|
+
final class CommentsHelpers {
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Display comments template - the comments and the form.
|
|
14
14
|
*
|
|
15
|
-
* @return
|
|
15
|
+
* @return string
|
|
16
16
|
*/
|
|
17
|
-
public static function comments_template() {
|
|
17
|
+
public static function comments_template(): string {
|
|
18
18
|
if ( ! post_type_supports( get_post_type(), 'comments' ) ) {
|
|
19
|
-
return;
|
|
19
|
+
return '';
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
if ( comments_open() ) {
|
|
23
|
-
return
|
|
23
|
+
return do_blocks( '<!-- wp:pattern {"slug":"chisel/comments"} /-->' );
|
|
24
24
|
}
|
|
25
|
+
|
|
26
|
+
return '';
|
|
25
27
|
}
|
|
26
28
|
}
|
package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Helper → Helpers}/DataHelpers.php
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<?php
|
|
2
2
|
|
|
3
|
-
namespace Chisel\
|
|
3
|
+
namespace Chisel\Helpers;
|
|
4
4
|
|
|
5
5
|
use Timber\Timber;
|
|
6
6
|
|
|
@@ -9,7 +9,7 @@ use Timber\Timber;
|
|
|
9
9
|
*
|
|
10
10
|
* @package Chisel
|
|
11
11
|
*/
|
|
12
|
-
class DataHelpers {
|
|
12
|
+
final class DataHelpers {
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Json decode data for storing in html attribute
|
|
@@ -18,7 +18,7 @@ class DataHelpers {
|
|
|
18
18
|
*
|
|
19
19
|
* @return string
|
|
20
20
|
*/
|
|
21
|
-
public static function json_encode_for_data_attribute( $data ) {
|
|
21
|
+
public static function json_encode_for_data_attribute( array $data ): string {
|
|
22
22
|
return htmlspecialchars( wp_json_encode( $data ) );
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -29,7 +29,7 @@ class DataHelpers {
|
|
|
29
29
|
*
|
|
30
30
|
* @return array
|
|
31
31
|
*/
|
|
32
|
-
public static function object_to_array( $object_to_convert ) {
|
|
33
|
-
|
|
32
|
+
public static function object_to_array( object $object_to_convert ): array {
|
|
33
|
+
return json_decode( wp_json_encode( $object_to_convert ), true );
|
|
34
34
|
}
|
|
35
35
|
}
|