| @@ -164,11 +164,11 @@ | ||
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | $upgrade_class = isset( $action_options['classes'] ) && $action_options['classes'] === 'frm_show_upgrade'; |
| 167 | 167 | if ( $action_options['group'] === $id_base ) { |
| 168 | - $upgrade_class = strpos( $action_options['classes'], 'frm_show_upgrade' ) !== false; | |
| 168 | + $upgrade_class = strpos( $action_options['classes'], 'frm_show_upgrade' ) !== false; | |
| 169 | 169 | $action_options['classes'] = $group['icon']; |
| 170 | - } elseif ( empty( $action_options['classes'] ) || $upgrade_class ) { | |
| 170 | + } elseif ( ! isset( $action_options['classes'] ) || empty( $action_options['classes'] ) || $upgrade_class ) { | |
| 171 | 171 | $action_options['classes'] = $group['icon']; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | if ( $upgrade_class ) { |
| @@ -234,9 +234,9 @@ | ||
| 234 | 234 | * |
| 235 | 235 | * @return string Name attribute for $field_name |
| 236 | 236 | */ |
| 237 | 237 | public function get_field_name( $field_name, $post_field = 'post_content' ) { |
| 238 | - $name = $this->option_name . '[' . $this->number . ']'; | |
| 238 | + $name = $this->option_name . '[' . $this->number . ']'; | |
| 239 | 239 | $name .= ( empty( $post_field ) ? '' : '[' . $post_field . ']' ); |
| 240 | 240 | $name .= '[' . $field_name . ']'; |
| 241 | 241 | |
| 242 | 242 | return $name; |
| @@ -329,12 +329,12 @@ | ||
| 329 | 329 | * |
| 330 | 330 | * @since 2.0 |
| 331 | 331 | * |
| 332 | 332 | * @param array $action |
| 333 | - * @return int $post_id | |
| 333 | + * @return integer $post_id | |
| 334 | 334 | */ |
| 335 | 335 | 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' ) { | |
| 336 | + if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && isset( $forms[ $action['menu_order'] ] ) && $forms[ $action['menu_order'] ] == 'updated' ) { | |
| 337 | 337 | // Update action only |
| 338 | 338 | $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] ); |
| 339 | 339 | $post_id = $this->save_settings( $action ); |
| 340 | 340 | } else { |
| @@ -434,9 +434,9 @@ | ||
| 434 | 434 | |
| 435 | 435 | foreach ( $settings as $number => $new_instance ) { |
| 436 | 436 | $this->_set( $number ); |
| 437 | 437 | |
| 438 | - $old_instance = $all_instances[ $number ] ?? array(); | |
| 438 | + $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array(); | |
| 439 | 439 | |
| 440 | 440 | if ( ! isset( $new_instance['post_status'] ) ) { |
| 441 | 441 | $new_instance['post_status'] = 'draft'; |
| 442 | 442 | } |
| @@ -451,10 +451,10 @@ | ||
| 451 | 451 | |
| 452 | 452 | $new_instance['post_type'] = FrmFormActionsController::$action_post_type; |
| 453 | 453 | $new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number; |
| 454 | 454 | $new_instance['menu_order'] = $this->form_id; |
| 455 | - $new_instance['post_date'] = $old_instance->post_date ?? ''; | |
| 456 | - $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 ); | |
| 457 | 457 | |
| 458 | 458 | /** |
| 459 | 459 | * Filter an action's settings before saving. |
| 460 | 460 | * |
| @@ -462,12 +462,11 @@ | ||
| 462 | 462 | * to update settings. |
| 463 | 463 | * |
| 464 | 464 | * @since 2.0 |
| 465 | 465 | * |
| 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. | |
| 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. | |
| 470 | 469 | */ |
| 471 | 470 | $instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this ); |
| 472 | 471 | |
| 473 | 472 | $instance['post_content'] = apply_filters( 'frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this ); |
| @@ -490,9 +489,9 @@ | ||
| 490 | 489 | * |
| 491 | 490 | * @since 3.04 |
| 492 | 491 | * |
| 493 | 492 | * @param array $new_instance |
| 494 | - * @param array|stdClass $old_instance | |
| 493 | + * @param stdClass|array $old_instance | |
| 495 | 494 | * @return void |
| 496 | 495 | */ |
| 497 | 496 | protected function maybe_update_status( $new_instance, $old_instance ) { |
| 498 | 497 | if ( ! is_object( $old_instance ) || $new_instance['post_status'] === $old_instance->post_status ) { |
| @@ -507,12 +506,8 @@ | ||
| 507 | 506 | ) |
| 508 | 507 | ); |
| 509 | 508 | } |
| 510 | 509 | |
| 511 | - /** | |
| 512 | - * @param array $settings | |
| 513 | - * @return int|WP_Error | |
| 514 | - */ | |
| 515 | 510 | public function save_settings( $settings ) { |
| 516 | 511 | self::clear_cache(); |
| 517 | 512 | |
| 518 | 513 | return FrmDb::save_settings( $settings, 'frm_actions' ); |
| @@ -538,18 +533,15 @@ | ||
| 538 | 533 | // don't continue if there are no available actions |
| 539 | 534 | return array(); |
| 540 | 535 | } |
| 541 | 536 | |
| 542 | - if ( 'all' !== $type ) { | |
| 543 | - if ( is_array( $action_controls ) ) { | |
| 544 | - return array(); | |
| 545 | - } | |
| 537 | + if ( 'all' != $type ) { | |
| 546 | 538 | return $action_controls->get_all( $form_id, $atts ); |
| 547 | 539 | } |
| 548 | 540 | |
| 549 | 541 | self::prepare_get_action( $atts ); |
| 550 | 542 | |
| 551 | - $limit = self::get_action_limit( $form_id, $atts['limit'] ); | |
| 543 | + $limit = apply_filters( 'frm_form_action_limit', $atts['limit'], compact( 'type', 'form_id' ) ); | |
| 552 | 544 | |
| 553 | 545 | $args = self::action_args( $form_id, $limit ); |
| 554 | 546 | $args['post_status'] = $atts['post_status']; |
| 555 | 547 | $actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' ); |
| @@ -582,24 +574,8 @@ | ||
| 582 | 574 | return $settings; |
| 583 | 575 | } |
| 584 | 576 | |
| 585 | 577 | /** |
| 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 | 578 | * @since 3.04 |
| 603 | 579 | * |
| 604 | 580 | * @param array $args |
| 605 | 581 | * @param string $default_status |
| @@ -626,12 +602,8 @@ | ||
| 626 | 602 | public static function get_single_action_type( $action_id, $type ) { |
| 627 | 603 | if ( ! $type ) { |
| 628 | 604 | return false; |
| 629 | 605 | } |
| 630 | - | |
| 631 | - /** | |
| 632 | - * @var FrmFormAction | |
| 633 | - */ | |
| 634 | 606 | $action_control = FrmFormActionsController::get_form_actions( $type ); |
| 635 | 607 | |
| 636 | 608 | return $action_control->get_single_action( $action_id ); |
| 637 | 609 | } |
| @@ -665,10 +637,10 @@ | ||
| 665 | 637 | global $frm_vars; |
| 666 | 638 | $frm_vars['action_type'] = $type; |
| 667 | 639 | |
| 668 | 640 | add_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' ); |
| 669 | - $query = self::action_args( $form_id, $limit ); | |
| 670 | - $query['post_status'] = $atts['post_status']; | |
| 641 | + $query = self::action_args( $form_id, $limit ); | |
| 642 | + $query['post_status'] = $atts['post_status']; | |
| 671 | 643 | $query['suppress_filters'] = false; |
| 672 | 644 | |
| 673 | 645 | $actions = FrmDb::check_cache( json_encode( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' ); |
| 674 | 646 | unset( $query ); |
| @@ -716,9 +688,9 @@ | ||
| 716 | 688 | return $args; |
| 717 | 689 | } |
| 718 | 690 | |
| 719 | 691 | /** |
| 720 | - * @param array|WP_Post $action | |
| 692 | + * @param WP_Post|array $action | |
| 721 | 693 | */ |
| 722 | 694 | public function prepare_action( $action ) { |
| 723 | 695 | $action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content ); |
| 724 | 696 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
| @@ -815,9 +787,9 @@ | ||
| 815 | 787 | /** |
| 816 | 788 | * Migrate settings from form->options into new action. |
| 817 | 789 | */ |
| 818 | 790 | public function migrate_to_2( $form, $update = 'update' ) { |
| 819 | - $action = $this->prepare_new( $form->id ); | |
| 791 | + $action = $this->prepare_new( $form->id ); | |
| 820 | 792 | FrmAppHelper::unserialize_or_decode( $form->options ); |
| 821 | 793 | |
| 822 | 794 | // fill with existing options |
| 823 | 795 | foreach ( $action->post_content as $name => $val ) { |
| @@ -855,26 +827,86 @@ | ||
| 855 | 827 | |
| 856 | 828 | return $post_id; |
| 857 | 829 | } |
| 858 | 830 | |
| 859 | - /** | |
| 860 | - * @param WP_Post $action | |
| 861 | - * @param stdClass $entry | |
| 862 | - * @return bool | |
| 863 | - */ | |
| 864 | 831 | public static function action_conditions_met( $action, $entry ) { |
| 865 | 832 | if ( is_callable( 'FrmProFormActionsController::action_conditions_met' ) ) { |
| 866 | 833 | return FrmProFormActionsController::action_conditions_met( $action, $entry ); |
| 867 | 834 | } |
| 868 | 835 | |
| 869 | - $stop = false; | |
| 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 | + | |
| 870 | 873 | return $stop; |
| 871 | 874 | } |
| 872 | 875 | |
| 873 | 876 | /** |
| 877 | + * Prepare the logic value for comparison against the entered value | |
| 878 | + * | |
| 879 | + * @since 2.01.02 | |
| 880 | + * | |
| 881 | + * @deprecated 4.06.02 | |
| 882 | + * | |
| 883 | + * @param array|string $logic_value | |
| 884 | + * | |
| 885 | + * @return void | |
| 886 | + */ | |
| 887 | + private static function prepare_logic_value( &$logic_value, $action, $entry ) { | |
| 888 | + if ( is_array( $logic_value ) ) { | |
| 889 | + $logic_value = reset( $logic_value ); | |
| 890 | + } | |
| 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 ); | |
| 902 | + } | |
| 903 | + | |
| 904 | + /** | |
| 874 | 905 | * Get the value from a specific field and entry |
| 875 | 906 | * |
| 876 | 907 | * @since 2.01.02 |
| 908 | + * @deprecated 4.06.02 | |
| 877 | 909 | * |
| 878 | 910 | * @param object $entry |
| 879 | 911 | * @param int $field_id |
| 880 | 912 | * |
| @@ -942,25 +974,6 @@ | ||
| 942 | 974 | * @return string |
| 943 | 975 | */ |
| 944 | 976 | protected function get_upgrade_text() { |
| 945 | 977 | 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 | 978 | } |
| 966 | 979 | } |