| 1 |
<?php |
| 2 |
|
| 3 |
namespace BitCode\BitForm\Widgets; |
| 4 |
|
| 5 |
use BitCode\BitForm\GlobalHelper; |
| 6 |
use Elementor\Controls_Manager; |
| 7 |
use Elementor\Widget_Base; |
| 8 |
|
| 9 |
if (!defined('ABSPATH')) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
|
| 13 |
class BitFormElementorWidget extends Widget_Base |
| 14 |
{ |
| 15 |
public function get_name() |
| 16 |
{ |
| 17 |
return 'bitform-widget'; |
| 18 |
} |
| 19 |
|
| 20 |
public function get_keywords() |
| 21 |
{ |
| 22 |
return [ |
| 23 |
'bitform', |
| 24 |
'bitforms', |
| 25 |
'form', |
| 26 |
'bitform widget', |
| 27 |
'form widget', |
| 28 |
'contact forms', |
| 29 |
'elementor form', |
| 30 |
'bit form', |
| 31 |
'form builder', |
| 32 |
'shortcode', |
| 33 |
]; |
| 34 |
} |
| 35 |
|
| 36 |
public function get_title() |
| 37 |
{ |
| 38 |
return __('Bit Form', 'bit-form'); |
| 39 |
} |
| 40 |
|
| 41 |
public function get_icon() |
| 42 |
{ |
| 43 |
return 'eicon-form-horizontal'; |
| 44 |
} |
| 45 |
|
| 46 |
public function get_script_depends() |
| 47 |
{ |
| 48 |
return ['bitform-style']; |
| 49 |
} |
| 50 |
|
| 51 |
public function get_categories() |
| 52 |
{ |
| 53 |
return ['general']; |
| 54 |
} |
| 55 |
|
| 56 |
protected function _register_controls() |
| 57 |
{ |
| 58 |
$this->start_controls_section( |
| 59 |
'section_bit_form', |
| 60 |
[ |
| 61 |
'label' => __('Bit Form', 'bit-form'), |
| 62 |
] |
| 63 |
); |
| 64 |
|
| 65 |
$this->add_control( |
| 66 |
'form_id', |
| 67 |
[ |
| 68 |
'label' => esc_html__('Select Forms', 'bit-form'), |
| 69 |
'type' => Controls_Manager::SELECT2, |
| 70 |
'placeholder' => esc_html__('Select a Bitform', 'bit-form'), |
| 71 |
'label_block' => true, |
| 72 |
'multiple' => false, |
| 73 |
'options' => GlobalHelper::getForms(), |
| 74 |
'default' => 0, |
| 75 |
'render_type' => 'template', |
| 76 |
] |
| 77 |
); |
| 78 |
|
| 79 |
$this->end_controls_section(); |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Render widget output on the frontend. |
| 84 |
* |
| 85 |
* @return void |
| 86 |
*/ |
| 87 |
protected function render() |
| 88 |
{ |
| 89 |
$settings = $this->get_settings_for_display(); |
| 90 |
$form_id = $settings['form_id']; |
| 91 |
|
| 92 |
if (empty($form_id)) { |
| 93 |
return; |
| 94 |
} |
| 95 |
|
| 96 |
$css_path = BITFORMS_UPLOAD_BASE_URL . '/form-styles/bitform-' . $form_id . '-formid.css'; |
| 97 |
|
| 98 |
wp_dequeue_style('bitform-style-css'); |
| 99 |
|
| 100 |
$formUpdateVersion = get_option('bitform_form_update_version'); |
| 101 |
wp_register_style('bitform-elementor-style-' . (int) $form_id, $css_path, [], $formUpdateVersion); |
| 102 |
wp_enqueue_style('bitform-elementor-style-' . (int) $form_id); |
| 103 |
|
| 104 |
if (\Elementor\Plugin::$instance->editor->is_edit_mode()) { |
| 105 |
echo '<div class="bitform-preview">'; |
| 106 |
echo do_shortcode('[bitform id="' . esc_attr($form_id) . '"]'); |
| 107 |
echo '</div>'; |
| 108 |
} else { |
| 109 |
echo do_shortcode('[bitform id="' . esc_attr($form_id) . '"]'); |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
|