PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.17
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.17
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 +72 -125 6.266.17 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,11 +539,8 @@
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 );
@@ -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
@@ -682,9 +609,8 @@
682 609 $args = array(
683 610 'limit' => $args,
684 611 );
685 612 }
686 -
687 613 $defaults = array(
688 614 'limit' => 99,
689 615 'post_status' => $default_status,
690 616 );
@@ -691,12 +617,9 @@
691 617 $args = wp_parse_args( $args, $defaults );
692 618 }
693 619
694 620 /**
695 - * @param int $action_id
696 - * @param string $type
697 - *
698 - * @return bool|object
621 + * @param int $action_id
699 622 */
700 623 public static function get_single_action_type( $action_id, $type ) {
701 624 if ( ! $type ) {
702 625 return false;
@@ -710,24 +633,18 @@
710 633 return $action_control->get_single_action( $action_id );
711 634 }
712 635
713 636 /**
714 - * @param int $form_id
715 - * @param string $type
637 + * @param int $form_id
716 638 *
717 639 * @return bool
718 640 */
719 641 public static function form_has_action_type( $form_id, $type ) {
720 - $actions = self::get_action_for_form( $form_id, $type );
721 - return ! empty( $actions );
642 + $payment_actions = self::get_action_for_form( $form_id, $type );
643 +
644 + return ! empty( $payment_actions );
722 645 }
723 646
724 - /**
725 - * @param false|int|string $form_id
726 - * @param array $atts
727 - *
728 - * @return array
729 - */
730 647 public function get_all( $form_id = false, $atts = array() ) {
731 648 if ( is_array( $atts ) && ! isset( $atts['limit'] ) && $this->action_options['limit'] > 99 ) {
732 649 $atts['limit'] = $this->action_options['limit'];
733 650 }
@@ -759,9 +676,8 @@
759 676 return array();
760 677 }
761 678
762 679 $settings = array();
763 -
764 680 foreach ( $actions as $action ) {
765 681 if ( count( $settings ) >= $limit ) {
766 682 continue;
767 683 }
@@ -778,11 +694,8 @@
778 694 return $settings;
779 695 }
780 696
781 697 /**
782 - * @param int $form_id
783 - * @param int $limit
784 - *
785 698 * @return array
786 699 */
787 700 public static function action_args( $form_id = 0, $limit = 99 ) {
788 701 $args = array(
@@ -800,11 +713,9 @@
800 713 return $args;
801 714 }
802 715
803 716 /**
804 - * @param WP_Post $action
805 - *
806 - * @return WP_Post
717 + * @param array|WP_Post $action
807 718 */
808 719 public function prepare_action( $action ) {
809 720 $action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content );
810 721 $action->post_excerpt = sanitize_title( $action->post_excerpt );
@@ -830,11 +741,8 @@
830 741 return $action;
831 742 }
832 743
833 744 /**
834 - * @param false|int|string $form_id
835 - * @param string $type
836 - *
837 745 * @return void
838 746 */
839 747 public function destroy( $form_id = false, $type = 'default' ) {
840 748 global $wpdb;
@@ -841,13 +749,11 @@
841 749
842 750 $this->form_id = $form_id;
843 751
844 752 $query = array( 'post_type' => FrmFormActionsController::$action_post_type );
845 -
846 753 if ( $form_id ) {
847 754 $query['menu_order'] = $form_id;
848 755 }
849 -
850 756 if ( 'all' != $type ) {
851 757 $query['post_excerpt'] = $this->id_base;
852 758 }
853 759
@@ -869,11 +775,8 @@
869 775 public static function clear_cache() {
870 776 FrmDb::cache_delete_group( 'frm_actions' );
871 777 }
872 778
873 - /**
874 - * @return array
875 - */
876 779 public function get_settings() {
877 780 return self::get_action_for_form( $this->form_id, $this->id_base );
878 781 }
879 782
@@ -896,11 +799,8 @@
896 799
897 800 return $defaults;
898 801 }
899 802
900 - /**
901 - * @return array
902 - */
903 803 public function get_global_switch_fields() {
904 804 $switch = $this->get_switch_fields();
905 805 $switch['conditions'] = array( 'hide_field' );
906 806
@@ -910,13 +810,8 @@
910 810 }
911 811
912 812 /**
913 813 * Migrate settings from form->options into new action.
914 - *
915 - * @param object $form
916 - * @param string $update
917 - *
918 - * @return int|WP_Error
919 814 */
920 815 public function migrate_to_2( $form, $update = 'update' ) {
921 816 $action = $this->prepare_new( $form->id );
922 817 FrmAppHelper::unserialize_or_decode( $form->options );
@@ -957,24 +852,80 @@
957 852
958 853 return $post_id;
959 854 }
960 855
961 - /**
962 - * @param WP_Post $action
963 - * @param stdClass $entry
964 - *
965 - * @return bool
966 - */
967 856 public static function action_conditions_met( $action, $entry ) {
968 857 if ( is_callable( 'FrmProFormActionsController::action_conditions_met' ) ) {
969 858 return FrmProFormActionsController::action_conditions_met( $action, $entry );
970 859 }
971 860
972 - $stop = false;
861 + // This is here for reverse compatibility.
862 + $notification = $action->post_content;
863 + $stop = false;
864 + $met = array();
865 +
866 + if ( empty( $notification['conditions'] ) ) {
867 + return $stop;
868 + }
869 +
870 + foreach ( $notification['conditions'] as $k => $condition ) {
871 + if ( ! is_numeric( $k ) ) {
872 + continue;
873 + }
874 +
875 + if ( $stop && 'any' == $notification['conditions']['any_all'] && 'stop' == $notification['conditions']['send_stop'] ) {
876 + continue;
877 + }
878 +
879 + self::prepare_logic_value( $condition['hide_opt'], $action, $entry );
880 +
881 + $observed_value = self::get_value_from_entry( $entry, $condition['hide_field'] );
882 +
883 + $stop = FrmFieldsHelper::value_meets_condition( $observed_value, $condition['hide_field_cond'], $condition['hide_opt'] );
884 +
885 + if ( $notification['conditions']['send_stop'] === 'send' ) {
886 + $stop = $stop ? false : true;
887 + }
888 +
889 + $met[ $stop ] = $stop;
890 + }//end foreach
891 +
892 + if ( $notification['conditions']['any_all'] === 'all' && ! empty( $met ) && isset( $met[0] ) && isset( $met[1] ) ) {
893 + $stop = ( $notification['conditions']['send_stop'] === 'send' );
894 + } elseif ( $notification['conditions']['any_all'] === 'any' && $notification['conditions']['send_stop'] === 'send' && isset( $met[0] ) ) {
895 + $stop = false;
896 + }
897 +
973 898 return $stop;
974 899 }
975 900
976 901 /**
902 + * Prepare the logic value for comparison against the entered value
903 + *
904 + * @since 2.01.02
905 + *
906 + * @param array|string $logic_value
907 + *
908 + * @return void
909 + */
910 + private static function prepare_logic_value( &$logic_value, $action, $entry ) {
911 + if ( is_array( $logic_value ) ) {
912 + $logic_value = reset( $logic_value );
913 + }
914 +
915 + if ( $logic_value === 'current_user' ) {
916 + $logic_value = get_current_user_id();
917 + }
918 +
919 + $logic_value = apply_filters( 'frm_content', $logic_value, $action->menu_order, $entry );
920 +
921 + /**
922 + * @since 4.04.05
923 + */
924 + $logic_value = apply_filters( 'frm_action_logic_value', $logic_value );
925 + }
926 +
927 + /**
977 928 * Get the value from a specific field and entry
978 929 *
979 930 * @since 2.01.02
980 931 *
@@ -1015,11 +966,8 @@
1015 966 'limit' => 0,
1016 967 );
1017 968 }
1018 969
1019 - /**
1020 - * @return array
1021 - */
1022 970 public static function trigger_labels() {
1023 971 $triggers = array(
1024 972 'draft' => __( 'Draft is saved', 'formidable' ),
1025 973 'create' => __( 'Entry is created', 'formidable' ),
@@ -1056,9 +1004,8 @@
1056 1004 *
1057 1005 * @since 6.10
1058 1006 *
1059 1007 * @param int $form_id Form ID.
1060 - *
1061 1008 * @return object[]
1062 1009 */
1063 1010 protected function get_form_fields( $form_id ) {
1064 1011 // Get form fields, include embedded and repeater child fields.