PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 3.06.06
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v3.06.06
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmFormAction.php +360 -671 6.323.06.06 View file →
@@ -1,74 +1,19 @@
1 1 <?php
2 -if ( ! defined( 'ABSPATH' ) ) {
3 - die( 'You are not allowed to call this page directly.' );
4 -}
5 2
6 3 class FrmFormAction {
7 4
8 - /**
9 - * Root id for all actions of this type.
10 - *
11 - * @var string
12 - */
13 - public $id_base;
14 -
15 - /**
16 - * Name for this action type.
17 - *
18 - * @var string
19 - */
20 - public $name;
21 -
22 - /**
23 - * Name of the option used to store the settings for this action type.
24 - *
25 - * @var string
26 - */
5 + public $id_base; // Root id for all actions of this type.
6 + public $name; // Name for this action type.
27 7 public $option_name;
8 + public $action_options; // Option array passed to wp_register_sidebar_widget()
9 + public $control_options; // Option array passed to wp_register_widget_control()
28 10
29 - /**
30 - * Option array passed to wp_register_sidebar_widget().
31 - *
32 - * @var array
33 - */
34 - public $action_options;
11 + public $form_id; // The ID of the form to evaluate
12 + public $number = false; // Unique ID number of the current instance.
13 + public $id = ''; // Unique ID string of the current instance (id_base-number)
14 + public $updated = false; // Set true when we update the data after a POST submit - makes sure we don't do it twice.
35 15
36 - /**
37 - * Option array passed to wp_register_widget_control().
38 - *
39 - * @var array
40 - */
41 - public $control_options;
42 -
43 - /**
44 - * The ID of the form to evaluate.
45 - *
46 - * @var int
47 - */
48 - public $form_id;
49 -
50 - /**
51 - * Unique ID number of the current instance.
52 - *
53 - * @var int
54 - */
55 - public $number = false;
56 -
57 - /**
58 - * Unique ID string of the current instance (id_base-number).
59 - *
60 - * @var string
61 - */
62 - public $id = '';
63 -
64 - /**
65 - * Set true when we update the data after a POST submit - makes sure we don't do it twice.
66 - *
67 - * @var bool
68 - */
69 - public $updated = false;
70 -
71 16 // Member functions that you must over-ride.
72 17
73 18 /**
74 19 * This function should check that $new_instance is set correctly.
@@ -74,11 +19,10 @@
74 19 * This function should check that $new_instance is set correctly.
75 20 * The newly calculated value of $instance should be returned.
76 21 * If "false" is returned, the instance won't be saved/updated.
77 22 *
78 - * @param array $new_instance New settings for this instance as input by the user via form().
79 - * @param array $old_instance Old settings for this instance.
80 - *
23 + * @param array $new_instance New settings for this instance as input by the user via form()
24 + * @param array $old_instance Old settings for this instance
81 25 * @return array Settings to save or bool false to cancel saving
82 26 */
83 27 public function update( $new_instance, $old_instance ) {
84 28 return $new_instance;
@@ -84,14 +28,11 @@
84 28 return $new_instance;
85 29 }
86 30
87 31 /**
88 - * Echo the settings update form
32 + * Echo the settings update form
89 33 *
90 - * @param WP_Post $instance Current settings.
91 - * @param array $args
92 - *
93 - * @return string
34 + * @param array $instance Current settings
94 35 */
95 36 public function form( $instance, $args = array() ) {
96 37 echo '<p class="no-options-widget">' . esc_html__( 'There are no options for this action.', 'formidable' ) . '</p>';
97 38 return 'noform';
@@ -100,26 +41,17 @@
100 41 /**
101 42 * @return array of the default options
102 43 */
103 44 public function get_defaults() {
104 - return array();
45 + return array();
105 46 }
106 47
107 - /**
108 - * @return array
109 - */
110 48 public function get_switch_fields() {
111 - return array();
49 + return array();
112 50 }
113 51
114 - /**
115 - * @param object $action
116 - * @param object $form
117 - *
118 - * @return object
119 - */
120 52 public function migrate_values( $action, $form ) {
121 - return $action;
53 + return $action;
122 54 }
123 55
124 56 // Functions you'll need to call.
125 57
@@ -128,14 +60,14 @@
128 60 *
129 61 * @param string $id_base Optional Base ID for the widget, lower case,
130 62 * if left empty a portion of the widget's class name will be used. Has to be unique.
131 63 * @param string $name Name for the widget displayed on the configuration page.
132 - * @param array $action_options Optional Passed to wp_register_sidebar_widget().
133 - * - description: shown on the configuration page.
134 - * - classname.
135 - * @param array $control_options Optional Passed to wp_register_widget_control().
136 - * - width: required if more than 250px.
137 - * - height: currently not used but may be needed in the future.
64 + * @param array $action_options Optional Passed to wp_register_sidebar_widget()
65 + * - description: shown on the configuration page
66 + * - classname
67 + * @param array $control_options Optional Passed to wp_register_widget_control()
68 + * - width: required if more than 250px
69 + * - height: currently not used but may be needed in the future
138 70 */
139 71 public function __construct( $id_base, $name, $action_options = array(), $control_options = array() ) {
140 72 if ( ! defined( 'ABSPATH' ) ) {
141 73 die( 'You are not allowed to call this page directly.' );
@@ -141,72 +73,30 @@
141 73 die( 'You are not allowed to call this page directly.' );
142 74 }
143 75
144 76 $this->id_base = strtolower( $id_base );
145 -
146 - /**
147 - * @since 6.31
148 - *
149 - * @param string $name
150 - */
151 - $name = apply_filters( 'frm_' . $id_base . '_action_name', $name );
152 -
153 - $this->name = $name;
77 + $this->name = $name;
154 78 $this->option_name = 'frm_' . $this->id_base . '_action';
155 79
156 - $default_options = array(
157 - 'classes' => '',
158 - 'active' => true,
159 - 'event' => array( 'create' ),
160 - 'limit' => 1,
161 - 'force_event' => false,
162 - 'priority' => 20,
163 - 'ajax_load' => true,
164 - 'plugin' => $this->id_base,
165 - 'tooltip' => $name,
166 - 'group' => $id_base,
167 - 'color' => '',
168 - 'keywords' => '',
169 - 'description' => '',
170 - 'is_new' => false,
171 - 'is_beta' => false,
172 - );
80 + $default_options = array(
81 + 'classes' => '',
82 + 'active' => true,
83 + 'event' => array( 'create' ),
84 + 'limit' => 1,
85 + 'force_event' => false,
86 + 'priority' => 20,
87 + 'ajax_load' => true,
88 + 'plugin' => $this->id_base,
89 + 'tooltip' => $name,
90 + );
173 91
174 - $action_options = apply_filters( 'frm_' . $id_base . '_action_options', $action_options );
175 - $group = $this->get_group( $action_options );
176 - $action_options['group'] = $group['id'];
177 -
178 - if ( ! isset( $action_options['color'] ) ) {
179 - // Deterministic fallback so all instances of the same action type render with the same color across requests.
180 - $colors = array( 'green', 'orange', 'purple' );
181 - $index = abs( crc32( $id_base ) ) % count( $colors );
182 - $action_options['color'] = 'var(--' . $colors[ $index ] . ')';
183 - }
184 -
185 - $upgrade_class = isset( $action_options['classes'] ) && $action_options['classes'] === 'frm_show_upgrade';
186 -
187 - if ( $action_options['group'] === $id_base ) {
188 - $upgrade_class = str_contains( $action_options['classes'], 'frm_show_upgrade' );
189 - $action_options['classes'] = $group['icon'];
190 - } elseif ( empty( $action_options['classes'] ) || $upgrade_class ) {
191 - $action_options['classes'] = $group['icon'];
192 - }
193 -
194 - if ( $upgrade_class ) {
195 - $action_options['classes'] .= ' frm_show_upgrade';
196 - }
197 -
198 - $this->action_options = wp_parse_args( $action_options, $default_options );
92 + $action_options = apply_filters( 'frm_' . $id_base . '_action_options', $action_options );
93 + $this->action_options = wp_parse_args( $action_options, $default_options );
199 94 $this->control_options = wp_parse_args( $control_options, array( 'id_base' => $this->id_base ) );
200 95 }
201 96
202 97 /**
203 98 * @param string $id_base
204 - * @param string $name
205 - * @param array $action_options
206 - * @param array $control_options
207 - *
208 - * @return void
209 99 */
210 100 public function FrmFormAction( $id_base, $name, $action_options = array(), $control_options = array() ) {
211 101 self::__construct( $id_base, $name, $action_options, $control_options );
212 102 }
@@ -211,67 +101,20 @@
211 101 self::__construct( $id_base, $name, $action_options, $control_options );
212 102 }
213 103
214 104 /**
215 - * Help to switch old field id by new field id for duplicate form
216 - *
217 - * @param string $action id of the field that needs to be switched.
218 - *
219 - * @return string
220 - */
221 - public function maybe_switch_field_ids( $action ) {
222 - $updated_action = apply_filters( 'frm_maybe_switch_field_ids', $action );
223 -
224 - if ( $updated_action === $action ) {
225 - return FrmFieldsHelper::switch_field_ids( $action );
226 - }
227 -
228 - return $updated_action;
229 - }
230 -
231 - /**
232 - * @since 4.0
233 - *
234 - * @param array $action_options
235 - *
236 - * @return array
237 - */
238 - protected function get_group( $action_options ) {
239 - $groups = FrmFormActionsController::form_action_groups();
240 - $group = 'misc';
241 -
242 - if ( isset( $action_options['group'] ) && isset( $groups[ $action_options['group'] ] ) ) {
243 - $group = $action_options['group'];
244 - } elseif ( isset( $groups[ $this->id_base ] ) ) {
245 - $group = $this->id_base;
246 - } else {
247 - foreach ( $groups as $name => $check_group ) {
248 - if ( isset( $check_group['actions'] ) && in_array( $this->id_base, $check_group['actions'], true ) ) {
249 - $group = $name;
250 - break;
251 - }
252 - }
253 - }
254 -
255 - $groups[ $group ]['id'] = $group;
256 - return $groups[ $group ];
257 - }
258 -
259 - /**
260 105 * Constructs name attributes for use in form() fields
261 106 *
262 107 * This function should be used in form() methods to create name attributes for fields to be saved by update()
263 108 *
264 - * @param string $field_name Field name.
265 - * @param string $post_field
266 - *
109 + * @param string $field_name Field name
267 110 * @return string Name attribute for $field_name
268 111 */
269 112 public function get_field_name( $field_name, $post_field = 'post_content' ) {
270 - $name = $this->option_name . '[' . $this->number . ']';
271 - $name .= $post_field ? '[' . $post_field . ']' : '';
272 -
273 - return $name . ( '[' . $field_name . ']' );
113 + $name = $this->option_name . '[' . $this->number . ']';
114 + $name .= ( empty( $post_field ) ? '' : '[' . $post_field . ']' );
115 + $name .= '[' . $field_name . ']';
116 + return $name;
274 117 }
275 118
276 119 /**
277 120 * Constructs id attributes for use in form() fields
@@ -277,10 +120,9 @@
277 120 * Constructs id attributes for use in form() fields
278 121 *
279 122 * This function should be used in form() methods to create id attributes for fields to be saved by update()
280 123 *
281 - * @param string $field_name Field name.
282 - *
124 + * @param string $field_name Field name
283 125 * @return string ID attribute for $field_name
284 126 */
285 127 public function get_field_id( $field_name ) {
286 128 return $field_name . '_' . $this->number;
@@ -285,32 +127,24 @@
285 127 public function get_field_id( $field_name ) {
286 128 return $field_name . '_' . $this->number;
287 129 }
288 130
289 - /**
290 - * @param int|string $number
291 - *
292 - * @return void
293 - */
131 + // Private Function. Don't worry about this.
132 +
294 133 public function _set( $number ) {
295 134 $this->number = $number;
296 - $this->id = $this->id_base . '-' . $number;
135 + $this->id = $this->id_base . '-' . $number;
297 136 }
298 137
299 - /**
300 - * @param false|int|string $form_id
301 - *
302 - * @return object
303 - */
304 138 public function prepare_new( $form_id = false ) {
305 - if ( $form_id ) {
306 - $this->form_id = $form_id;
307 - }
139 + if ( $form_id ) {
140 + $this->form_id = $form_id;
141 + }
308 142
309 - $post_content = array();
310 - $default_values = $this->get_global_defaults();
143 + $post_content = array();
144 + $default_values = $this->get_global_defaults();
311 145
312 - // Fill default values
146 + // fill default values
313 147 $post_content = wp_parse_args( $post_content, $default_values );
314 148
315 149 if ( ! isset( $post_content['event'] ) && ! $this->action_options['force_event'] ) {
316 150 $post_content['event'] = array( reset( $this->action_options['event'] ) );
@@ -315,99 +149,79 @@
315 149 if ( ! isset( $post_content['event'] ) && ! $this->action_options['force_event'] ) {
316 150 $post_content['event'] = array( reset( $this->action_options['event'] ) );
317 151 }
318 152
319 - $form_action = array(
320 - 'post_title' => $this->name,
321 - 'post_content' => $post_content,
322 - 'post_excerpt' => $this->id_base,
323 - 'ID' => '',
324 - 'post_status' => 'publish',
325 - 'post_type' => FrmFormActionsController::$action_post_type,
326 - 'post_name' => $this->form_id . '_' . $this->id_base . '_' . $this->number,
327 - 'menu_order' => $this->form_id,
328 - );
153 + $form_action = array(
154 + 'post_title' => $this->name,
155 + 'post_content' => $post_content,
156 + 'post_excerpt' => $this->id_base,
157 + 'ID' => '',
158 + 'post_status' => 'publish',
159 + 'post_type' => FrmFormActionsController::$action_post_type,
160 + 'post_name' => $this->form_id . '_' . $this->id_base . '_' . $this->number,
161 + 'menu_order' => $this->form_id,
162 + );
163 + unset( $post_content );
329 164
330 - return (object) $form_action;
331 - }
165 + return (object) $form_action;
166 + }
332 167
333 - /**
334 - * @param int|string $form_id
335 - *
336 - * @return int|WP_Error
337 - */
338 168 public function create( $form_id ) {
339 - $this->form_id = $form_id;
169 + $this->form_id = $form_id;
340 170
341 - $action = $this->prepare_new();
171 + $action = $this->prepare_new();
342 172
343 173 return $this->save_settings( $action );
344 - }
174 + }
345 175
346 - /**
347 - * @param int|string $form_id
348 - * @param int|string $old_id
349 - *
350 - * @return void
351 - */
352 176 public function duplicate_form_actions( $form_id, $old_id ) {
353 - // phpcs:ignore Universal.Operators.StrictComparisons
354 - if ( $form_id == $old_id ) {
355 - // Don't duplicate the actions if this is a template getting updated
356 - return;
357 - }
177 + if ( $form_id == $old_id ) {
178 + // don't duplicate the actions if this is a template getting updated
179 + return;
180 + }
358 181
359 - $this->form_id = $old_id;
360 - $actions = $this->get_all( $old_id );
182 + $this->form_id = $old_id;
183 + $actions = $this->get_all( $old_id );
361 184
362 - $this->form_id = $form_id;
363 -
364 - foreach ( $actions as $action ) {
185 + $this->form_id = $form_id;
186 + foreach ( $actions as $action ) {
365 187 $this->duplicate_one( $action, $form_id );
366 188 unset( $action );
367 - }
368 - }
189 + }
190 + }
369 191
370 - /**
371 - * Check if imported action should be created or updated.
372 - *
373 - * @since 2.0
374 - *
375 - * @param array $action
376 - * @param array $forms
377 - *
378 - * @return int Post ID.
379 - */
380 - public function maybe_create_action( $action, $forms ) {
381 - if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && isset( $forms[ $action['menu_order'] ] ) && $forms[ $action['menu_order'] ] === 'updated' ) {
382 - // Update action only
192 + /* Check if imported action should be created or updated
193 + *
194 + * Since 2.0
195 + *
196 + * @param array $action
197 + * @return integer $post_id
198 + */
199 + public function maybe_create_action( $action, $forms ) {
200 + if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && isset( $forms[ $action['menu_order'] ] ) && $forms[ $action['menu_order'] ] == 'updated' ) {
201 + // Update action only
202 + $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
203 + $post_id = $this->save_settings( $action );
204 + } else {
205 + // Create action
383 206 $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
384 - return $this->save_settings( $action );
385 - }
386 - // Create action
387 - $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
388 - return $this->duplicate_one( (object) $action, $action['menu_order'] );
389 - }
207 + $post_id = $this->duplicate_one( (object) $action, $action['menu_order'] );
208 + }
209 + return $post_id;
210 + }
390 211
391 - /**
392 - * @param object $action
393 - * @param int|string $form_id
394 - *
395 - * @return int|WP_Error
396 - */
397 212 public function duplicate_one( $action, $form_id ) {
398 - global $frm_duplicate_ids;
213 + global $frm_duplicate_ids;
399 214
400 - $action->menu_order = $form_id;
401 - $switch = $this->get_global_switch_fields();
402 -
403 - foreach ( (array) $action->post_content as $key => $val ) {
215 + $action->menu_order = $form_id;
216 + $switch = $this->get_global_switch_fields();
217 + foreach ( (array) $action->post_content as $key => $val ) {
404 218 if ( is_numeric( $val ) && isset( $frm_duplicate_ids[ $val ] ) ) {
405 219 $action->post_content[ $key ] = $frm_duplicate_ids[ $val ];
406 - } elseif ( ! is_array( $val ) ) {
220 + } else if ( ! is_array( $val ) ) {
407 221 $action->post_content[ $key ] = FrmFieldsHelper::switch_field_ids( $val );
408 - } elseif ( isset( $switch[ $key ] ) && is_array( $switch[ $key ] ) ) {
409 - // Loop through each value if empty
222 + } else if ( isset( $switch[ $key ] ) && is_array( $switch[ $key ] ) ) {
223 + // loop through each value if empty
410 224 if ( empty( $switch[ $key ] ) ) {
411 225 $switch[ $key ] = array_keys( $val );
412 226 }
413 227
@@ -412,10 +226,10 @@
412 226 }
413 227
414 228 foreach ( $switch[ $key ] as $subkey ) {
415 229 $action->post_content[ $key ] = $this->duplicate_array_walk( $action->post_content[ $key ], $subkey, $val );
416 - }
417 - }
230 + }
231 + }
418 232
419 233 unset( $key, $val );
420 234 }
421 235 unset( $action->ID );
@@ -420,98 +234,83 @@
420 234 }
421 235 unset( $action->ID );
422 236
423 237 return $this->save_settings( $action );
424 - }
238 + }
425 239
426 - /**
427 - * @param array $action
428 - * @param array|string $subkey
429 - * @param mixed $val
430 - *
431 - * @return array
432 - */
433 240 private function duplicate_array_walk( $action, $subkey, $val ) {
434 - global $frm_duplicate_ids;
241 + global $frm_duplicate_ids;
435 242
436 243 if ( is_array( $subkey ) ) {
437 - foreach ( $subkey as $subkey2 ) {
438 - foreach ( (array) $val as $ck => $cv ) {
244 + foreach ( $subkey as $subkey2 ) {
245 + foreach ( (array) $val as $ck => $cv ) {
439 246 if ( is_array( $cv ) ) {
440 247 $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey2, $cv );
441 - } elseif ( isset( $cv[ $subkey ] ) && is_numeric( $cv[ $subkey ] ) && isset( $frm_duplicate_ids[ $cv[ $subkey ] ] ) ) {
248 + } else if ( isset( $cv[ $subkey ] ) && is_numeric( $cv[ $subkey ] ) && isset( $frm_duplicate_ids[ $cv[ $subkey ] ] ) ) {
442 249 $action[ $ck ][ $subkey ] = $frm_duplicate_ids[ $cv[ $subkey ] ];
443 - }
444 - }
445 - }
446 - } else {
447 - foreach ( (array) $val as $ck => $cv ) {
250 + }
251 + }
252 + }
253 + } else {
254 + foreach ( (array) $val as $ck => $cv ) {
448 255 if ( is_array( $cv ) ) {
449 256 $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey, $cv );
450 - } elseif ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) { // phpcs:ignore Universal.Operators.StrictComparisons
257 + } else if ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) {
451 258 $action[ $ck ] = $frm_duplicate_ids[ $cv ];
452 - } elseif ( $ck == $subkey ) { // phpcs:ignore Universal.Operators.StrictComparisons
453 - $action[ $ck ] = $this->maybe_switch_field_ids( $action[ $ck ] );
454 - }
455 - }
456 - }//end if
259 + }
260 + }
261 + }
457 262
458 - return $action;
459 - }
263 + return $action;
264 + }
460 265
461 266 /**
462 267 * Deal with changed settings.
463 268 *
464 269 * Do NOT over-ride this function
465 - *
466 - * @param int|string $form_id
467 - *
468 - * @return array|null
469 270 */
470 - public function update_callback( $form_id ) {
471 - $this->form_id = $form_id;
271 + public function update_callback( $form_id ) {
272 + $this->form_id = $form_id;
472 273
473 - $all_instances = $this->get_settings();
274 + $all_instances = $this->get_settings();
474 275
475 - // We need to update the data
476 - if ( $this->updated ) {
477 - return null;
478 - }
276 + // We need to update the data
277 + if ( $this->updated ) {
278 + return;
279 + }
479 280
480 - // phpcs:ignore WordPress.Security.NonceVerification.Missing
481 - if ( ! isset( $_POST[ $this->option_name ] ) || ! is_array( $_POST[ $this->option_name ] ) ) {
482 - return null;
483 - }
281 + if ( isset( $_POST[ $this->option_name ] ) && is_array( $_POST[ $this->option_name ] ) ) {
282 + $settings = $_POST[ $this->option_name ];
283 + } else {
284 + return;
285 + }
484 286
485 - // Sanitizing removes scripts and <email> type of values.
486 - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
487 - $settings = wp_unslash( $_POST[ $this->option_name ] );
287 + $action_ids = array();
488 288
489 - $action_ids = array();
289 + foreach ( $settings as $number => $new_instance ) {
290 + $this->_set( $number );
490 291
491 - foreach ( $settings as $number => $new_instance ) {
492 - $this->_set( $number );
292 + $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array();
493 293
494 - $old_instance = $all_instances[ $number ] ?? array();
495 -
496 294 if ( ! isset( $new_instance['post_status'] ) ) {
497 295 $new_instance['post_status'] = 'draft';
498 296 }
499 297
500 - // Settings were never opened, so don't update
501 - if ( ! isset( $new_instance['post_title'] ) ) {
298 + // settings were never opened, so don't update
299 + if ( ! isset( $new_instance['post_title'] ) ) {
502 300 $this->maybe_update_status( $new_instance, $old_instance );
503 - $action_ids[] = $new_instance['ID'];
504 - $this->updated = true;
505 - continue;
506 - }
301 + $action_ids[] = $new_instance['ID'];
302 + $this->updated = true;
303 + continue;
304 + }
507 305
508 306 $new_instance['post_type'] = FrmFormActionsController::$action_post_type;
509 307 $new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number;
510 308 $new_instance['menu_order'] = $this->form_id;
511 - $new_instance['post_date'] = $old_instance->post_date ?? '';
512 - $instance = $this->update( $new_instance, $old_instance );
309 + $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : '';
513 310
311 + $instance = $this->update( $new_instance, $old_instance );
312 +
514 313 /**
515 314 * Filter an action's settings before saving.
516 315 *
517 316 * Returning false will effectively short-circuit the widget's ability
@@ -518,17 +317,17 @@
518 317 * to update settings.
519 318 *
520 319 * @since 2.0
521 320 *
522 - * @param array $instance The current widget instance's settings.
523 - * @param array $new_instance Array of new widget settings.
524 - * @param array $old_instance Array of old widget settings.
525 - * @param FrmFormAction $form_action FrmFormAction instance.
321 + * @param array $instance The current widget instance's settings.
322 + * @param array $new_instance Array of new widget settings.
323 + * @param array $old_instance Array of old widget settings.
324 + * @param WP_Widget $this The current widget instance.
526 325 */
527 326 $instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this );
528 327
529 328 $instance['post_content'] = apply_filters( 'frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this );
530 - $instance['post_content'] = apply_filters( 'frm_before_save_' . $this->id_base . '_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this );
329 + $instance['post_content'] = apply_filters( 'frm_before_save_' . $this->id_base . '_action', $new_instance['post_content'], $instance, $new_instance, $old_instance, $this );
531 330
532 331 if ( false !== $instance ) {
533 332 $all_instances[ $number ] = $instance;
534 333 }
@@ -534,255 +333,180 @@
534 333 }
535 334
536 335 $action_ids[] = $this->save_settings( $instance );
537 336
538 - $this->updated = true;
539 - }//end foreach
337 + $this->updated = true;
338 + }
540 339
541 - return $action_ids;
542 - }
340 + return $action_ids;
341 + }
543 342
544 343 /**
545 344 * If the status of the action has changed, update it
546 345 *
547 346 * @since 3.04
548 - *
549 - * @param array $new_instance
550 - * @param array|stdClass $old_instance
551 - *
552 - * @return void
553 347 */
554 348 protected function maybe_update_status( $new_instance, $old_instance ) {
555 - if ( ! is_object( $old_instance ) || $new_instance['post_status'] === $old_instance->post_status ) {
556 - return;
349 + if ( $new_instance['post_status'] !== $old_instance->post_status ) {
350 + self::clear_cache();
351 + wp_update_post(
352 + array(
353 + 'ID' => $new_instance['ID'],
354 + 'post_status' => $new_instance['post_status'],
355 + )
356 + );
557 357 }
558 -
559 - self::clear_cache();
560 - wp_update_post(
561 - array(
562 - 'ID' => $new_instance['ID'],
563 - 'post_status' => $new_instance['post_status'],
564 - )
565 - );
566 358 }
567 359
568 - /**
569 - * @param array $settings
570 - *
571 - * @return int|WP_Error
572 - */
573 360 public function save_settings( $settings ) {
574 361 self::clear_cache();
575 362 return FrmDb::save_settings( $settings, 'frm_actions' );
576 363 }
577 364
578 - /**
579 - * @param int $id
580 - *
581 - * @return object|null
582 - */
583 365 public function get_single_action( $id ) {
584 366 $action = get_post( $id );
585 -
586 367 if ( $action ) {
587 368 $action = $this->prepare_action( $action );
588 369 $this->_set( $id );
589 370 }
590 -
591 - return $action;
371 + return $action;
592 372 }
593 373
594 - /**
595 - * @param int|string $form_id
596 - *
597 - * @return array
598 - */
599 374 public function get_one( $form_id ) {
600 375 return $this->get_all( $form_id, 1 );
601 376 }
602 377
603 - /**
604 - * @param int|string $form_id
605 - * @param string $type
606 - * @param array $atts
607 - *
608 - * @return array
609 - */
610 - public static function get_action_for_form( $form_id, $type = 'all', $atts = array() ) {
611 - $action_controls = FrmFormActionsController::get_form_actions( $type );
378 + public static function get_action_for_form( $form_id, $type = 'all', $atts = array() ) {
379 + $action_controls = FrmFormActionsController::get_form_actions( $type );
380 + if ( empty( $action_controls ) ) {
381 + // don't continue if there are no available actions
382 + return array();
383 + }
612 384
613 - if ( ! $action_controls ) {
614 - // Don't continue if there are no available actions
615 - return array();
616 - }
617 -
618 - if ( 'all' !== $type ) {
619 - if ( is_array( $action_controls ) ) {
620 - return array();
621 - }
622 -
385 + if ( 'all' != $type ) {
623 386 return $action_controls->get_all( $form_id, $atts );
624 387 }
625 388
626 389 self::prepare_get_action( $atts );
627 390
628 - $limit = self::get_action_limit( $form_id, $atts['limit'] );
629 - $args = self::action_args( $form_id, $limit );
391 + $limit = apply_filters( 'frm_form_action_limit', $atts['limit'], compact( 'type', 'form_id' ) );
392 +
393 + $args = self::action_args( $form_id, $limit );
630 394 $args['post_status'] = $atts['post_status'];
631 - $actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' );
395 + $actions = FrmDb::check_cache( serialize( $args ), 'frm_actions', $args, 'get_posts' );
632 396
633 - if ( ! $actions ) {
634 - return array();
635 - }
397 + if ( ! $actions ) {
398 + return array();
399 + }
636 400
637 - $settings = array();
638 -
639 - foreach ( $actions as $action ) {
640 - // Some plugins/themes are formatting the post_excerpt
401 + $settings = array();
402 + foreach ( $actions as $action ) {
403 + // some plugins/themes are formatting the post_excerpt
641 404 $action->post_excerpt = sanitize_title( $action->post_excerpt );
642 405
643 406 if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) {
644 - continue;
645 - }
407 + continue;
408 + }
646 409
647 - $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action );
410 + $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action );
648 411 $settings[ $action->ID ] = $action;
649 412
650 413 if ( count( $settings ) >= $limit ) {
651 414 break;
652 415 }
653 - }
416 + }
654 417
655 - return 1 === $limit ? reset( $settings ) : $settings;
656 - }
418 + if ( 1 === $limit ) {
419 + $settings = reset( $settings );
420 + }
657 421
658 - /**
659 - * Get the limit for the number of actions for a single form. By default, this is 99, but
660 - * it can be modified with a code snippet.
661 - *
662 - * @since 6.17 This logic from moved from FrmFormAction::get_action_for_form.
663 - *
664 - * @param int|string $form_id
665 - * @param int|string $limit The unfiltered limit value.
666 - *
667 - * @return int The filtered limit value.
668 - */
669 - public static function get_action_limit( $form_id, $limit = 99 ) {
670 - $type = 'all';
671 - return (int) apply_filters( 'frm_form_action_limit', (int) $limit, compact( 'type', 'form_id' ) );
672 - }
422 + return $settings;
423 + }
673 424
674 425 /**
675 426 * @since 3.04
676 - *
677 - * @param array|string $args
678 - * @param string $default_status
679 - *
680 - * @return void
427 + * @param array $args
428 + * @param string $default_status
681 429 */
682 430 protected static function prepare_get_action( &$args, $default_status = 'publish' ) {
683 431 if ( is_numeric( $args ) ) {
684 - // For reverse compatibility. $limit was changed to $args
432 + // for reverse compatibility. $limit was changed to $args
685 433 $args = array(
686 434 'limit' => $args,
687 435 );
688 436 }
689 -
690 437 $defaults = array(
691 438 'limit' => 99,
692 439 'post_status' => $default_status,
693 440 );
694 - $args = wp_parse_args( $args, $defaults );
441 + $args = wp_parse_args( $args, $defaults );
695 442 }
696 443
697 444 /**
698 - * @param int $action_id
699 - * @param string $type
700 - *
701 - * @return bool|object
445 + * @param int $action_id
702 446 */
703 447 public static function get_single_action_type( $action_id, $type ) {
704 448 if ( ! $type ) {
705 449 return false;
706 450 }
707 -
708 - /**
709 - * @var FrmFormAction
710 - */
711 451 $action_control = FrmFormActionsController::get_form_actions( $type );
712 -
713 452 return $action_control->get_single_action( $action_id );
714 453 }
715 454
716 455 /**
717 - * @param int $form_id
718 - * @param string $type
719 - *
456 + * @param int $form_id
720 457 * @return bool
721 458 */
722 459 public static function form_has_action_type( $form_id, $type ) {
723 - $actions = self::get_action_for_form( $form_id, $type );
724 - return ! empty( $actions );
460 + $payment_actions = self::get_action_for_form( $form_id, $type );
461 + return ! empty( $payment_actions );
725 462 }
726 463
727 - /**
728 - * @param false|int|string $form_id
729 - * @param array $atts
730 - *
731 - * @return array
732 - */
733 464 public function get_all( $form_id = false, $atts = array() ) {
734 - if ( is_array( $atts ) && ! isset( $atts['limit'] ) && $this->action_options['limit'] > 99 ) {
735 - $atts['limit'] = $this->action_options['limit'];
736 - }
737 -
738 465 self::prepare_get_action( $atts, 'any' );
739 -
740 466 $limit = $atts['limit'];
741 467
742 - if ( $form_id ) {
743 - $this->form_id = $form_id;
744 - }
468 + if ( $form_id ) {
469 + $this->form_id = $form_id;
470 + }
745 471
746 - $type = $this->id_base;
472 + $type = $this->id_base;
747 473
748 - global $frm_vars;
749 - $frm_vars['action_type'] = $type;
474 + global $frm_vars;
475 + $frm_vars['action_type'] = $type;
750 476
751 477 add_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
752 - $query = self::action_args( $form_id, $limit );
753 - $query['post_status'] = $atts['post_status'];
754 - $query['suppress_filters'] = false;
478 + $query = self::action_args( $form_id, $limit );
479 + $query['post_status'] = $atts['post_status'];
480 + $query['suppress_filters'] = false;
755 481
756 - $actions = FrmDb::check_cache( json_encode( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' );
482 + $actions = FrmDb::check_cache( serialize( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' );
757 483 unset( $query );
758 484
759 485 remove_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
760 486
761 - if ( ! $actions ) {
762 - return array();
763 - }
487 + if ( empty( $actions ) ) {
488 + return array();
489 + }
764 490
765 - $settings = array();
491 + $settings = array();
492 + foreach ( $actions as $action ) {
493 + if ( count( $settings ) >= $limit ) {
494 + continue;
495 + }
766 496
767 - foreach ( $actions as $action ) {
768 - if ( count( $settings ) >= $limit ) {
769 - continue;
770 - }
497 + $action = $this->prepare_action( $action );
771 498
772 - $action = $this->prepare_action( $action );
773 499 $settings[ $action->ID ] = $action;
774 - }
500 + }
775 501
776 - return 1 === $limit ? reset( $settings ) : $settings;
502 + if ( 1 === $limit ) {
503 + $settings = reset( $settings );
504 + }
505 +
506 + return $settings;
777 507 }
778 508
779 - /**
780 - * @param int|string $form_id
781 - * @param int $limit
782 - *
783 - * @return array
784 - */
785 509 public static function action_args( $form_id = 0, $limit = 99 ) {
786 510 $args = array(
787 511 'post_type' => FrmFormActionsController::$action_post_type,
788 512 'post_status' => 'publish',
@@ -790,9 +514,9 @@
790 514 'orderby' => 'title',
791 515 'order' => 'ASC',
792 516 );
793 517
794 - if ( $form_id && $form_id !== 'all' ) {
518 + if ( $form_id && $form_id != 'all' ) {
795 519 $args['menu_order'] = $form_id;
796 520 }
797 521
798 522 return $args;
@@ -797,66 +521,51 @@
797 521
798 522 return $args;
799 523 }
800 524
801 - /**
802 - * @param WP_Post $action
803 - *
804 - * @return WP_Post
805 - */
806 525 public function prepare_action( $action ) {
807 526 $action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content );
808 527 $action->post_excerpt = sanitize_title( $action->post_excerpt );
809 528
810 - $default_values = $this->get_global_defaults();
529 + $default_values = $this->get_global_defaults();
811 530
812 - // Fill default values
813 - $action->post_content += $default_values;
531 + // fill default values
532 + $action->post_content += $default_values;
814 533
815 - foreach ( $default_values as $k => $vals ) {
816 - if ( ! is_array( $vals ) || ! $vals ) {
817 - continue;
818 - }
534 + foreach ( $default_values as $k => $vals ) {
535 + if ( is_array( $vals ) && ! empty( $vals ) ) {
536 + if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
537 + continue;
538 + }
539 + $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals );
540 + }
541 + }
819 542
820 - if ( 'event' === $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
821 - continue;
822 - }
823 - $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals );
824 - }
825 -
826 543 if ( ! is_array( $action->post_content['event'] ) ) {
827 544 $action->post_content['event'] = explode( ',', $action->post_content['event'] );
828 545 }
829 546
830 - return $action;
547 + return $action;
831 548 }
832 549
833 - /**
834 - * @param false|int|string $form_id
835 - * @param string $type
836 - *
837 - * @return void
838 - */
839 550 public function destroy( $form_id = false, $type = 'default' ) {
840 - global $wpdb;
551 + global $wpdb;
841 552
842 - $this->form_id = $form_id;
553 + $this->form_id = $form_id;
843 554
844 - $query = array( 'post_type' => FrmFormActionsController::$action_post_type );
555 + $query = array( 'post_type' => FrmFormActionsController::$action_post_type );
556 + if ( $form_id ) {
557 + $query['menu_order'] = $form_id;
558 + }
559 + if ( 'all' != $type ) {
560 + $query['post_excerpt'] = $this->id_base;
561 + }
845 562
846 - if ( $form_id ) {
847 - $query['menu_order'] = $form_id;
848 - }
563 + $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' );
849 564
850 - if ( 'all' !== $type ) {
851 - $query['post_excerpt'] = $this->id_base;
852 - }
853 -
854 - $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' );
855 -
856 - foreach ( $post_ids as $id ) {
565 + foreach ( $post_ids as $id ) {
857 566 wp_delete_post( $id );
858 - }
567 + }
859 568 self::clear_cache();
860 569 }
861 570
862 571 /**
@@ -862,204 +571,184 @@
862 571 /**
863 572 * Delete the action cache when a form action is created, deleted, or updated
864 573 *
865 574 * @since 2.0.5
866 - *
867 - * @return void
868 575 */
869 576 public static function clear_cache() {
870 577 FrmDb::cache_delete_group( 'frm_actions' );
871 578 }
872 579
873 - /**
874 - * @return array
875 - */
876 580 public function get_settings() {
877 581 return self::get_action_for_form( $this->form_id, $this->id_base );
878 582 }
879 583
880 - /**
881 - * @return array
882 - */
883 584 public function get_global_defaults() {
884 - $defaults = $this->get_defaults();
585 + $defaults = $this->get_defaults();
885 586
886 587 if ( ! isset( $defaults['event'] ) ) {
887 588 $defaults['event'] = array( 'create' );
888 - }
589 + }
889 590
890 591 if ( ! isset( $defaults['conditions'] ) ) {
891 - $defaults['conditions'] = array(
892 - 'send_stop' => '',
893 - 'any_all' => '',
894 - );
895 - }
592 + $defaults['conditions'] = array(
593 + 'send_stop' => '',
594 + 'any_all' => '',
595 + );
596 + }
896 597
897 - return $defaults;
598 + return $defaults;
898 599 }
899 600
900 - /**
901 - * @return array
902 - */
903 601 public function get_global_switch_fields() {
904 - $switch = $this->get_switch_fields();
602 + $switch = $this->get_switch_fields();
905 603 $switch['conditions'] = array( 'hide_field' );
906 -
907 - return apply_filters( 'frm_global_switch_fields', $switch );
604 + return $switch;
908 605 }
909 606
910 607 /**
911 608 * Migrate settings from form->options into new action.
912 - *
913 - * @param object $form
914 - * @param string $update
915 - *
916 - * @return int|WP_Error
917 609 */
918 610 public function migrate_to_2( $form, $update = 'update' ) {
919 611 $action = $this->prepare_new( $form->id );
920 - FrmAppHelper::unserialize_or_decode( $form->options );
612 + $form->options = maybe_unserialize( $form->options );
921 613
922 - // Fill with existing options
923 - foreach ( $action->post_content as $name => $val ) {
924 - if ( ! isset( $form->options[ $name ] ) ) {
925 - continue;
926 - }
614 + // fill with existing options
615 + foreach ( $action->post_content as $name => $val ) {
616 + if ( isset( $form->options[ $name ] ) ) {
617 + $action->post_content[ $name ] = $form->options[ $name ];
618 + unset( $form->options[ $name ] );
619 + }
620 + }
927 621
928 - $action->post_content[ $name ] = $form->options[ $name ];
929 - unset( $form->options[ $name ] );
930 - }
931 -
932 622 $action = $this->migrate_values( $action, $form );
933 623
934 - // Check if action already exists
624 + // check if action already exists
935 625 $post_id = get_posts(
936 626 array(
937 - 'name' => $action->post_name,
938 - 'post_type' => FrmFormActionsController::$action_post_type,
939 - 'post_status' => $action->post_status,
940 - 'numberposts' => 1,
627 + 'name' => $action->post_name,
628 + 'post_type' => FrmFormActionsController::$action_post_type,
629 + 'post_status' => $action->post_status,
630 + 'numberposts' => 1,
941 631 )
942 632 );
943 633
944 - if ( ! $post_id ) {
945 - // Create action now
634 + if ( empty( $post_id ) ) {
635 + // create action now
946 636 $post_id = $this->save_settings( $action );
947 637 }
948 638
949 - if ( ! $post_id || 'update' !== $update ) {
950 - return $post_id;
639 + if ( $post_id && 'update' == $update ) {
640 + global $wpdb;
641 + $form->options = maybe_serialize( $form->options );
642 +
643 + // update form options
644 + $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) );
645 + FrmForm::clear_form_cache();
646 + }
647 +
648 + return $post_id;
649 + }
650 +
651 + public static function action_conditions_met( $action, $entry ) {
652 + $notification = $action->post_content;
653 + $stop = false;
654 + $met = array();
655 +
656 + if ( ! isset( $notification['conditions'] ) || empty( $notification['conditions'] ) ) {
657 + return $stop;
951 658 }
952 659
953 - global $wpdb;
954 - $form->options = maybe_serialize( $form->options );
660 + foreach ( $notification['conditions'] as $k => $condition ) {
661 + if ( ! is_numeric( $k ) ) {
662 + continue;
663 + }
955 664
956 - // Update form options
957 - $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) );
958 - FrmForm::clear_form_cache();
665 + if ( $stop && 'any' == $notification['conditions']['any_all'] && 'stop' == $notification['conditions']['send_stop'] ) {
666 + continue;
667 + }
959 668
960 - return $post_id;
669 + self::prepare_logic_value( $condition['hide_opt'] );
670 +
671 + $observed_value = self::get_value_from_entry( $entry, $condition['hide_field'] );
672 +
673 + $stop = FrmFieldsHelper::value_meets_condition( $observed_value, $condition['hide_field_cond'], $condition['hide_opt'] );
674 +
675 + if ( $notification['conditions']['send_stop'] == 'send' ) {
676 + $stop = $stop ? false : true;
677 + }
678 +
679 + $met[ $stop ] = $stop;
680 + }
681 +
682 + if ( $notification['conditions']['any_all'] == 'all' && ! empty( $met ) && isset( $met[0] ) && isset( $met[1] ) ) {
683 + $stop = ( $notification['conditions']['send_stop'] == 'send' );
684 + } elseif ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset( $met[0] ) ) {
685 + $stop = false;
686 + }
687 +
688 + return $stop;
961 689 }
962 690
963 691 /**
964 - * @param WP_Post $action
965 - * @param stdClass $entry
692 + * Prepare the logic value for comparison against the entered value
966 693 *
967 - * @return bool
694 + * @since 2.01.02
695 + * @param array|string $logic_value
968 696 */
969 - public static function action_conditions_met( $action, $entry ) {
970 - if ( is_callable( 'FrmProFormActionsController::action_conditions_met' ) ) {
971 - return FrmProFormActionsController::action_conditions_met( $action, $entry );
697 + private static function prepare_logic_value( &$logic_value ) {
698 + if ( is_array( $logic_value ) ) {
699 + $logic_value = reset( $logic_value );
972 700 }
973 - return false;
974 - }
975 701
976 - /**
977 - * @param string $class
978 - *
979 - * @return array
980 - */
981 - public static function default_action_opts( $class = '' ) {
982 - return array(
983 - 'classes' => 'frmfont ' . $class,
984 - 'active' => false,
985 - 'limit' => 0,
986 - 'description' => '',
987 - );
702 + if ( $logic_value == 'current_user' ) {
703 + $logic_value = get_current_user_id();
704 + }
988 705 }
989 706
990 - /**
991 - * @return array
992 - */
993 - public static function trigger_labels() {
994 - $triggers = array(
995 - 'draft' => __( 'Draft is saved', 'formidable' ),
996 - 'create' => __( 'Entry is created', 'formidable' ),
997 - 'update' => __( 'Entry is updated', 'formidable' ),
998 - 'delete' => __( 'Entry is deleted', 'formidable' ),
999 - 'import' => __( 'Entry is imported', 'formidable' ),
1000 - );
1001 707
1002 - return apply_filters( 'frm_action_triggers', $triggers );
1003 - }
1004 -
1005 708 /**
1006 - * @param string $action_key The unique key for this action instance.
709 + * Get the value from a specific field and entry
1007 710 *
1008 - * @return void
711 + * @since 2.01.02
712 + * @param object $entry
713 + * @param int $field_id
714 + * @return array|bool|mixed|string
1009 715 */
1010 - public function render_conditional_logic_call_to_action( $action_key = '' ) {
1011 - $params = array(
1012 - 'class' => 'frm-h-stack-xs frm-bt-200 frm-py-md frm_show_upgrade',
1013 - 'data-upgrade' => $this->get_upgrade_text(),
1014 - 'data-medium' => 'conditional-' . $this->id_base,
1015 - );
1016 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
1017 - ?>
1018 - <div <?php FrmAppHelper::array_to_html_params( $params, true ); ?>>
1019 - <?php
1020 - FrmHtmlHelper::toggle(
1021 - 'frm_logic_cta_' . $action_key,
1022 - 'frm_logic_cta_' . $action_key,
716 + private static function get_value_from_entry( $entry, $field_id ) {
717 + $observed_value = '';
718 +
719 + if ( isset( $entry->metas[ $field_id ] ) ) {
720 + $observed_value = $entry->metas[ $field_id ];
721 + } else if ( $entry->post_id && FrmAppHelper::pro_is_installed() ) {
722 + $field = FrmField::getOne( $field_id );
723 + $observed_value = FrmProEntryMetaHelper::get_post_or_meta_value(
724 + $entry,
725 + $field,
1023 726 array(
1024 - 'div_class' => 'with_frm_style frm_toggle',
1025 - 'checked' => false,
1026 - 'echo' => true,
1027 - 'disabled' => true,
727 + 'links' => false,
728 + 'truncate' => false,
1028 729 )
1029 730 );
1030 - ?>
1031 - <label for="frm_logic_cta_<?php echo esc_attr( $action_key ); ?>" class="frm_noallow">
1032 - <?php esc_html_e( 'Use Conditional Logic', 'formidable' ); ?>
1033 - </label>
1034 - </div>
1035 - <?php
1036 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
731 + }
732 +
733 + return $observed_value;
1037 734 }
1038 735
1039 - /**
1040 - * @return string
1041 - */
1042 - protected function get_upgrade_text() {
1043 - return __( 'Conditional form actions', 'formidable' );
736 + public static function default_action_opts( $class = '' ) {
737 + return array(
738 + 'classes' => 'frm_icon_font ' . $class,
739 + 'active' => false,
740 + 'limit' => 0,
741 + );
1044 742 }
1045 743
1046 - /**
1047 - * Gets form fields for form action settings.
1048 - *
1049 - * @since 6.10
1050 - *
1051 - * @param int $form_id Form ID.
1052 - *
1053 - * @return object[]
1054 - */
1055 - protected function get_form_fields( $form_id ) {
1056 - // Get form fields, include embedded and repeater child fields.
1057 - $form_fields = FrmField::get_all_for_form( $form_id, '', 'include' );
1058 - return array_filter(
1059 - $form_fields,
1060 - function ( $form_field ) {
1061 - return ! FrmField::is_no_save_field( $form_field->type );
1062 - }
744 + public static function trigger_labels() {
745 + $triggers = array(
746 + 'draft' => __( 'Save Draft', 'formidable' ),
747 + 'create' => __( 'Create', 'formidable' ),
748 + 'update' => __( 'Update', 'formidable' ),
749 + 'delete' => __( 'Delete', 'formidable' ),
750 + 'import' => __( 'Import', 'formidable' ),
1063 751 );
752 + return apply_filters( 'frm_action_triggers', $triggers );
1064 753 }
1065 754 }