PluginProbe ʕ •ᴥ•ʔ
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 3.0.0-beta2
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v3.0.0-beta2
4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 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
336 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 // instead, use a static loader that injects the script at runtime.
150 $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/dialog/index.asset.php';
151 wp_register_script_module(
152 '@surecart/dialog',
153 trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/dialog/index.js',
154 array(
155 array(
156 'id' => '@wordpress/interactivity',
157 'import' => 'dynamic',
158 ),
159 ),
160 $static_assets['version']
161 );
162
163 // instead, use a static loader that injects the script at runtime.
164 $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/dropdown/index.asset.php';
165 wp_register_script_module(
166 '@surecart/dropdown',
167 trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/dropdown/index.js',
168 array(
169 array(
170 'id' => '@surecart/dialog',
171 'import' => 'dynamic',
172 ),
173 array(
174 'id' => '@wordpress/interactivity',
175 'import' => 'dynamic',
176 ),
177 ),
178 $static_assets['version']
179 );
180
181 // instead, use a static loader that injects the script at runtime.
182 $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/google/index.asset.php';
183 wp_register_script_module(
184 '@surecart/google-events',
185 trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/google/index.js',
186 [],
187 $static_assets['version']
188 );
189
190 // instead, use a static loader that injects the script at runtime.
191 $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/facebook/index.asset.php';
192 wp_register_script_module(
193 '@surecart/facebook-events',
194 trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/facebook/index.js',
195 [],
196 $static_assets['version']
197 );
198
199 // instead, use a static loader that injects the script at runtime.
200 $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/product-page/index.asset.php';
201 wp_register_script_module(
202 '@surecart/product-page',
203 trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/product-page/index.js',
204 [
205 [
206 'id' => '@surecart/dialog',
207 'import' => 'dynamic',
208 ],
209 [
210 'id' => '@surecart/checkout-service',
211 'import' => 'dynamic',
212 ],
213 [
214 'id' => '@surecart/google-events',
215 'import' => 'dynamic',
216 ],
217 [
218 'id' => '@surecart/facebook-events',
219 'import' => 'dynamic',
220 ],
221 ],
222 $static_assets['version']
223 );
224
225 // instead, use a static loader that injects the script at runtime.
226 $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/product-list/index.asset.php';
227 wp_register_script_module(
228 '@surecart/product-list',
229 trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/product-list/index.js',
230 [
231 [
232 'id' => '@wordpress/interactivity-router',
233 'import' => 'dynamic',
234 ],
235 [
236 'id' => '@surecart/google-events',
237 'import' => 'dynamic',
238 ],
239 [
240 'id' => '@surecart/facebook-events',
241 'import' => 'dynamic',
242 ],
243 ],
244 $static_assets['version']
245 );
246
247 // instead, use a static loader that injects the script at runtime.
248 $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/image-slider/index.asset.php';
249 wp_register_script_module(
250 '@surecart/image-slider',
251 trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/image-slider/index.js',
252 array(
253 array(
254 'id' => '@wordpress/interactivity',
255 'import' => 'dynamic',
256 ),
257 ),
258 $static_assets['version']
259 );
260
261 // Checkout actions.
262 $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/checkout-actions/index.asset.php';
263 wp_register_script_module(
264 '@surecart/checkout-service',
265 trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/checkout-actions/index.js',
266 array(
267 array(
268 'id' => '@surecart/api-fetch',
269 'import' => 'dynamic',
270 ),
271 ),
272 $static_assets['version']
273 );
274
275 // Checkout events.
276 $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/checkout-events/index.asset.php';
277 wp_register_script_module(
278 '@surecart/checkout-events',
279 trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/checkout-events/index.js',
280 array(
281 array(
282 'id' => '@surecart/api-fetch',
283 'import' => 'dynamic',
284 ),
285 ),
286 $static_assets['version']
287 );
288
289 // Cart side drawer.
290 $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/cart/index.asset.php';
291 wp_register_script_module(
292 '@surecart/cart',
293 trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/cart/index.js',
294 array(
295 array(
296 'id' => '@wordpress/interactivity',
297 'import' => 'dynamic',
298 ),
299 ),
300 $static_assets['version']
301 );
302
303 // SureCart Checkout.
304 $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/checkout/index.asset.php';
305 wp_register_script_module(
306 '@surecart/checkout',
307 trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/checkout/index.js',
308 array(
309 array(
310 'id' => '@surecart/checkout-service',
311 'import' => 'dynamic',
312 ),
313 array(
314 'id' => '@surecart/checkout-events',
315 'import' => 'dynamic',
316 ),
317 array(
318 'id' => '@surecart/google-events',
319 'import' => 'dynamic',
320 ),
321 array(
322 'id' => '@surecart/facebook-events',
323 'import' => 'dynamic',
324 ),
325 array(
326 'id' => '@surecart/cart',
327 'import' => 'dynamic',
328 ),
329 ),
330 $static_assets['version']
331 );
332 },
333 10,
334 3
335 );
336