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