PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.14
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.14
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
← All changes | app/Modules/Component/ComponentInitTrait.php +72 -60 3.6.656.2.14 View file →
@@ -1,8 +1,10 @@
1 1 <?php
2 2
3 3 namespace FluentForm\App\Modules\Component;
4 4
5 +defined('ABSPATH') or die;
6 +
5 7 trait ComponentInitTrait
6 8 {
7 9 /**
8 10 * Initialize the component and register the
@@ -13,65 +15,65 @@
13 15 // Validate certain important required properties
14 16 $this->_fluentFormValidateComponent();
15 17
16 18 // Hook to add component in the editor's components array
17 - add_filter('fluent_editor_components', [$this, '_fluentEditorComponenstCallback']);
19 + add_filter('fluentform/editor_components', [$this, '_fluentEditorComponenstCallback']);
18 20
19 21 // Hook to add search keywords for the component
20 - add_filter('fluent_editor_element_search_tags', [$this, '_fluentEditorElementSearchTagsCallback']);
21 -
22 + add_filter('fluentform/editor_element_search_tags', [$this, '_fluentEditorElementSearchTagsCallback']);
23 +
22 24 // Hook for component's editor items/options placement settings
23 - add_filter('fluent_editor_element_settings_placement', [$this, '_fluentEditorElementSettingsPlacementCallback']);
24 -
25 + add_filter('fluentform/editor_element_settings_placement', [$this, '_fluentEditorElementSettingsPlacementCallback']);
26 +
25 27 // Hook for component's customization settings
26 - add_filter('fluent_editor_element_customization_settings', [$this, '_fluentEditorElementCustomizationSettingsCallback']);
27 -
28 + add_filter('fluentform/editor_element_customization_settings', [$this, '_fluentEditorElementCustomizationSettingsCallback']);
29 +
28 30 // Hook for response data preperation on form submission
29 - add_filter('fluentform_insert_response_data', [$this, '_fluentformInsertResponseDataCallback'], 10, 3);
31 + add_filter('fluentform/insert_response_data', [$this, '_fluentformInsertResponseDataCallback'], 10, 3);
30 32
31 33 // Hook to add component type in fluentform field types to be available in FormFieldParser.
32 - add_filter('fluentform_form_input_types', [$this, '_fluentformFormInputTypesCallback']);
34 + add_filter('fluentform/form_input_types', [$this, '_fluentformFormInputTypesCallback']);
33 35
34 36 // Component render/compile hook (for form)
35 - add_action('fluentform_render_item_' . $this->element(), [$this, '_elementRenderHookCallback'], 10, 2);
36 -
37 + add_action('fluentform/render_item_' . $this->element(), [$this, '_elementRenderHookCallback'], 10, 2);
38 +
37 39 // Component's used element response transformation hook (for entries)
38 - add_filter('fluentform_response_render_' . $this->element(), [$this, '_elementEntryFormatCallback'], 10, 3);
40 + add_filter('fluentform/response_render_' . $this->element(), [$this, '_elementEntryFormatCallback'], 10, 3);
39 41 }
40 42
41 43 /**
42 44 * Validate certain required properties
43 - *
45 + *
44 46 * @return void
45 47 */
46 48 private function _fluentFormValidateComponent()
47 49 {
48 50 $name = $this->name();
49 - if (!$name || !is_string($name)) {
51 + if (! $name || ! is_string($name)) {
50 52 wp_die('The name must be a valid string.');
51 53 }
52 54
53 55 $label = $this->label();
54 - if (!$label || !is_string($label)) {
56 + if (! $label || ! is_string($label)) {
55 57 wp_die('The label must be a valid string.');
56 58 }
57 59
58 60 $element = $this->element();
59 - if (!$element || !is_string($element)) {
61 + if (! $element || ! is_string($element)) {
60 62 $elements = 'text_input, text_email, textarea';
61 - wp_die("The element must be one of the available elements, i.e: $elements e.t.c.");
63 + wp_die(esc_html("The element must be one of the available elements, i.e: $elements e.t.c."));
62 64 }
63 65
64 66 $template = $this->template();
65 - if (!$template || !is_string($template)) {
67 + if (! $template || ! is_string($template)) {
66 68 $templates = 'inputText, selectCountry. addressFields';
67 - wp_die("The template must be one of the available templates, i.e: $templates e.t.c.");
69 + wp_die(esc_html("The template must be one of the available templates, i.e: $templates e.t.c."));
68 70 }
69 71
70 72 $group = $this->group();
71 73 $groups = ['general', 'advanced', 'container'];
72 - if (!$group || !in_array($group, $groups)) {
73 - wp_die('Invalid group, available groups: ' . implode(', ', $groups) . '.');
74 + if (! $group || ! in_array($group, $groups)) {
75 + wp_die(esc_html('Invalid group, available groups: ' . implode(', ', $groups) . '.'));
74 76 }
75 77 }
76 78
77 79 /**
@@ -76,9 +78,10 @@
76 78
77 79 /**
78 80 * Add the component in fluentform editor's components array.
79 81 *
80 - * @param array $components
82 + * @param array $components
83 + *
81 84 * @return array $components
82 85 */
83 86 public function _fluentEditorComponenstCallback($components)
84 87 {
@@ -89,30 +92,30 @@
89 92 $element = $this->element();
90 93 $template = $this->template();
91 94 $iconClass = $this->elementIconClass();
92 95 $validationRules = $this->validationRules();
93 -
96 +
94 97 $settings = $this->settings([
95 - 'label' => $label,
96 - 'container_class' => '',
97 - 'label_placement' => '',
98 - 'help_message' => '',
99 - 'admin_field_label' => $label,
98 + 'label' => $label,
99 + 'container_class' => '',
100 + 'label_placement' => '',
101 + 'help_message' => '',
102 + 'admin_field_label' => $label,
100 103 'conditional_logics' => [],
101 - 'validation_rules' => $validationRules
104 + 'validation_rules' => $validationRules,
102 105 ]);
103 106
104 107 $attributes = $this->attributes([
105 - 'id' => "",
106 - 'name' => $name,
107 - 'class' => '',
108 - 'value' => '',
108 + 'id' => '',
109 + 'name' => $name,
110 + 'class' => '',
111 + 'value' => '',
109 112 'placeholder' => '',
110 113 ]);
111 114
112 115 $editorOptions = $this->options([
113 - 'title' => $label,
114 - 'template' => $template,
116 + 'title' => $label,
117 + 'template' => $template,
115 118 'icon_class' => $iconClass,
116 119 ]);
117 120
118 121 if (is_null($index)) {
@@ -119,12 +122,12 @@
119 122 $index = count($components[$group]) + 1;
120 123 }
121 124
122 125 $components[$group][] = [
123 - 'index' => $index,
124 - 'element' => $element,
125 - 'settings' => $settings,
126 - 'attributes' => $attributes,
126 + 'index' => $index,
127 + 'element' => $element,
128 + 'settings' => $settings,
129 + 'attributes' => $attributes,
127 130 'editor_options' => $editorOptions,
128 131 ];
129 132
130 133 return $components;
@@ -131,10 +134,11 @@
131 134 }
132 135
133 136 /**
134 137 * Add the keywords for the component to search in the editor.
135 - *
136 - * @param array $keywords
138 + *
139 + * @param array $keywords
140 + *
137 141 * @return array $keywords
138 142 */
139 143 public function _fluentEditorElementSearchTagsCallback($keywords)
140 144 {
@@ -139,9 +143,9 @@
139 143 public function _fluentEditorElementSearchTagsCallback($keywords)
140 144 {
141 145 $newKeywords = $this->searchBy();
142 146
143 - if (!$newKeywords) {
147 + if (! $newKeywords) {
144 148 return $keywords;
145 149 }
146 150
147 151 $existingKeywords = [];
@@ -150,9 +154,10 @@
150 154 $existingKeywords = $keywords[$element];
151 155 }
152 156
153 157 $keywords[$element] = array_merge(
154 - $existingKeywords, $newKeywords
158 + $existingKeywords,
159 + $newKeywords
155 160 );
156 161
157 162 return $keywords;
158 163 }
@@ -158,10 +163,11 @@
158 163 }
159 164
160 165 /**
161 166 * Configure placements of input customization options in editor.
162 - *
163 - * @param array $placemenSettings
167 + *
168 + * @param array $placemenSettings
169 + *
164 170 * @return array $placemenSettings
165 171 */
166 172 public function _fluentEditorElementSettingsPlacementCallback($placementSettings)
167 173 {
@@ -183,18 +189,20 @@
183 189 ],
184 190 ];
185 191
186 192 $placementSettings[$this->element()] = array_merge_recursive(
187 - $this->placementSettings($default), $placementSettings
193 + $this->placementSettings($default),
194 + $placementSettings
188 195 );
189 -
196 +
190 197 return $placementSettings;
191 198 }
192 199
193 200 /**
194 201 * Configure input customization options/items in the editor.
195 - *
196 - * @param array $customizationSettings
202 + *
203 + * @param array $customizationSettings
204 + *
197 205 * @return array $customizationSettings
198 206 */
199 207 public function _fluentEditorElementCustomizationSettingsCallback($customizationSettings)
200 208 {
@@ -203,11 +211,12 @@
203 211
204 212 /**
205 213 * Prepare the submission data for the element on Form Submission.
206 214 *
207 - * @param array $formData
208 - * @param int $formId
209 - * @param array $inputConfigs
215 + * @param array $formData
216 + * @param int $formId
217 + * @param array $inputConfigs
218 + *
210 219 * @return array $formData
211 220 */
212 221 public function _fluentformInsertResponseDataCallback($formData, $formId, $inputConfigs)
213 222 {
@@ -216,10 +225,11 @@
216 225
217 226 /**
218 227 * Add the component type in fluentform field
219 228 * types to be available in FormFieldParser.
220 - *
221 - * @param array $types
229 + *
230 + * @param array $types
231 + *
222 232 * @return array $types
223 233 */
224 234 public function _fluentformFormInputTypesCallback($types)
225 235 {
@@ -228,10 +238,11 @@
228 238
229 239 /**
230 240 * Render the component.
231 241 *
232 - * @param array $data
233 - * @param stdClass $form
242 + * @param array $data
243 + * @param \stdClass $form
244 + *
234 245 * @return void
235 246 */
236 247 public function _elementRenderHookCallback($item, $form)
237 248 {
@@ -239,12 +250,13 @@
239 250 }
240 251
241 252 /**
242 253 * Element's entry value transformation.
243 - *
244 - * @param mixed $value
245 - * @param string $field
246 - * @param int $formId
254 + *
255 + * @param mixed $value
256 + * @param string $field
257 + * @param int $formId
258 + *
247 259 * @return mixed $value
248 260 */
249 261 public function _elementEntryFormatCallback($value, $field, $formId)
250 262 {