PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.7.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.7.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 +154 -209 6.276.7.2 View file →
@@ -88,13 +88,12 @@
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>';
95 +
97 96 return 'noform';
98 97 }
99 98
100 99 /**
@@ -110,14 +109,8 @@
110 109 public function get_switch_fields() {
111 110 return array();
112 111 }
113 112
114 - /**
115 - * @param object $action
116 - * @param object $form
117 - *
118 - * @return object
119 - */
120 113 public function migrate_values( $action, $form ) {
121 114 return $action;
122 115 }
123 116
@@ -170,13 +163,12 @@
170 163 $action_options['color'] = 'var(--' . reset( $colors ) . ')';
171 164 }
172 165
173 166 $upgrade_class = isset( $action_options['classes'] ) && $action_options['classes'] === 'frm_show_upgrade';
174 -
175 167 if ( $action_options['group'] === $id_base ) {
176 - $upgrade_class = str_contains( $action_options['classes'], 'frm_show_upgrade' );
168 + $upgrade_class = strpos( $action_options['classes'], 'frm_show_upgrade' ) !== false;
177 169 $action_options['classes'] = $group['icon'];
178 - } elseif ( empty( $action_options['classes'] ) || $upgrade_class ) {
170 + } elseif ( ! isset( $action_options['classes'] ) || empty( $action_options['classes'] ) || $upgrade_class ) {
179 171 $action_options['classes'] = $group['icon'];
180 172 }
181 173
182 174 if ( $upgrade_class ) {
@@ -188,13 +180,8 @@
188 180 }
189 181
190 182 /**
191 183 * @param string $id_base
192 - * @param string $name
193 - * @param array $action_options
194 - * @param array $control_options
195 - *
196 - * @return void
197 184 */
198 185 public function FrmFormAction( $id_base, $name, $action_options = array(), $control_options = array() ) {
199 186 self::__construct( $id_base, $name, $action_options, $control_options );
200 187 }
@@ -207,22 +194,16 @@
207 194 * @return string
208 195 */
209 196 public function maybe_switch_field_ids( $action ) {
210 197 $updated_action = apply_filters( 'frm_maybe_switch_field_ids', $action );
211 -
212 198 if ( $updated_action === $action ) {
213 199 $updated_action = FrmFieldsHelper::switch_field_ids( $action );
214 200 }
215 -
216 201 return $updated_action;
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';
@@ -232,9 +213,9 @@
232 213 } elseif ( isset( $groups[ $this->id_base ] ) ) {
233 214 $group = $this->id_base;
234 215 } else {
235 216 foreach ( $groups as $name => $check_group ) {
236 - if ( isset( $check_group['actions'] ) && in_array( $this->id_base, $check_group['actions'], true ) ) {
217 + if ( isset( $check_group['actions'] ) && in_array( $this->id_base, $check_group['actions'] ) ) {
237 218 $group = $name;
238 219 break;
239 220 }
240 221 }
@@ -249,17 +230,17 @@
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' ) {
258 - $name = $this->option_name . '[' . $this->number . ']';
259 - $name .= empty( $post_field ) ? '' : '[' . $post_field . ']';
238 + $name = $this->option_name . '[' . $this->number . ']';
239 + $name .= ( empty( $post_field ) ? '' : '[' . $post_field . ']' );
240 + $name .= '[' . $field_name . ']';
260 241
261 - return $name . ( '[' . $field_name . ']' );
242 + return $name;
262 243 }
263 244
264 245 /**
265 246 * Constructs id attributes for use in form() fields
@@ -275,9 +256,8 @@
275 256 }
276 257
277 258 /**
278 259 * @param int|string $number
279 - *
280 260 * @return void
281 261 */
282 262 public function _set( $number ) {
283 263 $this->number = $number;
@@ -284,10 +264,8 @@
284 264 $this->id = $this->id_base . '-' . $number;
285 265 }
286 266
287 267 /**
288 - * @param false|int|string $form_id
289 - *
290 268 * @return object
291 269 */
292 270 public function prepare_new( $form_id = false ) {
293 271 if ( $form_id ) {
@@ -318,13 +296,8 @@
318 296
319 297 return (object) $form_action;
320 298 }
321 299
322 - /**
323 - * @param int|string $form_id
324 - *
325 - * @return int|WP_Error
326 - */
327 300 public function create( $form_id ) {
328 301 $this->form_id = $form_id;
329 302
330 303 $action = $this->prepare_new();
@@ -332,15 +305,11 @@
332 305 return $this->save_settings( $action );
333 306 }
334 307
335 308 /**
336 - * @param int|string $form_id
337 - * @param int|string $old_id
338 - *
339 309 * @return void
340 310 */
341 311 public function duplicate_form_actions( $form_id, $old_id ) {
342 - // phpcs:ignore Universal.Operators.StrictComparisons
343 312 if ( $form_id == $old_id ) {
344 313 // don't duplicate the actions if this is a template getting updated
345 314 return;
346 315 }
@@ -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,28 +329,26 @@
361 329 *
362 330 * @since 2.0
363 331 *
364 332 * @param array $action
365 - * @param array $forms
366 - *
367 - * @return int $post_id
333 + * @return integer $post_id
368 334 */
369 335 public function maybe_create_action( $action, $forms ) {
370 - 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' ) {
371 337 // Update action only
372 338 $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
373 - return $this->save_settings( $action );
339 + $post_id = $this->save_settings( $action );
340 + } else {
341 + // Create action
342 + $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
343 + $post_id = $this->duplicate_one( (object) $action, $action['menu_order'] );
374 344 }
375 - // Create action
376 - $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
377 - return $this->duplicate_one( (object) $action, $action['menu_order'] );
345 +
346 + return $post_id;
378 347 }
379 348
380 349 /**
381 - * @param object $action
382 - * @param int|string $form_id
383 - *
384 - * @return int|WP_Error
350 + * @param object $action
385 351 */
386 352 public function duplicate_one( $action, $form_id ) {
387 353 global $frm_duplicate_ids;
388 354
@@ -411,15 +377,8 @@
411 377
412 378 return $this->save_settings( $action );
413 379 }
414 380
415 - /**
416 - * @param array $action
417 - * @param array|string $subkey
418 - * @param mixed $val
419 - *
420 - * @return array
421 - */
422 381 private function duplicate_array_walk( $action, $subkey, $val ) {
423 382 global $frm_duplicate_ids;
424 383
425 384 if ( is_array( $subkey ) ) {
@@ -435,11 +394,11 @@
435 394 } else {
436 395 foreach ( (array) $val as $ck => $cv ) {
437 396 if ( is_array( $cv ) ) {
438 397 $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey, $cv );
439 - } elseif ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) { // phpcs:ignore Universal.Operators.StrictComparisons
398 + } elseif ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) {
440 399 $action[ $ck ] = $frm_duplicate_ids[ $cv ];
441 - } elseif ( $ck == $subkey ) { // phpcs:ignore Universal.Operators.StrictComparisons
400 + } elseif ( $ck == $subkey ) {
442 401 $action[ $ck ] = $this->maybe_switch_field_ids( $action[ $ck ] );
443 402 }
444 403 }
445 404 }//end if
@@ -450,12 +409,8 @@
450 409 /**
451 410 * Deal with changed settings.
452 411 *
453 412 * Do NOT over-ride this function
454 - *
455 - * @param int|string $form_id
456 - *
457 - * @return array|null
458 413 */
459 414 public function update_callback( $form_id ) {
460 415 $this->form_id = $form_id;
461 416
@@ -462,9 +417,9 @@
462 417 $all_instances = $this->get_settings();
463 418
464 419 // We need to update the data
465 420 if ( $this->updated ) {
466 - return null;
421 + return;
467 422 }
468 423
469 424 // phpcs:ignore WordPress.Security.NonceVerification.Missing
470 425 if ( isset( $_POST[ $this->option_name ] ) && is_array( $_POST[ $this->option_name ] ) ) {
@@ -471,9 +426,9 @@
471 426 // Sanitizing removes scripts and <email> type of values.
472 427 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
473 428 $settings = wp_unslash( $_POST[ $this->option_name ] );
474 429 } else {
475 - return null;
430 + return;
476 431 }
477 432
478 433 $action_ids = array();
479 434
@@ -479,9 +434,9 @@
479 434
480 435 foreach ( $settings as $number => $new_instance ) {
481 436 $this->_set( $number );
482 437
483 - $old_instance = $all_instances[ $number ] ?? array();
438 + $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array();
484 439
485 440 if ( ! isset( $new_instance['post_status'] ) ) {
486 441 $new_instance['post_status'] = 'draft';
487 442 }
@@ -496,10 +451,10 @@
496 451
497 452 $new_instance['post_type'] = FrmFormActionsController::$action_post_type;
498 453 $new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number;
499 454 $new_instance['menu_order'] = $this->form_id;
500 - $new_instance['post_date'] = $old_instance->post_date ?? '';
501 - $instance = $this->update( $new_instance, $old_instance );
455 + $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : '';
456 + $instance = $this->update( $new_instance, $old_instance );
502 457
503 458 /**
504 459 * Filter an action's settings before saving.
505 460 *
@@ -507,12 +462,11 @@
507 462 * to update settings.
508 463 *
509 464 * @since 2.0
510 465 *
511 - * @param array $instance The current widget instance's settings.
512 - * @param array $new_instance Array of new widget settings.
513 - * @param array $old_instance Array of old widget settings.
514 - * @param FrmFormAction $form_action FrmFormAction 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.
515 469 */
516 470 $instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this );
517 471
518 472 $instance['post_content'] = apply_filters( 'frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this );
@@ -535,10 +489,9 @@
535 489 *
536 490 * @since 3.04
537 491 *
538 492 * @param array $new_instance
539 - * @param array|stdClass $old_instance
540 - *
493 + * @param stdClass|array $old_instance
541 494 * @return void
542 495 */
543 496 protected function maybe_update_status( $new_instance, $old_instance ) {
544 497 if ( ! is_object( $old_instance ) || $new_instance['post_status'] === $old_instance->post_status ) {
@@ -553,26 +506,16 @@
553 506 )
554 507 );
555 508 }
556 509
557 - /**
558 - * @param array $settings
559 - *
560 - * @return int|WP_Error
561 - */
562 510 public function save_settings( $settings ) {
563 511 self::clear_cache();
512 +
564 513 return FrmDb::save_settings( $settings, 'frm_actions' );
565 514 }
566 515
567 - /**
568 - * @param int $id
569 - *
570 - * @return object|null
571 - */
572 516 public function get_single_action( $id ) {
573 517 $action = get_post( $id );
574 -
575 518 if ( $action ) {
576 519 $action = $this->prepare_action( $action );
577 520 $this->_set( $id );
578 521 }
@@ -579,43 +522,27 @@
579 522
580 523 return $action;
581 524 }
582 525
583 - /**
584 - * @param int|string $form_id
585 - *
586 - * @return array
587 - */
588 526 public function get_one( $form_id ) {
589 527 return $this->get_all( $form_id, 1 );
590 528 }
591 529
592 - /**
593 - * @param int|string $form_id
594 - * @param string $type
595 - * @param array $atts
596 - *
597 - * @return array
598 - */
599 530 public static function get_action_for_form( $form_id, $type = 'all', $atts = array() ) {
600 531 $action_controls = FrmFormActionsController::get_form_actions( $type );
601 -
602 - if ( ! $action_controls ) {
532 + if ( empty( $action_controls ) ) {
603 533 // don't continue if there are no available actions
604 534 return array();
605 535 }
606 536
607 - if ( 'all' !== $type ) {
608 - if ( is_array( $action_controls ) ) {
609 - return array();
610 - }
611 -
537 + if ( 'all' != $type ) {
612 538 return $action_controls->get_all( $form_id, $atts );
613 539 }
614 540
615 541 self::prepare_get_action( $atts );
616 542
617 - $limit = self::get_action_limit( $form_id, $atts['limit'] );
543 + $limit = apply_filters( 'frm_form_action_limit', $atts['limit'], compact( 'type', 'form_id' ) );
544 +
618 545 $args = self::action_args( $form_id, $limit );
619 546 $args['post_status'] = $atts['post_status'];
620 547 $actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' );
621 548
@@ -623,9 +550,8 @@
623 550 return array();
624 551 }
625 552
626 553 $settings = array();
627 -
628 554 foreach ( $actions as $action ) {
629 555 // some plugins/themes are formatting the post_excerpt
630 556 $action->post_excerpt = sanitize_title( $action->post_excerpt );
631 557
@@ -648,24 +574,8 @@
648 574 return $settings;
649 575 }
650 576
651 577 /**
652 - * Get the limit for the number of actions for a single form. By default, this is 99, but
653 - * it can be modified with a code snippet.
654 - *
655 - * @since 6.17 This logic from moved from FrmFormAction::get_action_for_form.
656 - *
657 - * @param int|string $form_id
658 - * @param int|string $limit The unfiltered limit value.
659 - *
660 - * @return int The filtered limit value.
661 - */
662 - public static function get_action_limit( $form_id, $limit = 99 ) {
663 - $type = 'all';
664 - return (int) apply_filters( 'frm_form_action_limit', (int) $limit, compact( 'type', 'form_id' ) );
665 - }
666 -
667 - /**
668 578 * @since 3.04
669 579 *
670 580 * @param array $args
671 581 * @param string $default_status
@@ -678,9 +588,8 @@
678 588 $args = array(
679 589 'limit' => $args,
680 590 );
681 591 }
682 -
683 592 $defaults = array(
684 593 'limit' => 99,
685 594 'post_status' => $default_status,
686 595 );
@@ -687,21 +596,14 @@
687 596 $args = wp_parse_args( $args, $defaults );
688 597 }
689 598
690 599 /**
691 - * @param int $action_id
692 - * @param string $type
693 - *
694 - * @return bool|object
600 + * @param int $action_id
695 601 */
696 602 public static function get_single_action_type( $action_id, $type ) {
697 603 if ( ! $type ) {
698 604 return false;
699 605 }
700 -
701 - /**
702 - * @var FrmFormAction
703 - */
704 606 $action_control = FrmFormActionsController::get_form_actions( $type );
705 607
706 608 return $action_control->get_single_action( $action_id );
707 609 }
@@ -706,24 +608,18 @@
706 608 return $action_control->get_single_action( $action_id );
707 609 }
708 610
709 611 /**
710 - * @param int $form_id
711 - * @param string $type
612 + * @param int $form_id
712 613 *
713 614 * @return bool
714 615 */
715 616 public static function form_has_action_type( $form_id, $type ) {
716 - $actions = self::get_action_for_form( $form_id, $type );
717 - return ! empty( $actions );
617 + $payment_actions = self::get_action_for_form( $form_id, $type );
618 +
619 + return ! empty( $payment_actions );
718 620 }
719 621
720 - /**
721 - * @param false|int|string $form_id
722 - * @param array $atts
723 - *
724 - * @return array
725 - */
726 622 public function get_all( $form_id = false, $atts = array() ) {
727 623 if ( is_array( $atts ) && ! isset( $atts['limit'] ) && $this->action_options['limit'] > 99 ) {
728 624 $atts['limit'] = $this->action_options['limit'];
729 625 }
@@ -741,10 +637,10 @@
741 637 global $frm_vars;
742 638 $frm_vars['action_type'] = $type;
743 639
744 640 add_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
745 - $query = self::action_args( $form_id, $limit );
746 - $query['post_status'] = $atts['post_status'];
641 + $query = self::action_args( $form_id, $limit );
642 + $query['post_status'] = $atts['post_status'];
747 643 $query['suppress_filters'] = false;
748 644
749 645 $actions = FrmDb::check_cache( json_encode( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' );
750 646 unset( $query );
@@ -750,20 +646,20 @@
750 646 unset( $query );
751 647
752 648 remove_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
753 649
754 - if ( ! $actions ) {
650 + if ( empty( $actions ) ) {
755 651 return array();
756 652 }
757 653
758 654 $settings = array();
759 -
760 655 foreach ( $actions as $action ) {
761 656 if ( count( $settings ) >= $limit ) {
762 657 continue;
763 658 }
764 659
765 - $action = $this->prepare_action( $action );
660 + $action = $this->prepare_action( $action );
661 +
766 662 $settings[ $action->ID ] = $action;
767 663 }
768 664
769 665 if ( 1 === $limit ) {
@@ -773,11 +669,8 @@
773 669 return $settings;
774 670 }
775 671
776 672 /**
777 - * @param int $form_id
778 - * @param int $limit
779 - *
780 673 * @return array
781 674 */
782 675 public static function action_args( $form_id = 0, $limit = 99 ) {
783 676 $args = array(
@@ -787,9 +680,9 @@
787 680 'orderby' => 'title',
788 681 'order' => 'ASC',
789 682 );
790 683
791 - if ( $form_id && $form_id !== 'all' ) {
684 + if ( $form_id && $form_id != 'all' ) {
792 685 $args['menu_order'] = $form_id;
793 686 }
794 687
795 688 return $args;
@@ -795,11 +688,9 @@
795 688 return $args;
796 689 }
797 690
798 691 /**
799 - * @param WP_Post $action
800 - *
801 - * @return WP_Post
692 + * @param WP_Post|array $action
802 693 */
803 694 public function prepare_action( $action ) {
804 695 $action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content );
805 696 $action->post_excerpt = sanitize_title( $action->post_excerpt );
@@ -809,9 +700,9 @@
809 700 // fill default values
810 701 $action->post_content += $default_values;
811 702
812 703 foreach ( $default_values as $k => $vals ) {
813 - if ( is_array( $vals ) && $vals ) {
704 + if ( is_array( $vals ) && ! empty( $vals ) ) {
814 705 if ( 'event' === $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
815 706 continue;
816 707 }
817 708 $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals );
@@ -825,11 +716,8 @@
825 716 return $action;
826 717 }
827 718
828 719 /**
829 - * @param false|int|string $form_id
830 - * @param string $type
831 - *
832 720 * @return void
833 721 */
834 722 public function destroy( $form_id = false, $type = 'default' ) {
835 723 global $wpdb;
@@ -836,14 +724,12 @@
836 724
837 725 $this->form_id = $form_id;
838 726
839 727 $query = array( 'post_type' => FrmFormActionsController::$action_post_type );
840 -
841 728 if ( $form_id ) {
842 729 $query['menu_order'] = $form_id;
843 730 }
844 -
845 - if ( 'all' !== $type ) {
731 + if ( 'all' != $type ) {
846 732 $query['post_excerpt'] = $this->id_base;
847 733 }
848 734
849 735 $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' );
@@ -864,11 +750,8 @@
864 750 public static function clear_cache() {
865 751 FrmDb::cache_delete_group( 'frm_actions' );
866 752 }
867 753
868 - /**
869 - * @return array
870 - */
871 754 public function get_settings() {
872 755 return self::get_action_for_form( $this->form_id, $this->id_base );
873 756 }
874 757
@@ -891,28 +774,22 @@
891 774
892 775 return $defaults;
893 776 }
894 777
895 - /**
896 - * @return array
897 - */
898 778 public function get_global_switch_fields() {
899 779 $switch = $this->get_switch_fields();
900 780 $switch['conditions'] = array( 'hide_field' );
901 781
902 - return apply_filters( 'frm_global_switch_fields', $switch );
782 + $switch = apply_filters( 'frm_global_switch_fields', $switch );
783 +
784 + return $switch;
903 785 }
904 786
905 787 /**
906 788 * Migrate settings from form->options into new action.
907 - *
908 - * @param object $form
909 - * @param string $update
910 - *
911 - * @return int|WP_Error
912 789 */
913 790 public function migrate_to_2( $form, $update = 'update' ) {
914 - $action = $this->prepare_new( $form->id );
791 + $action = $this->prepare_new( $form->id );
915 792 FrmAppHelper::unserialize_or_decode( $form->options );
916 793
917 794 // fill with existing options
918 795 foreach ( $action->post_content as $name => $val ) {
@@ -933,14 +810,14 @@
933 810 'numberposts' => 1,
934 811 )
935 812 );
936 813
937 - if ( ! $post_id ) {
814 + if ( empty( $post_id ) ) {
938 815 // create action now
939 816 $post_id = $this->save_settings( $action );
940 817 }
941 818
942 - if ( $post_id && 'update' === $update ) {
819 + if ( $post_id && 'update' == $update ) {
943 820 global $wpdb;
944 821 $form->options = maybe_serialize( $form->options );
945 822
946 823 // update form options
@@ -950,22 +827,113 @@
950 827
951 828 return $post_id;
952 829 }
953 830
831 + public static function action_conditions_met( $action, $entry ) {
832 + if ( is_callable( 'FrmProFormActionsController::action_conditions_met' ) ) {
833 + return FrmProFormActionsController::action_conditions_met( $action, $entry );
834 + }
835 +
836 + // This is here for reverse compatibility.
837 + $notification = $action->post_content;
838 + $stop = false;
839 + $met = array();
840 +
841 + if ( ! isset( $notification['conditions'] ) || empty( $notification['conditions'] ) ) {
842 + return $stop;
843 + }
844 +
845 + foreach ( $notification['conditions'] as $k => $condition ) {
846 + if ( ! is_numeric( $k ) ) {
847 + continue;
848 + }
849 +
850 + if ( $stop && 'any' == $notification['conditions']['any_all'] && 'stop' == $notification['conditions']['send_stop'] ) {
851 + continue;
852 + }
853 +
854 + self::prepare_logic_value( $condition['hide_opt'], $action, $entry );
855 +
856 + $observed_value = self::get_value_from_entry( $entry, $condition['hide_field'] );
857 +
858 + $stop = FrmFieldsHelper::value_meets_condition( $observed_value, $condition['hide_field_cond'], $condition['hide_opt'] );
859 +
860 + if ( $notification['conditions']['send_stop'] == 'send' ) {
861 + $stop = $stop ? false : true;
862 + }
863 +
864 + $met[ $stop ] = $stop;
865 + }//end foreach
866 +
867 + if ( $notification['conditions']['any_all'] == 'all' && ! empty( $met ) && isset( $met[0] ) && isset( $met[1] ) ) {
868 + $stop = ( $notification['conditions']['send_stop'] == 'send' );
869 + } elseif ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset( $met[0] ) ) {
870 + $stop = false;
871 + }
872 +
873 + return $stop;
874 + }
875 +
954 876 /**
955 - * @param WP_Post $action
956 - * @param stdClass $entry
877 + * Prepare the logic value for comparison against the entered value
957 878 *
958 - * @return bool
879 + * @since 2.01.02
880 + *
881 + * @deprecated 4.06.02
882 + *
883 + * @param array|string $logic_value
884 + *
885 + * @return void
959 886 */
960 - public static function action_conditions_met( $action, $entry ) {
961 - if ( is_callable( 'FrmProFormActionsController::action_conditions_met' ) ) {
962 - return FrmProFormActionsController::action_conditions_met( $action, $entry );
887 + private static function prepare_logic_value( &$logic_value, $action, $entry ) {
888 + if ( is_array( $logic_value ) ) {
889 + $logic_value = reset( $logic_value );
963 890 }
964 - return false;
891 +
892 + if ( $logic_value == 'current_user' ) {
893 + $logic_value = get_current_user_id();
894 + }
895 +
896 + $logic_value = apply_filters( 'frm_content', $logic_value, $action->menu_order, $entry );
897 +
898 + /**
899 + * @since 4.04.05
900 + */
901 + $logic_value = apply_filters( 'frm_action_logic_value', $logic_value );
965 902 }
966 903
967 904 /**
905 + * Get the value from a specific field and entry
906 + *
907 + * @since 2.01.02
908 + * @deprecated 4.06.02
909 + *
910 + * @param object $entry
911 + * @param int $field_id
912 + *
913 + * @return array|bool|mixed|string
914 + */
915 + private static function get_value_from_entry( $entry, $field_id ) {
916 + $observed_value = '';
917 +
918 + if ( isset( $entry->metas[ $field_id ] ) ) {
919 + $observed_value = $entry->metas[ $field_id ];
920 + } elseif ( $entry->post_id && FrmAppHelper::pro_is_installed() ) {
921 + $field = FrmField::getOne( $field_id );
922 + $observed_value = FrmProEntryMetaHelper::get_post_or_meta_value(
923 + $entry,
924 + $field,
925 + array(
926 + 'links' => false,
927 + 'truncate' => false,
928 + )
929 + );
930 + }
931 +
932 + return $observed_value;
933 + }
934 +
935 + /**
968 936 * @param string $class
969 937 *
970 938 * @return array
971 939 */
@@ -970,17 +938,14 @@
970 938 * @return array
971 939 */
972 940 public static function default_action_opts( $class = '' ) {
973 941 return array(
974 - 'classes' => 'frmfont ' . $class,
942 + 'classes' => 'frm_icon_font ' . $class,
975 943 'active' => false,
976 944 'limit' => 0,
977 945 );
978 946 }
979 947
980 - /**
981 - * @return array
982 - */
983 948 public static function trigger_labels() {
984 949 $triggers = array(
985 950 'draft' => __( 'Draft is saved', 'formidable' ),
986 951 'create' => __( 'Entry is created', 'formidable' ),
@@ -997,9 +962,9 @@
997 962 */
998 963 public function render_conditional_logic_call_to_action() {
999 964 ?>
1000 965 <h3>
1001 - <a href="javascript:void(0)" class="frm_show_upgrade frm_noallow" data-upgrade="<?php echo esc_attr( $this->get_upgrade_text() ); ?>" data-medium="conditional-<?php echo esc_attr( $this->id_base ); ?>"><?php // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?>
966 + <a href="javascript:void(0)" class="frm_show_upgrade frm_noallow" data-upgrade="<?php echo esc_attr( $this->get_upgrade_text() ); ?>" data-medium="conditional-<?php echo esc_attr( $this->id_base ); ?>">
1002 967 <?php esc_html_e( 'Use Conditional Logic', 'formidable' ); ?>
1003 968 </a>
1004 969 </h3>
1005 970 <?php
@@ -1009,26 +974,6 @@
1009 974 * @return string
1010 975 */
1011 976 protected function get_upgrade_text() {
1012 977 return __( 'Conditional form actions', 'formidable' );
1013 - }
1014 -
1015 - /**
1016 - * Gets form fields for form action settings.
1017 - *
1018 - * @since 6.10
1019 - *
1020 - * @param int $form_id Form ID.
1021 - *
1022 - * @return object[]
1023 - */
1024 - protected function get_form_fields( $form_id ) {
1025 - // Get form fields, include embedded and repeater child fields.
1026 - $form_fields = FrmField::get_all_for_form( $form_id, '', 'include' );
1027 - return array_filter(
1028 - $form_fields,
1029 - function ( $form_field ) {
1030 - return ! FrmField::is_no_save_field( $form_field->type );
1031 - }
1032 - );
1033 978 }
1034 979 }