| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Modules\Widgets; |
| 4 |
use Elementor\Plugin as Elementor; |
| 5 |
use FluentForm\App\Modules\Widgets\FluentFormWidget; |
| 6 |
|
| 7 |
class ElementorWidget |
| 8 |
{ |
| 9 |
private $app = null; |
| 10 |
|
| 11 |
public function __construct($app) |
| 12 |
{ |
| 13 |
$this->app = $app; |
| 14 |
add_action( 'elementor/widgets/widgets_registered', array($this, 'init_widgets') ); |
| 15 |
} |
| 16 |
|
| 17 |
|
| 18 |
public function init_widgets() |
| 19 |
{ |
| 20 |
$this->enqueueAssets(); |
| 21 |
|
| 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() ); |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
public function enqueueAssets() |
| 32 |
{ |
| 33 |
wp_enqueue_style('fluentform-elementor-widget', $this->app->publicUrl('css/fluent-forms-elementor-widget.css'), array(), FLUENTFORM_VERSION ); |
| 34 |
} |
| 35 |
|
| 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 |
|
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
} |
| 61 |
|