Conditions
1 year ago
Documents
1 year ago
DynamicTags
4 months ago
Widgets
2 months ago
assets
4 months ago
ElementorBlockAdapterService.php
4 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
8 months ago
ElementorShortcodeService.php
1 year ago
ElementorTemplatesService.php
4 months ago
ElementorWidgetsService.php
8 months ago
ElementorWidgetsService.php
121 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Integrations\Elementor; |
| 4 | |
| 5 | /** |
| 6 | * Class to handle elementor widgets. |
| 7 | */ |
| 8 | class ElementorWidgetsService { |
| 9 | /** |
| 10 | * The widgets. |
| 11 | * |
| 12 | * @var array |
| 13 | */ |
| 14 | protected $free_widgets = [ |
| 15 | 'ReusableFormWidget', |
| 16 | 'CartMenuIcon', |
| 17 | ]; |
| 18 | |
| 19 | /** |
| 20 | * Bootstrap the service. |
| 21 | * |
| 22 | * @return void |
| 23 | */ |
| 24 | public function bootstrap() { |
| 25 | add_action( 'init', [ $this, 'registerStyles' ] ); |
| 26 | add_action( 'elementor/elements/categories_registered', [ $this, 'registerCategories' ] ); |
| 27 | add_action( 'elementor/widgets/register', [ $this, 'registerWidgets' ] ); |
| 28 | add_action( 'elementor/frontend/after_enqueue_styles', [ $this, 'enqueueStyles' ], 1 ); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Register the styles. |
| 33 | * |
| 34 | * @return void |
| 35 | */ |
| 36 | public function registerStyles() { |
| 37 | wp_register_style( 'surecart-elementor-container-style', plugins_url( 'assets/container.css', __FILE__ ), [], '1.0', 'all' ); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Enqueue the styles. |
| 42 | * |
| 43 | * @return void |
| 44 | */ |
| 45 | public function enqueueStyles() { |
| 46 | wp_enqueue_style( 'surecart-elementor-container-style' ); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Elementor surecart categories register. |
| 51 | * |
| 52 | * @param \Elementor\Elements_Manager $elements_manager The elements manager. |
| 53 | * |
| 54 | * @return void |
| 55 | */ |
| 56 | public function registerCategories( $elements_manager ) { |
| 57 | $elements_manager->add_category( |
| 58 | 'surecart-elementor-layout', |
| 59 | [ |
| 60 | 'title' => esc_html__( 'SureCart Layout', 'surecart' ), |
| 61 | 'icon' => 'fa fa-plug', |
| 62 | ] |
| 63 | ); |
| 64 | |
| 65 | $elements_manager->add_category( |
| 66 | 'surecart-elementor-elements', |
| 67 | [ |
| 68 | 'title' => esc_html__( 'SureCart Elements', 'surecart' ), |
| 69 | 'icon' => 'fa fa-plug', |
| 70 | ] |
| 71 | ); |
| 72 | |
| 73 | $elements_manager->add_category( |
| 74 | 'surecart-elementor-checkout', |
| 75 | [ |
| 76 | 'title' => esc_html__( 'SureCart Checkout Page', 'surecart' ), |
| 77 | 'icon' => 'fa fa-plug', |
| 78 | ] |
| 79 | ); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Register the widgets. |
| 84 | * |
| 85 | * @param \Elementor\Widgets_Manager $widget_manager Widget manager. |
| 86 | * |
| 87 | * @return void |
| 88 | */ |
| 89 | public function registerWidgets( $widget_manager ) { |
| 90 | if ( ! class_exists( '\Elementor\Widget_Base' ) ) { |
| 91 | return; |
| 92 | } |
| 93 | |
| 94 | foreach ( glob( __DIR__ . '/Widgets/*.php' ) as $file ) { |
| 95 | if ( ! is_readable( $file ) ) { |
| 96 | continue; |
| 97 | } |
| 98 | |
| 99 | // pro is not active and the widget is not in the free widgets array. |
| 100 | if ( ! $this->is_pro_active() && ! in_array( basename( $file, '.php' ), $this->free_widgets, true ) ) { |
| 101 | continue; |
| 102 | } |
| 103 | |
| 104 | require_once $file; |
| 105 | $get_declared_classes = get_declared_classes(); |
| 106 | $widget_class_name = end( $get_declared_classes ); |
| 107 | |
| 108 | $widget_manager->register( new $widget_class_name() ); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Check if Elementor Pro is active. |
| 114 | * |
| 115 | * @return bool |
| 116 | */ |
| 117 | protected function is_pro_active(): bool { |
| 118 | return class_exists( '\ElementorPro\Plugin' ); |
| 119 | } |
| 120 | } |
| 121 |