| @@ -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,9 +451,9 @@ | ||
| 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 ?? ''; | |
| 455 | + $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : ''; | |
| 456 | 456 | $instance = $this->update( $new_instance, $old_instance ); |
| 457 | 457 | |
| 458 | 458 | /** |
| 459 | 459 | * Filter an action's settings before saving. |
| @@ -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 ); |
| @@ -538,18 +537,15 @@ | ||
| 538 | 537 | // don't continue if there are no available actions |
| 539 | 538 | return array(); |
| 540 | 539 | } |
| 541 | 540 | |
| 542 | - if ( 'all' !== $type ) { | |
| 543 | - if ( is_array( $action_controls ) ) { | |
| 544 | - return array(); | |
| 545 | - } | |
| 541 | + if ( 'all' != $type ) { | |
| 546 | 542 | return $action_controls->get_all( $form_id, $atts ); |
| 547 | 543 | } |
| 548 | 544 | |
| 549 | 545 | self::prepare_get_action( $atts ); |
| 550 | 546 | |
| 551 | - $limit = self::get_action_limit( $form_id, $atts['limit'] ); | |
| 547 | + $limit = apply_filters( 'frm_form_action_limit', $atts['limit'], compact( 'type', 'form_id' ) ); | |
| 552 | 548 | |
| 553 | 549 | $args = self::action_args( $form_id, $limit ); |
| 554 | 550 | $args['post_status'] = $atts['post_status']; |
| 555 | 551 | $actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' ); |
| @@ -582,24 +578,8 @@ | ||
| 582 | 578 | return $settings; |
| 583 | 579 | } |
| 584 | 580 | |
| 585 | 581 | /** |
| 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 | 582 | * @since 3.04 |
| 603 | 583 | * |
| 604 | 584 | * @param array $args |
| 605 | 585 | * @param string $default_status |
| @@ -626,12 +606,8 @@ | ||
| 626 | 606 | public static function get_single_action_type( $action_id, $type ) { |
| 627 | 607 | if ( ! $type ) { |
| 628 | 608 | return false; |
| 629 | 609 | } |
| 630 | - | |
| 631 | - /** | |
| 632 | - * @var FrmFormAction | |
| 633 | - */ | |
| 634 | 610 | $action_control = FrmFormActionsController::get_form_actions( $type ); |
| 635 | 611 | |
| 636 | 612 | return $action_control->get_single_action( $action_id ); |
| 637 | 613 | } |
| @@ -855,20 +831,77 @@ | ||
| 855 | 831 | |
| 856 | 832 | return $post_id; |
| 857 | 833 | } |
| 858 | 834 | |
| 859 | - /** | |
| 860 | - * @param WP_Post $action | |
| 861 | - * @param stdClass $entry | |
| 862 | - * @return bool | |
| 863 | - */ | |
| 864 | 835 | public static function action_conditions_met( $action, $entry ) { |
| 865 | 836 | if ( is_callable( 'FrmProFormActionsController::action_conditions_met' ) ) { |
| 866 | 837 | return FrmProFormActionsController::action_conditions_met( $action, $entry ); |
| 867 | 838 | } |
| 868 | 839 | |
| 869 | - $stop = false; | |
| 840 | + // This is here for reverse compatibility. | |
| 841 | + $notification = $action->post_content; | |
| 842 | + $stop = false; | |
| 843 | + $met = array(); | |
| 844 | + | |
| 845 | + if ( empty( $notification['conditions'] ) ) { | |
| 846 | + return $stop; | |
| 847 | + } | |
| 848 | + | |
| 849 | + foreach ( $notification['conditions'] as $k => $condition ) { | |
| 850 | + if ( ! is_numeric( $k ) ) { | |
| 851 | + continue; | |
| 852 | + } | |
| 853 | + | |
| 854 | + if ( $stop && 'any' == $notification['conditions']['any_all'] && 'stop' == $notification['conditions']['send_stop'] ) { | |
| 855 | + continue; | |
| 856 | + } | |
| 857 | + | |
| 858 | + self::prepare_logic_value( $condition['hide_opt'], $action, $entry ); | |
| 859 | + | |
| 860 | + $observed_value = self::get_value_from_entry( $entry, $condition['hide_field'] ); | |
| 861 | + | |
| 862 | + $stop = FrmFieldsHelper::value_meets_condition( $observed_value, $condition['hide_field_cond'], $condition['hide_opt'] ); | |
| 863 | + | |
| 864 | + if ( $notification['conditions']['send_stop'] === 'send' ) { | |
| 865 | + $stop = $stop ? false : true; | |
| 866 | + } | |
| 867 | + | |
| 868 | + $met[ $stop ] = $stop; | |
| 869 | + }//end foreach | |
| 870 | + | |
| 871 | + if ( $notification['conditions']['any_all'] === 'all' && ! empty( $met ) && isset( $met[0] ) && isset( $met[1] ) ) { | |
| 872 | + $stop = ( $notification['conditions']['send_stop'] === 'send' ); | |
| 873 | + } elseif ( $notification['conditions']['any_all'] === 'any' && $notification['conditions']['send_stop'] === 'send' && isset( $met[0] ) ) { | |
| 874 | + $stop = false; | |
| 875 | + } | |
| 876 | + | |
| 870 | 877 | return $stop; |
| 878 | + } | |
| 879 | + | |
| 880 | + /** | |
| 881 | + * Prepare the logic value for comparison against the entered value | |
| 882 | + * | |
| 883 | + * @since 2.01.02 | |
| 884 | + * | |
| 885 | + * @param array|string $logic_value | |
| 886 | + * | |
| 887 | + * @return void | |
| 888 | + */ | |
| 889 | + private static function prepare_logic_value( &$logic_value, $action, $entry ) { | |
| 890 | + if ( is_array( $logic_value ) ) { | |
| 891 | + $logic_value = reset( $logic_value ); | |
| 892 | + } | |
| 893 | + | |
| 894 | + if ( $logic_value === 'current_user' ) { | |
| 895 | + $logic_value = get_current_user_id(); | |
| 896 | + } | |
| 897 | + | |
| 898 | + $logic_value = apply_filters( 'frm_content', $logic_value, $action->menu_order, $entry ); | |
| 899 | + | |
| 900 | + /** | |
| 901 | + * @since 4.04.05 | |
| 902 | + */ | |
| 903 | + $logic_value = apply_filters( 'frm_action_logic_value', $logic_value ); | |
| 871 | 904 | } |
| 872 | 905 | |
| 873 | 906 | /** |
| 874 | 907 | * Get the value from a specific field and entry |