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
|
@@ -5,16 +5,16 @@ namespace Chisel\WP;
|
|
|
5
5
|
use Chisel\Interfaces\InstanceInterface;
|
|
6
6
|
use Chisel\Interfaces\HooksInterface;
|
|
7
7
|
use Chisel\Traits\Singleton;
|
|
8
|
-
use Chisel\
|
|
9
|
-
use Chisel\
|
|
10
|
-
use Chisel\
|
|
8
|
+
use Chisel\Helpers\ThemeHelpers;
|
|
9
|
+
use Chisel\Helpers\AjaxHelpers;
|
|
10
|
+
use Chisel\Helpers\AssetsHelpers;
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Class for enqueuing scripts and styles.
|
|
14
14
|
*
|
|
15
15
|
* @package Chisel
|
|
16
16
|
*/
|
|
17
|
-
class Assets implements InstanceInterface, HooksInterface {
|
|
17
|
+
final class Assets implements InstanceInterface, HooksInterface {
|
|
18
18
|
|
|
19
19
|
use Singleton;
|
|
20
20
|
|
|
@@ -23,70 +23,70 @@ class Assets implements InstanceInterface, HooksInterface {
|
|
|
23
23
|
*
|
|
24
24
|
* @var array
|
|
25
25
|
*/
|
|
26
|
-
private $frontend_styles = array();
|
|
26
|
+
private array $frontend_styles = array();
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Front-end styles to be registered and enqueued in footer.
|
|
30
30
|
*
|
|
31
31
|
* @var array
|
|
32
32
|
*/
|
|
33
|
-
private $frontend_footer_styles = array();
|
|
33
|
+
private array $frontend_footer_styles = array();
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* Front-end scripts to be registered and enqueued.
|
|
37
37
|
*
|
|
38
38
|
* @var array
|
|
39
39
|
*/
|
|
40
|
-
private $frontend_scripts = array();
|
|
40
|
+
private array $frontend_scripts = array();
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* Admin styles to be registered and enqueued.
|
|
44
44
|
*
|
|
45
45
|
* @var array
|
|
46
46
|
*/
|
|
47
|
-
private $admin_styles = array();
|
|
47
|
+
private array $admin_styles = array();
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* Admin scripts to be registered and enqueued.
|
|
51
51
|
*
|
|
52
52
|
* @var array
|
|
53
53
|
*/
|
|
54
|
-
private $admin_scripts = array();
|
|
54
|
+
private array $admin_scripts = array();
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
* Editor styles to be registered and enqueued.
|
|
58
58
|
*
|
|
59
59
|
* @var array
|
|
60
60
|
*/
|
|
61
|
-
private $editor_styles = array();
|
|
61
|
+
private array $editor_styles = array();
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
64
|
* Editor scripts to be registered and enqueued.
|
|
65
65
|
*
|
|
66
66
|
* @var array
|
|
67
67
|
*/
|
|
68
|
-
private $editor_scripts = array();
|
|
68
|
+
private array $editor_scripts = array();
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* Login page styles to be registered and enqueued.
|
|
72
72
|
*
|
|
73
73
|
* @var array
|
|
74
74
|
*/
|
|
75
|
-
private $login_styles = array();
|
|
75
|
+
private array $login_styles = array();
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
78
|
* Login page scripts to be registered and enqueued.
|
|
79
79
|
*
|
|
80
80
|
* @var array
|
|
81
81
|
*/
|
|
82
|
-
private $login_scripts = array();
|
|
82
|
+
private array $login_scripts = array();
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
85
|
* WP React Refresh runtime dependency.
|
|
86
86
|
*
|
|
87
87
|
* @var string
|
|
88
88
|
*/
|
|
89
|
-
private $refresh_runtime_dependency = 'wp-react-refresh-runtime';
|
|
89
|
+
private string $refresh_runtime_dependency = 'wp-react-refresh-runtime';
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
92
|
* Class constructor.
|
|
@@ -101,15 +101,13 @@ class Assets implements InstanceInterface, HooksInterface {
|
|
|
101
101
|
/**
|
|
102
102
|
* Set properties.
|
|
103
103
|
*/
|
|
104
|
-
public function set_properties() {
|
|
104
|
+
public function set_properties(): void {
|
|
105
105
|
// This is a required script for React Refresh. It is generated by Webpack and only exists in development mode.
|
|
106
106
|
$runtime_script = array(
|
|
107
107
|
'src' => get_template_directory_uri() . '/build/runtime.js',
|
|
108
108
|
'deps' => array( $this->refresh_runtime_dependency ),
|
|
109
109
|
'strategy' => false,
|
|
110
|
-
'condition' =>
|
|
111
|
-
return ThemeHelpers::is_fast_refresh();
|
|
112
|
-
},
|
|
110
|
+
'condition' => array( ThemeHelpers::class, 'is_fast_refresh' ),
|
|
113
111
|
);
|
|
114
112
|
|
|
115
113
|
if ( ! is_admin() ) {
|
|
@@ -192,9 +190,8 @@ class Assets implements InstanceInterface, HooksInterface {
|
|
|
192
190
|
/**
|
|
193
191
|
* Register action hooks.
|
|
194
192
|
*/
|
|
195
|
-
public function action_hooks() {
|
|
193
|
+
public function action_hooks(): void {
|
|
196
194
|
add_action( 'init', array( $this, 'register_assets' ) );
|
|
197
|
-
add_action( 'init', array( $this, 'move_scripts_to_footer' ), 2 );
|
|
198
195
|
|
|
199
196
|
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_frontend_assets' ), 99 ); // Higher priority, overwrite plugins if needed.
|
|
200
197
|
add_action( 'wp_footer', array( $this, 'enqueue_frontend_assets_in_footer' ), 11 ); // Higher priority, overwrite plugins if needed.
|
|
@@ -209,32 +206,16 @@ class Assets implements InstanceInterface, HooksInterface {
|
|
|
209
206
|
/**
|
|
210
207
|
* Register filter hooks.
|
|
211
208
|
*/
|
|
212
|
-
public function filter_hooks() {
|
|
209
|
+
public function filter_hooks(): void {
|
|
213
210
|
add_filter( 'script_loader_tag', array( $this, 'async_script' ), 99, 2 );
|
|
214
211
|
add_filter( 'script_loader_tag', array( $this, 'defer_script' ), 99, 2 );
|
|
215
212
|
add_filter( 'style_loader_tag', array( $this, 'preload_styles' ), 99, 2 );
|
|
216
213
|
}
|
|
217
214
|
|
|
218
|
-
/**
|
|
219
|
-
* Move all scripts to footer
|
|
220
|
-
*
|
|
221
|
-
* @return void
|
|
222
|
-
*/
|
|
223
|
-
public function move_scripts_to_footer() {
|
|
224
|
-
if ( ! is_admin() ) {
|
|
225
|
-
remove_action( 'wp_head', 'wp_print_scripts' );
|
|
226
|
-
remove_action( 'wp_head', 'wp_print_head_scripts', 9 );
|
|
227
|
-
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
|
|
228
|
-
|
|
229
|
-
add_action( 'wp_footer', 'wp_print_scripts', 5 );
|
|
230
|
-
add_action( 'wp_footer', 'wp_print_head_scripts', 5 );
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
215
|
/**
|
|
235
216
|
* Register assets.
|
|
236
217
|
*/
|
|
237
|
-
public function register_assets() {
|
|
218
|
+
public function register_assets(): void {
|
|
238
219
|
if ( ! is_admin() ) {
|
|
239
220
|
$this->frontend_styles = apply_filters( 'chisel_frontend_styles', $this->frontend_styles );
|
|
240
221
|
$this->frontend_footer_styles = apply_filters( 'chisel_frontend_footer_styles', $this->frontend_footer_styles );
|
|
@@ -314,7 +295,7 @@ class Assets implements InstanceInterface, HooksInterface {
|
|
|
314
295
|
/**
|
|
315
296
|
* Enqueue front-end assets.
|
|
316
297
|
*/
|
|
317
|
-
public function enqueue_frontend_assets() {
|
|
298
|
+
public function enqueue_frontend_assets(): void {
|
|
318
299
|
$this->frontend_styles = apply_filters( 'chisel_pre_enqueue_frontend_styles', $this->frontend_styles );
|
|
319
300
|
$this->frontend_scripts = apply_filters( 'chisel_pre_enqueue_frontend_scripts', $this->frontend_scripts );
|
|
320
301
|
|
|
@@ -347,7 +328,7 @@ class Assets implements InstanceInterface, HooksInterface {
|
|
|
347
328
|
/**
|
|
348
329
|
* Enqueue front-end styles in footer, ie. Gravity Forms custom styles.
|
|
349
330
|
*/
|
|
350
|
-
public function enqueue_frontend_assets_in_footer() {
|
|
331
|
+
public function enqueue_frontend_assets_in_footer(): void {
|
|
351
332
|
$this->frontend_footer_styles = apply_filters( 'chisel_pre_enqueue_frontend_footer_styles', $this->frontend_footer_styles );
|
|
352
333
|
|
|
353
334
|
if ( $this->frontend_footer_styles ) {
|
|
@@ -368,7 +349,7 @@ class Assets implements InstanceInterface, HooksInterface {
|
|
|
368
349
|
/**
|
|
369
350
|
* Enqueue admin assets.
|
|
370
351
|
*/
|
|
371
|
-
public function enqueue_admin_assets() {
|
|
352
|
+
public function enqueue_admin_assets(): void {
|
|
372
353
|
$this->admin_styles = apply_filters( 'chisel_pre_enqueue_admin_styles', $this->admin_styles );
|
|
373
354
|
$this->admin_scripts = apply_filters( 'chisel_pre_enqueue_admin_scripts', $this->admin_scripts );
|
|
374
355
|
|
|
@@ -401,7 +382,7 @@ class Assets implements InstanceInterface, HooksInterface {
|
|
|
401
382
|
/**
|
|
402
383
|
* Enqueue editor scripts.
|
|
403
384
|
*/
|
|
404
|
-
public function enqueue_editor_scripts() {
|
|
385
|
+
public function enqueue_editor_scripts(): void {
|
|
405
386
|
$this->editor_styles = apply_filters( 'chisel_pre_enqueue_editor_styles', $this->editor_styles );
|
|
406
387
|
$this->editor_scripts = apply_filters( 'chisel_pre_enqueue_editor_scripts', $this->editor_scripts );
|
|
407
388
|
|
|
@@ -434,7 +415,7 @@ class Assets implements InstanceInterface, HooksInterface {
|
|
|
434
415
|
/**
|
|
435
416
|
* Enqueue login page scripts.
|
|
436
417
|
*/
|
|
437
|
-
public function enqueue_login_page_assets() {
|
|
418
|
+
public function enqueue_login_page_assets(): void {
|
|
438
419
|
$stylesheet = wp_get_global_stylesheet();
|
|
439
420
|
|
|
440
421
|
if ( empty( $stylesheet ) ) {
|
|
@@ -481,7 +462,7 @@ class Assets implements InstanceInterface, HooksInterface {
|
|
|
481
462
|
*
|
|
482
463
|
* @return string
|
|
483
464
|
*/
|
|
484
|
-
public function async_script( $tag, $handle ) {
|
|
465
|
+
public function async_script( string $tag, string $handle ): string {
|
|
485
466
|
if ( is_admin() ) {
|
|
486
467
|
return $tag;
|
|
487
468
|
}
|
|
@@ -507,20 +488,13 @@ class Assets implements InstanceInterface, HooksInterface {
|
|
|
507
488
|
*
|
|
508
489
|
* @return string
|
|
509
490
|
*/
|
|
510
|
-
public function defer_script( $tag, $handle ) {
|
|
511
|
-
if ( is_admin() ) {
|
|
491
|
+
public function defer_script( string $tag, string $handle ): string {
|
|
492
|
+
if ( is_admin() || is_login() ) {
|
|
512
493
|
return $tag;
|
|
513
494
|
}
|
|
514
495
|
|
|
515
496
|
$scripts = array();
|
|
516
497
|
|
|
517
|
-
// Defer all wp scripts.
|
|
518
|
-
if ( strpos( $handle, 'wp' ) === false ) {
|
|
519
|
-
if ( strpos( $handle, 'defer' ) === false ) {
|
|
520
|
-
$tag = str_replace( ' src', ' defer src', $tag );
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
|
|
524
498
|
if ( $scripts ) {
|
|
525
499
|
foreach ( $scripts as $script_handle ) {
|
|
526
500
|
if ( $handle === $script_handle ) {
|
|
@@ -540,7 +514,7 @@ class Assets implements InstanceInterface, HooksInterface {
|
|
|
540
514
|
*
|
|
541
515
|
* @return string
|
|
542
516
|
*/
|
|
543
|
-
public function preload_styles( $tag, $handle ) {
|
|
517
|
+
public function preload_styles( string $tag, string $handle ): string {
|
|
544
518
|
if ( is_admin() ) {
|
|
545
519
|
return $tag;
|
|
546
520
|
}
|
|
@@ -580,7 +554,7 @@ class Assets implements InstanceInterface, HooksInterface {
|
|
|
580
554
|
*
|
|
581
555
|
* @return string
|
|
582
556
|
*/
|
|
583
|
-
private function preload_style( $tag ) {
|
|
557
|
+
private function preload_style( string $tag ): string {
|
|
584
558
|
$preload_tag = str_replace( "rel='stylesheet'", "rel='preload' as='style'", $tag );
|
|
585
559
|
$tag = $preload_tag . str_replace( "media='all'", "media='print' onload='this.media=\"all\"'", $tag );
|
|
586
560
|
|
|
@@ -594,9 +568,9 @@ class Assets implements InstanceInterface, HooksInterface {
|
|
|
594
568
|
* @param string $file_name
|
|
595
569
|
* @param array $args
|
|
596
570
|
*
|
|
597
|
-
* @return
|
|
571
|
+
* @return ?array
|
|
598
572
|
*/
|
|
599
|
-
private function register_style( $handle, $file_name, $args ) {
|
|
573
|
+
private function register_style( string $handle, string $file_name, array $args ): ?array {
|
|
600
574
|
$asset_data = $this->get_asset( $file_name, 'css' );
|
|
601
575
|
|
|
602
576
|
$src = isset( $args['src'] ) ? $args['src'] : $this->get_style_src( $file_name );
|
|
@@ -612,7 +586,7 @@ class Assets implements InstanceInterface, HooksInterface {
|
|
|
612
586
|
}
|
|
613
587
|
|
|
614
588
|
if ( ! $condition ) {
|
|
615
|
-
return;
|
|
589
|
+
return null;
|
|
616
590
|
}
|
|
617
591
|
}
|
|
618
592
|
|
|
@@ -651,7 +625,7 @@ class Assets implements InstanceInterface, HooksInterface {
|
|
|
651
625
|
*
|
|
652
626
|
* @return array
|
|
653
627
|
*/
|
|
654
|
-
private function enqueue_style( $handle, $args ) {
|
|
628
|
+
private function enqueue_style( string $handle, array $args ): array {
|
|
655
629
|
$inline = isset( $args['inline'] ) ? $args['inline'] : '';
|
|
656
630
|
|
|
657
631
|
if ( $inline ) {
|
|
@@ -672,9 +646,9 @@ class Assets implements InstanceInterface, HooksInterface {
|
|
|
672
646
|
* @param string $file_name
|
|
673
647
|
* @param array $args
|
|
674
648
|
*
|
|
675
|
-
* @return
|
|
649
|
+
* @return ?array
|
|
676
650
|
*/
|
|
677
|
-
private function register_script( $handle, $file_name, $args ) {
|
|
651
|
+
private function register_script( string $handle, string $file_name, array $args ): ?array {
|
|
678
652
|
$asset_data = $this->get_asset( $file_name, 'js' );
|
|
679
653
|
|
|
680
654
|
$src = isset( $args['src'] ) ? $args['src'] : $this->get_script_src( $file_name );
|
|
@@ -693,7 +667,7 @@ class Assets implements InstanceInterface, HooksInterface {
|
|
|
693
667
|
}
|
|
694
668
|
|
|
695
669
|
if ( ! $condition ) {
|
|
696
|
-
return;
|
|
670
|
+
return null;
|
|
697
671
|
}
|
|
698
672
|
}
|
|
699
673
|
|
|
@@ -721,7 +695,7 @@ class Assets implements InstanceInterface, HooksInterface {
|
|
|
721
695
|
*
|
|
722
696
|
* @return array
|
|
723
697
|
*/
|
|
724
|
-
private function enqueue_script( $handle, $args ) {
|
|
698
|
+
private function enqueue_script( string $handle, array $args ): array {
|
|
725
699
|
$localize = isset( $args['localize'] ) ? $args['localize'] : array();
|
|
726
700
|
$inline = isset( $args['inline'] ) ? $args['inline'] : '';
|
|
727
701
|
|
|
@@ -750,7 +724,7 @@ class Assets implements InstanceInterface, HooksInterface {
|
|
|
750
724
|
*
|
|
751
725
|
* @return void
|
|
752
726
|
*/
|
|
753
|
-
private function set_script_translations( $handle, $args ) {
|
|
727
|
+
private function set_script_translations( string $handle, array $args ): void {
|
|
754
728
|
if ( isset( $args['deps'] ) && in_array( 'wp-i18n', $args['deps'], true ) ) {
|
|
755
729
|
wp_set_script_translations( AssetsHelpers::get_final_handle( $handle ), 'chisel', get_template_directory() . '/languages' );
|
|
756
730
|
}
|
|
@@ -763,7 +737,7 @@ class Assets implements InstanceInterface, HooksInterface {
|
|
|
763
737
|
*
|
|
764
738
|
* @return void
|
|
765
739
|
*/
|
|
766
|
-
private function enqueue_style_js_for_dev( $handle ) {
|
|
740
|
+
private function enqueue_style_js_for_dev( string $handle ): void {
|
|
767
741
|
if ( ThemeHelpers::is_fast_refresh() ) {
|
|
768
742
|
wp_enqueue_script( 'style-' . AssetsHelpers::get_final_handle( $handle ) );
|
|
769
743
|
}
|
|
@@ -776,7 +750,7 @@ class Assets implements InstanceInterface, HooksInterface {
|
|
|
776
750
|
*
|
|
777
751
|
* @return string
|
|
778
752
|
*/
|
|
779
|
-
private function get_script_src( $file_name ) {
|
|
753
|
+
private function get_script_src( string $file_name ): string {
|
|
780
754
|
return get_template_directory_uri() . '/build/scripts/' . $file_name . '.js';
|
|
781
755
|
}
|
|
782
756
|
|
|
@@ -788,7 +762,7 @@ class Assets implements InstanceInterface, HooksInterface {
|
|
|
788
762
|
*
|
|
789
763
|
* @return string
|
|
790
764
|
*/
|
|
791
|
-
private function get_style_src( $file_name, $refresh_script = false ) {
|
|
765
|
+
private function get_style_src( string $file_name, bool $refresh_script = false ): string {
|
|
792
766
|
if ( $refresh_script ) {
|
|
793
767
|
return get_template_directory_uri() . '/build/styles/' . $file_name . '.js';
|
|
794
768
|
}
|
|
@@ -804,7 +778,7 @@ class Assets implements InstanceInterface, HooksInterface {
|
|
|
804
778
|
*
|
|
805
779
|
* @return array
|
|
806
780
|
*/
|
|
807
|
-
private function get_asset( $file_name, $type ) {
|
|
781
|
+
private function get_asset( string $file_name, string $type ): array {
|
|
808
782
|
if ( $type === 'css' ) {
|
|
809
783
|
$asset_path = get_template_directory() . '/build/styles/' . $file_name . '.asset.php';
|
|
810
784
|
} else {
|
|
@@ -7,9 +7,9 @@ use Timber\Timber;
|
|
|
7
7
|
use Chisel\Interfaces\InstanceInterface;
|
|
8
8
|
use Chisel\Interfaces\HooksInterface;
|
|
9
9
|
use Chisel\Traits\Singleton;
|
|
10
|
-
use Chisel\
|
|
11
|
-
use Chisel\
|
|
12
|
-
use Chisel\
|
|
10
|
+
use Chisel\Factories\RegisterBlocks;
|
|
11
|
+
use Chisel\Helpers\BlocksHelpers;
|
|
12
|
+
use Chisel\Helpers\ThemeHelpers;
|
|
13
13
|
use Chisel\Traits\PageBlocks;
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -17,7 +17,7 @@ use Chisel\Traits\PageBlocks;
|
|
|
17
17
|
*
|
|
18
18
|
* @package Chisel
|
|
19
19
|
*/
|
|
20
|
-
class Blocks implements InstanceInterface, HooksInterface {
|
|
20
|
+
final class Blocks implements InstanceInterface, HooksInterface {
|
|
21
21
|
|
|
22
22
|
use Singleton;
|
|
23
23
|
use PageBlocks;
|
|
@@ -27,21 +27,21 @@ class Blocks implements InstanceInterface, HooksInterface {
|
|
|
27
27
|
*
|
|
28
28
|
* @var RegisterBlocks
|
|
29
29
|
*/
|
|
30
|
-
private $register_blocks_factory;
|
|
30
|
+
private RegisterBlocks $register_blocks_factory;
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Blocks.
|
|
34
34
|
*
|
|
35
35
|
* @var array
|
|
36
36
|
*/
|
|
37
|
-
private $blocks = array();
|
|
37
|
+
private array $blocks = array();
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Chisel blocks category.
|
|
41
41
|
*
|
|
42
42
|
* @var string
|
|
43
43
|
*/
|
|
44
|
-
private $blocks_category;
|
|
44
|
+
private string $blocks_category = '';
|
|
45
45
|
|
|
46
46
|
|
|
47
47
|
/**
|
|
@@ -49,14 +49,14 @@ class Blocks implements InstanceInterface, HooksInterface {
|
|
|
49
49
|
*
|
|
50
50
|
* @var array
|
|
51
51
|
*/
|
|
52
|
-
private $block_patterns_categories = array();
|
|
52
|
+
private array $block_patterns_categories = array();
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
55
|
* Blocks twig file base path.
|
|
56
56
|
*
|
|
57
57
|
* @var string
|
|
58
58
|
*/
|
|
59
|
-
private $blocks_twig_base_path = 'build/blocks/';
|
|
59
|
+
private string $blocks_twig_base_path = 'build/blocks/';
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
62
|
* Class constructor.
|
|
@@ -74,7 +74,7 @@ class Blocks implements InstanceInterface, HooksInterface {
|
|
|
74
74
|
/**
|
|
75
75
|
* Set properties.
|
|
76
76
|
*/
|
|
77
|
-
public function set_properties() {
|
|
77
|
+
public function set_properties(): void {
|
|
78
78
|
$this->blocks_category = 'chisel-blocks';
|
|
79
79
|
$this->block_patterns_categories = array(
|
|
80
80
|
'cta' => array(
|
|
@@ -87,7 +87,7 @@ class Blocks implements InstanceInterface, HooksInterface {
|
|
|
87
87
|
/**
|
|
88
88
|
* Register action hooks.
|
|
89
89
|
*/
|
|
90
|
-
public function action_hooks() {
|
|
90
|
+
public function action_hooks(): void {
|
|
91
91
|
add_action( 'init', array( $this, 'register_blocks' ) );
|
|
92
92
|
add_action( 'after_setup_theme', array( $this, 'blocks_theme_supports' ) );
|
|
93
93
|
add_action( 'init', array( $this, 'register_block_patterns_categories' ) );
|
|
@@ -97,7 +97,7 @@ class Blocks implements InstanceInterface, HooksInterface {
|
|
|
97
97
|
/**
|
|
98
98
|
* Register filter hooks.
|
|
99
99
|
*/
|
|
100
|
-
public function filter_hooks() {
|
|
100
|
+
public function filter_hooks(): void {
|
|
101
101
|
add_filter( 'block_categories_all', array( $this, 'block_categories' ) );
|
|
102
102
|
add_filter( 'timber/locations', array( $this, 'tiwg_files_locations' ) );
|
|
103
103
|
add_filter( 'render_block', array( $this, 'render_block' ), 10, 3 );
|
|
@@ -110,14 +110,14 @@ class Blocks implements InstanceInterface, HooksInterface {
|
|
|
110
110
|
/**
|
|
111
111
|
* Register blocks and their assets.
|
|
112
112
|
*/
|
|
113
|
-
public function register_blocks() {
|
|
113
|
+
public function register_blocks(): void {
|
|
114
114
|
$this->register_blocks_factory->register_custom_blocks();
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
/**
|
|
118
118
|
* Set up theme supports for blocks.
|
|
119
119
|
*/
|
|
120
|
-
public function blocks_theme_supports() {
|
|
120
|
+
public function blocks_theme_supports(): void {
|
|
121
121
|
add_theme_support( 'wp-block-styles' ); // extra core blocks styles.
|
|
122
122
|
|
|
123
123
|
remove_theme_support( 'core-block-patterns' ); // remove default wp patterns and use only custom ones.
|
|
@@ -131,7 +131,7 @@ class Blocks implements InstanceInterface, HooksInterface {
|
|
|
131
131
|
*
|
|
132
132
|
* @return array
|
|
133
133
|
*/
|
|
134
|
-
public function block_categories( $categories ) {
|
|
134
|
+
public function block_categories( array $categories ): array {
|
|
135
135
|
$include = true;
|
|
136
136
|
|
|
137
137
|
foreach ( $categories as $category ) {
|
|
@@ -160,7 +160,7 @@ class Blocks implements InstanceInterface, HooksInterface {
|
|
|
160
160
|
*
|
|
161
161
|
* @return void
|
|
162
162
|
*/
|
|
163
|
-
public function register_block_patterns_categories() {
|
|
163
|
+
public function register_block_patterns_categories(): void {
|
|
164
164
|
if ( ! $this->block_patterns_categories || ! function_exists( 'register_block_pattern_category' ) ) {
|
|
165
165
|
return;
|
|
166
166
|
}
|
|
@@ -177,7 +177,7 @@ class Blocks implements InstanceInterface, HooksInterface {
|
|
|
177
177
|
* @param array $locations The locations.
|
|
178
178
|
* @return array
|
|
179
179
|
*/
|
|
180
|
-
public function tiwg_files_locations( $locations ) {
|
|
180
|
+
public function tiwg_files_locations( array $locations ): array {
|
|
181
181
|
if ( ! is_array( $this->blocks ) || ! $this->blocks ) {
|
|
182
182
|
return $locations;
|
|
183
183
|
}
|
|
@@ -198,7 +198,7 @@ class Blocks implements InstanceInterface, HooksInterface {
|
|
|
198
198
|
*
|
|
199
199
|
* @return string
|
|
200
200
|
*/
|
|
201
|
-
public function render_block( $block_content, $block, $block_instance ) {
|
|
201
|
+
public function render_block( string $block_content, array $block, object $block_instance ): string {
|
|
202
202
|
if ( is_admin() || wp_doing_ajax() || wp_doing_cron() ) {
|
|
203
203
|
return $block_content;
|
|
204
204
|
}
|
|
@@ -237,7 +237,7 @@ class Blocks implements InstanceInterface, HooksInterface {
|
|
|
237
237
|
*
|
|
238
238
|
* @return int
|
|
239
239
|
*/
|
|
240
|
-
public function styles_inline_size_limit( $limit ) {
|
|
240
|
+
public function styles_inline_size_limit( int $limit ): int {
|
|
241
241
|
$limit = apply_filters( 'chisel_styles_inline_size_limit', 10000 );
|
|
242
242
|
|
|
243
243
|
return $limit;
|
|
@@ -250,7 +250,7 @@ class Blocks implements InstanceInterface, HooksInterface {
|
|
|
250
250
|
*
|
|
251
251
|
* @return bool
|
|
252
252
|
*/
|
|
253
|
-
public function should_load_separate_core_block_assets( $load ) {
|
|
253
|
+
public function should_load_separate_core_block_assets( bool $load ): bool {
|
|
254
254
|
$load = apply_filters( 'chisel_load_separate_core_block_assets', false );
|
|
255
255
|
|
|
256
256
|
return $load;
|
|
@@ -263,7 +263,7 @@ class Blocks implements InstanceInterface, HooksInterface {
|
|
|
263
263
|
*
|
|
264
264
|
* @return array
|
|
265
265
|
*/
|
|
266
|
-
public function blocks_alignment_data( $editor_scripts_data ) {
|
|
266
|
+
public function blocks_alignment_data( array $editor_scripts_data ): array {
|
|
267
267
|
$editor_scripts_data['editor']['localize']['data']['blocksDefaultAlignment'] = array(
|
|
268
268
|
'chisel/slider' => 'full',
|
|
269
269
|
);
|
|
@@ -276,7 +276,7 @@ class Blocks implements InstanceInterface, HooksInterface {
|
|
|
276
276
|
*
|
|
277
277
|
* @return void
|
|
278
278
|
*/
|
|
279
|
-
public function dequeue_blocks_styles() {
|
|
279
|
+
public function dequeue_blocks_styles(): void {
|
|
280
280
|
if ( is_admin() ) {
|
|
281
281
|
return;
|
|
282
282
|
}
|
|
@@ -284,7 +284,7 @@ class Blocks implements InstanceInterface, HooksInterface {
|
|
|
284
284
|
$blocks_used_on_page = $this->get_content_blocks_names();
|
|
285
285
|
$blocks = $this->blocks;
|
|
286
286
|
|
|
287
|
-
if ( $blocks ) {
|
|
287
|
+
if ( ! empty( $blocks ) ) {
|
|
288
288
|
$blocks_path = $this->register_blocks_factory->get_blocks_path();
|
|
289
289
|
$blocks_url = $this->register_blocks_factory->get_blocks_url();
|
|
290
290
|
|
|
@@ -7,14 +7,14 @@ use Timber\Loader;
|
|
|
7
7
|
use Chisel\Interfaces\InstanceInterface;
|
|
8
8
|
use Chisel\Interfaces\HooksInterface;
|
|
9
9
|
use Chisel\Traits\Singleton;
|
|
10
|
-
use Chisel\
|
|
10
|
+
use Chisel\Helpers\ThemeHelpers;
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Cache related functionalities.
|
|
14
14
|
*
|
|
15
15
|
* @package Chisel
|
|
16
16
|
*/
|
|
17
|
-
class Cache implements InstanceInterface, HooksInterface {
|
|
17
|
+
final class Cache implements InstanceInterface, HooksInterface {
|
|
18
18
|
|
|
19
19
|
use Singleton;
|
|
20
20
|
|
|
@@ -23,21 +23,21 @@ class Cache implements InstanceInterface, HooksInterface {
|
|
|
23
23
|
*
|
|
24
24
|
* @var int
|
|
25
25
|
*/
|
|
26
|
-
public $cache_expiry = HOUR_IN_SECONDS;
|
|
26
|
+
public int $cache_expiry = HOUR_IN_SECONDS;
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Cache everything mode. The whole template you render and its data will be cached.
|
|
30
30
|
*
|
|
31
31
|
* @var int
|
|
32
32
|
*/
|
|
33
|
-
public $cache_everything = false;
|
|
33
|
+
public bool $cache_everything = false;
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* Environment cache.
|
|
37
37
|
*
|
|
38
38
|
* @var int
|
|
39
39
|
*/
|
|
40
|
-
private $environment_cache = false;
|
|
40
|
+
private bool $environment_cache = false;
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* Class constructor.
|
|
@@ -52,7 +52,7 @@ class Cache implements InstanceInterface, HooksInterface {
|
|
|
52
52
|
/**
|
|
53
53
|
* Set properties.
|
|
54
54
|
*/
|
|
55
|
-
public function set_properties() {
|
|
55
|
+
public function set_properties(): void {
|
|
56
56
|
$this->cache_expiry = apply_filters( 'chisel_cache_expiry', $this->cache_expiry );
|
|
57
57
|
$this->cache_everything = apply_filters( 'chisel_cache_everything', $this->cache_everything );
|
|
58
58
|
$this->environment_cache = apply_filters( 'chisel_environment_cache', $this->environment_cache );
|
|
@@ -61,13 +61,12 @@ class Cache implements InstanceInterface, HooksInterface {
|
|
|
61
61
|
/**
|
|
62
62
|
* Register action hooks.
|
|
63
63
|
*/
|
|
64
|
-
public function action_hooks() {
|
|
65
|
-
}
|
|
64
|
+
public function action_hooks(): void {}
|
|
66
65
|
|
|
67
66
|
/**
|
|
68
67
|
* Register filter hooks.
|
|
69
68
|
*/
|
|
70
|
-
public function filter_hooks() {
|
|
69
|
+
public function filter_hooks(): void {
|
|
71
70
|
add_filter( 'timber/cache/mode', array( $this, 'cache_mode' ) );
|
|
72
71
|
add_filter( 'timber/twig/environment/options', array( $this, 'environment_cache' ) );
|
|
73
72
|
}
|
|
@@ -79,7 +78,7 @@ class Cache implements InstanceInterface, HooksInterface {
|
|
|
79
78
|
*
|
|
80
79
|
* @return string
|
|
81
80
|
*/
|
|
82
|
-
public function cache_mode( $cache_mode ) {
|
|
81
|
+
public function cache_mode( string $cache_mode ): string {
|
|
83
82
|
// Available cache modes: 'CACHE_NONE', 'CACHE_OBJECT' (WP Object Cache), 'CACHE_TRANSIENT', 'CACHE_SITE_TRANSIENT', 'CACHE_USE_DEFAULT'.
|
|
84
83
|
$cache_mode = Loader::CACHE_USE_DEFAULT;
|
|
85
84
|
|
|
@@ -93,7 +92,7 @@ class Cache implements InstanceInterface, HooksInterface {
|
|
|
93
92
|
*
|
|
94
93
|
* @return array
|
|
95
94
|
*/
|
|
96
|
-
public function environment_cache( $options ) {
|
|
95
|
+
public function environment_cache( array $options ): array {
|
|
97
96
|
$options['cache'] = $this->environment_cache;
|
|
98
97
|
$options['auto_reload'] = ThemeHelpers::is_dev_env();
|
|
99
98
|
$options['debug'] = ThemeHelpers::is_dev_env();
|
|
@@ -16,9 +16,10 @@ class ChiselImage extends TimberImage {
|
|
|
16
16
|
*
|
|
17
17
|
* @param string $size Thumbnail size.
|
|
18
18
|
* @param array $attrs Image attributes.
|
|
19
|
-
*
|
|
19
|
+
*
|
|
20
|
+
* @return string The responsive <img> HTML.
|
|
20
21
|
*/
|
|
21
|
-
public function responsive( $size = 'medium', $attrs = array() ) {
|
|
22
|
+
public function responsive( string $size = 'medium', array $attrs = array() ): string {
|
|
22
23
|
return wp_get_attachment_image( $this->ID, $size, false, $attrs );
|
|
23
24
|
}
|
|
24
25
|
}
|
|
@@ -4,7 +4,7 @@ namespace Chisel\WP;
|
|
|
4
4
|
|
|
5
5
|
use Timber\Post as TimberPost;
|
|
6
6
|
use Timber\Timber;
|
|
7
|
-
use Chisel\
|
|
7
|
+
use Chisel\Helpers\ImageHelpers;
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Extend Timber Post class with custom functionality.
|
|
@@ -16,19 +16,25 @@ class ChiselPost extends TimberPost {
|
|
|
16
16
|
/**
|
|
17
17
|
* Post thumbnail.
|
|
18
18
|
*
|
|
19
|
-
* @var
|
|
19
|
+
* @var ?string
|
|
20
20
|
*/
|
|
21
|
-
public $thumbnail_html;
|
|
21
|
+
public ?string $thumbnail_html = null;
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Get the post thumbnail. Returns the thumbnail responsive image html.
|
|
25
25
|
*
|
|
26
26
|
* @param string $size Thumbnail size.
|
|
27
|
-
*
|
|
27
|
+
*
|
|
28
|
+
* @return string Responsive <img> HTML, or empty string.
|
|
28
29
|
*/
|
|
29
|
-
public function get_thumbnail( $size = 'medium' ) {
|
|
30
|
-
if (
|
|
31
|
-
$this->thumbnail_html =
|
|
30
|
+
public function get_thumbnail( string $size = 'medium' ): string {
|
|
31
|
+
if ( $this->thumbnail_html === null ) {
|
|
32
|
+
$this->thumbnail_html = '';
|
|
33
|
+
|
|
34
|
+
if ( has_post_thumbnail( $this->ID ) ) {
|
|
35
|
+
$thumbnail_id = get_post_thumbnail_id( $this->ID );
|
|
36
|
+
$this->thumbnail_html = ImageHelpers::get_responsive_image( $thumbnail_id, $size );
|
|
37
|
+
}
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
return $this->thumbnail_html;
|