Admin
2 years ago
Assets
2 years ago
Pages
3 years ago
PostTypes
3 years ago
Shortcodes
2 years ago
Sitemap
3 years ago
Templates
2 years ago
Users
3 years ago
ActionsService.php
3 years ago
CompatibilityService.php
2 years ago
HealthService.php
2 years ago
PluginService.php
3 years ago
PluginServiceProvider.php
2 years ago
RecaptchaValidationService.php
2 years ago
ThemeService.php
3 years ago
ThemeServiceProvider.php
3 years ago
TranslationsServiceProvider.php
3 years ago
CompatibilityService.php
90 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package SureCartAppCore |
| 4 | * @author SureCart <support@surecart.com> |
| 5 | * @copyright SureCart |
| 6 | * @license https://www.gnu.org/licenses/gpl-2.0.html GPL-2.0 |
| 7 | * @link https://surecart.com |
| 8 | */ |
| 9 | |
| 10 | namespace SureCart\WordPress; |
| 11 | |
| 12 | /** |
| 13 | * Provides compatibility with other plugins. |
| 14 | */ |
| 15 | class CompatibilityService { |
| 16 | /** |
| 17 | * Bootstrap the service. |
| 18 | * |
| 19 | * @return void |
| 20 | */ |
| 21 | public function bootstrap() { |
| 22 | // UAG fix. |
| 23 | add_action( 'render_block_data', [ $this, 'maybeEnqueueUAGBAssets' ] ); |
| 24 | |
| 25 | add_filter( 'surecart/shortcode/render', [ $this, 'maybeEnqueueUAGBAssetsForShortcode' ], 5, 3 ); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Render block data. |
| 30 | * |
| 31 | * @param array $parsed_block Block data. |
| 32 | * |
| 33 | * @return array |
| 34 | */ |
| 35 | public function maybeEnqueueUAGBAssets( $parsed_block ) { |
| 36 | // UAGB must be activated. |
| 37 | if ( ! class_exists( '\UAGB_Post_Assets' ) ) { |
| 38 | return $parsed_block; |
| 39 | } |
| 40 | |
| 41 | // must be our checkout form block. |
| 42 | if ( 'surecart/checkout-form' !== $parsed_block['blockName'] ) { |
| 43 | return $parsed_block; |
| 44 | } |
| 45 | |
| 46 | // must have an ID. |
| 47 | if ( empty( $parsed_block['attrs']['id'] ) ) { |
| 48 | return $parsed_block; |
| 49 | } |
| 50 | |
| 51 | // If Spectra Blocks are present in the form, enqueue the assets. |
| 52 | $post_assets_instance = new \UAGB_Post_Assets( $parsed_block['attrs']['id'] ); |
| 53 | $post_assets_instance->enqueue_scripts(); |
| 54 | |
| 55 | return $parsed_block; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Filter SC Form Shortcode to load the Spectra Blocks Assets. |
| 60 | * |
| 61 | * @param string $output Content. |
| 62 | * @param array $attributes Shortcode attributes. |
| 63 | * @param string $name Shortcode Tag. |
| 64 | * |
| 65 | * @return array |
| 66 | */ |
| 67 | public function maybeEnqueueUAGBAssetsForShortcode( $output, $attributes, $name ) { |
| 68 | // UAGB must be activated. |
| 69 | if ( ! class_exists( '\UAGB_Post_Assets' ) ) { |
| 70 | return $output; |
| 71 | } |
| 72 | |
| 73 | // must be our form shortcode. |
| 74 | if ( 'sc_form' !== $name ) { |
| 75 | return $output; |
| 76 | } |
| 77 | |
| 78 | // must have an ID. |
| 79 | if ( empty( $attributes['id'] ) ) { |
| 80 | return $output; |
| 81 | } |
| 82 | |
| 83 | // If Spectra Blocks are present in the form, enqueue the assets. |
| 84 | $post_assets_instance = new \UAGB_Post_Assets( $attributes['id'] ); |
| 85 | $post_assets_instance->enqueue_scripts(); |
| 86 | |
| 87 | return $output; |
| 88 | } |
| 89 | } |
| 90 |