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