PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.2
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 +112 -150 6.256.2 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,10 +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
38 + * @param array $instance Current settings
92 39 */
93 40 public function form( $instance, $args = array() ) {
94 41 echo '<p class="no-options-widget">' . esc_html__( 'There are no options for this action.', 'formidable' ) . '</p>';
95 42
@@ -121,14 +68,14 @@
121 68 *
122 69 * @param string $id_base Optional Base ID for the widget, lower case,
123 70 * if left empty a portion of the widget's class name will be used. Has to be unique.
124 71 * @param string $name Name for the widget displayed on the configuration page.
125 - * @param array $action_options Optional Passed to wp_register_sidebar_widget().
126 - * - description: shown on the configuration page.
127 - * - classname.
128 - * @param array $control_options Optional Passed to wp_register_widget_control().
129 - * - width: required if more than 250px.
130 - * - height: currently not used but may be needed in the future.
72 + * @param array $action_options Optional Passed to wp_register_sidebar_widget()
73 + * - description: shown on the configuration page
74 + * - classname
75 + * @param array $control_options Optional Passed to wp_register_widget_control()
76 + * - width: required if more than 250px
77 + * - height: currently not used but may be needed in the future
131 78 */
132 79 public function __construct( $id_base, $name, $action_options = array(), $control_options = array() ) {
133 80 if ( ! defined( 'ABSPATH' ) ) {
134 81 die( 'You are not allowed to call this page directly.' );
@@ -164,11 +111,11 @@
164 111 }
165 112
166 113 $upgrade_class = isset( $action_options['classes'] ) && $action_options['classes'] === 'frm_show_upgrade';
167 114 if ( $action_options['group'] === $id_base ) {
168 - $upgrade_class = strpos( $action_options['classes'], 'frm_show_upgrade' ) !== false;
115 + $upgrade_class = strpos( $action_options['classes'], 'frm_show_upgrade' ) !== false;
169 116 $action_options['classes'] = $group['icon'];
170 - } elseif ( empty( $action_options['classes'] ) || $upgrade_class ) {
117 + } elseif ( ! isset( $action_options['classes'] ) || empty( $action_options['classes'] ) || $upgrade_class ) {
171 118 $action_options['classes'] = $group['icon'];
172 119 }
173 120
174 121 if ( $upgrade_class ) {
@@ -188,9 +135,9 @@
188 135
189 136 /**
190 137 * Help to switch old field id by new field id for duplicate form
191 138 *
192 - * @param string $action id of the field that needs to be switched.
139 + * @param string $action id of the field that needs to be switched
193 140 *
194 141 * @return string
195 142 */
196 143 public function maybe_switch_field_ids( $action ) {
@@ -229,14 +176,14 @@
229 176 * Constructs name attributes for use in form() fields
230 177 *
231 178 * This function should be used in form() methods to create name attributes for fields to be saved by update()
232 179 *
233 - * @param string $field_name Field name.
180 + * @param string $field_name Field name
234 181 *
235 182 * @return string Name attribute for $field_name
236 183 */
237 184 public function get_field_name( $field_name, $post_field = 'post_content' ) {
238 - $name = $this->option_name . '[' . $this->number . ']';
185 + $name = $this->option_name . '[' . $this->number . ']';
239 186 $name .= ( empty( $post_field ) ? '' : '[' . $post_field . ']' );
240 187 $name .= '[' . $field_name . ']';
241 188
242 189 return $name;
@@ -246,9 +193,9 @@
246 193 * Constructs id attributes for use in form() fields
247 194 *
248 195 * This function should be used in form() methods to create id attributes for fields to be saved by update()
249 196 *
250 - * @param string $field_name Field name.
197 + * @param string $field_name Field name
251 198 *
252 199 * @return string ID attribute for $field_name
253 200 */
254 201 public function get_field_id( $field_name ) {
@@ -254,8 +201,10 @@
254 201 public function get_field_id( $field_name ) {
255 202 return $field_name . '_' . $this->number;
256 203 }
257 204
205 + // Private Function. Don't worry about this.
206 +
258 207 /**
259 208 * @param int|string $number
260 209 * @return void
261 210 */
@@ -323,18 +272,17 @@
323 272 unset( $action );
324 273 }
325 274 }
326 275
327 - /**
328 - * Check if imported action should be created or updated.
276 + /* Check if imported action should be created or updated
329 277 *
330 278 * @since 2.0
331 279 *
332 280 * @param array $action
333 - * @return int $post_id
281 + * @return integer $post_id
334 282 */
335 283 public function maybe_create_action( $action, $forms ) {
336 - if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && isset( $forms[ $action['menu_order'] ] ) && $forms[ $action['menu_order'] ] === 'updated' ) {
284 + if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && isset( $forms[ $action['menu_order'] ] ) && $forms[ $action['menu_order'] ] == 'updated' ) {
337 285 // Update action only
338 286 $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
339 287 $post_id = $this->save_settings( $action );
340 288 } else {
@@ -400,9 +348,9 @@
400 348 } elseif ( $ck == $subkey ) {
401 349 $action[ $ck ] = $this->maybe_switch_field_ids( $action[ $ck ] );
402 350 }
403 351 }
404 - }//end if
352 + }
405 353
406 354 return $action;
407 355 }
408 356
@@ -434,9 +382,9 @@
434 382
435 383 foreach ( $settings as $number => $new_instance ) {
436 384 $this->_set( $number );
437 385
438 - $old_instance = $all_instances[ $number ] ?? array();
386 + $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array();
439 387
440 388 if ( ! isset( $new_instance['post_status'] ) ) {
441 389 $new_instance['post_status'] = 'draft';
442 390 }
@@ -451,10 +399,10 @@
451 399
452 400 $new_instance['post_type'] = FrmFormActionsController::$action_post_type;
453 401 $new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number;
454 402 $new_instance['menu_order'] = $this->form_id;
455 - $new_instance['post_date'] = $old_instance->post_date ?? '';
456 - $instance = $this->update( $new_instance, $old_instance );
403 + $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : '';
404 + $instance = $this->update( $new_instance, $old_instance );
457 405
458 406 /**
459 407 * Filter an action's settings before saving.
460 408 *
@@ -462,12 +410,12 @@
462 410 * to update settings.
463 411 *
464 412 * @since 2.0
465 413 *
466 - * @param array $instance The current widget instance's settings.
467 - * @param array $new_instance Array of new widget settings.
468 - * @param array $old_instance Array of old widget settings.
469 - * @param FrmFormAction $form_action FrmFormAction instance.
414 + * @param array $instance The current widget instance's settings.
415 + * @param array $new_instance Array of new widget settings.
416 + * @param array $old_instance Array of old widget settings.
417 + * @param WP_Widget $this The current widget instance.
470 418 */
471 419 $instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this );
472 420
473 421 $instance['post_content'] = apply_filters( 'frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this );
@@ -479,9 +427,9 @@
479 427
480 428 $action_ids[] = $this->save_settings( $instance );
481 429
482 430 $this->updated = true;
483 - }//end foreach
431 + }
484 432
485 433 return $action_ids;
486 434 }
487 435
@@ -490,9 +438,9 @@
490 438 *
491 439 * @since 3.04
492 440 *
493 441 * @param array $new_instance
494 - * @param array|stdClass $old_instance
442 + * @param stdClass|array $old_instance
495 443 * @return void
496 444 */
497 445 protected function maybe_update_status( $new_instance, $old_instance ) {
498 446 if ( ! is_object( $old_instance ) || $new_instance['post_status'] === $old_instance->post_status ) {
@@ -507,12 +455,8 @@
507 455 )
508 456 );
509 457 }
510 458
511 - /**
512 - * @param array $settings
513 - * @return int|WP_Error
514 - */
515 459 public function save_settings( $settings ) {
516 460 self::clear_cache();
517 461
518 462 return FrmDb::save_settings( $settings, 'frm_actions' );
@@ -538,18 +482,15 @@
538 482 // don't continue if there are no available actions
539 483 return array();
540 484 }
541 485
542 - if ( 'all' !== $type ) {
543 - if ( is_array( $action_controls ) ) {
544 - return array();
545 - }
486 + if ( 'all' != $type ) {
546 487 return $action_controls->get_all( $form_id, $atts );
547 488 }
548 489
549 490 self::prepare_get_action( $atts );
550 491
551 - $limit = self::get_action_limit( $form_id, $atts['limit'] );
492 + $limit = apply_filters( 'frm_form_action_limit', $atts['limit'], compact( 'type', 'form_id' ) );
552 493
553 494 $args = self::action_args( $form_id, $limit );
554 495 $args['post_status'] = $atts['post_status'];
555 496 $actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' );
@@ -582,24 +523,8 @@
582 523 return $settings;
583 524 }
584 525
585 526 /**
586 - * Get the limit for the number of actions for a single form. By default, this is 99, but
587 - * it can be modified with a code snippet.
588 - *
589 - * @since 6.17 This logic from moved from FrmFormAction::get_action_for_form.
590 - *
591 - * @param int|string $form_id
592 - * @param int|string $limit The unfiltered limit value.
593 - *
594 - * @return int The filtered limit value.
595 - */
596 - public static function get_action_limit( $form_id, $limit = 99 ) {
597 - $type = 'all';
598 - return (int) apply_filters( 'frm_form_action_limit', (int) $limit, compact( 'type', 'form_id' ) );
599 - }
600 -
601 - /**
602 527 * @since 3.04
603 528 *
604 529 * @param array $args
605 530 * @param string $default_status
@@ -626,12 +551,8 @@
626 551 public static function get_single_action_type( $action_id, $type ) {
627 552 if ( ! $type ) {
628 553 return false;
629 554 }
630 -
631 - /**
632 - * @var FrmFormAction
633 - */
634 555 $action_control = FrmFormActionsController::get_form_actions( $type );
635 556
636 557 return $action_control->get_single_action( $action_id );
637 558 }
@@ -665,10 +586,10 @@
665 586 global $frm_vars;
666 587 $frm_vars['action_type'] = $type;
667 588
668 589 add_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
669 - $query = self::action_args( $form_id, $limit );
670 - $query['post_status'] = $atts['post_status'];
590 + $query = self::action_args( $form_id, $limit );
591 + $query['post_status'] = $atts['post_status'];
671 592 $query['suppress_filters'] = false;
672 593
673 594 $actions = FrmDb::check_cache( json_encode( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' );
674 595 unset( $query );
@@ -716,9 +637,9 @@
716 637 return $args;
717 638 }
718 639
719 640 /**
720 - * @param array|WP_Post $action
641 + * @param WP_Post|array $action
721 642 */
722 643 public function prepare_action( $action ) {
723 644 $action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content );
724 645 $action->post_excerpt = sanitize_title( $action->post_excerpt );
@@ -729,9 +650,9 @@
729 650 $action->post_content += $default_values;
730 651
731 652 foreach ( $default_values as $k => $vals ) {
732 653 if ( is_array( $vals ) && ! empty( $vals ) ) {
733 - if ( 'event' === $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
654 + if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
734 655 continue;
735 656 }
736 657 $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals );
737 658 }
@@ -815,9 +736,9 @@
815 736 /**
816 737 * Migrate settings from form->options into new action.
817 738 */
818 739 public function migrate_to_2( $form, $update = 'update' ) {
819 - $action = $this->prepare_new( $form->id );
740 + $action = $this->prepare_new( $form->id );
820 741 FrmAppHelper::unserialize_or_decode( $form->options );
821 742
822 743 // fill with existing options
823 744 foreach ( $action->post_content as $name => $val ) {
@@ -855,29 +776,89 @@
855 776
856 777 return $post_id;
857 778 }
858 779
859 - /**
860 - * @param WP_Post $action
861 - * @param stdClass $entry
862 - * @return bool
863 - */
864 780 public static function action_conditions_met( $action, $entry ) {
865 781 if ( is_callable( 'FrmProFormActionsController::action_conditions_met' ) ) {
866 782 return FrmProFormActionsController::action_conditions_met( $action, $entry );
867 783 }
868 784
869 - $stop = false;
785 + // This is here for reverse compatibility.
786 + $notification = $action->post_content;
787 + $stop = false;
788 + $met = array();
789 +
790 + if ( ! isset( $notification['conditions'] ) || empty( $notification['conditions'] ) ) {
791 + return $stop;
792 + }
793 +
794 + foreach ( $notification['conditions'] as $k => $condition ) {
795 + if ( ! is_numeric( $k ) ) {
796 + continue;
797 + }
798 +
799 + if ( $stop && 'any' == $notification['conditions']['any_all'] && 'stop' == $notification['conditions']['send_stop'] ) {
800 + continue;
801 + }
802 +
803 + self::prepare_logic_value( $condition['hide_opt'], $action, $entry );
804 +
805 + $observed_value = self::get_value_from_entry( $entry, $condition['hide_field'] );
806 +
807 + $stop = FrmFieldsHelper::value_meets_condition( $observed_value, $condition['hide_field_cond'], $condition['hide_opt'] );
808 +
809 + if ( $notification['conditions']['send_stop'] == 'send' ) {
810 + $stop = $stop ? false : true;
811 + }
812 +
813 + $met[ $stop ] = $stop;
814 + }
815 +
816 + if ( $notification['conditions']['any_all'] == 'all' && ! empty( $met ) && isset( $met[0] ) && isset( $met[1] ) ) {
817 + $stop = ( $notification['conditions']['send_stop'] == 'send' );
818 + } elseif ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset( $met[0] ) ) {
819 + $stop = false;
820 + }
821 +
870 822 return $stop;
871 823 }
872 824
873 825 /**
826 + * Prepare the logic value for comparison against the entered value
827 + *
828 + * @since 2.01.02
829 + *
830 + * @deprecated 4.06.02
831 + *
832 + * @param array|string $logic_value
833 + *
834 + * @return void
835 + */
836 + private static function prepare_logic_value( &$logic_value, $action, $entry ) {
837 + if ( is_array( $logic_value ) ) {
838 + $logic_value = reset( $logic_value );
839 + }
840 +
841 + if ( $logic_value == 'current_user' ) {
842 + $logic_value = get_current_user_id();
843 + }
844 +
845 + $logic_value = apply_filters( 'frm_content', $logic_value, $action->menu_order, $entry );
846 +
847 + /**
848 + * @since 4.04.05
849 + */
850 + $logic_value = apply_filters( 'frm_action_logic_value', $logic_value );
851 + }
852 +
853 + /**
874 854 * Get the value from a specific field and entry
875 855 *
876 856 * @since 2.01.02
857 + * @deprecated 4.06.02
877 858 *
878 859 * @param object $entry
879 - * @param int $field_id
860 + * @param int $field_id
880 861 *
881 862 * @return array|bool|mixed|string
882 863 */
883 864 private static function get_value_from_entry( $entry, $field_id ) {
@@ -942,25 +923,6 @@
942 923 * @return string
943 924 */
944 925 protected function get_upgrade_text() {
945 926 return __( 'Conditional form actions', 'formidable' );
946 - }
947 -
948 - /**
949 - * Gets form fields for form action settings.
950 - *
951 - * @since 6.10
952 - *
953 - * @param int $form_id Form ID.
954 - * @return object[]
955 - */
956 - protected function get_form_fields( $form_id ) {
957 - // Get form fields, include embedded and repeater child fields.
958 - $form_fields = FrmField::get_all_for_form( $form_id, '', 'include' );
959 - return array_filter(
960 - $form_fields,
961 - function ( $form_field ) {
962 - return ! FrmField::is_no_save_field( $form_field->type );
963 - }
964 - );
965 927 }
966 928 }