PluginProbe
Hello Plus / 1.1.3
Hello Plus v1.1.3
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 1.1.3, at modules/forms/module.php

144 lines 3.3 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' ],
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
98 public function register_scripts() {
99 wp_register_script(
100 'helloplus-forms-fe',
101 HELLOPLUS_SCRIPTS_URL . 'helloplus-forms-fe.js',
102 [ 'elementor-common', 'elementor-frontend-modules', 'elementor-frontend' ],
103 HELLOPLUS_VERSION,
104 true
105 );
106
107 wp_localize_script(
108 'helloplus-forms-fe',
109 'ehpFormsData',
110 [
111 'nonce' => wp_create_nonce( Ajax_Handler::NONCE_ACTION ),
112 ]
113 );
114 }
115
116 protected function get_component_ids(): array {
117 return [ 'Ajax_Handler' ];
118 }
119
120 public static function get_site_domain() {
121 return str_ireplace( 'www.', '', wp_parse_url( home_url(), PHP_URL_HOST ) );
122 }
123
124 protected function register_hooks(): void {
125 parent::register_hooks();
126
127 add_action( 'elementor/frontend/after_register_scripts', [ $this, 'register_scripts' ] );
128 add_action( 'elementor/frontend/after_register_styles', [ $this, 'register_styles' ] );
129 add_action( 'elementor/controls/register', [ $this, 'register_controls' ] );
130 add_action( 'elementor/editor/after_enqueue_scripts', [ $this, 'enqueue_editor_scripts' ] );
131 }
132
133 /**
134 * Module constructor.
135 */
136 public function __construct() {
137 parent::__construct();
138
139 // Initialize registrars.
140 $this->actions_registrar = new Form_Actions_Registrar();
141 $this->fields_registrar = new Form_Fields_Registrar();
142 }
143 }
144