PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.5.4
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.5.4
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 -311 6.265.5.4 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 );
@@ -171,13 +106,12 @@
171 106 $action_options['color'] = 'var(--' . reset( $colors ) . ')';
172 107 }
173 108
174 109 $upgrade_class = isset( $action_options['classes'] ) && $action_options['classes'] === 'frm_show_upgrade';
175 -
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,10 +382,10 @@
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 : '';
387 + $instance = $this->update( $new_instance, $old_instance );
505 388
506 389 /**
507 390 * Filter an action's settings before saving.
508 391 *
@@ -510,12 +393,12 @@
510 393 * to update settings.
511 394 *
512 395 * @since 2.0
513 396 *
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.
397 + * @param array $instance The current widget instance's settings.
398 + * @param array $new_instance Array of new widget settings.
399 + * @param array $old_instance Array of old widget settings.
400 + * @param WP_Widget $this The current widget instance.
518 401 */
519 402 $instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this );
520 403
521 404 $instance['post_content'] = apply_filters( 'frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this );
@@ -527,9 +410,9 @@
527 410
528 411 $action_ids[] = $this->save_settings( $instance );
529 412
530 413 $this->updated = true;
531 - }//end foreach
414 + }
532 415
533 416 return $action_ids;
534 417 }
535 418
@@ -538,10 +421,9 @@
538 421 *
539 422 * @since 3.04
540 423 *
541 424 * @param array $new_instance
542 - * @param array|stdClass $old_instance
543 - *
425 + * @param stdClass|array $old_instance
544 426 * @return void
545 427 */
546 428 protected function maybe_update_status( $new_instance, $old_instance ) {
547 429 if ( ! is_object( $old_instance ) || $new_instance['post_status'] === $old_instance->post_status ) {
@@ -556,13 +438,8 @@
556 438 )
557 439 );
558 440 }
559 441
560 - /**
561 - * @param array $settings
562 - *
563 - * @return int|WP_Error
564 - */
565 442 public function save_settings( $settings ) {
566 443 self::clear_cache();
567 444
568 445 return FrmDb::save_settings( $settings, 'frm_actions' );
@@ -567,16 +444,10 @@
567 444
568 445 return FrmDb::save_settings( $settings, 'frm_actions' );
569 446 }
570 447
571 - /**
572 - * @param int $id
573 - *
574 - * @return object|null
575 - */
576 448 public function get_single_action( $id ) {
577 449 $action = get_post( $id );
578 -
579 450 if ( $action ) {
580 451 $action = $this->prepare_action( $action );
581 452 $this->_set( $id );
582 453 }
@@ -583,42 +454,26 @@
583 454
584 455 return $action;
585 456 }
586 457
587 - /**
588 - * @param int|string $form_id
589 - *
590 - * @return array
591 - */
592 458 public function get_one( $form_id ) {
593 459 return $this->get_all( $form_id, 1 );
594 460 }
595 461
596 - /**
597 - * @param int|string $form_id
598 - * @param string $type
599 - * @param array $atts
600 - *
601 - * @return array
602 - */
603 462 public static function get_action_for_form( $form_id, $type = 'all', $atts = array() ) {
604 463 $action_controls = FrmFormActionsController::get_form_actions( $type );
605 -
606 464 if ( empty( $action_controls ) ) {
607 465 // don't continue if there are no available actions
608 466 return array();
609 467 }
610 468
611 - if ( 'all' !== $type ) {
612 - if ( is_array( $action_controls ) ) {
613 - return array();
614 - }
469 + if ( 'all' != $type ) {
615 470 return $action_controls->get_all( $form_id, $atts );
616 471 }
617 472
618 473 self::prepare_get_action( $atts );
619 474
620 - $limit = self::get_action_limit( $form_id, $atts['limit'] );
475 + $limit = apply_filters( 'frm_form_action_limit', $atts['limit'], compact( 'type', 'form_id' ) );
621 476
622 477 $args = self::action_args( $form_id, $limit );
623 478 $args['post_status'] = $atts['post_status'];
624 479 $actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' );
@@ -627,9 +482,8 @@
627 482 return array();
628 483 }
629 484
630 485 $settings = array();
631 -
632 486 foreach ( $actions as $action ) {
633 487 // some plugins/themes are formatting the post_excerpt
634 488 $action->post_excerpt = sanitize_title( $action->post_excerpt );
635 489
@@ -652,30 +506,11 @@
652 506 return $settings;
653 507 }
654 508
655 509 /**
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 510 * @since 3.04
673 - *
674 511 * @param array $args
675 512 * @param string $default_status
676 - *
677 - * @return void
678 513 */
679 514 protected static function prepare_get_action( &$args, $default_status = 'publish' ) {
680 515 if ( is_numeric( $args ) ) {
681 516 // for reverse compatibility. $limit was changed to $args
@@ -682,9 +517,8 @@
682 517 $args = array(
683 518 'limit' => $args,
684 519 );
685 520 }
686 -
687 521 $defaults = array(
688 522 'limit' => 99,
689 523 'post_status' => $default_status,
690 524 );
@@ -691,21 +525,14 @@
691 525 $args = wp_parse_args( $args, $defaults );
692 526 }
693 527
694 528 /**
695 - * @param int $action_id
696 - * @param string $type
697 - *
698 - * @return bool|object
529 + * @param int $action_id
699 530 */
700 531 public static function get_single_action_type( $action_id, $type ) {
701 532 if ( ! $type ) {
702 533 return false;
703 534 }
704 -
705 - /**
706 - * @var FrmFormAction
707 - */
708 535 $action_control = FrmFormActionsController::get_form_actions( $type );
709 536
710 537 return $action_control->get_single_action( $action_id );
711 538 }
@@ -710,31 +537,20 @@
710 537 return $action_control->get_single_action( $action_id );
711 538 }
712 539
713 540 /**
714 - * @param int $form_id
715 - * @param string $type
541 + * @param int $form_id
716 542 *
717 543 * @return bool
718 544 */
719 545 public static function form_has_action_type( $form_id, $type ) {
720 - $actions = self::get_action_for_form( $form_id, $type );
721 - return ! empty( $actions );
546 + $payment_actions = self::get_action_for_form( $form_id, $type );
547 +
548 + return ! empty( $payment_actions );
722 549 }
723 550
724 - /**
725 - * @param false|int|string $form_id
726 - * @param array $atts
727 - *
728 - * @return array
729 - */
730 551 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 552 self::prepare_get_action( $atts, 'any' );
736 -
737 553 $limit = $atts['limit'];
738 554
739 555 if ( $form_id ) {
740 556 $this->form_id = $form_id;
@@ -745,10 +561,10 @@
745 561 global $frm_vars;
746 562 $frm_vars['action_type'] = $type;
747 563
748 564 add_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
749 - $query = self::action_args( $form_id, $limit );
750 - $query['post_status'] = $atts['post_status'];
565 + $query = self::action_args( $form_id, $limit );
566 + $query['post_status'] = $atts['post_status'];
751 567 $query['suppress_filters'] = false;
752 568
753 569 $actions = FrmDb::check_cache( json_encode( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' );
754 570 unset( $query );
@@ -759,9 +575,8 @@
759 575 return array();
760 576 }
761 577
762 578 $settings = array();
763 -
764 579 foreach ( $actions as $action ) {
765 580 if ( count( $settings ) >= $limit ) {
766 581 continue;
767 582 }
@@ -777,14 +592,8 @@
777 592
778 593 return $settings;
779 594 }
780 595
781 - /**
782 - * @param int $form_id
783 - * @param int $limit
784 - *
785 - * @return array
786 - */
787 596 public static function action_args( $form_id = 0, $limit = 99 ) {
788 597 $args = array(
789 598 'post_type' => FrmFormActionsController::$action_post_type,
790 599 'post_status' => 'publish',
@@ -799,13 +608,8 @@
799 608
800 609 return $args;
801 610 }
802 611
803 - /**
804 - * @param WP_Post $action
805 - *
806 - * @return WP_Post
807 - */
808 612 public function prepare_action( $action ) {
809 613 $action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content );
810 614 $action->post_excerpt = sanitize_title( $action->post_excerpt );
811 615
@@ -815,9 +619,9 @@
815 619 $action->post_content += $default_values;
816 620
817 621 foreach ( $default_values as $k => $vals ) {
818 622 if ( is_array( $vals ) && ! empty( $vals ) ) {
819 - if ( 'event' === $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
623 + if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
820 624 continue;
821 625 }
822 626 $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals );
823 627 }
@@ -829,14 +633,8 @@
829 633
830 634 return $action;
831 635 }
832 636
833 - /**
834 - * @param false|int|string $form_id
835 - * @param string $type
836 - *
837 - * @return void
838 - */
839 637 public function destroy( $form_id = false, $type = 'default' ) {
840 638 global $wpdb;
841 639
842 640 $this->form_id = $form_id;
@@ -841,13 +639,11 @@
841 639
842 640 $this->form_id = $form_id;
843 641
844 642 $query = array( 'post_type' => FrmFormActionsController::$action_post_type );
845 -
846 643 if ( $form_id ) {
847 644 $query['menu_order'] = $form_id;
848 645 }
849 -
850 646 if ( 'all' != $type ) {
851 647 $query['post_excerpt'] = $this->id_base;
852 648 }
853 649
@@ -862,25 +658,17 @@
862 658 /**
863 659 * Delete the action cache when a form action is created, deleted, or updated
864 660 *
865 661 * @since 2.0.5
866 - *
867 - * @return void
868 662 */
869 663 public static function clear_cache() {
870 664 FrmDb::cache_delete_group( 'frm_actions' );
871 665 }
872 666
873 - /**
874 - * @return array
875 - */
876 667 public function get_settings() {
877 668 return self::get_action_for_form( $this->form_id, $this->id_base );
878 669 }
879 670
880 - /**
881 - * @return array
882 - */
883 671 public function get_global_defaults() {
884 672 $defaults = $this->get_defaults();
885 673
886 674 if ( ! isset( $defaults['event'] ) ) {
@@ -896,11 +684,8 @@
896 684
897 685 return $defaults;
898 686 }
899 687
900 - /**
901 - * @return array
902 - */
903 688 public function get_global_switch_fields() {
904 689 $switch = $this->get_switch_fields();
905 690 $switch['conditions'] = array( 'hide_field' );
906 691
@@ -910,16 +695,11 @@
910 695 }
911 696
912 697 /**
913 698 * Migrate settings from form->options into new action.
914 - *
915 - * @param object $form
916 - * @param string $update
917 - *
918 - * @return int|WP_Error
919 699 */
920 700 public function migrate_to_2( $form, $update = 'update' ) {
921 - $action = $this->prepare_new( $form->id );
701 + $action = $this->prepare_new( $form->id );
922 702 FrmAppHelper::unserialize_or_decode( $form->options );
923 703
924 704 // fill with existing options
925 705 foreach ( $action->post_content as $name => $val ) {
@@ -957,30 +737,86 @@
957 737
958 738 return $post_id;
959 739 }
960 740
961 - /**
962 - * @param WP_Post $action
963 - * @param stdClass $entry
964 - *
965 - * @return bool
966 - */
967 741 public static function action_conditions_met( $action, $entry ) {
968 742 if ( is_callable( 'FrmProFormActionsController::action_conditions_met' ) ) {
969 743 return FrmProFormActionsController::action_conditions_met( $action, $entry );
970 744 }
971 745
972 - $stop = false;
746 + // This is here for reverse compatibility.
747 + $notification = $action->post_content;
748 + $stop = false;
749 + $met = array();
750 +
751 + if ( ! isset( $notification['conditions'] ) || empty( $notification['conditions'] ) ) {
752 + return $stop;
753 + }
754 +
755 + foreach ( $notification['conditions'] as $k => $condition ) {
756 + if ( ! is_numeric( $k ) ) {
757 + continue;
758 + }
759 +
760 + if ( $stop && 'any' == $notification['conditions']['any_all'] && 'stop' == $notification['conditions']['send_stop'] ) {
761 + continue;
762 + }
763 +
764 + self::prepare_logic_value( $condition['hide_opt'], $action, $entry );
765 +
766 + $observed_value = self::get_value_from_entry( $entry, $condition['hide_field'] );
767 +
768 + $stop = FrmFieldsHelper::value_meets_condition( $observed_value, $condition['hide_field_cond'], $condition['hide_opt'] );
769 +
770 + if ( $notification['conditions']['send_stop'] == 'send' ) {
771 + $stop = $stop ? false : true;
772 + }
773 +
774 + $met[ $stop ] = $stop;
775 + }
776 +
777 + if ( $notification['conditions']['any_all'] == 'all' && ! empty( $met ) && isset( $met[0] ) && isset( $met[1] ) ) {
778 + $stop = ( $notification['conditions']['send_stop'] == 'send' );
779 + } elseif ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset( $met[0] ) ) {
780 + $stop = false;
781 + }
782 +
973 783 return $stop;
974 784 }
975 785
976 786 /**
787 + * Prepare the logic value for comparison against the entered value
788 + *
789 + * @since 2.01.02
790 + * @deprecated 4.06.02
791 + *
792 + * @param array|string $logic_value
793 + */
794 + private static function prepare_logic_value( &$logic_value, $action, $entry ) {
795 + if ( is_array( $logic_value ) ) {
796 + $logic_value = reset( $logic_value );
797 + }
798 +
799 + if ( $logic_value == 'current_user' ) {
800 + $logic_value = get_current_user_id();
801 + }
802 +
803 + $logic_value = apply_filters( 'frm_content', $logic_value, $action->menu_order, $entry );
804 +
805 + /**
806 + * @since 4.04.05
807 + */
808 + $logic_value = apply_filters( 'frm_action_logic_value', $logic_value );
809 + }
810 +
811 + /**
977 812 * Get the value from a specific field and entry
978 813 *
979 814 * @since 2.01.02
815 + * @deprecated 4.06.02
980 816 *
981 817 * @param object $entry
982 - * @param int $field_id
818 + * @param int $field_id
983 819 *
984 820 * @return array|bool|mixed|string
985 821 */
986 822 private static function get_value_from_entry( $entry, $field_id ) {
@@ -1002,13 +838,8 @@
1002 838
1003 839 return $observed_value;
1004 840 }
1005 841
1006 - /**
1007 - * @param string $class
1008 - *
1009 - * @return array
1010 - */
1011 842 public static function default_action_opts( $class = '' ) {
1012 843 return array(
1013 844 'classes' => 'frm_icon_font ' . $class,
1014 845 'active' => false,
@@ -1015,11 +846,8 @@
1015 846 'limit' => 0,
1016 847 );
1017 848 }
1018 849
1019 - /**
1020 - * @return array
1021 - */
1022 850 public static function trigger_labels() {
1023 851 $triggers = array(
1024 852 'draft' => __( 'Draft is saved', 'formidable' ),
1025 853 'create' => __( 'Entry is created', 'formidable' ),
@@ -1030,11 +858,8 @@
1030 858
1031 859 return apply_filters( 'frm_action_triggers', $triggers );
1032 860 }
1033 861
1034 - /**
1035 - * @return void
1036 - */
1037 862 public function render_conditional_logic_call_to_action() {
1038 863 ?>
1039 864 <h3>
1040 865 <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 +868,8 @@
1043 868 </h3>
1044 869 <?php
1045 870 }
1046 871
1047 - /**
1048 - * @return string
1049 - */
1050 872 protected function get_upgrade_text() {
1051 873 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 874 }
1073 875 }