Conditions
1 year ago
Documents
1 year ago
DynamicTags
5 months ago
Widgets
5 days ago
assets
5 months ago
ElementorBlockAdapterService.php
5 months ago
ElementorCoreBlockStylesService.php
1 year ago
ElementorDocumentsService.php
1 year ago
ElementorDynamicTagsService.php
1 year ago
ElementorEditorService.php
1 year ago
ElementorFseScriptLoaderService.php
1 year ago
ElementorServiceProvider.php
9 months ago
ElementorShortcodeService.php
1 year ago
ElementorTemplatesService.php
5 months ago
ElementorWidgetsService.php
8 months ago
ElementorEditorService.php
106 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Integrations\Elementor; |
| 4 | |
| 5 | /** |
| 6 | * Class to handle elementor editor scripts. |
| 7 | */ |
| 8 | class ElementorEditorService { |
| 9 | /** |
| 10 | * Templates service instance. |
| 11 | * |
| 12 | * @var ElementorTemplatesService |
| 13 | */ |
| 14 | protected $templates_service; |
| 15 | |
| 16 | /** |
| 17 | * Constructor. |
| 18 | */ |
| 19 | public function __construct() { |
| 20 | $this->templates_service = new ElementorTemplatesService(); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Bootstrap the service. |
| 25 | * |
| 26 | * @return void |
| 27 | */ |
| 28 | public function bootstrap() { |
| 29 | add_action( 'elementor/frontend/before_enqueue_styles', [ $this, 'enqueue_editor_styles' ], 1 ); |
| 30 | add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_editor_scripts' ] ); |
| 31 | add_action( 'elementor/editor/after_enqueue_scripts', [ $this, 'show_template_selection_modal' ] ); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Enqueue SureCart editor assets. |
| 36 | * |
| 37 | * @return void |
| 38 | */ |
| 39 | public function enqueue_editor_styles() { |
| 40 | wp_register_style( |
| 41 | 'surecart-elementor-editor', |
| 42 | plugins_url( 'app/src/Integrations/Elementor/assets/editor.css', SURECART_PLUGIN_FILE ), |
| 43 | [], |
| 44 | filemtime( plugin_dir_path( SURECART_PLUGIN_FILE ) . 'app/src/Integrations/Elementor/assets/editor.css' ) |
| 45 | ); |
| 46 | |
| 47 | wp_enqueue_style( 'surecart-elementor-editor' ); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Enqueue editor scripts. |
| 52 | * |
| 53 | * @return void |
| 54 | */ |
| 55 | public function enqueue_editor_scripts() { |
| 56 | wp_enqueue_script( |
| 57 | 'surecart-elementor-editor', |
| 58 | plugins_url( 'assets/editor.js', __FILE__ ), |
| 59 | array( 'jquery' ), |
| 60 | \SureCart::plugin()->version(), |
| 61 | true |
| 62 | ); |
| 63 | |
| 64 | wp_enqueue_style( |
| 65 | 'surecart-elementor-style', |
| 66 | plugins_url( 'assets/editor.css', __FILE__ ), |
| 67 | '', |
| 68 | \SureCart::plugin()->version(), |
| 69 | 'all' |
| 70 | ); |
| 71 | |
| 72 | wp_localize_script( |
| 73 | 'surecart-elementor-editor', |
| 74 | 'scElementorData', |
| 75 | [ |
| 76 | 'site_url' => site_url(), |
| 77 | 'templates' => $this->templates_service->get_templates(), |
| 78 | 'i18n' => [ |
| 79 | 'no_product_form_templates' => __( 'No product form templates available.', 'surecart' ), |
| 80 | 'no_product_card_templates' => __( 'No product card templates available.', 'surecart' ), |
| 81 | 'no_templates' => __( 'No templates found.', 'surecart' ), |
| 82 | ], |
| 83 | ] |
| 84 | ); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Output the template selection modal. |
| 89 | * |
| 90 | * @return void |
| 91 | */ |
| 92 | public function show_template_selection_modal() { |
| 93 | $all_templates = $this->templates_service->get_templates(); |
| 94 | |
| 95 | // Filter out hidden templates for the list. |
| 96 | $templates = array_filter( |
| 97 | $all_templates, |
| 98 | function ( $template ) { |
| 99 | return ! ( isset( $template['hidden'] ) && true === $template['hidden'] ); |
| 100 | } |
| 101 | ); |
| 102 | |
| 103 | require plugin_dir_path( SURECART_PLUGIN_FILE ) . 'templates/elementor/template-selector-modal.php'; |
| 104 | } |
| 105 | } |
| 106 |