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
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
<!-- INSERT-NEW-ENTRIES-HERE -->
|
|
4
4
|
|
|
5
|
+
## 2.2.0 (2025-10-22)
|
|
6
|
+
|
|
7
|
+
- composer update, min req php 8.2, refactor to modern php ([d55aae0](https://github.com/xfiveco/generator-chisel/commit/d55aae0))
|
|
8
|
+
|
|
5
9
|
## <small>2.1.2 (2025-09-30)</small>
|
|
6
10
|
|
|
7
11
|
- minor fixes and adjustments, disable xmlrpc ([0bf6f64](https://github.com/xfiveco/generator-chisel/commit/0bf6f64))
|
|
@@ -6,16 +6,17 @@
|
|
|
6
6
|
"dealerdirect/phpcodesniffer-composer-installer": true
|
|
7
7
|
},
|
|
8
8
|
"platform": {
|
|
9
|
-
"php": "
|
|
9
|
+
"php": "8.2"
|
|
10
10
|
}
|
|
11
11
|
},
|
|
12
12
|
"require-dev": {
|
|
13
|
-
"squizlabs/php_codesniffer": "^3.
|
|
14
|
-
"wp-coding-standards/wpcs": "^3.
|
|
15
|
-
"friendsoftwig/twigcs": "^6.
|
|
16
|
-
"vincentlanglet/twig-cs-fixer": "^
|
|
13
|
+
"squizlabs/php_codesniffer": "^3.13",
|
|
14
|
+
"wp-coding-standards/wpcs": "^3.2",
|
|
15
|
+
"friendsoftwig/twigcs": "^6.5",
|
|
16
|
+
"vincentlanglet/twig-cs-fixer": "^3.10"
|
|
17
17
|
},
|
|
18
18
|
"require": {
|
|
19
|
-
"
|
|
19
|
+
"php": "^8.2",
|
|
20
|
+
"timber/timber": "^2.3"
|
|
20
21
|
}
|
|
21
22
|
}
|
|
@@ -39,6 +39,6 @@ Timber\Timber::init();
|
|
|
39
39
|
\Chisel\WP\CustomPostTypes::get_instance();
|
|
40
40
|
\Chisel\WP\CustomTaxonomies::get_instance();
|
|
41
41
|
\Chisel\WP\Twig::get_instance();
|
|
42
|
-
\Chisel\
|
|
43
|
-
\Chisel\
|
|
44
|
-
\Chisel\
|
|
42
|
+
\Chisel\Plugins\GravityForms::get_instance();
|
|
43
|
+
\Chisel\Plugins\Woocommerce::get_instance();
|
|
44
|
+
\Chisel\Plugins\Yoast::get_instance();
|
package/lib/commands/create/creators/app/chisel-starter-theme/inc/Controllers/AjaxController.php
CHANGED
|
@@ -12,7 +12,7 @@ use Chisel\Traits\Singleton;
|
|
|
12
12
|
*
|
|
13
13
|
* @package Chisel
|
|
14
14
|
*/
|
|
15
|
-
class AjaxController extends \WP_REST_Controller implements InstanceInterface, HooksInterface {
|
|
15
|
+
final class AjaxController extends \WP_REST_Controller implements InstanceInterface, HooksInterface {
|
|
16
16
|
|
|
17
17
|
use Singleton;
|
|
18
18
|
|
|
@@ -21,21 +21,21 @@ class AjaxController extends \WP_REST_Controller implements InstanceInterface, H
|
|
|
21
21
|
*
|
|
22
22
|
* @var string
|
|
23
23
|
*/
|
|
24
|
-
const ROUTE_NAMESPACE = 'chisel/v2';
|
|
24
|
+
public const ROUTE_NAMESPACE = 'chisel/v2';
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Ajax custom route base.
|
|
28
28
|
*
|
|
29
29
|
* @var string
|
|
30
30
|
*/
|
|
31
|
-
const ROUTE_BASE = 'ajax';
|
|
31
|
+
public const ROUTE_BASE = 'ajax';
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* Ajax custom routes.
|
|
35
35
|
*
|
|
36
36
|
* @var array
|
|
37
37
|
*/
|
|
38
|
-
private $routes = array();
|
|
38
|
+
private array $routes = array();
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
* Class constructor.
|
|
@@ -50,7 +50,7 @@ class AjaxController extends \WP_REST_Controller implements InstanceInterface, H
|
|
|
50
50
|
/**
|
|
51
51
|
* Set properties.
|
|
52
52
|
*/
|
|
53
|
-
public function set_properties() {
|
|
53
|
+
public function set_properties(): void {
|
|
54
54
|
$this->routes = array(
|
|
55
55
|
'load-more' => array(),
|
|
56
56
|
);
|
|
@@ -59,26 +59,26 @@ class AjaxController extends \WP_REST_Controller implements InstanceInterface, H
|
|
|
59
59
|
/**
|
|
60
60
|
* Register action hooks.
|
|
61
61
|
*/
|
|
62
|
-
public function action_hooks() {
|
|
62
|
+
public function action_hooks(): void {
|
|
63
63
|
add_action( 'rest_api_init', array( $this, 'register_endpoints' ) );
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* Register filter hooks.
|
|
68
68
|
*/
|
|
69
|
-
public function filter_hooks() {}
|
|
69
|
+
public function filter_hooks(): void {}
|
|
70
70
|
|
|
71
71
|
/**
|
|
72
72
|
* Register endpoints
|
|
73
73
|
*
|
|
74
74
|
* @return void
|
|
75
75
|
*/
|
|
76
|
-
public function register_endpoints() {
|
|
76
|
+
public function register_endpoints(): void {
|
|
77
77
|
$this->routes = apply_filters( 'chisel_ajax_routes', $this->routes );
|
|
78
78
|
|
|
79
79
|
if ( $this->routes ) {
|
|
80
80
|
foreach ( $this->routes as $route_name => $route_params ) {
|
|
81
|
-
$route = sprintf(
|
|
81
|
+
$route = sprintf( '%s/%s/', self::ROUTE_BASE, $route_name );
|
|
82
82
|
$methods = isset( $route_params['methods'] ) ? $route_params['methods'] : array( 'POST' );
|
|
83
83
|
|
|
84
84
|
register_rest_route(
|
|
@@ -100,9 +100,9 @@ class AjaxController extends \WP_REST_Controller implements InstanceInterface, H
|
|
|
100
100
|
*
|
|
101
101
|
* @param \WP_REST_Request $request WP_REST_Request.
|
|
102
102
|
*
|
|
103
|
-
* @return
|
|
103
|
+
* @return \WP_REST_Response|\WP_Error|array
|
|
104
104
|
*/
|
|
105
|
-
public function callback( $request ) {
|
|
105
|
+
public function callback( \WP_REST_Request $request ): \WP_REST_Response|\WP_Error|array {
|
|
106
106
|
$callback = $this->get_callback_name( $request );
|
|
107
107
|
$ajax_endpoints = new AjaxEndpoints();
|
|
108
108
|
|
|
@@ -115,8 +115,12 @@ class AjaxController extends \WP_REST_Controller implements InstanceInterface, H
|
|
|
115
115
|
define( 'DOING_CHISEL_AJAX', true );
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
|
|
118
|
+
$callable = array( $ajax_endpoints, $callback );
|
|
119
|
+
|
|
120
|
+
return $callable( $request );
|
|
119
121
|
}
|
|
122
|
+
|
|
123
|
+
return new \WP_Error( 'chisel_ajax_callback_missing', sprintf( 'Callback %s not found', $callback ), array( 'status' => 404 ) );
|
|
120
124
|
}
|
|
121
125
|
|
|
122
126
|
/**
|
|
@@ -126,10 +130,11 @@ class AjaxController extends \WP_REST_Controller implements InstanceInterface, H
|
|
|
126
130
|
*
|
|
127
131
|
* @return boolean
|
|
128
132
|
*/
|
|
129
|
-
public function permissions_check( $request ) {
|
|
133
|
+
public function permissions_check( \WP_REST_Request $request ): bool|\WP_Error {
|
|
130
134
|
$verify_nonce = wp_verify_nonce( $request->get_header( 'x_wp_nonce' ), 'wp_rest' );
|
|
135
|
+
$allowed = (bool) $verify_nonce;
|
|
131
136
|
|
|
132
|
-
$permission = apply_filters( 'chisel_ajax_permissions_check',
|
|
137
|
+
$permission = apply_filters( 'chisel_ajax_permissions_check', $allowed, $this->get_callback_name( $request ), $request );
|
|
133
138
|
|
|
134
139
|
return $permission;
|
|
135
140
|
}
|
|
@@ -141,7 +146,7 @@ class AjaxController extends \WP_REST_Controller implements InstanceInterface, H
|
|
|
141
146
|
*
|
|
142
147
|
* @return string
|
|
143
148
|
*/
|
|
144
|
-
private function get_callback_name( $request ) {
|
|
149
|
+
private function get_callback_name( \WP_REST_Request $request ): string {
|
|
145
150
|
$route = $request->get_route();
|
|
146
151
|
$route_parts = explode( '/', $route );
|
|
147
152
|
$callback = str_replace( '-', '_', end( $route_parts ) );
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Chisel\Enums;
|
|
4
|
+
|
|
5
|
+
enum BlocksType: string {
|
|
6
|
+
case ACF = 'acf';
|
|
7
|
+
case WP = 'wp';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Get the folder name based on the blocks type.
|
|
11
|
+
*
|
|
12
|
+
* @return string
|
|
13
|
+
*/
|
|
14
|
+
public function folder_name(): string {
|
|
15
|
+
return $this === self::ACF ? 'blocks-acf' : 'blocks';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Chisel\Factories;
|
|
4
|
+
|
|
5
|
+
use Chisel\Enums\AcfOptionsPageType;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Custom post types wrapper class.
|
|
9
|
+
*
|
|
10
|
+
* @package Chisel
|
|
11
|
+
*/
|
|
12
|
+
final class RegisterAcfOptionsPage {
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Page arguments.
|
|
16
|
+
*
|
|
17
|
+
* @var array
|
|
18
|
+
*/
|
|
19
|
+
private array $args;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Page type - inc/Enums/Acf.php/AcfOptionsPageType
|
|
23
|
+
*
|
|
24
|
+
* @var AcfOptionsPageType
|
|
25
|
+
*/
|
|
26
|
+
private AcfOptionsPageType $type;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Class constructor.
|
|
30
|
+
*
|
|
31
|
+
* @param array $args page arguments.
|
|
32
|
+
* @param AcfOptionsPageType|string $type page or subpage.
|
|
33
|
+
*/
|
|
34
|
+
public function __construct( array $args, AcfOptionsPageType|string $type = AcfOptionsPageType::Page ) {
|
|
35
|
+
$this->args = $args;
|
|
36
|
+
$this->type = $type instanceof AcfOptionsPageType ? $type : AcfOptionsPageType::from( $type );
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Register ACF options page.
|
|
41
|
+
*/
|
|
42
|
+
public function register(): void {
|
|
43
|
+
$page_title = $this->args['page_title'] ?? 'Options';
|
|
44
|
+
$menu_title = $this->args['menu_title'] ?? $page_title;
|
|
45
|
+
$menu_slug = $this->args['menu_slug'] ?? 'options';
|
|
46
|
+
$capability = $this->args['capability'] ?? 'edit_posts';
|
|
47
|
+
$position = $this->args['position'] ?? 45;
|
|
48
|
+
$redirect = $this->args['redirect'] ?? true;
|
|
49
|
+
$icon_url = $this->args['icon_url'] ?? 'dashicons-screenoptions';
|
|
50
|
+
$post_id = $this->args['post_id'] ?? 'options';
|
|
51
|
+
$autoload = $this->args['autoload'] ?? false;
|
|
52
|
+
$update_button = $this->args['update_button'] ?? __( 'Update', 'chisel' );
|
|
53
|
+
$updated_message = $this->args['updated_message'] ?? __( 'Options Updated', 'chisel' );
|
|
54
|
+
$parent_slug = $this->args['parent_slug'] ?? '';
|
|
55
|
+
|
|
56
|
+
$options_page_args = array(
|
|
57
|
+
'page_title' => $page_title,
|
|
58
|
+
'menu_title' => $menu_title,
|
|
59
|
+
'menu_slug' => $menu_slug,
|
|
60
|
+
'capability' => $capability,
|
|
61
|
+
'position' => $position,
|
|
62
|
+
'redirect' => $redirect,
|
|
63
|
+
'icon_url' => $icon_url,
|
|
64
|
+
'post_id' => $post_id,
|
|
65
|
+
'autoload' => $autoload,
|
|
66
|
+
'update_button' => $update_button,
|
|
67
|
+
'updated_message' => $updated_message,
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
if ( $this->type === AcfOptionsPageType::SubPage ) {
|
|
71
|
+
$options_page_args['parent_slug'] = $parent_slug;
|
|
72
|
+
|
|
73
|
+
acf_add_options_sub_page( $options_page_args );
|
|
74
|
+
} else {
|
|
75
|
+
acf_add_options_page( $options_page_args );
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -1,113 +1,115 @@
|
|
|
1
1
|
<?php
|
|
2
2
|
|
|
3
|
-
namespace Chisel\
|
|
3
|
+
namespace Chisel\Factories;
|
|
4
4
|
|
|
5
5
|
use Chisel\WP\Assets;
|
|
6
|
-
use Chisel\
|
|
6
|
+
use Chisel\Helpers\ThemeHelpers;
|
|
7
|
+
use Chisel\Enums\BlocksType;
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Class to register custom blocks.
|
|
10
11
|
*
|
|
11
12
|
* @package Chisel
|
|
12
13
|
*/
|
|
13
|
-
class RegisterBlocks {
|
|
14
|
+
final class RegisterBlocks {
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Blocks type.
|
|
17
18
|
*
|
|
18
|
-
* @var string
|
|
19
|
+
* @var BlocksType|string
|
|
19
20
|
*/
|
|
20
|
-
private $blocks_type;
|
|
21
|
+
private BlocksType|string $blocks_type;
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* Blocks path.
|
|
24
25
|
*
|
|
25
26
|
* @var string
|
|
26
27
|
*/
|
|
27
|
-
private $blocks_folder;
|
|
28
|
+
private string $blocks_folder;
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
* Blocks src path.
|
|
31
32
|
*
|
|
32
33
|
* @var string
|
|
33
34
|
*/
|
|
34
|
-
private $blocks_path_src;
|
|
35
|
+
private string $blocks_path_src;
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
38
|
* Blocks path.
|
|
38
39
|
*
|
|
39
40
|
* @var string
|
|
40
41
|
*/
|
|
41
|
-
private $blocks_path;
|
|
42
|
+
private string $blocks_path;
|
|
42
43
|
|
|
43
44
|
/**
|
|
44
45
|
* Blocks url.
|
|
45
46
|
*
|
|
46
47
|
* @var string
|
|
47
48
|
*/
|
|
48
|
-
private $blocks_url;
|
|
49
|
+
private string $blocks_url;
|
|
49
50
|
|
|
50
51
|
/**
|
|
51
52
|
* Blocks.
|
|
52
53
|
*
|
|
53
54
|
* @var array
|
|
54
55
|
*/
|
|
55
|
-
private $blocks = array();
|
|
56
|
+
private array $blocks = array();
|
|
56
57
|
|
|
57
58
|
/**
|
|
58
59
|
* Theme.
|
|
59
60
|
*
|
|
60
|
-
* @var
|
|
61
|
+
* @var \WP_Theme
|
|
61
62
|
*/
|
|
62
|
-
private $theme = null;
|
|
63
|
+
private ?\WP_Theme $theme = null;
|
|
63
64
|
|
|
64
65
|
/**
|
|
65
66
|
* Build folder.
|
|
66
67
|
*
|
|
67
68
|
* @var string
|
|
68
69
|
*/
|
|
69
|
-
private $build_folder = 'build';
|
|
70
|
+
private string $build_folder = 'build';
|
|
70
71
|
|
|
71
72
|
/**
|
|
72
73
|
* Src folder.
|
|
73
74
|
*
|
|
74
75
|
* @var string
|
|
75
76
|
*/
|
|
76
|
-
private $src_folder = 'src';
|
|
77
|
+
private string $src_folder = 'src';
|
|
77
78
|
|
|
78
79
|
/**
|
|
79
80
|
* Register scripts. By default block styles are inlined and js is registered by wp. Setting this to true will use custom hndles to register and enqueue scripts and styles and styles will not be inlined.
|
|
80
81
|
*
|
|
81
82
|
* @var bool
|
|
82
83
|
*/
|
|
83
|
-
private $register_scripts;
|
|
84
|
+
private bool $register_scripts;
|
|
84
85
|
|
|
85
86
|
/**
|
|
86
87
|
* Class constructor.
|
|
87
88
|
*
|
|
88
|
-
* @param string $blocks_type The blocks type : acf or wp.
|
|
89
|
+
* @param BlocksType|string $blocks_type The blocks type : acf or wp.
|
|
89
90
|
*/
|
|
90
|
-
public function __construct( $blocks_type ) {
|
|
91
|
-
$
|
|
91
|
+
public function __construct( BlocksType|string $blocks_type ) {
|
|
92
|
+
$blocks_type = $blocks_type instanceof BlocksType ? $blocks_type : BlocksType::from( $blocks_type );
|
|
93
|
+
$this->blocks_type = $blocks_type->value;
|
|
92
94
|
$this->theme = wp_get_theme();
|
|
93
|
-
$this->blocks_folder = $
|
|
95
|
+
$this->blocks_folder = $blocks_type->folder_name();
|
|
94
96
|
$this->blocks_path = get_template_directory() . '/' . $this->build_folder . '/' . $this->blocks_folder;
|
|
95
97
|
$this->blocks_path_src = get_template_directory() . '/' . $this->src_folder . '/' . $this->blocks_folder;
|
|
96
98
|
$this->blocks_url = get_template_directory_uri() . '/' . $this->build_folder . '/' . $this->blocks_folder;
|
|
97
99
|
$this->blocks = $this->get_blocks();
|
|
98
100
|
|
|
99
|
-
$this->register_scripts = apply_filters( 'chisel_blocks_register_scripts', true, $this->blocks_type );
|
|
101
|
+
$this->register_scripts = (bool) apply_filters( 'chisel_blocks_register_scripts', true, $this->blocks_type );
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
/**
|
|
103
105
|
* Register custom blocks and their assets.
|
|
104
106
|
*/
|
|
105
|
-
public function register_custom_blocks() {
|
|
107
|
+
public function register_custom_blocks(): void {
|
|
106
108
|
if ( ! function_exists( 'register_block_type' ) ) {
|
|
107
109
|
return;
|
|
108
110
|
}
|
|
109
111
|
|
|
110
|
-
if ( ! is_array( $this->blocks ) ||
|
|
112
|
+
if ( ! is_array( $this->blocks ) || empty( $this->blocks ) ) {
|
|
111
113
|
return;
|
|
112
114
|
}
|
|
113
115
|
|
|
@@ -133,7 +135,13 @@ class RegisterBlocks {
|
|
|
133
135
|
$block_url = $this->blocks_url . '/' . $block . '/';
|
|
134
136
|
|
|
135
137
|
// Read json file to array.
|
|
136
|
-
$
|
|
138
|
+
$decoded = wp_json_file_decode( $block_json, array( 'associative' => true ) );
|
|
139
|
+
if ( ! is_array( $decoded ) ) {
|
|
140
|
+
// Skip malformed block.json.
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
$block_metadata = $decoded;
|
|
137
145
|
|
|
138
146
|
foreach ( $block_scripts as $script ) {
|
|
139
147
|
if ( ! isset( $block_metadata[$script] ) ) {
|
|
@@ -194,14 +202,17 @@ class RegisterBlocks {
|
|
|
194
202
|
}
|
|
195
203
|
|
|
196
204
|
if ( $this->register_scripts ) {
|
|
205
|
+
// Server-side registration with customized asset handles.
|
|
197
206
|
register_block_type( $block_path, $block_metadata );
|
|
198
207
|
} else {
|
|
208
|
+
// Let WP infer assets from block.json.
|
|
199
209
|
register_block_type( $block_json );
|
|
200
210
|
}
|
|
201
211
|
|
|
202
212
|
// In case we need to do some custom logic. All variables from this method are available in the init file.
|
|
203
|
-
|
|
204
|
-
|
|
213
|
+
$init_php = $block_path_src . 'init.php';
|
|
214
|
+
if ( is_file( $init_php ) ) {
|
|
215
|
+
include_once $init_php;
|
|
205
216
|
}
|
|
206
217
|
}
|
|
207
218
|
}
|
|
@@ -211,7 +222,7 @@ class RegisterBlocks {
|
|
|
211
222
|
*
|
|
212
223
|
* @return array
|
|
213
224
|
*/
|
|
214
|
-
public function get_blocks() {
|
|
225
|
+
public function get_blocks(): array {
|
|
215
226
|
if ( $this->blocks ) {
|
|
216
227
|
return $this->blocks;
|
|
217
228
|
}
|
|
@@ -240,7 +251,7 @@ class RegisterBlocks {
|
|
|
240
251
|
*
|
|
241
252
|
* @return string
|
|
242
253
|
*/
|
|
243
|
-
public function get_blocks_url() {
|
|
254
|
+
public function get_blocks_url(): string {
|
|
244
255
|
return $this->blocks_url;
|
|
245
256
|
}
|
|
246
257
|
|
|
@@ -249,7 +260,7 @@ class RegisterBlocks {
|
|
|
249
260
|
*
|
|
250
261
|
* @return string
|
|
251
262
|
*/
|
|
252
|
-
public function get_blocks_path() {
|
|
263
|
+
public function get_blocks_path(): string {
|
|
253
264
|
return $this->blocks_path;
|
|
254
265
|
}
|
|
255
266
|
|
|
@@ -258,7 +269,7 @@ class RegisterBlocks {
|
|
|
258
269
|
*
|
|
259
270
|
* @return string
|
|
260
271
|
*/
|
|
261
|
-
public function get_blocks_path_src() {
|
|
272
|
+
public function get_blocks_path_src(): string {
|
|
262
273
|
return $this->blocks_path_src;
|
|
263
274
|
}
|
|
264
275
|
|
|
@@ -270,7 +281,7 @@ class RegisterBlocks {
|
|
|
270
281
|
*
|
|
271
282
|
* @return array
|
|
272
283
|
*/
|
|
273
|
-
private function get_block_script_asset( $block, $file_name ) {
|
|
284
|
+
private function get_block_script_asset( string $block, string $file_name ): array {
|
|
274
285
|
$block_path = $this->blocks_path . '/' . $block . '/';
|
|
275
286
|
$assets_file_name = preg_replace( '/\.[^.]+$/', '', $file_name ) . '.asset.php';
|
|
276
287
|
$script_asset_path = $block_path . $assets_file_name;
|