elementor-controller.php
82 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Widgets; |
| 5 | |
| 6 | use Jet_Form_Builder\Plugin; |
| 7 | use Jet_Form_Builder\Widgets\Types; |
| 8 | |
| 9 | class Elementor_Controller { |
| 10 | |
| 11 | private $_types = array(); |
| 12 | |
| 13 | public function __construct() { |
| 14 | add_action( 'elementor/init', array( $this, 'setup_widgets' ) ); |
| 15 | add_action( 'elementor/editor/after_enqueue_styles', array( $this, 'editor_styles' ) ); |
| 16 | add_action( 'elementor/widgets/widgets_registered', array( $this, 'register_widgets' ), 11 ); |
| 17 | add_action( 'elementor/preview/enqueue_scripts', array( $this, 'enqueue_form_assets' ) ); |
| 18 | add_action( 'elementor/elements/categories_registered', array( $this, 'register_category' ) ); |
| 19 | } |
| 20 | |
| 21 | public function enqueue_form_assets() { |
| 22 | wp_enqueue_style( 'jet-form-builder-frontend' ); |
| 23 | } |
| 24 | |
| 25 | private function widgets() { |
| 26 | return array( |
| 27 | new Types\Form(), |
| 28 | ); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Register category for elementor if not exists |
| 33 | * |
| 34 | * @return void |
| 35 | */ |
| 36 | public function register_category() { |
| 37 | |
| 38 | $elements_manager = \Elementor\Plugin::instance()->elements_manager; |
| 39 | |
| 40 | $elements_manager->add_category( |
| 41 | 'jet-form-builder', |
| 42 | array( |
| 43 | 'title' => esc_html__( 'JetFormBuilder', 'jet-form-builder' ), |
| 44 | 'icon' => 'font', |
| 45 | ) |
| 46 | ); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Enqueue editor styles |
| 51 | * |
| 52 | * @return void |
| 53 | */ |
| 54 | public function editor_styles() { |
| 55 | wp_enqueue_style( |
| 56 | 'jet-form-builder-icons', |
| 57 | jet_form_builder()->plugin_url( 'assets/css/icons.css' ), |
| 58 | array(), |
| 59 | jet_form_builder()->get_version() |
| 60 | ); |
| 61 | |
| 62 | } |
| 63 | |
| 64 | public function setup_widgets() { |
| 65 | foreach ( $this->widgets() as $widget ) { |
| 66 | $this->setup_widget( $widget ); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | private function setup_widget( $widget ) { |
| 71 | $widget->init_hooks(); |
| 72 | $this->_types[ $widget->get_name() ] = $widget; |
| 73 | } |
| 74 | |
| 75 | public function register_widgets( $manager ) { |
| 76 | foreach ( $this->_types as $widget ) { |
| 77 | $manager->register_widget_type( $widget ); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | } |
| 82 |