generator-chisel 2.0.0-alpha.8 → 2.0.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 +57 -0
- package/bin/chisel.js +6 -0
- package/lib/commands/create/Creator.js +6 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/.gitignore.chisel-tpl +3 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/.nvmrc +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/404.php +2 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/README.md +37 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/acf-json/group_6772609e3c28c.json +83 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/acf-json/group_6772615562fb4.json +49 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/archive.php +2 -4
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example/block.json +31 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example/edit.js +35 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example/editor.scss +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example/index.js +45 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example/save.js +20 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example/script.js +7 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example/style.scss +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example/view.js +7 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example/view.scss +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example-server-side/block.json +32 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example-server-side/edit.js +33 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example-server-side/editor.scss +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example-server-side/index.js +45 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example-server-side/render.php +12 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example-server-side/render.twig +5 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example-server-side/save.js +6 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example-server-side/script.js +7 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example-server-side/style.scss +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example-server-side/view.js +7 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks/example-server-side/view.scss +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks-acf/example/block.json +36 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks-acf/example/critical.scss +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks-acf/example/editor.scss +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks-acf/example/example.twig +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks-acf/example/index.js +7 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks-acf/example/init.php +0 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks-acf/example/script.js +8 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks-acf/example/style.scss +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks-acf/example/view.js +7 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/example-blocks/blocks-acf/example/view.scss +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/icons-source/arrow-left.svg +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/icons-source/arrow-right.svg +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/icons-source/chisel-icon.svg +1 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/icons-source/chisel-logo.svg +1 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/icons-source/close-line.svg +1 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/icons-source/color/chisel-icon.svg +1 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/icons-source/color/chisel-logo.svg +1 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/icons-source/color/facebook-logo.svg +10 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/icons-source/color/instagram-logo.svg +14 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/assets/icons-source/x-logo.svg +1 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/author.php +3 -4
- package/lib/commands/create/creators/app/chisel-starter-theme/composer.json +3 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/footer.php +2 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/functions.php +18 -24
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Factory/RegisterAcfOptionsPage.php +62 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/Factory}/RegisterBlocks.php +53 -22
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Factory/RegisterCustomPostType.php +211 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Factory/RegisterCustomTaxonomy.php +174 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helper/AcfHelpers.php +46 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helper/AjaxHelpers.php +33 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helper/AssetsHelpers.php +28 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helper/BlocksHelpers.php +118 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helper/CacheHelpers.php +41 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helper/CommentsHelpers.php +26 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helper/DataHelpers.php +35 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helper/GravityFormsHelpers.php +65 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helper/ImageHelpers.php +102 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes/Helpers.php → inc/Helper/ThemeHelpers.php} +53 -93
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helper/WoocommerceHelpers.php +72 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helper/YoastHelpers.php +37 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes/interfaces/Instance.php → inc/Interfaces/HooksInterface.php} +3 -8
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Interfaces/InstanceInterface.php +16 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/Module}/AcfSync.php +13 -20
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/Module}/Ajax.php +16 -41
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/Plugin}/GravityForms.php +15 -72
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/Plugin}/Woocommerce.php +26 -80
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Plugin/Yoast.php +46 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Traits/PageBlocks.php +92 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/Traits/Singleton.php +23 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/Acf.php +118 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/WP}/AcfBlocks.php +62 -61
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/WP}/AjaxEnpoints.php +6 -6
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/WP}/Assets.php +258 -119
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/WP}/Blocks.php +69 -55
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/Cache.php +103 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes/ExtendedImage.php → inc/WP/ChiselImage.php} +2 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes/ExtendedPost.php → inc/WP/ChiselPost.php} +4 -10
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes/ExtendedProduct.php → inc/WP/ChiselProduct.php} +4 -3
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes/ExtendedTerm.php → inc/WP/ChiselTerm.php} +2 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/WP}/Comments.php +10 -32
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/WP}/Components.php +61 -36
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/CustomPostTypes.php +124 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/CustomTaxonomies.php +129 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/WP}/Sidebars.php +11 -17
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/WP}/Site.php +15 -21
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/WP}/Theme.php +22 -15
- package/lib/commands/create/creators/app/chisel-starter-theme/{classes → inc/WP}/Twig.php +34 -21
- package/lib/commands/create/creators/app/chisel-starter-theme/index.php +2 -3
- package/lib/commands/create/creators/app/chisel-starter-theme/package.chisel-tpl.json +5 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/page.php +3 -3
- package/lib/commands/create/creators/app/chisel-starter-theme/phpcs.xml +5 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/search.php +3 -4
- package/lib/commands/create/creators/app/chisel-starter-theme/single.php +3 -3
- package/lib/commands/create/creators/app/chisel-starter-theme/src/blocks/accordion/accordion-item.js +2 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/src/blocks/accordion/style.scss +12 -5
- package/lib/commands/create/creators/app/chisel-starter-theme/src/blocks-acf/slider/acf-json/group_66462c70b851f.json +107 -105
- package/lib/commands/create/creators/app/chisel-starter-theme/src/blocks-acf/slider/block.json +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/src/blocks-acf/slider/slider.twig +4 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/src/design/settings/_index.scss +2 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/src/design/tools/_buttons.scss +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/src/design/tools/_icon.scss +39 -7
- package/lib/commands/create/creators/app/chisel-starter-theme/src/design/tools/_index.scss +1 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/src/design/tools/_layout.scss +11 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/src/scripts/admin/acf.js +65 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/src/scripts/app.js +2 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/src/scripts/editor/blocks.js +10 -4
- package/lib/commands/create/creators/app/chisel-starter-theme/src/scripts/editor/mods/blocks-alignment.js +2 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/src/scripts/editor/mods/core-button.js +18 -14
- package/lib/commands/create/creators/app/chisel-starter-theme/src/scripts/editor/utils.js +0 -12
- package/lib/commands/create/creators/app/chisel-starter-theme/src/scripts/modules/loaded.js +7 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/src/styles/admin.scss +2 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/src/styles/blocks/_core-button.scss +14 -13
- package/lib/commands/create/creators/app/chisel-starter-theme/src/styles/components/_buttons.scss +14 -13
- package/lib/commands/create/creators/app/chisel-starter-theme/src/styles/components/_icons-preview.scss +97 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/src/styles/components/_main-nav.scss +19 -9
- package/lib/commands/create/creators/app/chisel-starter-theme/src/styles/components/_posts-items.scss +6 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/src/styles/objects/_icon.scss +51 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/src/styles/objects/_layout.scss +0 -13
- package/lib/commands/create/creators/app/chisel-starter-theme/src/styles/wp-admin/_acf.scss +29 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/src/styles/wp-admin/_index.scss +4 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/style.chisel-tpl.css +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/views/base.twig +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/views/components/header.twig +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/views/{partials → components}/logo.twig +2 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/views/components/main-nav-item.twig +2 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/views/components/main-nav.twig +5 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/views/components/pagination.twig +70 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/views/components/post-item.twig +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/views/components/slider.twig +2 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/views/{partials → components}/the-title.twig +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/views/index.twig +10 -5
- package/lib/commands/create/creators/app/chisel-starter-theme/views/objects/icon.twig +37 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/views/partials/icons-preview.twig +81 -0
- package/lib/commands/create/creators/app/chisel-starter-theme/views/sidebar-blog.twig +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/views/sidebar-woocommerce.twig +1 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/views/single.twig +2 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/views/woocommerce/archive-product.twig +2 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/views/woocommerce/linked-products.twig +2 -2
- package/lib/commands/create/creators/app/chisel-starter-theme/views/woocommerce/single-product.twig +4 -4
- package/lib/commands/create/creators/app/chisel-starter-theme/woocommerce.php +6 -6
- package/lib/commands/create/creators/app/index.js +74 -20
- package/lib/commands/create/creators/app/template/.devcontainer/Dockerfile +21 -0
- package/lib/commands/create/creators/app/template/.devcontainer/compose.chisel-tpl +3 -0
- package/lib/commands/create/creators/app/template/.devcontainer/devcontainer.json.chisel-tpl +31 -0
- package/lib/commands/create/creators/app/template/.devcontainer/docker-compose.yml.chisel-tpl +40 -0
- package/lib/commands/create/creators/app/template/.devcontainer/exec +8 -0
- package/lib/commands/create/creators/app/template/.devcontainer/post-create-command.sh.chisel-tpl +24 -0
- package/lib/commands/create/creators/devcontainer.js +62 -0
- package/lib/commands/create/creators/utils.js +58 -0
- package/lib/commands/create/creators/wp/index.js +24 -3
- package/lib/commands/create/creators/wp-plugins/plugins.json +1 -1
- package/lib/commands/create/index.js +9 -2
- package/lib/commands/create/packages-versions.js +3 -3
- package/package.json +3 -3
- package/lib/commands/create/creators/app/chisel-starter-theme/classes/Acf.php +0 -188
- package/lib/commands/create/creators/app/chisel-starter-theme/classes/ChiselCache.php +0 -87
- package/lib/commands/create/creators/app/chisel-starter-theme/classes/CustomPostTypes.php +0 -444
- package/lib/commands/create/creators/app/chisel-starter-theme/classes/Yoast.php +0 -78
- package/lib/commands/create/creators/app/chisel-starter-theme/src/styles/components/_icon.scss +0 -19
- package/lib/commands/create/creators/app/chisel-starter-theme/views/components/icon.twig +0 -1
- package/lib/commands/create/creators/app/chisel-starter-theme/views/partials/pagination.twig +0 -70
- /package/lib/commands/create/creators/app/chisel-starter-theme/assets/icons/{loader.svg → animated/loader.svg} +0 -0
- /package/lib/commands/create/creators/app/chisel-starter-theme/assets/{icons → icons-source}/minus.svg +0 -0
- /package/lib/commands/create/creators/app/chisel-starter-theme/assets/{icons → icons-source}/plus.svg +0 -0
|
@@ -1,89 +1,99 @@
|
|
|
1
1
|
<?php
|
|
2
2
|
|
|
3
|
-
namespace Chisel;
|
|
3
|
+
namespace Chisel\WP;
|
|
4
|
+
|
|
5
|
+
use Chisel\Interfaces\InstanceInterface;
|
|
6
|
+
use Chisel\Interfaces\HooksInterface;
|
|
7
|
+
use Chisel\Traits\Singleton;
|
|
8
|
+
use Chisel\Helper\ThemeHelpers;
|
|
9
|
+
use Chisel\Helper\AjaxHelpers;
|
|
10
|
+
use Chisel\Helper\AssetsHelpers;
|
|
4
11
|
|
|
5
12
|
/**
|
|
6
13
|
* Class for enqueuing scripts and styles.
|
|
7
14
|
*
|
|
8
15
|
* @package Chisel
|
|
9
16
|
*/
|
|
10
|
-
class Assets implements
|
|
17
|
+
class Assets implements InstanceInterface, HooksInterface {
|
|
18
|
+
|
|
19
|
+
use Singleton;
|
|
11
20
|
|
|
12
21
|
/**
|
|
13
22
|
* Front-end styles to be registered and enqueued.
|
|
14
23
|
*
|
|
15
24
|
* @var array
|
|
16
25
|
*/
|
|
17
|
-
|
|
26
|
+
private $frontend_styles = array();
|
|
18
27
|
|
|
19
28
|
/**
|
|
20
29
|
* Front-end styles to be registered and enqueued in footer.
|
|
21
30
|
*
|
|
22
31
|
* @var array
|
|
23
32
|
*/
|
|
24
|
-
|
|
33
|
+
private $frontend_footer_styles = array();
|
|
25
34
|
|
|
26
35
|
/**
|
|
27
36
|
* Front-end scripts to be registered and enqueued.
|
|
28
37
|
*
|
|
29
38
|
* @var array
|
|
30
39
|
*/
|
|
31
|
-
|
|
40
|
+
private $frontend_scripts = array();
|
|
32
41
|
|
|
33
42
|
/**
|
|
34
43
|
* Admin styles to be registered and enqueued.
|
|
35
44
|
*
|
|
36
45
|
* @var array
|
|
37
46
|
*/
|
|
38
|
-
|
|
47
|
+
private $admin_styles = array();
|
|
39
48
|
|
|
40
49
|
/**
|
|
41
50
|
* Admin scripts to be registered and enqueued.
|
|
42
51
|
*
|
|
43
52
|
* @var array
|
|
44
53
|
*/
|
|
45
|
-
|
|
54
|
+
private $admin_scripts = array();
|
|
46
55
|
|
|
47
56
|
/**
|
|
48
57
|
* Editor styles to be registered and enqueued.
|
|
49
58
|
*
|
|
50
59
|
* @var array
|
|
51
60
|
*/
|
|
52
|
-
|
|
61
|
+
private $editor_styles = array();
|
|
53
62
|
|
|
54
63
|
/**
|
|
55
64
|
* Editor scripts to be registered and enqueued.
|
|
56
65
|
*
|
|
57
66
|
* @var array
|
|
58
67
|
*/
|
|
59
|
-
|
|
68
|
+
private $editor_scripts = array();
|
|
60
69
|
|
|
61
70
|
/**
|
|
62
71
|
* Login page styles to be registered and enqueued.
|
|
63
72
|
*
|
|
64
73
|
* @var array
|
|
65
74
|
*/
|
|
66
|
-
|
|
75
|
+
private $login_styles = array();
|
|
67
76
|
|
|
68
77
|
/**
|
|
69
78
|
* Login page scripts to be registered and enqueued.
|
|
70
79
|
*
|
|
71
80
|
* @var array
|
|
72
81
|
*/
|
|
73
|
-
|
|
82
|
+
private $login_scripts = array();
|
|
74
83
|
|
|
75
84
|
/**
|
|
76
85
|
* WP React Refresh runtime dependency.
|
|
77
86
|
*
|
|
78
87
|
* @var string
|
|
79
88
|
*/
|
|
80
|
-
|
|
89
|
+
private $refresh_runtime_dependency = 'wp-react-refresh-runtime';
|
|
81
90
|
|
|
82
91
|
/**
|
|
83
92
|
* Class constructor.
|
|
84
93
|
*/
|
|
85
94
|
private function __construct() {
|
|
86
|
-
$this
|
|
95
|
+
add_action( 'after_setup_theme', array( $this, 'set_properties' ), 7 );
|
|
96
|
+
|
|
87
97
|
$this->action_hooks();
|
|
88
98
|
$this->filter_hooks();
|
|
89
99
|
}
|
|
@@ -98,7 +108,7 @@ class Assets implements Instance {
|
|
|
98
108
|
'deps' => array( $this->refresh_runtime_dependency ),
|
|
99
109
|
'strategy' => false,
|
|
100
110
|
'condition' => function () {
|
|
101
|
-
return
|
|
111
|
+
return ThemeHelpers::is_fast_refresh();
|
|
102
112
|
},
|
|
103
113
|
);
|
|
104
114
|
|
|
@@ -115,7 +125,7 @@ class Assets implements Instance {
|
|
|
115
125
|
'name' => 'chiselScripts',
|
|
116
126
|
'data' => array(
|
|
117
127
|
'ajax' => array(
|
|
118
|
-
'url' => esc_url(
|
|
128
|
+
'url' => esc_url( AjaxHelpers::get_ajax_endpoint_url() ),
|
|
119
129
|
'nonce' => wp_create_nonce( 'wp_rest' ), // this (wp_rest) authenticates users and allows using get_current_user functions in rest api endpoints.
|
|
120
130
|
),
|
|
121
131
|
),
|
|
@@ -134,7 +144,7 @@ class Assets implements Instance {
|
|
|
134
144
|
'localize' => array(
|
|
135
145
|
'name' => 'chiselScripts',
|
|
136
146
|
'data' => array(
|
|
137
|
-
'logoData' =>
|
|
147
|
+
'logoData' => ThemeHelpers::get_login_page_logo_data(),
|
|
138
148
|
),
|
|
139
149
|
),
|
|
140
150
|
),
|
|
@@ -151,7 +161,7 @@ class Assets implements Instance {
|
|
|
151
161
|
'localize' => array(
|
|
152
162
|
'name' => 'chiselAdminScripts',
|
|
153
163
|
'data' => array(
|
|
154
|
-
'acfColorPickerPalette' =>
|
|
164
|
+
'acfColorPickerPalette' => ThemeHelpers::get_colors_palette( 'acf' ),
|
|
155
165
|
),
|
|
156
166
|
),
|
|
157
167
|
),
|
|
@@ -167,8 +177,10 @@ class Assets implements Instance {
|
|
|
167
177
|
'name' => 'chiselEditorScripts',
|
|
168
178
|
'data' => array(
|
|
169
179
|
'icons' => array(
|
|
170
|
-
'
|
|
171
|
-
'
|
|
180
|
+
'arrow-left' => __( 'Arrow Left', 'chisel' ),
|
|
181
|
+
'arrow-right' => __( 'Arrow Right', 'chisel' ),
|
|
182
|
+
'minus' => __( 'Minus', 'chisel' ),
|
|
183
|
+
'plus' => __( 'Plus', 'chisel' ),
|
|
172
184
|
),
|
|
173
185
|
),
|
|
174
186
|
),
|
|
@@ -182,6 +194,7 @@ class Assets implements Instance {
|
|
|
182
194
|
*/
|
|
183
195
|
public function action_hooks() {
|
|
184
196
|
add_action( 'init', array( $this, 'register_assets' ) );
|
|
197
|
+
add_action( 'init', array( $this, 'move_scripts_to_footer' ), 2 );
|
|
185
198
|
|
|
186
199
|
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_frontend_assets' ), 99 ); // Higher priority, overwrite plugins if needed.
|
|
187
200
|
add_action( 'wp_footer', array( $this, 'enqueue_frontend_assets_in_footer' ), 11 ); // Higher priority, overwrite plugins if needed.
|
|
@@ -197,6 +210,25 @@ class Assets implements Instance {
|
|
|
197
210
|
* Register filter hooks.
|
|
198
211
|
*/
|
|
199
212
|
public function filter_hooks() {
|
|
213
|
+
add_filter( 'script_loader_tag', array( $this, 'async_script' ), 99, 2 );
|
|
214
|
+
add_filter( 'script_loader_tag', array( $this, 'defer_script' ), 99, 2 );
|
|
215
|
+
add_filter( 'style_loader_tag', array( $this, 'preload_styles' ), 99, 2 );
|
|
216
|
+
}
|
|
217
|
+
|
|
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
|
+
}
|
|
200
232
|
}
|
|
201
233
|
|
|
202
234
|
/**
|
|
@@ -212,19 +244,19 @@ class Assets implements Instance {
|
|
|
212
244
|
|
|
213
245
|
if ( $this->frontend_styles ) {
|
|
214
246
|
foreach ( $this->frontend_styles as $file_name => $args ) {
|
|
215
|
-
$this->register_style(
|
|
247
|
+
$this->register_style( AssetsHelpers::get_final_handle( $file_name ), $file_name, $args );
|
|
216
248
|
}
|
|
217
249
|
}
|
|
218
250
|
|
|
219
251
|
if ( $this->frontend_footer_styles ) {
|
|
220
252
|
foreach ( $this->frontend_footer_styles as $file_name => $args ) {
|
|
221
|
-
$this->register_style(
|
|
253
|
+
$this->register_style( AssetsHelpers::get_final_handle( $file_name ), $file_name, $args );
|
|
222
254
|
}
|
|
223
255
|
}
|
|
224
256
|
|
|
225
257
|
if ( $this->frontend_scripts ) {
|
|
226
258
|
foreach ( $this->frontend_scripts as $file_name => $args ) {
|
|
227
|
-
$this->register_script(
|
|
259
|
+
$this->register_script( AssetsHelpers::get_final_handle( $file_name ), $file_name, $args );
|
|
228
260
|
}
|
|
229
261
|
}
|
|
230
262
|
|
|
@@ -233,7 +265,7 @@ class Assets implements Instance {
|
|
|
233
265
|
$login_styles_data = array();
|
|
234
266
|
|
|
235
267
|
foreach ( $this->login_styles as $file_name => $args ) {
|
|
236
|
-
$login_styles_data = $this->register_style(
|
|
268
|
+
$login_styles_data = $this->register_style( AssetsHelpers::get_final_handle( $file_name ), $file_name, $args );
|
|
237
269
|
}
|
|
238
270
|
|
|
239
271
|
if ( isset( $login_styles_data['ver'] ) ) {
|
|
@@ -243,7 +275,7 @@ class Assets implements Instance {
|
|
|
243
275
|
|
|
244
276
|
if ( $this->login_scripts ) {
|
|
245
277
|
foreach ( $this->login_scripts as $file_name => $args ) {
|
|
246
|
-
$this->register_script(
|
|
278
|
+
$this->register_script( AssetsHelpers::get_final_handle( $file_name ), $file_name, $args );
|
|
247
279
|
}
|
|
248
280
|
}
|
|
249
281
|
}
|
|
@@ -255,25 +287,25 @@ class Assets implements Instance {
|
|
|
255
287
|
|
|
256
288
|
if ( $this->admin_styles ) {
|
|
257
289
|
foreach ( $this->admin_styles as $file_name => $args ) {
|
|
258
|
-
$this->register_style(
|
|
290
|
+
$this->register_style( AssetsHelpers::get_final_handle( $file_name ), $file_name, $args );
|
|
259
291
|
}
|
|
260
292
|
}
|
|
261
293
|
|
|
262
294
|
if ( $this->admin_scripts ) {
|
|
263
295
|
foreach ( $this->admin_scripts as $file_name => $args ) {
|
|
264
|
-
$this->register_script(
|
|
296
|
+
$this->register_script( AssetsHelpers::get_final_handle( $file_name ), $file_name, $args );
|
|
265
297
|
}
|
|
266
298
|
}
|
|
267
299
|
|
|
268
300
|
if ( $this->editor_styles ) {
|
|
269
301
|
foreach ( $this->editor_styles as $file_name => $args ) {
|
|
270
|
-
$this->register_style(
|
|
302
|
+
$this->register_style( AssetsHelpers::get_final_handle( $file_name ), $file_name, $args );
|
|
271
303
|
}
|
|
272
304
|
}
|
|
273
305
|
|
|
274
306
|
if ( $this->editor_scripts ) {
|
|
275
307
|
foreach ( $this->editor_scripts as $file_name => $args ) {
|
|
276
|
-
$this->register_script(
|
|
308
|
+
$this->register_script( AssetsHelpers::get_final_handle( $file_name ), $file_name, $args );
|
|
277
309
|
}
|
|
278
310
|
}
|
|
279
311
|
}
|
|
@@ -289,10 +321,10 @@ class Assets implements Instance {
|
|
|
289
321
|
if ( $this->frontend_styles ) {
|
|
290
322
|
foreach ( $this->frontend_styles as $handle => $args ) {
|
|
291
323
|
$enqueue_style = apply_filters( 'chisel_enqueue_frontend_style', true, $handle, $args );
|
|
292
|
-
$style_handle =
|
|
324
|
+
$style_handle = AssetsHelpers::get_final_handle( $handle );
|
|
293
325
|
|
|
294
326
|
if ( $enqueue_style && wp_style_is( $style_handle, 'registered' ) ) {
|
|
295
|
-
|
|
327
|
+
$this->enqueue_style( $style_handle, $args );
|
|
296
328
|
|
|
297
329
|
// Enqueue js file for fast refresh of the css file.
|
|
298
330
|
$this->enqueue_style_js_for_dev( $handle );
|
|
@@ -303,11 +335,10 @@ class Assets implements Instance {
|
|
|
303
335
|
if ( $this->frontend_scripts ) {
|
|
304
336
|
foreach ( $this->frontend_scripts as $handle => $args ) {
|
|
305
337
|
$enqueue_script = apply_filters( 'chisel_enqueue_frontend_script', true, $handle, $args );
|
|
306
|
-
$script_handle =
|
|
338
|
+
$script_handle = AssetsHelpers::get_final_handle( $handle );
|
|
307
339
|
|
|
308
340
|
if ( $enqueue_script && wp_script_is( $script_handle, 'registered' ) ) {
|
|
309
|
-
|
|
310
|
-
$this->set_script_translations( $handle, $args );
|
|
341
|
+
$this->enqueue_script( $script_handle, $args );
|
|
311
342
|
}
|
|
312
343
|
}
|
|
313
344
|
}
|
|
@@ -322,10 +353,10 @@ class Assets implements Instance {
|
|
|
322
353
|
if ( $this->frontend_footer_styles ) {
|
|
323
354
|
foreach ( $this->frontend_footer_styles as $handle => $args ) {
|
|
324
355
|
$enqueue_style = apply_filters( 'chisel_enqueue_frontend_footer_style', true, $handle, $args );
|
|
325
|
-
$style_handle =
|
|
356
|
+
$style_handle = AssetsHelpers::get_final_handle( $handle );
|
|
326
357
|
|
|
327
358
|
if ( $enqueue_style && wp_style_is( $style_handle, 'registered' ) ) {
|
|
328
|
-
|
|
359
|
+
$this->enqueue_style( $style_handle, $args );
|
|
329
360
|
|
|
330
361
|
// Enqueue js file for fast refresh of the css file.
|
|
331
362
|
$this->enqueue_style_js_for_dev( $handle );
|
|
@@ -344,10 +375,10 @@ class Assets implements Instance {
|
|
|
344
375
|
if ( $this->admin_styles ) {
|
|
345
376
|
foreach ( $this->admin_styles as $handle => $args ) {
|
|
346
377
|
$enqueue_style = apply_filters( 'chisel_enqueue_admin_style', true, $handle, $args );
|
|
347
|
-
$style_handle =
|
|
378
|
+
$style_handle = AssetsHelpers::get_final_handle( $handle );
|
|
348
379
|
|
|
349
380
|
if ( $enqueue_style && wp_style_is( $style_handle, 'registered' ) ) {
|
|
350
|
-
|
|
381
|
+
$this->enqueue_style( $style_handle, $args );
|
|
351
382
|
|
|
352
383
|
// Enqueue js file for fast refresh of the css file.
|
|
353
384
|
$this->enqueue_style_js_for_dev( $handle );
|
|
@@ -358,11 +389,10 @@ class Assets implements Instance {
|
|
|
358
389
|
if ( $this->admin_scripts ) {
|
|
359
390
|
foreach ( $this->admin_scripts as $handle => $args ) {
|
|
360
391
|
$enqueue_script = apply_filters( 'chisel_enqueue_admin_script', true, $handle, $args );
|
|
361
|
-
$script_handle =
|
|
392
|
+
$script_handle = AssetsHelpers::get_final_handle( $handle );
|
|
362
393
|
|
|
363
394
|
if ( $enqueue_script && wp_script_is( $script_handle, 'registered' ) ) {
|
|
364
|
-
|
|
365
|
-
$this->set_script_translations( $handle, $args );
|
|
395
|
+
$this->enqueue_script( $script_handle, $args );
|
|
366
396
|
}
|
|
367
397
|
}
|
|
368
398
|
}
|
|
@@ -378,10 +408,10 @@ class Assets implements Instance {
|
|
|
378
408
|
if ( $this->editor_styles ) {
|
|
379
409
|
foreach ( $this->editor_styles as $handle => $args ) {
|
|
380
410
|
$enqueue_style = apply_filters( 'chisel_enqueue_editor_style', true, $handle, $args );
|
|
381
|
-
$style_handle =
|
|
411
|
+
$style_handle = AssetsHelpers::get_final_handle( $handle );
|
|
382
412
|
|
|
383
413
|
if ( $enqueue_style && wp_style_is( $style_handle, 'registered' ) ) {
|
|
384
|
-
|
|
414
|
+
$this->enqueue_style( $style_handle, $args );
|
|
385
415
|
|
|
386
416
|
// Enqueue js file for fast refresh of the css file.
|
|
387
417
|
$this->enqueue_style_js_for_dev( $handle );
|
|
@@ -392,11 +422,10 @@ class Assets implements Instance {
|
|
|
392
422
|
if ( $this->editor_scripts ) {
|
|
393
423
|
foreach ( $this->editor_scripts as $handle => $args ) {
|
|
394
424
|
$enqueue_script = apply_filters( 'chisel_enqueue_editor_script', true, $handle, $args );
|
|
395
|
-
$script_handle =
|
|
425
|
+
$script_handle = AssetsHelpers::get_final_handle( $handle );
|
|
396
426
|
|
|
397
427
|
if ( $enqueue_script && wp_script_is( $script_handle, 'registered' ) ) {
|
|
398
|
-
|
|
399
|
-
$this->set_script_translations( $handle, $args );
|
|
428
|
+
$this->enqueue_script( $script_handle, $args );
|
|
400
429
|
}
|
|
401
430
|
}
|
|
402
431
|
}
|
|
@@ -421,10 +450,10 @@ class Assets implements Instance {
|
|
|
421
450
|
if ( $this->login_styles ) {
|
|
422
451
|
foreach ( $this->login_styles as $handle => $args ) {
|
|
423
452
|
$enqueue_style = apply_filters( 'chisel_enqueue_login_style', true, $handle, $args );
|
|
424
|
-
$style_handle =
|
|
453
|
+
$style_handle = AssetsHelpers::get_final_handle( $handle );
|
|
425
454
|
|
|
426
455
|
if ( $enqueue_style && wp_style_is( $style_handle, 'registered' ) ) {
|
|
427
|
-
|
|
456
|
+
$this->enqueue_style( $style_handle, $args );
|
|
428
457
|
|
|
429
458
|
// Enqueue js file for fast refresh of the css file.
|
|
430
459
|
$this->enqueue_style_js_for_dev( $handle );
|
|
@@ -435,14 +464,127 @@ class Assets implements Instance {
|
|
|
435
464
|
if ( $this->login_scripts ) {
|
|
436
465
|
foreach ( $this->login_scripts as $handle => $args ) {
|
|
437
466
|
$enqueue_script = apply_filters( 'chisel_enqueue_login_script', true, $handle, $args );
|
|
438
|
-
$script_handle =
|
|
467
|
+
$script_handle = AssetsHelpers::get_final_handle( $handle );
|
|
439
468
|
|
|
440
469
|
if ( $enqueue_script && wp_script_is( $script_handle, 'registered' ) ) {
|
|
441
|
-
|
|
442
|
-
|
|
470
|
+
$this->enqueue_script( $script_handle, $args );
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Async scripts by handle.
|
|
478
|
+
*
|
|
479
|
+
* @param string $tag
|
|
480
|
+
* @param string $handle
|
|
481
|
+
*
|
|
482
|
+
* @return string
|
|
483
|
+
*/
|
|
484
|
+
public function async_script( $tag, $handle ) {
|
|
485
|
+
if ( is_admin() ) {
|
|
486
|
+
return $tag;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
$scripts = array();
|
|
490
|
+
|
|
491
|
+
if ( $scripts ) {
|
|
492
|
+
foreach ( $scripts as $script_handle ) {
|
|
493
|
+
if ( $handle === $script_handle ) {
|
|
494
|
+
$tag = str_replace( ' src', ' async src', $tag );
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
return $tag;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Defer scripts by handle.
|
|
504
|
+
*
|
|
505
|
+
* @param string $tag
|
|
506
|
+
* @param string $handle
|
|
507
|
+
*
|
|
508
|
+
* @return string
|
|
509
|
+
*/
|
|
510
|
+
public function defer_script( $tag, $handle ) {
|
|
511
|
+
if ( is_admin() ) {
|
|
512
|
+
return $tag;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
$scripts = array();
|
|
516
|
+
|
|
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
|
+
if ( $scripts ) {
|
|
525
|
+
foreach ( $scripts as $script_handle ) {
|
|
526
|
+
if ( $handle === $script_handle ) {
|
|
527
|
+
$tag = str_replace( ' src', ' defer src', $tag );
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
return $tag;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Preload styles by handle.
|
|
537
|
+
*
|
|
538
|
+
* @param string $tag
|
|
539
|
+
* @param string $handle
|
|
540
|
+
*
|
|
541
|
+
* @return string
|
|
542
|
+
*/
|
|
543
|
+
public function preload_styles( $tag, $handle ) {
|
|
544
|
+
if ( is_admin() ) {
|
|
545
|
+
return $tag;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
$styles_handles = array(
|
|
549
|
+
'wp-block-library',
|
|
550
|
+
);
|
|
551
|
+
|
|
552
|
+
$styles_handles_start_with = array(
|
|
553
|
+
'gform_',
|
|
554
|
+
'block',
|
|
555
|
+
);
|
|
556
|
+
|
|
557
|
+
if ( $styles_handles ) {
|
|
558
|
+
foreach ( $styles_handles as $style_handle ) {
|
|
559
|
+
if ( $handle === $style_handle ) {
|
|
560
|
+
$tag = $this->preload_style( $tag );
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
if ( $styles_handles_start_with ) {
|
|
566
|
+
foreach ( $styles_handles_start_with as $style_handle ) {
|
|
567
|
+
if ( strpos( $handle, $style_handle ) === 0 ) {
|
|
568
|
+
$tag = $this->preload_style( $tag );
|
|
443
569
|
}
|
|
444
570
|
}
|
|
445
571
|
}
|
|
572
|
+
|
|
573
|
+
return $tag;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* Preload style tag.
|
|
578
|
+
*
|
|
579
|
+
* @param string $tag
|
|
580
|
+
*
|
|
581
|
+
* @return string
|
|
582
|
+
*/
|
|
583
|
+
private function preload_style( $tag ) {
|
|
584
|
+
$preload_tag = str_replace( "rel='stylesheet'", "rel='preload' as='style'", $tag );
|
|
585
|
+
$tag = $preload_tag . str_replace( "media='all'", "media='print' onload='this.media=\"all\"'", $tag );
|
|
586
|
+
|
|
587
|
+
return $tag;
|
|
446
588
|
}
|
|
447
589
|
|
|
448
590
|
/**
|
|
@@ -454,14 +596,13 @@ class Assets implements Instance {
|
|
|
454
596
|
*
|
|
455
597
|
* @return void
|
|
456
598
|
*/
|
|
457
|
-
|
|
599
|
+
private function register_style( $handle, $file_name, $args ) {
|
|
458
600
|
$asset_data = $this->get_asset( $file_name, 'css' );
|
|
459
601
|
|
|
460
602
|
$src = isset( $args['src'] ) ? $args['src'] : $this->get_style_src( $file_name );
|
|
461
603
|
$deps = isset( $args['deps'] ) ? $args['deps'] : array();
|
|
462
604
|
$ver = isset( $args['ver'] ) ? $args['ver'] : $asset_data['version'];
|
|
463
605
|
$media = isset( $args['media'] ) ? $args['media'] : 'all';
|
|
464
|
-
$inline = isset( $args['inline'] ) ? $args['inline'] : '';
|
|
465
606
|
$condition = isset( $args['condition'] ) ? $args['condition'] : null;
|
|
466
607
|
|
|
467
608
|
// Use condition to determine if the style should be registered. It can be either a boolean or a function.
|
|
@@ -481,12 +622,8 @@ class Assets implements Instance {
|
|
|
481
622
|
|
|
482
623
|
wp_register_style( $handle, $src, $deps, $ver, $media );
|
|
483
624
|
|
|
484
|
-
if ( $inline ) {
|
|
485
|
-
wp_add_inline_style( $handle, $inline['data'] );
|
|
486
|
-
}
|
|
487
|
-
|
|
488
625
|
// Register js file for fast refresh of the css file.
|
|
489
|
-
if (
|
|
626
|
+
if ( ThemeHelpers::is_fast_refresh() ) {
|
|
490
627
|
$this->register_script(
|
|
491
628
|
'style-' . $handle,
|
|
492
629
|
$file_name,
|
|
@@ -506,6 +643,28 @@ class Assets implements Instance {
|
|
|
506
643
|
);
|
|
507
644
|
}
|
|
508
645
|
|
|
646
|
+
/**
|
|
647
|
+
* Enqueue script wrapper function.
|
|
648
|
+
*
|
|
649
|
+
* @param string $handle - full script handle.
|
|
650
|
+
* @param array $args
|
|
651
|
+
*
|
|
652
|
+
* @return array
|
|
653
|
+
*/
|
|
654
|
+
private function enqueue_style( $handle, $args ) {
|
|
655
|
+
$inline = isset( $args['inline'] ) ? $args['inline'] : '';
|
|
656
|
+
|
|
657
|
+
if ( $inline ) {
|
|
658
|
+
wp_add_inline_style( $handle, $inline['data'] );
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
wp_enqueue_style( $handle );
|
|
662
|
+
|
|
663
|
+
return array(
|
|
664
|
+
'handle' => $handle,
|
|
665
|
+
);
|
|
666
|
+
}
|
|
667
|
+
|
|
509
668
|
/**
|
|
510
669
|
* Register script wrapper function.
|
|
511
670
|
*
|
|
@@ -515,15 +674,16 @@ class Assets implements Instance {
|
|
|
515
674
|
*
|
|
516
675
|
* @return void
|
|
517
676
|
*/
|
|
518
|
-
|
|
677
|
+
private function register_script( $handle, $file_name, $args ) {
|
|
519
678
|
$asset_data = $this->get_asset( $file_name, 'js' );
|
|
520
679
|
|
|
521
680
|
$src = isset( $args['src'] ) ? $args['src'] : $this->get_script_src( $file_name );
|
|
522
681
|
$deps = isset( $args['deps'] ) ? $args['deps'] : array();
|
|
523
682
|
$ver = isset( $args['ver'] ) ? $args['ver'] : $asset_data['version'];
|
|
524
|
-
$strategy = isset( $args['strategy'] ) ? $args['strategy'] :
|
|
525
|
-
|
|
526
|
-
|
|
683
|
+
$strategy = isset( $args['strategy'] ) ? $args['strategy'] : array(
|
|
684
|
+
'in_footer' => true,
|
|
685
|
+
'strategy' => 'defer',
|
|
686
|
+
); // Strategy can be a boolean, which determines if the script should be enqueued in the footer, or an array with the following keys: 'in_footer':boolean and 'strategy':string (defer or async).
|
|
527
687
|
$condition = isset( $args['condition'] ) ? $args['condition'] : null;
|
|
528
688
|
|
|
529
689
|
// Use condition to determine if the script should be registered. It can be either a boolean or a function.
|
|
@@ -543,6 +703,28 @@ class Assets implements Instance {
|
|
|
543
703
|
|
|
544
704
|
wp_register_script( $handle, $src, $deps, $ver, $strategy );
|
|
545
705
|
|
|
706
|
+
return array(
|
|
707
|
+
'src' => $src,
|
|
708
|
+
'deps' => $deps,
|
|
709
|
+
'ver' => $ver,
|
|
710
|
+
'strategy' => $strategy,
|
|
711
|
+
'condition' => $condition,
|
|
712
|
+
'handle' => $handle,
|
|
713
|
+
);
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
/**
|
|
717
|
+
* Enqueue script wrapper function.
|
|
718
|
+
*
|
|
719
|
+
* @param string $handle - full script handle.
|
|
720
|
+
* @param array $args
|
|
721
|
+
*
|
|
722
|
+
* @return array
|
|
723
|
+
*/
|
|
724
|
+
private function enqueue_script( $handle, $args ) {
|
|
725
|
+
$localize = isset( $args['localize'] ) ? $args['localize'] : array();
|
|
726
|
+
$inline = isset( $args['inline'] ) ? $args['inline'] : '';
|
|
727
|
+
|
|
546
728
|
if ( $localize ) {
|
|
547
729
|
wp_localize_script( $handle, $localize['name'], $localize['data'] );
|
|
548
730
|
}
|
|
@@ -551,14 +733,12 @@ class Assets implements Instance {
|
|
|
551
733
|
wp_add_inline_script( $handle, $inline['data'], $inline['position'] );
|
|
552
734
|
}
|
|
553
735
|
|
|
736
|
+
wp_enqueue_script( $handle );
|
|
737
|
+
$this->set_script_translations( $handle, $args );
|
|
738
|
+
|
|
554
739
|
return array(
|
|
555
|
-
'
|
|
556
|
-
'
|
|
557
|
-
'ver' => $ver,
|
|
558
|
-
'strategy' => $strategy,
|
|
559
|
-
'condition' => $condition,
|
|
560
|
-
'localize' => $localize,
|
|
561
|
-
'handle' => $handle,
|
|
740
|
+
'localize' => $localize,
|
|
741
|
+
'handle' => $handle,
|
|
562
742
|
);
|
|
563
743
|
}
|
|
564
744
|
|
|
@@ -570,9 +750,9 @@ class Assets implements Instance {
|
|
|
570
750
|
*
|
|
571
751
|
* @return void
|
|
572
752
|
*/
|
|
573
|
-
|
|
753
|
+
private function set_script_translations( $handle, $args ) {
|
|
574
754
|
if ( isset( $args['deps'] ) && in_array( 'wp-i18n', $args['deps'], true ) ) {
|
|
575
|
-
wp_set_script_translations(
|
|
755
|
+
wp_set_script_translations( AssetsHelpers::get_final_handle( $handle ), 'chisel', get_template_directory() . '/languages' );
|
|
576
756
|
}
|
|
577
757
|
}
|
|
578
758
|
|
|
@@ -583,9 +763,9 @@ class Assets implements Instance {
|
|
|
583
763
|
*
|
|
584
764
|
* @return void
|
|
585
765
|
*/
|
|
586
|
-
|
|
587
|
-
if (
|
|
588
|
-
wp_enqueue_script( 'style-' .
|
|
766
|
+
private function enqueue_style_js_for_dev( $handle ) {
|
|
767
|
+
if ( ThemeHelpers::is_fast_refresh() ) {
|
|
768
|
+
wp_enqueue_script( 'style-' . AssetsHelpers::get_final_handle( $handle ) );
|
|
589
769
|
}
|
|
590
770
|
}
|
|
591
771
|
|
|
@@ -596,7 +776,7 @@ class Assets implements Instance {
|
|
|
596
776
|
*
|
|
597
777
|
* @return string
|
|
598
778
|
*/
|
|
599
|
-
|
|
779
|
+
private function get_script_src( $file_name ) {
|
|
600
780
|
return get_template_directory_uri() . '/build/scripts/' . $file_name . '.js';
|
|
601
781
|
}
|
|
602
782
|
|
|
@@ -608,7 +788,7 @@ class Assets implements Instance {
|
|
|
608
788
|
*
|
|
609
789
|
* @return string
|
|
610
790
|
*/
|
|
611
|
-
|
|
791
|
+
private function get_style_src( $file_name, $refresh_script = false ) {
|
|
612
792
|
if ( $refresh_script ) {
|
|
613
793
|
return get_template_directory_uri() . '/build/styles/' . $file_name . '.js';
|
|
614
794
|
}
|
|
@@ -624,7 +804,7 @@ class Assets implements Instance {
|
|
|
624
804
|
*
|
|
625
805
|
* @return array
|
|
626
806
|
*/
|
|
627
|
-
|
|
807
|
+
private function get_asset( $file_name, $type ) {
|
|
628
808
|
if ( $type === 'css' ) {
|
|
629
809
|
$asset_path = get_template_directory() . '/build/styles/' . $file_name . '.asset.php';
|
|
630
810
|
} else {
|
|
@@ -633,7 +813,7 @@ class Assets implements Instance {
|
|
|
633
813
|
|
|
634
814
|
$asset = array(
|
|
635
815
|
'dependencies' => array(),
|
|
636
|
-
'version' =>
|
|
816
|
+
'version' => ThemeHelpers::get_theme_version(),
|
|
637
817
|
);
|
|
638
818
|
|
|
639
819
|
if ( is_file( $asset_path ) ) {
|
|
@@ -642,7 +822,7 @@ class Assets implements Instance {
|
|
|
642
822
|
// We must remove that dependency for styles in fast refresh mode. For some reason styles are not loaded otherwise.
|
|
643
823
|
if (
|
|
644
824
|
$type === 'css' &&
|
|
645
|
-
|
|
825
|
+
ThemeHelpers::is_fast_refresh() &&
|
|
646
826
|
( $index = array_search( $this->refresh_runtime_dependency, $asset['dependencies'] ) ) !== false // phpcs:ignore
|
|
647
827
|
) {
|
|
648
828
|
unset( $asset['dependencies'][ $index ] );
|
|
@@ -651,45 +831,4 @@ class Assets implements Instance {
|
|
|
651
831
|
|
|
652
832
|
return $asset;
|
|
653
833
|
}
|
|
654
|
-
|
|
655
|
-
/**
|
|
656
|
-
* Get the final handle for the asset.
|
|
657
|
-
*
|
|
658
|
-
* @param string $handle
|
|
659
|
-
*
|
|
660
|
-
* @return string
|
|
661
|
-
*/
|
|
662
|
-
protected function get_final_handle( $handle ) {
|
|
663
|
-
$handle = 'chisel-' . $handle;
|
|
664
|
-
|
|
665
|
-
if ( self::is_fast_refresh() ) {
|
|
666
|
-
$handle .= '-fast-refresh';
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
return $handle;
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
/**
|
|
673
|
-
* Check if current environment is development and runnning in fast refresh mode. Set define( 'WP_ENVIRONMENT_TYPE', 'development' ); in wp-config-local.
|
|
674
|
-
*
|
|
675
|
-
* @return bool
|
|
676
|
-
*/
|
|
677
|
-
public static function is_fast_refresh() {
|
|
678
|
-
$runtime = get_template_directory() . '/build/runtime.js';
|
|
679
|
-
|
|
680
|
-
return Helpers::is_dev_env() && is_file( $runtime );
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
/**
|
|
684
|
-
* Get the instance of the class.
|
|
685
|
-
*/
|
|
686
|
-
public static function get_instance() {
|
|
687
|
-
static $instance = null;
|
|
688
|
-
|
|
689
|
-
if ( null === $instance ) {
|
|
690
|
-
$instance = new self();
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
return $instance;
|
|
694
|
-
}
|
|
695
834
|
}
|