ElementorServiceProvider.php
80 lines
| 1 | <?php |
| 2 | namespace SureCart\Integrations\Elementor; |
| 3 | |
| 4 | use SureCartCore\ServiceProviders\ServiceProviderInterface; |
| 5 | |
| 6 | /** |
| 7 | * Elementor service provider. |
| 8 | */ |
| 9 | class ElementorServiceProvider implements ServiceProviderInterface { |
| 10 | /** |
| 11 | * Register all dependencies in the IoC container. |
| 12 | * |
| 13 | * @param \Pimple\Container $container Service container. |
| 14 | * @return void |
| 15 | */ |
| 16 | public function register( $container ) { |
| 17 | // nothing to register. |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * {@inheritDoc} |
| 22 | * |
| 23 | * @param \Pimple\Container $container Service Container. |
| 24 | */ |
| 25 | public function bootstrap( $container ) { |
| 26 | if ( ! class_exists( '\Elementor\Plugin' ) ) { |
| 27 | return; |
| 28 | } |
| 29 | add_action( 'elementor/widgets/widgets_registered', [ $this, 'widget' ] ); |
| 30 | add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'load_scripts' ] ); |
| 31 | add_action( 'elementor/elements/categories_registered', [ $this, 'categories_registered' ] ); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Elementor load scripts |
| 36 | * |
| 37 | * @return void |
| 38 | */ |
| 39 | public function load_scripts() { |
| 40 | wp_enqueue_script( 'surecart-elementor-editor', plugins_url( 'assets/editor.js', __FILE__ ), array( 'jquery' ), \SureCart::plugin()->version(), true ); |
| 41 | wp_enqueue_style( 'surecart-elementor-style', plugins_url( 'assets/editor.css', __FILE__ ), '', \SureCart::plugin()->version(), 'all' ); |
| 42 | wp_localize_script( |
| 43 | 'surecart-elementor-editor', |
| 44 | 'scElementorData', |
| 45 | [ |
| 46 | 'site_url' => site_url(), |
| 47 | ] |
| 48 | ); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Elementor surecart categories register |
| 53 | * |
| 54 | * @param Obj $elements_manager Elementor category manager. |
| 55 | * |
| 56 | * @return void |
| 57 | */ |
| 58 | public function categories_registered( $elements_manager ) { |
| 59 | $elements_manager->add_category( |
| 60 | 'surecart-elementor', |
| 61 | [ |
| 62 | 'title' => esc_html__( 'SureCart', 'surecart' ), |
| 63 | 'icon' => 'fa fa-plug', |
| 64 | ] |
| 65 | ); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Elementor widget register |
| 70 | * |
| 71 | * @return void |
| 72 | */ |
| 73 | public function widget() { |
| 74 | if ( ! class_exists( '\Elementor\Plugin' ) ) { |
| 75 | return; |
| 76 | } |
| 77 | \Elementor\Plugin::instance()->widgets_manager->register( new ReusableFormWidget() ); |
| 78 | } |
| 79 | } |
| 80 |