PluginProbe
Hello Plus / trunk
Hello Plus vtrunk
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.6.0 1.6.1 1.6.2 1.7.0 1.7.1 1.7.2 1.7.3 All 30 releases
hello-plus / modules / forms / module.php

module.php in Hello Plus trunk, at modules/forms/module.php

162 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace HelloPlus\Modules\Forms;
4
5 use Elementor\Controls_Manager;
6 use HelloPlus\Includes\Module_Base;
7 use HelloPlus\Modules\Forms\components\Ajax_Handler;
8 use HelloPlus\Modules\Forms\Controls\Fields_Map;
9 use HelloPlus\Modules\Forms\Controls\Fields_Repeater;
10 use HelloPlus\Modules\Forms\Registrars\Form_Actions_Registrar;
11 use HelloPlus\Modules\Forms\Registrars\Form_Fields_Registrar;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit; // Exit if accessed directly.
15 }
16
17 class Module extends Module_Base {
18 /**
19 * @var Form_Actions_Registrar
20 */
21 public $actions_registrar;
22
23 /**
24 * @var Form_Fields_Registrar
25 */
26 public $fields_registrar;
27
28
29 public static function get_name(): string {
30 return 'forms';
31 }
32
33 protected function get_widget_ids(): array {
34 return [
35 'Ehp_Form',
36 ];
37 }
38
39 /**
40 * Get the base URL for assets.
41 *
42 * @return string
43 */
44 public function get_assets_base_url(): string {
45 return HELLOPLUS_URL;
46 }
47
48 /**
49 * Register styles.
50 *
51 * At build time, Elementor compiles `/modules/forms/assets/scss/frontend.scss`
52 * to `/assets/css/widget-forms.min.css`.
53 *
54 * @return void
55 */
56 public function register_styles() {
57 wp_register_style(
58 'helloplus-forms',
59 HELLOPLUS_STYLE_URL . 'helloplus-forms.css',
60 [ 'elementor-frontend', 'elementor-icons' ],
61 HELLOPLUS_VERSION
62 );
63 }
64
65 public static function find_element_recursive( $elements, $form_id ) {
66 foreach ( $elements as $element ) {
67 if ( $form_id === $element['id'] ) {
68 return $element;
69 }
70
71 if ( ! empty( $element['elements'] ) ) {
72 $element = self::find_element_recursive( $element['elements'], $form_id );
73
74 if ( $element ) {
75 return $element;
76 }
77 }
78 }
79
80 return false;
81 }
82
83 public function register_controls( Controls_Manager $controls_manager ) {
84 $controls_manager->register( new Fields_Repeater() );
85 $controls_manager->register( new Fields_Map() );
86 }
87
88 public function enqueue_editor_scripts() {
89 wp_enqueue_script(
90 'helloplus-forms-editor',
91 HELLOPLUS_SCRIPTS_URL . 'helloplus-forms-editor.js',
92 [ 'elementor-editor', 'wp-i18n' ],
93 HELLOPLUS_VERSION,
94 true
95 );
96
97 $promotion_data = [
98 'title' => __( 'Collect Submissions', 'hello-plus' ),
99 'description' => [ __( 'Unlock form submissions by upgrading to Elementor Pro on an eligible plan.', 'hello-plus' ) ],
100 'upgrade_text' => __( 'Upgrade', 'hello-plus' ),
101 'upgrade_url' => 'https://go.elementor.com/biz-form-submissions',
102 'image' => HELLOPLUS_IMAGES_URL . 'collect-submission.jpg',
103 'image_alt' => __( 'Upgrade', 'hello-plus' ),
104 ];
105
106 wp_localize_script(
107 'helloplus-forms-editor',
108 'ehpFormsPromotionData',
109 $promotion_data
110 );
111
112 wp_set_script_translations( 'helloplus-forms-editor', 'hello-plus' );
113 }
114
115 public function register_scripts() {
116
117 wp_register_script(
118 'helloplus-forms-fe',
119 HELLOPLUS_SCRIPTS_URL . 'helloplus-forms-fe.js',
120 [ 'elementor-frontend-modules', 'elementor-frontend' ],
121 HELLOPLUS_VERSION,
122 true
123 );
124
125 wp_localize_script(
126 'helloplus-forms-fe',
127 'ehpFormsData',
128 [
129 'nonce' => wp_create_nonce( Ajax_Handler::NONCE_ACTION ),
130 ]
131 );
132 }
133
134 protected function get_component_ids(): array {
135 return [ 'Ajax_Handler' ];
136 }
137
138 public static function get_site_domain() {
139 return str_ireplace( 'www.', '', wp_parse_url( home_url(), PHP_URL_HOST ) );
140 }
141
142 protected function register_hooks(): void {
143 parent::register_hooks();
144
145 add_action( 'elementor/frontend/after_register_scripts', [ $this, 'register_scripts' ] );
146 add_action( 'elementor/frontend/after_register_styles', [ $this, 'register_styles' ] );
147 add_action( 'elementor/controls/register', [ $this, 'register_controls' ] );
148 add_action( 'elementor/editor/after_enqueue_scripts', [ $this, 'enqueue_editor_scripts' ] );
149 }
150
151 /**
152 * Module constructor.
153 */
154 public function __construct() {
155 parent::__construct();
156
157 // Initialize registrars.
158 $this->actions_registrar = new Form_Actions_Registrar();
159 $this->fields_registrar = new Form_Fields_Registrar();
160 }
161 }
162