PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.0
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 +113 -310 6.266.0 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.' );
@@ -171,13 +107,12 @@
171 107 $action_options['color'] = 'var(--' . reset( $colors ) . ')';
172 108 }
173 109
174 110 $upgrade_class = isset( $action_options['classes'] ) && $action_options['classes'] === 'frm_show_upgrade';
175 -
176 111 if ( $action_options['group'] === $id_base ) {
177 - $upgrade_class = strpos( $action_options['classes'], 'frm_show_upgrade' ) !== false;
112 + $upgrade_class = strpos( $action_options['classes'], 'frm_show_upgrade' ) !== false;
178 113 $action_options['classes'] = $group['icon'];
179 - } elseif ( empty( $action_options['classes'] ) || $upgrade_class ) {
114 + } elseif ( ! isset( $action_options['classes'] ) || empty( $action_options['classes'] ) || $upgrade_class ) {
180 115 $action_options['classes'] = $group['icon'];
181 116 }
182 117
183 118 if ( $upgrade_class ) {
@@ -189,13 +124,8 @@
189 124 }
190 125
191 126 /**
192 127 * @param string $id_base
193 - * @param string $name
194 - * @param array $action_options
195 - * @param array $control_options
196 - *
197 - * @return void
198 128 */
199 129 public function FrmFormAction( $id_base, $name, $action_options = array(), $control_options = array() ) {
200 130 self::__construct( $id_base, $name, $action_options, $control_options );
201 131 }
@@ -202,15 +132,14 @@
202 132
203 133 /**
204 134 * Help to switch old field id by new field id for duplicate form
205 135 *
206 - * @param string $action id of the field that needs to be switched.
136 + * @param string $action id of the field that needs to be switched
207 137 *
208 138 * @return string
209 139 */
210 140 public function maybe_switch_field_ids( $action ) {
211 141 $updated_action = apply_filters( 'frm_maybe_switch_field_ids', $action );
212 -
213 142 if ( $updated_action === $action ) {
214 143 $updated_action = FrmFieldsHelper::switch_field_ids( $action );
215 144 }
216 145 return $updated_action;
@@ -217,12 +146,8 @@
217 146 }
218 147
219 148 /**
220 149 * @since 4.0
221 - *
222 - * @param array $action_options
223 - *
224 - * @return array
225 150 */
226 151 protected function get_group( $action_options ) {
227 152 $groups = FrmFormActionsController::form_action_groups();
228 153 $group = 'misc';
@@ -248,15 +173,14 @@
248 173 * Constructs name attributes for use in form() fields
249 174 *
250 175 * This function should be used in form() methods to create name attributes for fields to be saved by update()
251 176 *
252 - * @param string $field_name Field name.
253 - * @param string $post_field
177 + * @param string $field_name Field name
254 178 *
255 179 * @return string Name attribute for $field_name
256 180 */
257 181 public function get_field_name( $field_name, $post_field = 'post_content' ) {
258 - $name = $this->option_name . '[' . $this->number . ']';
182 + $name = $this->option_name . '[' . $this->number . ']';
259 183 $name .= ( empty( $post_field ) ? '' : '[' . $post_field . ']' );
260 184 $name .= '[' . $field_name . ']';
261 185
262 186 return $name;
@@ -266,9 +190,9 @@
266 190 * Constructs id attributes for use in form() fields
267 191 *
268 192 * This function should be used in form() methods to create id attributes for fields to be saved by update()
269 193 *
270 - * @param string $field_name Field name.
194 + * @param string $field_name Field name
271 195 *
272 196 * @return string ID attribute for $field_name
273 197 */
274 198 public function get_field_id( $field_name ) {
@@ -274,23 +198,15 @@
274 198 public function get_field_id( $field_name ) {
275 199 return $field_name . '_' . $this->number;
276 200 }
277 201
278 - /**
279 - * @param int|string $number
280 - *
281 - * @return void
282 - */
202 + // Private Function. Don't worry about this.
203 +
283 204 public function _set( $number ) {
284 205 $this->number = $number;
285 206 $this->id = $this->id_base . '-' . $number;
286 207 }
287 208
288 - /**
289 - * @param false|int|string $form_id
290 - *
291 - * @return object
292 - */
293 209 public function prepare_new( $form_id = false ) {
294 210 if ( $form_id ) {
295 211 $this->form_id = $form_id;
296 212 }
@@ -319,13 +235,8 @@
319 235
320 236 return (object) $form_action;
321 237 }
322 238
323 - /**
324 - * @param int|string $form_id
325 - *
326 - * @return int|WP_Error
327 - */
328 239 public function create( $form_id ) {
329 240 $this->form_id = $form_id;
330 241
331 242 $action = $this->prepare_new();
@@ -332,14 +243,8 @@
332 243
333 244 return $this->save_settings( $action );
334 245 }
335 246
336 - /**
337 - * @param int|string $form_id
338 - * @param int|string $old_id
339 - *
340 - * @return void
341 - */
342 247 public function duplicate_form_actions( $form_id, $old_id ) {
343 248 if ( $form_id == $old_id ) {
344 249 // don't duplicate the actions if this is a template getting updated
345 250 return;
@@ -348,9 +253,8 @@
348 253 $this->form_id = $old_id;
349 254 $actions = $this->get_all( $old_id );
350 255
351 256 $this->form_id = $form_id;
352 -
353 257 foreach ( $actions as $action ) {
354 258 $this->duplicate_one( $action, $form_id );
355 259 unset( $action );
356 260 }
@@ -355,20 +259,17 @@
355 259 unset( $action );
356 260 }
357 261 }
358 262
359 - /**
360 - * Check if imported action should be created or updated.
263 + /* Check if imported action should be created or updated
361 264 *
362 265 * @since 2.0
363 266 *
364 267 * @param array $action
365 - * @param array $forms
366 - *
367 - * @return int $post_id
268 + * @return integer $post_id
368 269 */
369 270 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' ) {
271 + if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && isset( $forms[ $action['menu_order'] ] ) && $forms[ $action['menu_order'] ] == 'updated' ) {
371 272 // Update action only
372 273 $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
373 274 $post_id = $this->save_settings( $action );
374 275 } else {
@@ -379,14 +280,8 @@
379 280
380 281 return $post_id;
381 282 }
382 283
383 - /**
384 - * @param object $action
385 - * @param int|string $form_id
386 - *
387 - * @return int|WP_Error
388 - */
389 284 public function duplicate_one( $action, $form_id ) {
390 285 global $frm_duplicate_ids;
391 286
392 287 $action->menu_order = $form_id;
@@ -414,15 +309,8 @@
414 309
415 310 return $this->save_settings( $action );
416 311 }
417 312
418 - /**
419 - * @param array $action
420 - * @param array|string $subkey
421 - * @param mixed $val
422 - *
423 - * @return array
424 - */
425 313 private function duplicate_array_walk( $action, $subkey, $val ) {
426 314 global $frm_duplicate_ids;
427 315
428 316 if ( is_array( $subkey ) ) {
@@ -444,9 +332,9 @@
444 332 } elseif ( $ck == $subkey ) {
445 333 $action[ $ck ] = $this->maybe_switch_field_ids( $action[ $ck ] );
446 334 }
447 335 }
448 - }//end if
336 + }
449 337
450 338 return $action;
451 339 }
452 340
@@ -453,12 +341,8 @@
453 341 /**
454 342 * Deal with changed settings.
455 343 *
456 344 * Do NOT over-ride this function
457 - *
458 - * @param int|string $form_id
459 - *
460 - * @return array|null
461 345 */
462 346 public function update_callback( $form_id ) {
463 347 $this->form_id = $form_id;
464 348
@@ -482,9 +366,9 @@
482 366
483 367 foreach ( $settings as $number => $new_instance ) {
484 368 $this->_set( $number );
485 369
486 - $old_instance = $all_instances[ $number ] ?? array();
370 + $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array();
487 371
488 372 if ( ! isset( $new_instance['post_status'] ) ) {
489 373 $new_instance['post_status'] = 'draft';
490 374 }
@@ -499,10 +383,10 @@
499 383
500 384 $new_instance['post_type'] = FrmFormActionsController::$action_post_type;
501 385 $new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number;
502 386 $new_instance['menu_order'] = $this->form_id;
503 - $new_instance['post_date'] = $old_instance->post_date ?? '';
504 - $instance = $this->update( $new_instance, $old_instance );
387 + $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : '';
388 + $instance = $this->update( $new_instance, $old_instance );
505 389
506 390 /**
507 391 * Filter an action's settings before saving.
508 392 *
@@ -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
@@ -538,10 +422,9 @@
538 422 *
539 423 * @since 3.04
540 424 *
541 425 * @param array $new_instance
542 - * @param array|stdClass $old_instance
543 - *
426 + * @param stdClass|array $old_instance
544 427 * @return void
545 428 */
546 429 protected function maybe_update_status( $new_instance, $old_instance ) {
547 430 if ( ! is_object( $old_instance ) || $new_instance['post_status'] === $old_instance->post_status ) {
@@ -556,13 +439,8 @@
556 439 )
557 440 );
558 441 }
559 442
560 - /**
561 - * @param array $settings
562 - *
563 - * @return int|WP_Error
564 - */
565 443 public function save_settings( $settings ) {
566 444 self::clear_cache();
567 445
568 446 return FrmDb::save_settings( $settings, 'frm_actions' );
@@ -567,16 +445,10 @@
567 445
568 446 return FrmDb::save_settings( $settings, 'frm_actions' );
569 447 }
570 448
571 - /**
572 - * @param int $id
573 - *
574 - * @return object|null
575 - */
576 449 public function get_single_action( $id ) {
577 450 $action = get_post( $id );
578 -
579 451 if ( $action ) {
580 452 $action = $this->prepare_action( $action );
581 453 $this->_set( $id );
582 454 }
@@ -583,42 +455,26 @@
583 455
584 456 return $action;
585 457 }
586 458
587 - /**
588 - * @param int|string $form_id
589 - *
590 - * @return array
591 - */
592 459 public function get_one( $form_id ) {
593 460 return $this->get_all( $form_id, 1 );
594 461 }
595 462
596 - /**
597 - * @param int|string $form_id
598 - * @param string $type
599 - * @param array $atts
600 - *
601 - * @return array
602 - */
603 463 public static function get_action_for_form( $form_id, $type = 'all', $atts = array() ) {
604 464 $action_controls = FrmFormActionsController::get_form_actions( $type );
605 -
606 465 if ( empty( $action_controls ) ) {
607 466 // don't continue if there are no available actions
608 467 return array();
609 468 }
610 469
611 - if ( 'all' !== $type ) {
612 - if ( is_array( $action_controls ) ) {
613 - return array();
614 - }
470 + if ( 'all' != $type ) {
615 471 return $action_controls->get_all( $form_id, $atts );
616 472 }
617 473
618 474 self::prepare_get_action( $atts );
619 475
620 - $limit = self::get_action_limit( $form_id, $atts['limit'] );
476 + $limit = apply_filters( 'frm_form_action_limit', $atts['limit'], compact( 'type', 'form_id' ) );
621 477
622 478 $args = self::action_args( $form_id, $limit );
623 479 $args['post_status'] = $atts['post_status'];
624 480 $actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' );
@@ -627,9 +483,8 @@
627 483 return array();
628 484 }
629 485
630 486 $settings = array();
631 -
632 487 foreach ( $actions as $action ) {
633 488 // some plugins/themes are formatting the post_excerpt
634 489 $action->post_excerpt = sanitize_title( $action->post_excerpt );
635 490
@@ -652,30 +507,11 @@
652 507 return $settings;
653 508 }
654 509
655 510 /**
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 511 * @since 3.04
673 - *
674 512 * @param array $args
675 513 * @param string $default_status
676 - *
677 - * @return void
678 514 */
679 515 protected static function prepare_get_action( &$args, $default_status = 'publish' ) {
680 516 if ( is_numeric( $args ) ) {
681 517 // for reverse compatibility. $limit was changed to $args
@@ -682,9 +518,8 @@
682 518 $args = array(
683 519 'limit' => $args,
684 520 );
685 521 }
686 -
687 522 $defaults = array(
688 523 'limit' => 99,
689 524 'post_status' => $default_status,
690 525 );
@@ -691,21 +526,14 @@
691 526 $args = wp_parse_args( $args, $defaults );
692 527 }
693 528
694 529 /**
695 - * @param int $action_id
696 - * @param string $type
697 - *
698 - * @return bool|object
530 + * @param int $action_id
699 531 */
700 532 public static function get_single_action_type( $action_id, $type ) {
701 533 if ( ! $type ) {
702 534 return false;
703 535 }
704 -
705 - /**
706 - * @var FrmFormAction
707 - */
708 536 $action_control = FrmFormActionsController::get_form_actions( $type );
709 537
710 538 return $action_control->get_single_action( $action_id );
711 539 }
@@ -710,31 +538,20 @@
710 538 return $action_control->get_single_action( $action_id );
711 539 }
712 540
713 541 /**
714 - * @param int $form_id
715 - * @param string $type
542 + * @param int $form_id
716 543 *
717 544 * @return bool
718 545 */
719 546 public static function form_has_action_type( $form_id, $type ) {
720 - $actions = self::get_action_for_form( $form_id, $type );
721 - return ! empty( $actions );
547 + $payment_actions = self::get_action_for_form( $form_id, $type );
548 +
549 + return ! empty( $payment_actions );
722 550 }
723 551
724 - /**
725 - * @param false|int|string $form_id
726 - * @param array $atts
727 - *
728 - * @return array
729 - */
730 552 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 553 self::prepare_get_action( $atts, 'any' );
736 -
737 554 $limit = $atts['limit'];
738 555
739 556 if ( $form_id ) {
740 557 $this->form_id = $form_id;
@@ -745,10 +562,10 @@
745 562 global $frm_vars;
746 563 $frm_vars['action_type'] = $type;
747 564
748 565 add_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
749 - $query = self::action_args( $form_id, $limit );
750 - $query['post_status'] = $atts['post_status'];
566 + $query = self::action_args( $form_id, $limit );
567 + $query['post_status'] = $atts['post_status'];
751 568 $query['suppress_filters'] = false;
752 569
753 570 $actions = FrmDb::check_cache( json_encode( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' );
754 571 unset( $query );
@@ -759,9 +576,8 @@
759 576 return array();
760 577 }
761 578
762 579 $settings = array();
763 -
764 580 foreach ( $actions as $action ) {
765 581 if ( count( $settings ) >= $limit ) {
766 582 continue;
767 583 }
@@ -777,14 +593,8 @@
777 593
778 594 return $settings;
779 595 }
780 596
781 - /**
782 - * @param int $form_id
783 - * @param int $limit
784 - *
785 - * @return array
786 - */
787 597 public static function action_args( $form_id = 0, $limit = 99 ) {
788 598 $args = array(
789 599 'post_type' => FrmFormActionsController::$action_post_type,
790 600 'post_status' => 'publish',
@@ -799,13 +609,8 @@
799 609
800 610 return $args;
801 611 }
802 612
803 - /**
804 - * @param WP_Post $action
805 - *
806 - * @return WP_Post
807 - */
808 613 public function prepare_action( $action ) {
809 614 $action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content );
810 615 $action->post_excerpt = sanitize_title( $action->post_excerpt );
811 616
@@ -815,9 +620,9 @@
815 620 $action->post_content += $default_values;
816 621
817 622 foreach ( $default_values as $k => $vals ) {
818 623 if ( is_array( $vals ) && ! empty( $vals ) ) {
819 - if ( 'event' === $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
624 + if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
820 625 continue;
821 626 }
822 627 $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals );
823 628 }
@@ -829,14 +634,8 @@
829 634
830 635 return $action;
831 636 }
832 637
833 - /**
834 - * @param false|int|string $form_id
835 - * @param string $type
836 - *
837 - * @return void
838 - */
839 638 public function destroy( $form_id = false, $type = 'default' ) {
840 639 global $wpdb;
841 640
842 641 $this->form_id = $form_id;
@@ -841,13 +640,11 @@
841 640
842 641 $this->form_id = $form_id;
843 642
844 643 $query = array( 'post_type' => FrmFormActionsController::$action_post_type );
845 -
846 644 if ( $form_id ) {
847 645 $query['menu_order'] = $form_id;
848 646 }
849 -
850 647 if ( 'all' != $type ) {
851 648 $query['post_excerpt'] = $this->id_base;
852 649 }
853 650
@@ -862,25 +659,17 @@
862 659 /**
863 660 * Delete the action cache when a form action is created, deleted, or updated
864 661 *
865 662 * @since 2.0.5
866 - *
867 - * @return void
868 663 */
869 664 public static function clear_cache() {
870 665 FrmDb::cache_delete_group( 'frm_actions' );
871 666 }
872 667
873 - /**
874 - * @return array
875 - */
876 668 public function get_settings() {
877 669 return self::get_action_for_form( $this->form_id, $this->id_base );
878 670 }
879 671
880 - /**
881 - * @return array
882 - */
883 672 public function get_global_defaults() {
884 673 $defaults = $this->get_defaults();
885 674
886 675 if ( ! isset( $defaults['event'] ) ) {
@@ -896,11 +685,8 @@
896 685
897 686 return $defaults;
898 687 }
899 688
900 - /**
901 - * @return array
902 - */
903 689 public function get_global_switch_fields() {
904 690 $switch = $this->get_switch_fields();
905 691 $switch['conditions'] = array( 'hide_field' );
906 692
@@ -910,16 +696,11 @@
910 696 }
911 697
912 698 /**
913 699 * Migrate settings from form->options into new action.
914 - *
915 - * @param object $form
916 - * @param string $update
917 - *
918 - * @return int|WP_Error
919 700 */
920 701 public function migrate_to_2( $form, $update = 'update' ) {
921 - $action = $this->prepare_new( $form->id );
702 + $action = $this->prepare_new( $form->id );
922 703 FrmAppHelper::unserialize_or_decode( $form->options );
923 704
924 705 // fill with existing options
925 706 foreach ( $action->post_content as $name => $val ) {
@@ -957,30 +738,86 @@
957 738
958 739 return $post_id;
959 740 }
960 741
961 - /**
962 - * @param WP_Post $action
963 - * @param stdClass $entry
964 - *
965 - * @return bool
966 - */
967 742 public static function action_conditions_met( $action, $entry ) {
968 743 if ( is_callable( 'FrmProFormActionsController::action_conditions_met' ) ) {
969 744 return FrmProFormActionsController::action_conditions_met( $action, $entry );
970 745 }
971 746
972 - $stop = false;
747 + // This is here for reverse compatibility.
748 + $notification = $action->post_content;
749 + $stop = false;
750 + $met = array();
751 +
752 + if ( ! isset( $notification['conditions'] ) || empty( $notification['conditions'] ) ) {
753 + return $stop;
754 + }
755 +
756 + foreach ( $notification['conditions'] as $k => $condition ) {
757 + if ( ! is_numeric( $k ) ) {
758 + continue;
759 + }
760 +
761 + if ( $stop && 'any' == $notification['conditions']['any_all'] && 'stop' == $notification['conditions']['send_stop'] ) {
762 + continue;
763 + }
764 +
765 + self::prepare_logic_value( $condition['hide_opt'], $action, $entry );
766 +
767 + $observed_value = self::get_value_from_entry( $entry, $condition['hide_field'] );
768 +
769 + $stop = FrmFieldsHelper::value_meets_condition( $observed_value, $condition['hide_field_cond'], $condition['hide_opt'] );
770 +
771 + if ( $notification['conditions']['send_stop'] == 'send' ) {
772 + $stop = $stop ? false : true;
773 + }
774 +
775 + $met[ $stop ] = $stop;
776 + }
777 +
778 + if ( $notification['conditions']['any_all'] == 'all' && ! empty( $met ) && isset( $met[0] ) && isset( $met[1] ) ) {
779 + $stop = ( $notification['conditions']['send_stop'] == 'send' );
780 + } elseif ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset( $met[0] ) ) {
781 + $stop = false;
782 + }
783 +
973 784 return $stop;
974 785 }
975 786
976 787 /**
788 + * Prepare the logic value for comparison against the entered value
789 + *
790 + * @since 2.01.02
791 + * @deprecated 4.06.02
792 + *
793 + * @param array|string $logic_value
794 + */
795 + private static function prepare_logic_value( &$logic_value, $action, $entry ) {
796 + if ( is_array( $logic_value ) ) {
797 + $logic_value = reset( $logic_value );
798 + }
799 +
800 + if ( $logic_value == 'current_user' ) {
801 + $logic_value = get_current_user_id();
802 + }
803 +
804 + $logic_value = apply_filters( 'frm_content', $logic_value, $action->menu_order, $entry );
805 +
806 + /**
807 + * @since 4.04.05
808 + */
809 + $logic_value = apply_filters( 'frm_action_logic_value', $logic_value );
810 + }
811 +
812 + /**
977 813 * Get the value from a specific field and entry
978 814 *
979 815 * @since 2.01.02
816 + * @deprecated 4.06.02
980 817 *
981 818 * @param object $entry
982 - * @param int $field_id
819 + * @param int $field_id
983 820 *
984 821 * @return array|bool|mixed|string
985 822 */
986 823 private static function get_value_from_entry( $entry, $field_id ) {
@@ -1002,13 +839,8 @@
1002 839
1003 840 return $observed_value;
1004 841 }
1005 842
1006 - /**
1007 - * @param string $class
1008 - *
1009 - * @return array
1010 - */
1011 843 public static function default_action_opts( $class = '' ) {
1012 844 return array(
1013 845 'classes' => 'frm_icon_font ' . $class,
1014 846 'active' => false,
@@ -1015,11 +847,8 @@
1015 847 'limit' => 0,
1016 848 );
1017 849 }
1018 850
1019 - /**
1020 - * @return array
1021 - */
1022 851 public static function trigger_labels() {
1023 852 $triggers = array(
1024 853 'draft' => __( 'Draft is saved', 'formidable' ),
1025 854 'create' => __( 'Entry is created', 'formidable' ),
@@ -1030,11 +859,8 @@
1030 859
1031 860 return apply_filters( 'frm_action_triggers', $triggers );
1032 861 }
1033 862
1034 - /**
1035 - * @return void
1036 - */
1037 863 public function render_conditional_logic_call_to_action() {
1038 864 ?>
1039 865 <h3>
1040 866 <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 +869,8 @@
1043 869 </h3>
1044 870 <?php
1045 871 }
1046 872
1047 - /**
1048 - * @return string
1049 - */
1050 873 protected function get_upgrade_text() {
1051 874 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 875 }
1073 876 }