index.php
639 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 ( empty( $metadata['file'] ) ) { |
| 26 | return $settings; |
| 27 | } |
| 28 | |
| 29 | // if there is a controller file, use it. |
| 30 | $controller_path = wp_normalize_path( |
| 31 | realpath( |
| 32 | dirname( $metadata['file'] ) . '/' . |
| 33 | remove_block_asset_path_prefix( 'file:./controller.php' ) |
| 34 | ) |
| 35 | ); |
| 36 | |
| 37 | if ( ! file_exists( $controller_path ) ) { |
| 38 | return $settings; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Renders the block on the server. |
| 43 | * |
| 44 | * @since 6.1.0 |
| 45 | * |
| 46 | * @param array $attributes Block attributes. |
| 47 | * @param string $content Block default content. |
| 48 | * @param WP_Block $block Block instance. |
| 49 | * |
| 50 | * @return string Returns the block content. |
| 51 | */ |
| 52 | $settings['render_callback'] = static function ( $attributes, $content, $block ) use ( $controller_path, $metadata ) { |
| 53 | $view = require $controller_path; |
| 54 | |
| 55 | if ( ! $view ) { |
| 56 | return ''; |
| 57 | } |
| 58 | |
| 59 | // if not using 'file:', then it's content output. |
| 60 | $view_path = remove_block_asset_path_prefix( $view ); |
| 61 | if ( $view_path === $view ) { |
| 62 | return $view; |
| 63 | } |
| 64 | |
| 65 | $template_path = wp_normalize_path( |
| 66 | realpath( |
| 67 | dirname( $metadata['file'] ) . '/' . |
| 68 | remove_block_asset_path_prefix( $view ) |
| 69 | ) |
| 70 | ); |
| 71 | |
| 72 | ob_start(); |
| 73 | require $template_path; |
| 74 | return ob_get_clean(); |
| 75 | }; |
| 76 | |
| 77 | return $settings; |
| 78 | }, |
| 79 | 11, |
| 80 | 2 |
| 81 | ); |
| 82 | |
| 83 | add_filter( |
| 84 | 'render_block_context', |
| 85 | function ( $context, $parsed_block ) { |
| 86 | // we have product context. |
| 87 | if ( get_query_var( 'surecart_current_product' ) ) { |
| 88 | $context['surecart/product'] = sc_get_product(); |
| 89 | } |
| 90 | |
| 91 | // pass a unique id to each product list block. |
| 92 | if ( in_array( $parsed_block['blockName'], [ 'surecart/product-list', 'surecart/product-list-related' ], true ) ) { |
| 93 | // we use our own counter to ensure uniqueness so that product page urls don't have ids. |
| 94 | global $sc_query_id; |
| 95 | $sc_query_id = sc_unique_product_list_id(); |
| 96 | } |
| 97 | |
| 98 | // pass a unique id to each product list block. |
| 99 | if ( 'surecart/product-page' === $parsed_block['blockName'] ) { |
| 100 | // we use our own counter to ensure uniqueness so that product page urls don't have ids. |
| 101 | global $sc_query_id; |
| 102 | $sc_query_id = sc_unique_product_page_id(); |
| 103 | } |
| 104 | |
| 105 | return $context; |
| 106 | }, |
| 107 | 10, |
| 108 | 2 |
| 109 | ); |
| 110 | |
| 111 | /** |
| 112 | * Register all css at src/styles folder. |
| 113 | */ |
| 114 | add_action( |
| 115 | 'init', |
| 116 | function () { |
| 117 | $css_files = glob( __DIR__ . '/build/styles/*.css' ) ?? []; |
| 118 | |
| 119 | foreach ( $css_files as $css_file ) { |
| 120 | // Extract the file name without the extension and prepend with 'surecart-'. |
| 121 | $handle = 'surecart-' . basename( $css_file, '.css' ); |
| 122 | |
| 123 | wp_register_style( |
| 124 | $handle, |
| 125 | plugins_url( 'build/styles/' . basename( $css_file ), __FILE__ ), |
| 126 | [], |
| 127 | filemtime( $css_file ) |
| 128 | ); |
| 129 | } |
| 130 | } |
| 131 | ); |
| 132 | |
| 133 | add_action( |
| 134 | 'wp_footer', |
| 135 | function () { |
| 136 | // if lightbox is enqueued, then add the lightbox markup. |
| 137 | if ( ! wp_style_is( 'surecart-lightbox', 'enqueued' ) ) { |
| 138 | return; |
| 139 | } |
| 140 | |
| 141 | $close_button_label = esc_attr__( 'Close', 'surecart' ); |
| 142 | $dialog_label = esc_attr__( 'Enlarged images', 'surecart' ); |
| 143 | $prev_button_label = esc_attr__( 'Previous', 'surecart' ); |
| 144 | $next_button_label = esc_attr__( 'Next', 'surecart' ); |
| 145 | |
| 146 | // If the current theme does NOT have a `theme.json`, or the colors are not |
| 147 | // defined, it needs to set the background color & close button color to some |
| 148 | // default values because it can't get them from the Global Styles. |
| 149 | $background_color = '#fff'; |
| 150 | $close_button_color = '#000'; |
| 151 | if ( wp_theme_has_theme_json() ) { |
| 152 | $global_styles_color = wp_get_global_styles( array( 'color' ) ); |
| 153 | if ( ! empty( $global_styles_color['background'] ) ) { |
| 154 | $background_color = esc_attr( $global_styles_color['background'] ); |
| 155 | } |
| 156 | if ( ! empty( $global_styles_color['text'] ) ) { |
| 157 | $close_button_color = esc_attr( $global_styles_color['text'] ); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | echo <<<HTML |
| 162 | <div |
| 163 | class="sc-lightbox-overlay zoom" |
| 164 | aria-label="$dialog_label" |
| 165 | data-wp-interactive="surecart/lightbox" |
| 166 | data-wp-bind--role="state.roleAttribute" |
| 167 | data-wp-bind--aria-modal="state.ariaModal" |
| 168 | data-wp-class--active="state.overlayEnabled" |
| 169 | data-wp-class--show-closing-animation="state.showClosingAnimation" |
| 170 | data-wp-watch="callbacks.setOverlayFocus" |
| 171 | data-wp-on--keydown="actions.handleKeydown" |
| 172 | data-wp-on--touchstart="actions.handleTouchStart" |
| 173 | data-wp-on--touchmove="actions.handleTouchMove" |
| 174 | data-wp-on--touchend="actions.handleTouchEnd" |
| 175 | data-wp-on--click="actions.hideLightbox" |
| 176 | data-wp-on-window--resize="callbacks.setOverlayStyles" |
| 177 | data-wp-on-window--scroll="actions.handleScroll" |
| 178 | tabindex="-1" |
| 179 | > |
| 180 | <button type="button" aria-label="$close_button_label" style="fill: $close_button_color" class="sc-lightbox-close-button"> |
| 181 | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20" aria-hidden="true" focusable="false">><path d="m13.06 12 6.47-6.47-1.06-1.06L12 10.94 5.53 4.47 4.47 5.53 10.94 12l-6.47 6.47 1.06 1.06L12 13.06l6.47 6.47 1.06-1.06L13.06 12Z"></path></svg> |
| 182 | </button> |
| 183 | <button type="button" aria-label="$prev_button_label" style="fill: $close_button_color" class="sc-lightbox-prev-button" data-wp-bind--hidden="!state.hasNavigation" data-wp-on--click="actions.showPreviousImage" data-wp-bind--aria-disabled="!state.hasPreviousImage"> |
| 184 | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="28" height="28" aria-hidden="true" focusable="false">><path d="M14.6 7l-1.2-1L8 12l5.4 6 1.2-1-4.6-5z"></path></svg> |
| 185 | </button> |
| 186 | <button type="button" aria-label="$next_button_label" style="fill: $close_button_color" class="sc-lightbox-next-button" data-wp-bind--hidden="!state.hasNavigation" data-wp-on--click="actions.showNextImage" data-wp-bind--aria-disabled="!state.hasNextImage"> |
| 187 | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="28" height="28" aria-hidden="true" focusable="false">><path d="M10.6 6L9.4 7l4.6 5-4.6 5 1.2 1 5.4-6z"></path></svg> |
| 188 | </button> |
| 189 | <div class="sc-lightbox-image-container"> |
| 190 | <figure> |
| 191 | <img data-wp-bind--alt="state.currentImage.alt" data-wp-bind--class="state.currentImage.imgClassNames" data-wp-bind--style="state.imgStyles" data-wp-bind--src="state.currentImage.currentSrc"> |
| 192 | </figure> |
| 193 | </div> |
| 194 | <div class="sc-lightbox-image-container"> |
| 195 | <figure> |
| 196 | <img data-wp-bind--alt="state.currentImage.alt" data-wp-bind--class="state.currentImage.imgClassNames" data-wp-bind--style="state.imgStyles" data-wp-bind--src="state.enlargedSrc"> |
| 197 | </figure> |
| 198 | </div> |
| 199 | <div data-wp-watch="callbacks.setScreenReaderText" aria-live="polite" aria-atomic="true" class="lightbox-speak screen-reader-text"></div> |
| 200 | <div class="scrim" style="background-color: $background_color" aria-hidden="true"></div> |
| 201 | <style data-wp-text="state.overlayStyles"></style> |
| 202 | </div> |
| 203 | HTML; |
| 204 | }, |
| 205 | ); |
| 206 | |
| 207 | add_action( |
| 208 | 'init', |
| 209 | function () { |
| 210 | // Skip script module registration if build files don't exist. |
| 211 | $build_path = trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/'; |
| 212 | if ( ! is_dir( $build_path ) ) { |
| 213 | return; |
| 214 | } |
| 215 | |
| 216 | // instead, use a static loader that injects the script at runtime. |
| 217 | $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/fetch/index.asset.php'; |
| 218 | wp_register_script_module( |
| 219 | '@surecart/api-fetch', |
| 220 | trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/fetch/index.js', |
| 221 | $static_assets['dependencies'], |
| 222 | $static_assets['version'] |
| 223 | ); |
| 224 | |
| 225 | add_action( |
| 226 | 'wp_footer', |
| 227 | function () { |
| 228 | ?> |
| 229 | <script> |
| 230 | window.scFetchData = |
| 231 | <?php |
| 232 | echo wp_json_encode( |
| 233 | [ |
| 234 | 'root_url' => esc_url_raw( get_rest_url() ), |
| 235 | 'nonce' => ( wp_installing() && ! is_multisite() ) ? '' : wp_create_nonce( 'wp_rest' ), |
| 236 | 'nonce_endpoint' => admin_url( 'admin-ajax.php?action=sc-rest-nonce' ), |
| 237 | ] |
| 238 | ); |
| 239 | ?> |
| 240 | </script> |
| 241 | <?php |
| 242 | } |
| 243 | ); |
| 244 | |
| 245 | // instead, use a static loader that injects the script at runtime. |
| 246 | $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/dialog/index.asset.php'; |
| 247 | wp_register_script_module( |
| 248 | '@surecart/dialog', |
| 249 | trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/dialog/index.js', |
| 250 | array( |
| 251 | array( |
| 252 | 'id' => '@wordpress/interactivity', |
| 253 | 'import' => 'dynamic', |
| 254 | ), |
| 255 | ), |
| 256 | $static_assets['version'] |
| 257 | ); |
| 258 | |
| 259 | // instead, use a static loader that injects the script at runtime. |
| 260 | $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/dropdown/index.asset.php'; |
| 261 | wp_register_script_module( |
| 262 | '@surecart/dropdown', |
| 263 | trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/dropdown/index.js', |
| 264 | array( |
| 265 | array( |
| 266 | 'id' => '@wordpress/interactivity', |
| 267 | 'import' => 'dynamic', |
| 268 | ), |
| 269 | ), |
| 270 | $static_assets['version'] |
| 271 | ); |
| 272 | |
| 273 | // instead, use a static loader that injects the script at runtime. |
| 274 | $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/google/index.asset.php'; |
| 275 | wp_register_script_module( |
| 276 | '@surecart/google-events', |
| 277 | trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/google/index.js', |
| 278 | [], |
| 279 | $static_assets['version'] |
| 280 | ); |
| 281 | |
| 282 | // instead, use a static loader that injects the script at runtime. |
| 283 | $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/facebook/index.asset.php'; |
| 284 | wp_register_script_module( |
| 285 | '@surecart/facebook-events', |
| 286 | trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/facebook/index.js', |
| 287 | [], |
| 288 | $static_assets['version'] |
| 289 | ); |
| 290 | |
| 291 | // instead, use a static loader that injects the script at runtime. |
| 292 | $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/product-page/index.asset.php'; |
| 293 | wp_register_script_module( |
| 294 | '@surecart/product-page', |
| 295 | trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/product-page/index.js', |
| 296 | [ |
| 297 | [ |
| 298 | 'id' => '@wordpress/interactivity', |
| 299 | 'import' => 'dynamic', |
| 300 | ], |
| 301 | [ |
| 302 | 'id' => '@surecart/checkout-service', |
| 303 | 'import' => 'dynamic', |
| 304 | ], |
| 305 | [ |
| 306 | 'id' => '@surecart/google-events', |
| 307 | 'import' => 'dynamic', |
| 308 | ], |
| 309 | [ |
| 310 | 'id' => '@surecart/facebook-events', |
| 311 | 'import' => 'dynamic', |
| 312 | ], |
| 313 | [ |
| 314 | 'id' => '@wordpress/a11y', |
| 315 | 'import' => 'dynamic', |
| 316 | ], |
| 317 | ], |
| 318 | $static_assets['version'] |
| 319 | ); |
| 320 | |
| 321 | // Product review script. |
| 322 | $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/product-review/index.asset.php'; |
| 323 | wp_register_script_module( |
| 324 | '@surecart/product-review', |
| 325 | trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/product-review/index.js', |
| 326 | [ |
| 327 | [ |
| 328 | 'id' => '@wordpress/interactivity', |
| 329 | 'import' => 'dynamic', |
| 330 | ], |
| 331 | [ |
| 332 | 'id' => '@wordpress/a11y', |
| 333 | 'import' => 'dynamic', |
| 334 | ], |
| 335 | ], |
| 336 | $static_assets['version'] |
| 337 | ); |
| 338 | |
| 339 | // Product review form script. |
| 340 | $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/product-review-form/index.asset.php'; |
| 341 | wp_register_script_module( |
| 342 | '@surecart/product-review-form', |
| 343 | trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/product-review-form/index.js', |
| 344 | [ |
| 345 | [ |
| 346 | 'id' => '@wordpress/interactivity', |
| 347 | 'import' => 'dynamic', |
| 348 | ], |
| 349 | [ |
| 350 | 'id' => 'surecart/lightbox', |
| 351 | 'import' => 'dynamic', |
| 352 | ], |
| 353 | [ |
| 354 | 'id' => '@wordpress/a11y', |
| 355 | 'import' => 'dynamic', |
| 356 | ], |
| 357 | ], |
| 358 | $static_assets['version'] |
| 359 | ); |
| 360 | |
| 361 | // Sticky purchase button interactivity script. |
| 362 | $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/sticky-purchase/index.asset.php'; |
| 363 | wp_register_script_module( |
| 364 | '@surecart/sticky-purchase', |
| 365 | trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/sticky-purchase/index.js', |
| 366 | array( |
| 367 | array( |
| 368 | 'id' => '@wordpress/interactivity', |
| 369 | 'import' => 'dynamic', |
| 370 | ), |
| 371 | array( |
| 372 | 'id' => '@surecart/product-page', |
| 373 | 'import' => 'dynamic', |
| 374 | ), |
| 375 | ), |
| 376 | $static_assets['version'] |
| 377 | ); |
| 378 | |
| 379 | // instead, use a static loader that injects the script at runtime. |
| 380 | $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/product-list/index.asset.php'; |
| 381 | wp_register_script_module( |
| 382 | '@surecart/product-list', |
| 383 | trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/product-list/index.js', |
| 384 | [ |
| 385 | [ |
| 386 | 'id' => '@wordpress/interactivity', |
| 387 | 'import' => 'dynamic', |
| 388 | ], |
| 389 | [ |
| 390 | 'id' => '@wordpress/interactivity-router', |
| 391 | 'import' => 'dynamic', |
| 392 | ], |
| 393 | [ |
| 394 | 'id' => '@surecart/google-events', |
| 395 | 'import' => 'dynamic', |
| 396 | ], |
| 397 | [ |
| 398 | 'id' => '@surecart/facebook-events', |
| 399 | 'import' => 'dynamic', |
| 400 | ], |
| 401 | ], |
| 402 | $static_assets['version'] |
| 403 | ); |
| 404 | |
| 405 | // instead, use a static loader that injects the script at runtime. |
| 406 | $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/image-slider/index.asset.php'; |
| 407 | wp_register_script_module( |
| 408 | '@surecart/image-slider', |
| 409 | trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/image-slider/index.js', |
| 410 | array( |
| 411 | array( |
| 412 | 'id' => '@wordpress/interactivity', |
| 413 | 'import' => 'dynamic', |
| 414 | ), |
| 415 | ), |
| 416 | $static_assets['version'] |
| 417 | ); |
| 418 | |
| 419 | // instead, use a static loader that injects the script at runtime. |
| 420 | $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/lightbox/index.asset.php'; |
| 421 | wp_register_script_module( |
| 422 | 'surecart/lightbox', |
| 423 | trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/lightbox/index.js', |
| 424 | array( |
| 425 | array( |
| 426 | 'id' => '@wordpress/interactivity', |
| 427 | 'import' => 'dynamic', |
| 428 | ), |
| 429 | ), |
| 430 | $static_assets['version'] |
| 431 | ); |
| 432 | |
| 433 | $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/video/index.asset.php'; |
| 434 | wp_register_script_module( |
| 435 | '@surecart/video', |
| 436 | trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/video/index.js', |
| 437 | array( |
| 438 | array( |
| 439 | 'id' => '@wordpress/interactivity', |
| 440 | 'import' => 'dynamic', |
| 441 | ), |
| 442 | ), |
| 443 | $static_assets['version'] |
| 444 | ); |
| 445 | |
| 446 | // Checkout actions. |
| 447 | $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/checkout-actions/index.asset.php'; |
| 448 | wp_register_script_module( |
| 449 | '@surecart/checkout-service', |
| 450 | trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/checkout-actions/index.js', |
| 451 | array( |
| 452 | array( |
| 453 | 'id' => '@surecart/api-fetch', |
| 454 | 'import' => 'dynamic', |
| 455 | ), |
| 456 | array( |
| 457 | 'id' => '@wordpress/interactivity', |
| 458 | 'import' => 'dynamic', |
| 459 | ), |
| 460 | ), |
| 461 | $static_assets['version'] |
| 462 | ); |
| 463 | |
| 464 | // Checkout events. |
| 465 | $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/checkout-events/index.asset.php'; |
| 466 | wp_register_script_module( |
| 467 | '@surecart/checkout-events', |
| 468 | trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/checkout-events/index.js', |
| 469 | [], |
| 470 | $static_assets['version'] |
| 471 | ); |
| 472 | |
| 473 | // Cart side drawer. |
| 474 | $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/cart/index.asset.php'; |
| 475 | wp_register_script_module( |
| 476 | '@surecart/cart', |
| 477 | trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/cart/index.js', |
| 478 | array( |
| 479 | array( |
| 480 | 'id' => '@surecart/checkout', |
| 481 | 'import' => 'dynamic', |
| 482 | ), |
| 483 | array( |
| 484 | 'id' => '@surecart/checkout-events', |
| 485 | 'import' => 'dynamic', |
| 486 | ), |
| 487 | array( |
| 488 | 'id' => '@wordpress/interactivity', |
| 489 | 'import' => 'dynamic', |
| 490 | ), |
| 491 | ), |
| 492 | $static_assets['version'] |
| 493 | ); |
| 494 | |
| 495 | // Product Quick View. |
| 496 | $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/product-quick-view/index.asset.php'; |
| 497 | wp_register_script_module( |
| 498 | '@surecart/product-quick-view', |
| 499 | trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/product-quick-view/index.js', |
| 500 | array( |
| 501 | array( |
| 502 | 'id' => '@surecart/checkout', |
| 503 | 'import' => 'dynamic', |
| 504 | ), |
| 505 | array( |
| 506 | 'id' => '@surecart/product-page', |
| 507 | 'import' => 'dynamic', |
| 508 | ), |
| 509 | array( |
| 510 | 'id' => 'surecart/lightbox', |
| 511 | 'import' => 'dynamic', |
| 512 | ), |
| 513 | array( |
| 514 | 'id' => '@surecart/image-slider', |
| 515 | 'import' => 'dynamic', |
| 516 | ), |
| 517 | array( |
| 518 | 'id' => '@surecart/checkout-events', |
| 519 | 'import' => 'dynamic', |
| 520 | ), |
| 521 | array( |
| 522 | 'id' => '@wordpress/interactivity', |
| 523 | 'import' => 'dynamic', |
| 524 | ), |
| 525 | array( |
| 526 | 'id' => '@wordpress/interactivity-router', |
| 527 | 'import' => 'dynamic', |
| 528 | ), |
| 529 | ), |
| 530 | $static_assets['version'] |
| 531 | ); |
| 532 | |
| 533 | // Cart side drawer. |
| 534 | $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/sidebar/index.asset.php'; |
| 535 | wp_register_script_module( |
| 536 | '@surecart/sidebar', |
| 537 | trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/sidebar/index.js', |
| 538 | array( |
| 539 | array( |
| 540 | 'id' => '@wordpress/interactivity', |
| 541 | 'import' => 'dynamic', |
| 542 | ), |
| 543 | ), |
| 544 | $static_assets['version'] |
| 545 | ); |
| 546 | |
| 547 | // SureCart Checkout. |
| 548 | $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/checkout/index.asset.php'; |
| 549 | wp_register_script_module( |
| 550 | '@surecart/checkout', |
| 551 | trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/checkout/index.js', |
| 552 | array( |
| 553 | array( |
| 554 | 'id' => '@wordpress/interactivity', |
| 555 | 'import' => 'dynamic', |
| 556 | ), |
| 557 | array( |
| 558 | 'id' => '@surecart/checkout-service', |
| 559 | 'import' => 'dynamic', |
| 560 | ), |
| 561 | array( |
| 562 | 'id' => '@surecart/checkout-events', |
| 563 | 'import' => 'dynamic', |
| 564 | ), |
| 565 | array( |
| 566 | 'id' => '@surecart/google-events', |
| 567 | 'import' => 'dynamic', |
| 568 | ), |
| 569 | array( |
| 570 | 'id' => '@surecart/facebook-events', |
| 571 | 'import' => 'dynamic', |
| 572 | ), |
| 573 | array( |
| 574 | 'id' => '@wordpress/a11y', |
| 575 | 'import' => 'dynamic', |
| 576 | ), |
| 577 | ), |
| 578 | $static_assets['version'] |
| 579 | ); |
| 580 | |
| 581 | // Line Item Note. |
| 582 | $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/line-item-note/index.asset.php'; |
| 583 | wp_register_script_module( |
| 584 | '@surecart/line-item-note', |
| 585 | trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/line-item-note/index.js', |
| 586 | array( |
| 587 | array( |
| 588 | 'id' => '@wordpress/interactivity', |
| 589 | 'import' => 'dynamic', |
| 590 | ), |
| 591 | ), |
| 592 | $static_assets['version'] |
| 593 | ); |
| 594 | |
| 595 | // Order Bumps. |
| 596 | $static_assets = include trailingslashit( plugin_dir_path( __FILE__ ) ) . 'build/scripts/order-bumps/index.asset.php'; |
| 597 | wp_register_script_module( |
| 598 | '@surecart/order-bumps', |
| 599 | trailingslashit( plugin_dir_url( __FILE__ ) ) . 'build/scripts/order-bumps/index.js', |
| 600 | array( |
| 601 | array( |
| 602 | 'id' => '@wordpress/interactivity', |
| 603 | 'import' => 'dynamic', |
| 604 | ), |
| 605 | array( |
| 606 | 'id' => '@surecart/checkout', |
| 607 | 'import' => 'dynamic', |
| 608 | ), |
| 609 | array( |
| 610 | 'id' => '@surecart/checkout-service', |
| 611 | 'import' => 'dynamic', |
| 612 | ), |
| 613 | array( |
| 614 | 'id' => '@wordpress/a11y', |
| 615 | 'import' => 'dynamic', |
| 616 | ), |
| 617 | ), |
| 618 | $static_assets['version'] |
| 619 | ); |
| 620 | }, |
| 621 | 10, |
| 622 | 3 |
| 623 | ); |
| 624 | |
| 625 | /** |
| 626 | * Load custom block styles only when the block is used. |
| 627 | */ |
| 628 | add_action( |
| 629 | 'init', |
| 630 | function () { |
| 631 | // Scan our styles folder to locate block styles. |
| 632 | $files = glob( __DIR__ . '/src/blocks-styles/**.php' ); |
| 633 | foreach ( $files as $file ) { |
| 634 | include $file; |
| 635 | } |
| 636 | } |
| 637 | ); |
| 638 | |
| 639 |