PluginProbe
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management / 1.1.1
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management v1.1.1
1.6.0 1.5.1 1.5.0 1.4.0 1.3.0 trunk 0.0.1 1.0.0 1.1.0 1.1.1 1.1.2 1.2.0
suredonation / inc / assets / register.php

register.php in SureDonation – Donation Forms, Fundraising Campaigns & Donor Management 1.1.1, at inc/assets/register.php

195 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Assets Register
4 *
5 * @package SureDonation
6 */
7
8 namespace SureDonation\Inc\Assets;
9
10 use SureDonation\Inc\Traits\Get_Instance;
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 /**
18 * Register class for frontend assets.
19 *
20 * @since 0.0.1
21 */
22 class Register {
23
24 use Get_Instance;
25
26 /**
27 * Constructor.
28 *
29 * @since 0.0.1
30 */
31 public function __construct() {
32 add_action( 'wp_enqueue_scripts', [ $this, 'register_frontend_assets' ] );
33 // Progressive-enhancement gate: mark that JS is available before the body
34 // paints, so enhanced fields (e.g. the dropdown) can hide their native
35 // control and show a matching placeholder without a flash. The native
36 // control stays visible when this class is absent (JS disabled/failed).
37 add_action( 'wp_head', [ $this, 'print_js_gate' ], 1 );
38 }
39
40 /**
41 * Print the progressive-enhancement gate inline in the head.
42 *
43 * A one-liner that adds the `suredonation-js` class to <html> synchronously,
44 * before the body renders. The class only has a visual effect where a
45 * SureDonation field stylesheet is loaded, so printing it on every front-end
46 * page is harmless and keeps the fix independent of where forms are embedded.
47 *
48 * @return void
49 * @since 1.1.1
50 */
51 public function print_js_gate() {
52 if ( is_admin() ) {
53 return;
54 }
55
56 wp_print_inline_script_tag(
57 "document.documentElement.classList.add('suredonation-js');",
58 [ 'id' => 'suredonation-js-gate' ]
59 );
60 }
61
62 /**
63 * Register frontend assets.
64 *
65 * @return void
66 * @since 0.0.1
67 */
68 public function register_frontend_assets() {
69 // Register donation form frontend styles (for custom Gutenberg forms).
70 // Use filemtime so rebuilds bust the browser cache.
71 $style_file = SUREDONATION_DIR . 'assets/build/blocks/donation-form/style-style.css';
72 $style_version = file_exists( $style_file )
73 ? (string) filemtime( $style_file )
74 : SUREDONATION_VER;
75
76 wp_register_style(
77 'suredonation-donation-form',
78 SUREDONATION_URL . 'assets/build/blocks/donation-form/style-style.css',
79 [],
80 $style_version
81 );
82
83 // Register campaign display blocks frontend styles.
84 // Enqueued conditionally by each campaign block render only when present.
85 $campaign_style_file = SUREDONATION_DIR . 'assets/build/blocks/campaign/style-style.css';
86 $campaign_style_version = file_exists( $campaign_style_file )
87 ? (string) filemtime( $campaign_style_file )
88 : SUREDONATION_VER;
89
90 wp_register_style(
91 'suredonation-campaign-blocks',
92 SUREDONATION_URL . 'assets/build/blocks/campaign/style-style.css',
93 [],
94 $campaign_style_version
95 );
96
97 // Register donation form frontend script (used by both block and shortcode render paths).
98 $form_frontend_asset_file = SUREDONATION_DIR . 'assets/build/form-frontend.asset.php';
99 $form_frontend_asset = file_exists( $form_frontend_asset_file )
100 ? require $form_frontend_asset_file
101 : [
102 'dependencies' => [],
103 'version' => SUREDONATION_VER,
104 ];
105
106 wp_register_script(
107 'suredonation-form-frontend',
108 SUREDONATION_URL . 'assets/build/form-frontend.js',
109 $form_frontend_asset['dependencies'],
110 $form_frontend_asset['version'],
111 true
112 );
113
114 // Register the Inputmask library (vendored).
115 // Enqueued conditionally by the input block render only when a field uses an input pattern.
116 wp_register_script(
117 'suredonation-inputmask',
118 SUREDONATION_URL . 'assets/js/vendor/inputmask.min.js',
119 [],
120 SUREDONATION_VER,
121 true
122 );
123
124 // Register the tom-select library (vendored) + its styles.
125 // Enqueued conditionally by the dropdown block render only when present.
126 wp_register_style(
127 'suredonation-tom-select',
128 SUREDONATION_URL . 'assets/css/vendor/tom-select.css',
129 [],
130 SUREDONATION_VER
131 );
132
133 wp_register_script(
134 'suredonation-tom-select',
135 SUREDONATION_URL . 'assets/js/vendor/tom-select.min.js',
136 [],
137 SUREDONATION_VER,
138 true
139 );
140
141 // Register the dropdown initializer. Depends on tom-select so enqueuing
142 // the dropdown handle pulls the library in, in the right order.
143 $dropdown_asset_file = SUREDONATION_DIR . 'assets/build/blocks/dropdown/frontend.asset.php';
144 $dropdown_asset = file_exists( $dropdown_asset_file )
145 ? require $dropdown_asset_file
146 : [
147 'dependencies' => [],
148 'version' => SUREDONATION_VER,
149 ];
150
151 wp_register_script(
152 'suredonation-dropdown',
153 SUREDONATION_URL . 'assets/build/blocks/dropdown/frontend.js',
154 array_merge( $dropdown_asset['dependencies'], [ 'suredonation-tom-select', 'wp-a11y' ] ),
155 $dropdown_asset['version'],
156 true
157 );
158
159 // Register the intl-tel-input library (vendored) + its styles.
160 // Enqueued conditionally by the phone block render only when present.
161 wp_register_style(
162 'suredonation-intl-tel-input',
163 SUREDONATION_URL . 'assets/css/vendor/intl/intlTelInput.min.css',
164 [],
165 SUREDONATION_VER
166 );
167
168 wp_register_script(
169 'suredonation-intl-tel-input',
170 SUREDONATION_URL . 'assets/js/vendor/intl/intTelInputWithUtils.min.js',
171 [],
172 SUREDONATION_VER,
173 true
174 );
175
176 // Register the phone initializer. Depends on intl-tel-input so enqueuing
177 // the phone handle pulls the library in, in the right order.
178 $phone_asset_file = SUREDONATION_DIR . 'assets/build/blocks/phone/frontend.asset.php';
179 $phone_asset = file_exists( $phone_asset_file )
180 ? require $phone_asset_file
181 : [
182 'dependencies' => [],
183 'version' => SUREDONATION_VER,
184 ];
185
186 wp_register_script(
187 'suredonation-phone',
188 SUREDONATION_URL . 'assets/build/blocks/phone/frontend.js',
189 array_merge( $phone_asset['dependencies'], [ 'suredonation-intl-tel-input' ] ),
190 $phone_asset['version'],
191 true
192 );
193 }
194 }
195