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 +73 -142 6.266.16 View file →
@@ -88,10 +88,8 @@
88 88 * Echo the settings update form
89 89 *
90 90 * @param WP_Post $instance Current settings.
91 91 * @param array $args
92 - *
93 - * @return string
94 92 */
95 93 public function form( $instance, $args = array() ) {
96 94 echo '<p class="no-options-widget">' . esc_html__( 'There are no options for this action.', 'formidable' ) . '</p>';
97 95
@@ -111,14 +109,8 @@
111 109 public function get_switch_fields() {
112 110 return array();
113 111 }
114 112
115 - /**
116 - * @param object $action
117 - * @param object $form
118 - *
119 - * @return object
120 - */
121 113 public function migrate_values( $action, $form ) {
122 114 return $action;
123 115 }
124 116
@@ -171,9 +163,8 @@
171 163 $action_options['color'] = 'var(--' . reset( $colors ) . ')';
172 164 }
173 165
174 166 $upgrade_class = isset( $action_options['classes'] ) && $action_options['classes'] === 'frm_show_upgrade';
175 -
176 167 if ( $action_options['group'] === $id_base ) {
177 168 $upgrade_class = strpos( $action_options['classes'], 'frm_show_upgrade' ) !== false;
178 169 $action_options['classes'] = $group['icon'];
179 170 } elseif ( empty( $action_options['classes'] ) || $upgrade_class ) {
@@ -189,13 +180,8 @@
189 180 }
190 181
191 182 /**
192 183 * @param string $id_base
193 - * @param string $name
194 - * @param array $action_options
195 - * @param array $control_options
196 - *
197 - * @return void
198 184 */
199 185 public function FrmFormAction( $id_base, $name, $action_options = array(), $control_options = array() ) {
200 186 self::__construct( $id_base, $name, $action_options, $control_options );
201 187 }
@@ -208,9 +194,8 @@
208 194 * @return string
209 195 */
210 196 public function maybe_switch_field_ids( $action ) {
211 197 $updated_action = apply_filters( 'frm_maybe_switch_field_ids', $action );
212 -
213 198 if ( $updated_action === $action ) {
214 199 $updated_action = FrmFieldsHelper::switch_field_ids( $action );
215 200 }
216 201 return $updated_action;
@@ -217,12 +202,8 @@
217 202 }
218 203
219 204 /**
220 205 * @since 4.0
221 - *
222 - * @param array $action_options
223 - *
224 - * @return array
225 206 */
226 207 protected function get_group( $action_options ) {
227 208 $groups = FrmFormActionsController::form_action_groups();
228 209 $group = 'misc';
@@ -249,9 +230,8 @@
249 230 *
250 231 * This function should be used in form() methods to create name attributes for fields to be saved by update()
251 232 *
252 233 * @param string $field_name Field name.
253 - * @param string $post_field
254 234 *
255 235 * @return string Name attribute for $field_name
256 236 */
257 237 public function get_field_name( $field_name, $post_field = 'post_content' ) {
@@ -276,9 +256,8 @@
276 256 }
277 257
278 258 /**
279 259 * @param int|string $number
280 - *
281 260 * @return void
282 261 */
283 262 public function _set( $number ) {
284 263 $this->number = $number;
@@ -285,10 +264,8 @@
285 264 $this->id = $this->id_base . '-' . $number;
286 265 }
287 266
288 267 /**
289 - * @param false|int|string $form_id
290 - *
291 268 * @return object
292 269 */
293 270 public function prepare_new( $form_id = false ) {
294 271 if ( $form_id ) {
@@ -319,13 +296,8 @@
319 296
320 297 return (object) $form_action;
321 298 }
322 299
323 - /**
324 - * @param int|string $form_id
325 - *
326 - * @return int|WP_Error
327 - */
328 300 public function create( $form_id ) {
329 301 $this->form_id = $form_id;
330 302
331 303 $action = $this->prepare_new();
@@ -333,11 +305,8 @@
333 305 return $this->save_settings( $action );
334 306 }
335 307
336 308 /**
337 - * @param int|string $form_id
338 - * @param int|string $old_id
339 - *
340 309 * @return void
341 310 */
342 311 public function duplicate_form_actions( $form_id, $old_id ) {
343 312 if ( $form_id == $old_id ) {
@@ -348,9 +317,8 @@
348 317 $this->form_id = $old_id;
349 318 $actions = $this->get_all( $old_id );
350 319
351 320 $this->form_id = $form_id;
352 -
353 321 foreach ( $actions as $action ) {
354 322 $this->duplicate_one( $action, $form_id );
355 323 unset( $action );
356 324 }
@@ -361,10 +329,8 @@
361 329 *
362 330 * @since 2.0
363 331 *
364 332 * @param array $action
365 - * @param array $forms
366 - *
367 333 * @return int $post_id
368 334 */
369 335 public function maybe_create_action( $action, $forms ) {
370 336 if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && isset( $forms[ $action['menu_order'] ] ) && $forms[ $action['menu_order'] ] === 'updated' ) {
@@ -380,12 +346,9 @@
380 346 return $post_id;
381 347 }
382 348
383 349 /**
384 - * @param object $action
385 - * @param int|string $form_id
386 - *
387 - * @return int|WP_Error
350 + * @param object $action
388 351 */
389 352 public function duplicate_one( $action, $form_id ) {
390 353 global $frm_duplicate_ids;
391 354
@@ -414,15 +377,8 @@
414 377
415 378 return $this->save_settings( $action );
416 379 }
417 380
418 - /**
419 - * @param array $action
420 - * @param array|string $subkey
421 - * @param mixed $val
422 - *
423 - * @return array
424 - */
425 381 private function duplicate_array_walk( $action, $subkey, $val ) {
426 382 global $frm_duplicate_ids;
427 383
428 384 if ( is_array( $subkey ) ) {
@@ -453,12 +409,8 @@
453 409 /**
454 410 * Deal with changed settings.
455 411 *
456 412 * Do NOT over-ride this function
457 - *
458 - * @param int|string $form_id
459 - *
460 - * @return array|null
461 413 */
462 414 public function update_callback( $form_id ) {
463 415 $this->form_id = $form_id;
464 416
@@ -482,9 +434,9 @@
482 434
483 435 foreach ( $settings as $number => $new_instance ) {
484 436 $this->_set( $number );
485 437
486 - $old_instance = $all_instances[ $number ] ?? array();
438 + $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array();
487 439
488 440 if ( ! isset( $new_instance['post_status'] ) ) {
489 441 $new_instance['post_status'] = 'draft';
490 442 }
@@ -499,9 +451,9 @@
499 451
500 452 $new_instance['post_type'] = FrmFormActionsController::$action_post_type;
501 453 $new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number;
502 454 $new_instance['menu_order'] = $this->form_id;
503 - $new_instance['post_date'] = $old_instance->post_date ?? '';
455 + $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : '';
504 456 $instance = $this->update( $new_instance, $old_instance );
505 457
506 458 /**
507 459 * Filter an action's settings before saving.
@@ -539,9 +491,8 @@
539 491 * @since 3.04
540 492 *
541 493 * @param array $new_instance
542 494 * @param array|stdClass $old_instance
543 - *
544 495 * @return void
545 496 */
546 497 protected function maybe_update_status( $new_instance, $old_instance ) {
547 498 if ( ! is_object( $old_instance ) || $new_instance['post_status'] === $old_instance->post_status ) {
@@ -558,9 +509,8 @@
558 509 }
559 510
560 511 /**
561 512 * @param array $settings
562 - *
563 513 * @return int|WP_Error
564 514 */
565 515 public function save_settings( $settings ) {
566 516 self::clear_cache();
@@ -567,16 +517,10 @@
567 517
568 518 return FrmDb::save_settings( $settings, 'frm_actions' );
569 519 }
570 520
571 - /**
572 - * @param int $id
573 - *
574 - * @return object|null
575 - */
576 521 public function get_single_action( $id ) {
577 522 $action = get_post( $id );
578 -
579 523 if ( $action ) {
580 524 $action = $this->prepare_action( $action );
581 525 $this->_set( $id );
582 526 }
@@ -583,27 +527,14 @@
583 527
584 528 return $action;
585 529 }
586 530
587 - /**
588 - * @param int|string $form_id
589 - *
590 - * @return array
591 - */
592 531 public function get_one( $form_id ) {
593 532 return $this->get_all( $form_id, 1 );
594 533 }
595 534
596 - /**
597 - * @param int|string $form_id
598 - * @param string $type
599 - * @param array $atts
600 - *
601 - * @return array
602 - */
603 535 public static function get_action_for_form( $form_id, $type = 'all', $atts = array() ) {
604 536 $action_controls = FrmFormActionsController::get_form_actions( $type );
605 -
606 537 if ( empty( $action_controls ) ) {
607 538 // don't continue if there are no available actions
608 539 return array();
609 540 }
@@ -608,17 +539,14 @@
608 539 return array();
609 540 }
610 541
611 542 if ( 'all' !== $type ) {
612 - if ( is_array( $action_controls ) ) {
613 - return array();
614 - }
615 543 return $action_controls->get_all( $form_id, $atts );
616 544 }
617 545
618 546 self::prepare_get_action( $atts );
619 547
620 - $limit = self::get_action_limit( $form_id, $atts['limit'] );
548 + $limit = apply_filters( 'frm_form_action_limit', $atts['limit'], compact( 'type', 'form_id' ) );
621 549
622 550 $args = self::action_args( $form_id, $limit );
623 551 $args['post_status'] = $atts['post_status'];
624 552 $actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' );
@@ -627,9 +555,8 @@
627 555 return array();
628 556 }
629 557
630 558 $settings = array();
631 -
632 559 foreach ( $actions as $action ) {
633 560 // some plugins/themes are formatting the post_excerpt
634 561 $action->post_excerpt = sanitize_title( $action->post_excerpt );
635 562
@@ -652,24 +579,8 @@
652 579 return $settings;
653 580 }
654 581
655 582 /**
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 583 * @since 3.04
673 584 *
674 585 * @param array $args
675 586 * @param string $default_status
@@ -682,9 +593,8 @@
682 593 $args = array(
683 594 'limit' => $args,
684 595 );
685 596 }
686 -
687 597 $defaults = array(
688 598 'limit' => 99,
689 599 'post_status' => $default_status,
690 600 );
@@ -691,12 +601,9 @@
691 601 $args = wp_parse_args( $args, $defaults );
692 602 }
693 603
694 604 /**
695 - * @param int $action_id
696 - * @param string $type
697 - *
698 - * @return bool|object
605 + * @param int $action_id
699 606 */
700 607 public static function get_single_action_type( $action_id, $type ) {
701 608 if ( ! $type ) {
702 609 return false;
@@ -710,24 +617,18 @@
710 617 return $action_control->get_single_action( $action_id );
711 618 }
712 619
713 620 /**
714 - * @param int $form_id
715 - * @param string $type
621 + * @param int $form_id
716 622 *
717 623 * @return bool
718 624 */
719 625 public static function form_has_action_type( $form_id, $type ) {
720 - $actions = self::get_action_for_form( $form_id, $type );
721 - return ! empty( $actions );
626 + $payment_actions = self::get_action_for_form( $form_id, $type );
627 +
628 + return ! empty( $payment_actions );
722 629 }
723 630
724 - /**
725 - * @param false|int|string $form_id
726 - * @param array $atts
727 - *
728 - * @return array
729 - */
730 631 public function get_all( $form_id = false, $atts = array() ) {
731 632 if ( is_array( $atts ) && ! isset( $atts['limit'] ) && $this->action_options['limit'] > 99 ) {
732 633 $atts['limit'] = $this->action_options['limit'];
733 634 }
@@ -759,9 +660,8 @@
759 660 return array();
760 661 }
761 662
762 663 $settings = array();
763 -
764 664 foreach ( $actions as $action ) {
765 665 if ( count( $settings ) >= $limit ) {
766 666 continue;
767 667 }
@@ -778,11 +678,8 @@
778 678 return $settings;
779 679 }
780 680
781 681 /**
782 - * @param int $form_id
783 - * @param int $limit
784 - *
785 682 * @return array
786 683 */
787 684 public static function action_args( $form_id = 0, $limit = 99 ) {
788 685 $args = array(
@@ -800,11 +697,9 @@
800 697 return $args;
801 698 }
802 699
803 700 /**
804 - * @param WP_Post $action
805 - *
806 - * @return WP_Post
701 + * @param array|WP_Post $action
807 702 */
808 703 public function prepare_action( $action ) {
809 704 $action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content );
810 705 $action->post_excerpt = sanitize_title( $action->post_excerpt );
@@ -830,11 +725,8 @@
830 725 return $action;
831 726 }
832 727
833 728 /**
834 - * @param false|int|string $form_id
835 - * @param string $type
836 - *
837 729 * @return void
838 730 */
839 731 public function destroy( $form_id = false, $type = 'default' ) {
840 732 global $wpdb;
@@ -841,13 +733,11 @@
841 733
842 734 $this->form_id = $form_id;
843 735
844 736 $query = array( 'post_type' => FrmFormActionsController::$action_post_type );
845 -
846 737 if ( $form_id ) {
847 738 $query['menu_order'] = $form_id;
848 739 }
849 -
850 740 if ( 'all' != $type ) {
851 741 $query['post_excerpt'] = $this->id_base;
852 742 }
853 743
@@ -869,11 +759,8 @@
869 759 public static function clear_cache() {
870 760 FrmDb::cache_delete_group( 'frm_actions' );
871 761 }
872 762
873 - /**
874 - * @return array
875 - */
876 763 public function get_settings() {
877 764 return self::get_action_for_form( $this->form_id, $this->id_base );
878 765 }
879 766
@@ -896,11 +783,8 @@
896 783
897 784 return $defaults;
898 785 }
899 786
900 - /**
901 - * @return array
902 - */
903 787 public function get_global_switch_fields() {
904 788 $switch = $this->get_switch_fields();
905 789 $switch['conditions'] = array( 'hide_field' );
906 790
@@ -910,13 +794,8 @@
910 794 }
911 795
912 796 /**
913 797 * Migrate settings from form->options into new action.
914 - *
915 - * @param object $form
916 - * @param string $update
917 - *
918 - * @return int|WP_Error
919 798 */
920 799 public function migrate_to_2( $form, $update = 'update' ) {
921 800 $action = $this->prepare_new( $form->id );
922 801 FrmAppHelper::unserialize_or_decode( $form->options );
@@ -957,24 +836,80 @@
957 836
958 837 return $post_id;
959 838 }
960 839
961 - /**
962 - * @param WP_Post $action
963 - * @param stdClass $entry
964 - *
965 - * @return bool
966 - */
967 840 public static function action_conditions_met( $action, $entry ) {
968 841 if ( is_callable( 'FrmProFormActionsController::action_conditions_met' ) ) {
969 842 return FrmProFormActionsController::action_conditions_met( $action, $entry );
970 843 }
971 844
972 - $stop = false;
845 + // This is here for reverse compatibility.
846 + $notification = $action->post_content;
847 + $stop = false;
848 + $met = array();
849 +
850 + if ( empty( $notification['conditions'] ) ) {
851 + return $stop;
852 + }
853 +
854 + foreach ( $notification['conditions'] as $k => $condition ) {
855 + if ( ! is_numeric( $k ) ) {
856 + continue;
857 + }
858 +
859 + if ( $stop && 'any' == $notification['conditions']['any_all'] && 'stop' == $notification['conditions']['send_stop'] ) {
860 + continue;
861 + }
862 +
863 + self::prepare_logic_value( $condition['hide_opt'], $action, $entry );
864 +
865 + $observed_value = self::get_value_from_entry( $entry, $condition['hide_field'] );
866 +
867 + $stop = FrmFieldsHelper::value_meets_condition( $observed_value, $condition['hide_field_cond'], $condition['hide_opt'] );
868 +
869 + if ( $notification['conditions']['send_stop'] === 'send' ) {
870 + $stop = $stop ? false : true;
871 + }
872 +
873 + $met[ $stop ] = $stop;
874 + }//end foreach
875 +
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] ) ) {
879 + $stop = false;
880 + }
881 +
973 882 return $stop;
974 883 }
975 884
976 885 /**
886 + * Prepare the logic value for comparison against the entered value
887 + *
888 + * @since 2.01.02
889 + *
890 + * @param array|string $logic_value
891 + *
892 + * @return void
893 + */
894 + private static function prepare_logic_value( &$logic_value, $action, $entry ) {
895 + if ( is_array( $logic_value ) ) {
896 + $logic_value = reset( $logic_value );
897 + }
898 +
899 + if ( $logic_value === 'current_user' ) {
900 + $logic_value = get_current_user_id();
901 + }
902 +
903 + $logic_value = apply_filters( 'frm_content', $logic_value, $action->menu_order, $entry );
904 +
905 + /**
906 + * @since 4.04.05
907 + */
908 + $logic_value = apply_filters( 'frm_action_logic_value', $logic_value );
909 + }
910 +
911 + /**
977 912 * Get the value from a specific field and entry
978 913 *
979 914 * @since 2.01.02
980 915 *
@@ -1015,11 +950,8 @@
1015 950 'limit' => 0,
1016 951 );
1017 952 }
1018 953
1019 - /**
1020 - * @return array
1021 - */
1022 954 public static function trigger_labels() {
1023 955 $triggers = array(
1024 956 'draft' => __( 'Draft is saved', 'formidable' ),
1025 957 'create' => __( 'Entry is created', 'formidable' ),
@@ -1056,9 +988,8 @@
1056 988 *
1057 989 * @since 6.10
1058 990 *
1059 991 * @param int $form_id Form ID.
1060 - *
1061 992 * @return object[]
1062 993 */
1063 994 protected function get_form_fields( $form_id ) {
1064 995 // Get form fields, include embedded and repeater child fields.