| @@ -1,8 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace FluentForm\App\Modules\Widgets; |
| 4 | -use Elementor\Plugin as Elementor; | |
| 4 | + | |
| 5 | +defined('ABSPATH') or die; | |
| 6 | + | |
| 5 | 7 | use FluentForm\App\Modules\Widgets\FluentFormWidget; |
| 6 | 8 | |
| 7 | 9 | class ElementorWidget |
| 8 | 10 | { |
| @@ -10,51 +12,27 @@ | ||
| 10 | 12 | |
| 11 | 13 | public function __construct($app) |
| 12 | 14 | { |
| 13 | 15 | $this->app = $app; |
| 14 | - add_action( 'elementor/widgets/widgets_registered', array($this, 'init_widgets') ); | |
| 16 | + add_action('elementor/widgets/register', [$this, 'init_widgets']); | |
| 15 | 17 | } |
| 16 | 18 | |
| 17 | - | |
| 18 | - public function init_widgets() | |
| 19 | + public function init_widgets($widgets_manager) | |
| 19 | 20 | { |
| 20 | 21 | $this->enqueueAssets(); |
| 21 | 22 | |
| 22 | - $widgets_manager = Elementor::instance()->widgets_manager; | |
| 23 | - | |
| 24 | - if ( file_exists( FLUENTFORM_DIR_PATH.'app/Modules/Widgets/FluentFormWidget.php' ) ) { | |
| 25 | - require_once FLUENTFORM_DIR_PATH.'app/Modules/Widgets/FluentFormWidget.php'; | |
| 26 | - $widgets_manager->register_widget_type( new FluentFormWidget() ); | |
| 23 | + if (file_exists(FLUENTFORM_DIR_PATH . 'app/Modules/Widgets/FluentFormWidget.php')) { | |
| 24 | + require_once FLUENTFORM_DIR_PATH . 'app/Modules/Widgets/FluentFormWidget.php'; | |
| 25 | + $widgets_manager->register(new FluentFormWidget()); | |
| 27 | 26 | } |
| 28 | 27 | } |
| 29 | 28 | |
| 30 | - | |
| 31 | 29 | public function enqueueAssets() |
| 32 | 30 | { |
| 33 | - wp_enqueue_style('fluentform-elementor-widget', $this->app->publicUrl('css/fluent-forms-elementor-widget.css'), array(), FLUENTFORM_VERSION ); | |
| 34 | - } | |
| 31 | + wp_enqueue_style('fluentform-elementor-widget', fluentformMix('css/fluent-forms-elementor-widget.css'), [], FLUENTFORM_VERSION); | |
| 32 | + wp_enqueue_script('fluentform-elementor', fluentformMix('js/fluent-forms-elementor-widget.js'), [], FLUENTFORM_VERSION, true); | |
| 35 | 33 | |
| 36 | - public static function getForms() | |
| 37 | - { | |
| 38 | - $ff_list = wpFluent()->table('fluentform_forms') | |
| 39 | - ->select(['id', 'title']) | |
| 40 | - ->orderBy('id', 'DESC') | |
| 41 | - ->get(); | |
| 42 | - | |
| 43 | - | |
| 44 | - $forms = array(); | |
| 45 | - | |
| 46 | - if ($ff_list) { | |
| 47 | - $forms[0] = esc_html__('Select a Fluent Form', 'fluentform'); | |
| 48 | - foreach ($ff_list as $form) { | |
| 49 | - $forms[$form->id] = $form->title .' ('.$form->id.')'; | |
| 50 | - } | |
| 51 | - } else { | |
| 52 | - $forms[0] = esc_html__('Create a Form First', 'fluentform'); | |
| 53 | - } | |
| 54 | - | |
| 55 | - return $forms; | |
| 56 | - | |
| 34 | + wp_localize_script('fluentform-elementor', 'fluentformElementor', [ | |
| 35 | + 'adminUrl' => admin_url('admin.php'), | |
| 36 | + ]); | |
| 57 | 37 | } |
| 58 | - | |
| 59 | - | |
| 60 | 38 | } |