PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.16
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.16
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 +129 -51 6.46.16 View file →
@@ -4,19 +4,71 @@
4 4 }
5 5
6 6 class FrmFormAction {
7 7
8 - public $id_base; // Root id for all actions of this type.
9 - public $name; // Name for this action type.
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 + */
10 27 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()
13 28
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.
29 + /**
30 + * Option array passed to wp_register_sidebar_widget().
31 + *
32 + * @var array
33 + */
34 + public $action_options;
18 35
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 +
19 71 // Member functions that you must over-ride.
20 72
21 73 /**
22 74 * This function should check that $new_instance is set correctly.
@@ -22,10 +74,10 @@
22 74 * This function should check that $new_instance is set correctly.
23 75 * The newly calculated value of $instance should be returned.
24 76 * If "false" is returned, the instance won't be saved/updated.
25 77 *
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
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.
28 80 *
29 81 * @return array Settings to save or bool false to cancel saving
30 82 */
31 83 public function update( $new_instance, $old_instance ) {
@@ -34,9 +86,10 @@
34 86
35 87 /**
36 88 * Echo the settings update form
37 89 *
38 - * @param array $instance Current settings
90 + * @param WP_Post $instance Current settings.
91 + * @param array $args
39 92 */
40 93 public function form( $instance, $args = array() ) {
41 94 echo '<p class="no-options-widget">' . esc_html__( 'There are no options for this action.', 'formidable' ) . '</p>';
42 95
@@ -68,14 +121,14 @@
68 121 *
69 122 * @param string $id_base Optional Base ID for the widget, lower case,
70 123 * if left empty a portion of the widget's class name will be used. Has to be unique.
71 124 * @param string $name Name for the widget displayed on the configuration page.
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
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.
78 131 */
79 132 public function __construct( $id_base, $name, $action_options = array(), $control_options = array() ) {
80 133 if ( ! defined( 'ABSPATH' ) ) {
81 134 die( 'You are not allowed to call this page directly.' );
@@ -111,11 +164,11 @@
111 164 }
112 165
113 166 $upgrade_class = isset( $action_options['classes'] ) && $action_options['classes'] === 'frm_show_upgrade';
114 167 if ( $action_options['group'] === $id_base ) {
115 - $upgrade_class = strpos( $action_options['classes'], 'frm_show_upgrade' ) !== false;
168 + $upgrade_class = strpos( $action_options['classes'], 'frm_show_upgrade' ) !== false;
116 169 $action_options['classes'] = $group['icon'];
117 - } elseif ( ! isset( $action_options['classes'] ) || empty( $action_options['classes'] ) || $upgrade_class ) {
170 + } elseif ( empty( $action_options['classes'] ) || $upgrade_class ) {
118 171 $action_options['classes'] = $group['icon'];
119 172 }
120 173
121 174 if ( $upgrade_class ) {
@@ -135,9 +188,9 @@
135 188
136 189 /**
137 190 * Help to switch old field id by new field id for duplicate form
138 191 *
139 - * @param string $action id of the field that needs to be switched
192 + * @param string $action id of the field that needs to be switched.
140 193 *
141 194 * @return string
142 195 */
143 196 public function maybe_switch_field_ids( $action ) {
@@ -176,14 +229,14 @@
176 229 * Constructs name attributes for use in form() fields
177 230 *
178 231 * This function should be used in form() methods to create name attributes for fields to be saved by update()
179 232 *
180 - * @param string $field_name Field name
233 + * @param string $field_name Field name.
181 234 *
182 235 * @return string Name attribute for $field_name
183 236 */
184 237 public function get_field_name( $field_name, $post_field = 'post_content' ) {
185 - $name = $this->option_name . '[' . $this->number . ']';
238 + $name = $this->option_name . '[' . $this->number . ']';
186 239 $name .= ( empty( $post_field ) ? '' : '[' . $post_field . ']' );
187 240 $name .= '[' . $field_name . ']';
188 241
189 242 return $name;
@@ -193,9 +246,9 @@
193 246 * Constructs id attributes for use in form() fields
194 247 *
195 248 * This function should be used in form() methods to create id attributes for fields to be saved by update()
196 249 *
197 - * @param string $field_name Field name
250 + * @param string $field_name Field name.
198 251 *
199 252 * @return string ID attribute for $field_name
200 253 */
201 254 public function get_field_id( $field_name ) {
@@ -270,17 +323,18 @@
270 323 unset( $action );
271 324 }
272 325 }
273 326
274 - /* Check if imported action should be created or updated
327 + /**
328 + * Check if imported action should be created or updated.
275 329 *
276 330 * @since 2.0
277 331 *
278 332 * @param array $action
279 - * @return integer $post_id
333 + * @return int $post_id
280 334 */
281 335 public function maybe_create_action( $action, $forms ) {
282 - if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && isset( $forms[ $action['menu_order'] ] ) && $forms[ $action['menu_order'] ] == 'updated' ) {
336 + if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && isset( $forms[ $action['menu_order'] ] ) && $forms[ $action['menu_order'] ] === 'updated' ) {
283 337 // Update action only
284 338 $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
285 339 $post_id = $this->save_settings( $action );
286 340 } else {
@@ -346,9 +400,9 @@
346 400 } elseif ( $ck == $subkey ) {
347 401 $action[ $ck ] = $this->maybe_switch_field_ids( $action[ $ck ] );
348 402 }
349 403 }
350 - }
404 + }//end if
351 405
352 406 return $action;
353 407 }
354 408
@@ -398,9 +452,9 @@
398 452 $new_instance['post_type'] = FrmFormActionsController::$action_post_type;
399 453 $new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number;
400 454 $new_instance['menu_order'] = $this->form_id;
401 455 $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : '';
402 - $instance = $this->update( $new_instance, $old_instance );
456 + $instance = $this->update( $new_instance, $old_instance );
403 457
404 458 /**
405 459 * Filter an action's settings before saving.
406 460 *
@@ -408,12 +462,12 @@
408 462 * to update settings.
409 463 *
410 464 * @since 2.0
411 465 *
412 - * @param array $instance The current widget instance's settings.
413 - * @param array $new_instance Array of new widget settings.
414 - * @param array $old_instance Array of old widget settings.
415 - * @param WP_Widget $this The current widget instance.
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.
416 470 */
417 471 $instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this );
418 472
419 473 $instance['post_content'] = apply_filters( 'frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this );
@@ -425,9 +479,9 @@
425 479
426 480 $action_ids[] = $this->save_settings( $instance );
427 481
428 482 $this->updated = true;
429 - }
483 + }//end foreach
430 484
431 485 return $action_ids;
432 486 }
433 487
@@ -436,9 +490,9 @@
436 490 *
437 491 * @since 3.04
438 492 *
439 493 * @param array $new_instance
440 - * @param stdClass|array $old_instance
494 + * @param array|stdClass $old_instance
441 495 * @return void
442 496 */
443 497 protected function maybe_update_status( $new_instance, $old_instance ) {
444 498 if ( ! is_object( $old_instance ) || $new_instance['post_status'] === $old_instance->post_status ) {
@@ -453,8 +507,12 @@
453 507 )
454 508 );
455 509 }
456 510
511 + /**
512 + * @param array $settings
513 + * @return int|WP_Error
514 + */
457 515 public function save_settings( $settings ) {
458 516 self::clear_cache();
459 517
460 518 return FrmDb::save_settings( $settings, 'frm_actions' );
@@ -480,9 +538,9 @@
480 538 // don't continue if there are no available actions
481 539 return array();
482 540 }
483 541
484 - if ( 'all' != $type ) {
542 + if ( 'all' !== $type ) {
485 543 return $action_controls->get_all( $form_id, $atts );
486 544 }
487 545
488 546 self::prepare_get_action( $atts );
@@ -549,8 +607,12 @@
549 607 public static function get_single_action_type( $action_id, $type ) {
550 608 if ( ! $type ) {
551 609 return false;
552 610 }
611 +
612 + /**
613 + * @var FrmFormAction
614 + */
553 615 $action_control = FrmFormActionsController::get_form_actions( $type );
554 616
555 617 return $action_control->get_single_action( $action_id );
556 618 }
@@ -584,10 +646,10 @@
584 646 global $frm_vars;
585 647 $frm_vars['action_type'] = $type;
586 648
587 649 add_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
588 - $query = self::action_args( $form_id, $limit );
589 - $query['post_status'] = $atts['post_status'];
650 + $query = self::action_args( $form_id, $limit );
651 + $query['post_status'] = $atts['post_status'];
590 652 $query['suppress_filters'] = false;
591 653
592 654 $actions = FrmDb::check_cache( json_encode( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' );
593 655 unset( $query );
@@ -635,9 +697,9 @@
635 697 return $args;
636 698 }
637 699
638 700 /**
639 - * @param WP_Post|array $action
701 + * @param array|WP_Post $action
640 702 */
641 703 public function prepare_action( $action ) {
642 704 $action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content );
643 705 $action->post_excerpt = sanitize_title( $action->post_excerpt );
@@ -648,9 +710,9 @@
648 710 $action->post_content += $default_values;
649 711
650 712 foreach ( $default_values as $k => $vals ) {
651 713 if ( is_array( $vals ) && ! empty( $vals ) ) {
652 - if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
714 + if ( 'event' === $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
653 715 continue;
654 716 }
655 717 $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals );
656 718 }
@@ -734,9 +796,9 @@
734 796 /**
735 797 * Migrate settings from form->options into new action.
736 798 */
737 799 public function migrate_to_2( $form, $update = 'update' ) {
738 - $action = $this->prepare_new( $form->id );
800 + $action = $this->prepare_new( $form->id );
739 801 FrmAppHelper::unserialize_or_decode( $form->options );
740 802
741 803 // fill with existing options
742 804 foreach ( $action->post_content as $name => $val ) {
@@ -784,9 +846,9 @@
784 846 $notification = $action->post_content;
785 847 $stop = false;
786 848 $met = array();
787 849
788 - if ( ! isset( $notification['conditions'] ) || empty( $notification['conditions'] ) ) {
850 + if ( empty( $notification['conditions'] ) ) {
789 851 return $stop;
790 852 }
791 853
792 854 foreach ( $notification['conditions'] as $k => $condition ) {
@@ -803,18 +865,18 @@
803 865 $observed_value = self::get_value_from_entry( $entry, $condition['hide_field'] );
804 866
805 867 $stop = FrmFieldsHelper::value_meets_condition( $observed_value, $condition['hide_field_cond'], $condition['hide_opt'] );
806 868
807 - if ( $notification['conditions']['send_stop'] == 'send' ) {
869 + if ( $notification['conditions']['send_stop'] === 'send' ) {
808 870 $stop = $stop ? false : true;
809 871 }
810 872
811 873 $met[ $stop ] = $stop;
812 - }
874 + }//end foreach
813 875
814 - if ( $notification['conditions']['any_all'] == 'all' && ! empty( $met ) && isset( $met[0] ) && isset( $met[1] ) ) {
815 - $stop = ( $notification['conditions']['send_stop'] == 'send' );
816 - } elseif ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset( $met[0] ) ) {
876 + if ( $notification['conditions']['any_all'] === 'all' && ! empty( $met ) && isset( $met[0] ) && isset( $met[1] ) ) {
877 + $stop = ( $notification['conditions']['send_stop'] === 'send' );
878 + } elseif ( $notification['conditions']['any_all'] === 'any' && $notification['conditions']['send_stop'] === 'send' && isset( $met[0] ) ) {
817 879 $stop = false;
818 880 }
819 881
820 882 return $stop;
@@ -824,10 +886,8 @@
824 886 * Prepare the logic value for comparison against the entered value
825 887 *
826 888 * @since 2.01.02
827 889 *
828 - * @deprecated 4.06.02
829 - *
830 890 * @param array|string $logic_value
831 891 *
832 892 * @return void
833 893 */
@@ -835,9 +895,9 @@
835 895 if ( is_array( $logic_value ) ) {
836 896 $logic_value = reset( $logic_value );
837 897 }
838 898
839 - if ( $logic_value == 'current_user' ) {
899 + if ( $logic_value === 'current_user' ) {
840 900 $logic_value = get_current_user_id();
841 901 }
842 902
843 903 $logic_value = apply_filters( 'frm_content', $logic_value, $action->menu_order, $entry );
@@ -851,12 +911,11 @@
851 911 /**
852 912 * Get the value from a specific field and entry
853 913 *
854 914 * @since 2.01.02
855 - * @deprecated 4.06.02
856 915 *
857 916 * @param object $entry
858 - * @param int $field_id
917 + * @param int $field_id
859 918 *
860 919 * @return array|bool|mixed|string
861 920 */
862 921 private static function get_value_from_entry( $entry, $field_id ) {
@@ -921,6 +980,25 @@
921 980 * @return string
922 981 */
923 982 protected function get_upgrade_text() {
924 983 return __( 'Conditional form actions', 'formidable' );
984 + }
985 +
986 + /**
987 + * Gets form fields for form action settings.
988 + *
989 + * @since 6.10
990 + *
991 + * @param int $form_id Form ID.
992 + * @return object[]
993 + */
994 + protected function get_form_fields( $form_id ) {
995 + // Get form fields, include embedded and repeater child fields.
996 + $form_fields = FrmField::get_all_for_form( $form_id, '', 'include' );
997 + return array_filter(
998 + $form_fields,
999 + function ( $form_field ) {
1000 + return ! FrmField::is_no_save_field( $form_field->type );
1001 + }
1002 + );
925 1003 }
926 1004 }