PluginProbe ʕ •ᴥ•ʔ
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 3.0.3
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v3.0.3
4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.11.1 1.11.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.9.0 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 2.0.0 2.0.1 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.12.0 2.13.0 2.14.0 2.14.1 2.15.0 2.15.1 2.16.0 2.16.1 2.16.2 2.16.3 2.17.0 2.17.1 2.17.2 2.18.0 2.19.0 2.19.2 2.19.3 2.19.4 2.2.0 2.2.1 2.20.0 2.20.1 2.20.2 2.20.3 2.20.4 2.20.5 2.20.6 2.21.0 2.22.0 2.22.1 2.23.0 2.24.0 2.25.0 2.25.1 2.25.2 2.26.0 2.27.0 2.27.1 2.28.0 2.29.0 2.29.1 2.29.2 2.29.3 2.29.4 2.3.0 2.3.1 2.30.0 2.31.0 2.31.1 2.31.2 2.31.3 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.40.0 2.40.1 2.5.0 2.5.1 2.5.2 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.9.0 3.0.0 3.0.0-RC1 3.0.0-RC2 3.0.0-beta1 3.0.0-beta2 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.10.0 3.10.1 3.11.0 3.12.0 3.13.0 3.13.1 3.13.2 3.13.3 3.13.4 3.14.0 3.15.0 3.15.1 3.15.2 3.15.3 3.15.4 3.15.5 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.16.6 3.16.7 3.16.8 3.17.0 3.17.1 3.17.2 3.17.3 3.17.4 3.17.5 3.17.6 3.18.0 3.19.0 3.19.1 3.19.2 3.2.0 3.2.1 3.2.2 3.20.0 3.20.1 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 trunk 4.1.0 0.2.19.1 4.1.1 1.0.0 4.2.0 1.0.1 1.0.2
surecart / packages / blocks-next / index.php
surecart / packages / blocks-next Last commit date
build 1 year ago index.php 1 year ago
index.php
363 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly.
5 }
6
7 /**
8 * Register all blocks.
9 */
10 add_action(
11 'init',
12 function () {
13 foreach ( glob( __DIR__ . '/build/blocks/**/block.json' ) as $file ) {
14 register_block_type( dirname( $file ) );
15 }
16 }
17 );
18
19 /**
20 * Use our controller view pattern.
21 */
22 add_filter(
23 'block_type_metadata_settings',
24 function ( $settings, $metadata ) {
25 // if there is a controller file, use it.
26 $controller_path = wp_normalize_path(
27 realpath(
28 dirname( $metadata['file'] ) . '/' .
29 remove_block_asset_path_prefix( 'file:./controller.php' )
30 )
31 );
32
33 if ( ! file_exists( $controller_path ) ) {
34 return $settings;
35 }
36
37 /**
38 * Renders the block on the server.
39 *
40 * @since 6.1.0
41 *
42 * @param array $attributes Block attributes.
43 * @param string $content Block default content.
44 * @param WP_Block $block Block instance.
45 *
46 * @return string Returns the block content.
47 */
48 $settings['render_callback'] = static function ( $attributes, $content, $block ) use ( $controller_path, $metadata ) {
49 $view = require $controller_path;
50
51 if ( ! $view ) {
52 return '';
53 }
54
55 // if not using 'file:', then it's content output.
56 $view_path = remove_block_asset_path_prefix( $view );
57 if ( $view_path === $view ) {
58 return $view;
59 }
60
61 $template_path = wp_normalize_path(
62 realpath(
63 dirname( $metadata['file'] ) . '/' .
64 remove_block_asset_path_prefix( $view )
65 )
66 );
67
68 ob_start();
69 require $template_path;
70 return ob_get_clean();
71 };
72
73 return $settings;
74 },
75 11,
76 2
77 );
78
79 add_filter(
80 'render_block_context',
81 function ( $context, $parsed_block ) {
82 // we have product context.
83 if ( get_query_var( 'surecart_current_product' ) ) {
84 $context['surecart/product'] = sc_get_product();
85 }
86
87 // pass a unique id to each product list block.
88 if ( 'surecart/product-list' === $parsed_block['blockName'] ) {
89 // we use our own counter to ensure uniqueness so that product page urls don't have ids.
90 global $sc_query_id;
91 $sc_query_id = sc_unique_product_list_id();
92 }
93
94 // pass a unique id to each product list block.
95 if ( 'surecart/product-page' === $parsed_block['blockName'] ) {
96 // we use our own counter to ensure uniqueness so that product page urls don't have ids.
97 global $sc_query_id;
98 $sc_query_id = sc_unique_product_page_id();
99 }
100 return $context;
101 },
102 10,
103 2
104 );
105
106 /**
107 * Register all css at src/styles folder.
108 */
109 add_action(
110 'init',
111 function () {
112 $css_files = glob( __DIR__ . '/build/styles/*.css' ) ?? [];
113
114 foreach ( $css_files as $css_file ) {
115 // Extract the file name without the extension and prepend with 'surecart-'.
116 $handle = 'surecart-' . basename( $css_file, '.css' );
117
118 wp_register_style(
119 $handle,
120 plugins_url( 'build/styles/' . basename( $css_file ), __FILE__ ),
121 [],
122 filemtime( $css_file )
123 );
124 }
125 }
126 );
127
128 add_action(
129 'init',
130 function () {
131 // instead, use a static loader that injects the script at runtime.
132 $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/fetch/index.asset.php';
133 wp_register_script_module(
134 '@surecart/api-fetch',
135 trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/fetch/index.js',
136 array(
137 array(
138 'id' => 'wp-url',
139 'import' => 'dynamic',
140 ),
141 array(
142 'id' => 'wp-api-fetch',
143 'import' => 'dynamic',
144 ),
145 ),
146 $static_assets['version']
147 );
148
149 add_action(
150 'wp_footer',
151 function () {
152 ?>
153 <script>
154 window.scFetchData =
155 <?php
156 echo wp_json_encode(
157 [
158 'root_url' => esc_url_raw( get_rest_url() ),
159 'nonce' => ( wp_installing() && ! is_multisite() ) ? '' : wp_create_nonce( 'wp_rest' ),
160 'nonce_endpoint' => admin_url( 'admin-ajax.php?action=sc-rest-nonce' ),
161 ]
162 );
163 ?>
164 </script>
165 <?php
166 }
167 );
168
169 // instead, use a static loader that injects the script at runtime.
170 $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/dialog/index.asset.php';
171 wp_register_script_module(
172 '@surecart/dialog',
173 trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/dialog/index.js',
174 array(
175 array(
176 'id' => '@wordpress/interactivity',
177 'import' => 'dynamic',
178 ),
179 ),
180 $static_assets['version']
181 );
182
183 // instead, use a static loader that injects the script at runtime.
184 $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/dropdown/index.asset.php';
185 wp_register_script_module(
186 '@surecart/dropdown',
187 trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/dropdown/index.js',
188 array(
189 array(
190 'id' => '@wordpress/interactivity',
191 'import' => 'dynamic',
192 ),
193 ),
194 $static_assets['version']
195 );
196
197 // instead, use a static loader that injects the script at runtime.
198 $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/google/index.asset.php';
199 wp_register_script_module(
200 '@surecart/google-events',
201 trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/google/index.js',
202 [],
203 $static_assets['version']
204 );
205
206 // instead, use a static loader that injects the script at runtime.
207 $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/facebook/index.asset.php';
208 wp_register_script_module(
209 '@surecart/facebook-events',
210 trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/facebook/index.js',
211 [],
212 $static_assets['version']
213 );
214
215 // instead, use a static loader that injects the script at runtime.
216 $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/product-page/index.asset.php';
217 wp_register_script_module(
218 '@surecart/product-page',
219 trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/product-page/index.js',
220 [
221 [
222 'id' => '@wordpress/interactivity',
223 'import' => 'dynamic',
224 ],
225 [
226 'id' => '@surecart/checkout-service',
227 'import' => 'dynamic',
228 ],
229 [
230 'id' => '@surecart/google-events',
231 'import' => 'dynamic',
232 ],
233 [
234 'id' => '@surecart/facebook-events',
235 'import' => 'dynamic',
236 ],
237 ],
238 $static_assets['version']
239 );
240
241 // instead, use a static loader that injects the script at runtime.
242 $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/product-list/index.asset.php';
243 wp_register_script_module(
244 '@surecart/product-list',
245 trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/product-list/index.js',
246 [
247 [
248 'id' => '@wordpress/interactivity',
249 'import' => 'dynamic',
250 ],
251 [
252 'id' => '@wordpress/interactivity-router',
253 'import' => 'dynamic',
254 ],
255 [
256 'id' => '@surecart/google-events',
257 'import' => 'dynamic',
258 ],
259 [
260 'id' => '@surecart/facebook-events',
261 'import' => 'dynamic',
262 ],
263 ],
264 $static_assets['version']
265 );
266
267 // instead, use a static loader that injects the script at runtime.
268 $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/image-slider/index.asset.php';
269 wp_register_script_module(
270 '@surecart/image-slider',
271 trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/image-slider/index.js',
272 array(
273 array(
274 'id' => '@wordpress/interactivity',
275 'import' => 'dynamic',
276 ),
277 ),
278 $static_assets['version']
279 );
280
281 // Checkout actions.
282 $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/checkout-actions/index.asset.php';
283 wp_register_script_module(
284 '@surecart/checkout-service',
285 trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/checkout-actions/index.js',
286 array(
287 array(
288 'id' => '@surecart/api-fetch',
289 'import' => 'dynamic',
290 ),
291 array(
292 'id' => '@wordpress/interactivity',
293 'import' => 'dynamic',
294 ),
295 ),
296 $static_assets['version']
297 );
298
299 // Checkout events.
300 $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/checkout-events/index.asset.php';
301 wp_register_script_module(
302 '@surecart/checkout-events',
303 trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/checkout-events/index.js',
304 [],
305 $static_assets['version']
306 );
307
308 // Cart side drawer.
309 $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/cart/index.asset.php';
310 wp_register_script_module(
311 '@surecart/cart',
312 trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/cart/index.js',
313 array(
314 array(
315 'id' => '@surecart/checkout',
316 'import' => 'dynamic',
317 ),
318 array(
319 'id' => '@surecart/checkout-events',
320 'import' => 'dynamic',
321 ),
322 array(
323 'id' => '@wordpress/interactivity',
324 'import' => 'dynamic',
325 ),
326 ),
327 $static_assets['version']
328 );
329
330 // SureCart Checkout.
331 $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/checkout/index.asset.php';
332 wp_register_script_module(
333 '@surecart/checkout',
334 trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/checkout/index.js',
335 array(
336 array(
337 'id' => '@wordpress/interactivity',
338 'import' => 'dynamic',
339 ),
340 array(
341 'id' => '@surecart/checkout-service',
342 'import' => 'dynamic',
343 ),
344 array(
345 'id' => '@surecart/checkout-events',
346 'import' => 'dynamic',
347 ),
348 array(
349 'id' => '@surecart/google-events',
350 'import' => 'dynamic',
351 ),
352 array(
353 'id' => '@surecart/facebook-events',
354 'import' => 'dynamic',
355 ),
356 ),
357 $static_assets['version']
358 );
359 },
360 10,
361 3
362 );
363