Plugin Directory

Changeset 3366254


Ignore:
Timestamp:
09/23/2025 07:13:01 AM (3 months ago)
Author:
themefic
Message:

update uacf7 3.5.28

Location:
ultimate-addons-for-contact-form-7
Files:
1174 added
3 edited

Legend:

Unmodified
Added
Removed
  • ultimate-addons-for-contact-form-7/trunk/addons/conditional-field/conditional-fields.php

    r3353641 r3366254  
    534534    }
    535535
    536 
    537536    /**
    538537     * uacf7_conditional_mail_properties Function
     
    541540     */
    542541    public function uacf7_conditional_mail_properties( $WPCF7_ContactForm ) {
    543         $wpcf7 = WPCF7_ContactForm::get_current();
     542        $wpcf7      = WPCF7_ContactForm::get_current();
    544543        $submission = WPCF7_Submission::get_instance();
    545544
    546         // Get the conditional fields
    547         // $uacf7_conditions = get_post_meta( $wpcf7->id(), 'conditional', true );
    548         $uacf7_conditions = uacf7_get_form_option( $wpcf7->id(), 'conditional' );
    549         $conditional_repeater = isset( $uacf7_conditions['conditional_repeater'] ) ? $uacf7_conditions['conditional_repeater'] : array();
     545        $uacf7_conditions     = uacf7_get_form_option( $wpcf7->id(), 'conditional' );
     546        $conditional_repeater = isset( $uacf7_conditions['conditional_repeater'] ) ? $uacf7_conditions['conditional_repeater'] : [];
    550547
    551548        $posted_data = $submission->get_posted_data();
    552         $form_tags = $submission->get_contact_form()->scan_form_tags();
    553 
    554         // Set the email body in the mail properties
    555         $properties = $submission->get_contact_form()->get_properties();
    556 
    557         // Get the email body
     549
     550        $properties  = $submission->get_contact_form()->get_properties();
    558551        $mail_body   = $properties['mail']['body'];
    559552        $mail_body_2 = $properties['mail_2']['body'];
    560553
    561 
    562554        if ( $submission && is_array( $conditional_repeater ) && ! empty( $conditional_repeater ) ) {
    563            
    564             // Loop through the conditional fields
    565555            foreach ( $conditional_repeater as $key => $condition ) {
    566                 $uacf7_cf_hs = $condition['uacf7_cf_hs'];
    567                 $uacf7_cf_group = $condition['uacf7_cf_group'];
     556                $uacf7_cf_hs            = $condition['uacf7_cf_hs'];
     557                $uacf7_cf_group         = $condition['uacf7_cf_group'];
    568558                $uacf7_cf_conditions_for = $condition['uacf7_cf_condition_for'];
    569                 $uacf7_cf_conditions = $condition['uacf7_cf_conditions'] ?? [];
    570                 $condition_status = [];
    571                
    572                 // Check if the conditional field is hidden or shown
     559                $uacf7_cf_conditions    = $condition['uacf7_cf_conditions'] ?? [];
     560                $condition_status       = [];
     561
    573562                foreach ( $uacf7_cf_conditions as $key => $value ) {
    574                     $uacf7_cf_val = $value['uacf7_cf_val'];
     563                    $uacf7_cf_val      = $value['uacf7_cf_val'];
    575564                    $uacf7_cf_operator = $value['uacf7_cf_operator'];
    576                     $uacf7_cf_tn = rtrim($value['uacf7_cf_tn'], '[]');
    577                    
    578                     // $posted_value = is_array( $posted_data[ $uacf7_cf_tn ] ) && in_array( $uacf7_cf_val, $posted_data[ $uacf7_cf_tn ] ) ? $uacf7_cf_val : $posted_data[ $uacf7_cf_tn ];
    579                     @$posted_value = is_array($posted_data[$uacf7_cf_tn]) ? implode(',', $posted_data[$uacf7_cf_tn]) : $posted_data[$uacf7_cf_tn];
    580                
    581                     // Condition for Equal 
    582                     if ( $uacf7_cf_operator == 'equal' && $posted_value == $uacf7_cf_val ) {
    583                         $condition_status[] = 'true';
     565                    $uacf7_cf_tn       = rtrim( $value['uacf7_cf_tn'], '[]' );
     566
     567                    $posted_value = $posted_data[ $uacf7_cf_tn ] ?? '';
     568
     569                    // Normalize to array for easier checking
     570                    if ( ! is_array( $posted_value ) ) {
     571                        $posted_value = [ $posted_value ];
    584572                    }
    585                     // Condition for Not Equal
    586                     else if ( $uacf7_cf_operator == 'not_equal' && $posted_value != $uacf7_cf_val ) {
    587 
    588                         $condition_status[] = 'true';
     573
     574                    // TRUE/FALSE for this condition
     575                    $result = false;
     576
     577                    foreach ( $posted_value as $pv ) {
     578                        switch ( $uacf7_cf_operator ) {
     579                            case 'equal':
     580                                if ( $pv == $uacf7_cf_val ) $result = true;
     581                                break;
     582
     583                            case 'not_equal':
     584                                if ( $pv != $uacf7_cf_val ) $result = true;
     585                                break;
     586
     587                            case 'greater_than':
     588                                if ( is_numeric( $pv ) && $pv > $uacf7_cf_val ) $result = true;
     589                                break;
     590
     591                            case 'less_than':
     592                                if ( is_numeric( $pv ) && $pv < $uacf7_cf_val ) $result = true;
     593                                break;
     594
     595                            case 'greater_than_or_equal_to':
     596                                if ( is_numeric( $pv ) && $pv >= $uacf7_cf_val ) $result = true;
     597                                break;
     598
     599                            case 'less_than_or_equal_to':
     600                                if ( is_numeric( $pv ) && $pv <= $uacf7_cf_val ) $result = true;
     601                                break;
     602
     603                            case 'starts_with':
     604                                if ( strpos( $pv, $uacf7_cf_val ) === 0 ) $result = true;
     605                                break;
     606
     607                            case 'ends_with':
     608                                if ( substr( $pv, -strlen( $uacf7_cf_val ) ) === $uacf7_cf_val ) $result = true;
     609                                break;
     610
     611                            case 'contains':
     612                                if ( strpos( $pv, $uacf7_cf_val ) !== false ) $result = true;
     613                                break;
     614
     615                            case 'does_not_contain':
     616                                if ( strpos( $pv, $uacf7_cf_val ) === false ) $result = true;
     617                                break;
     618                        }
     619
     620                        // Early exit for "any" conditions
     621                        if ( $result && $uacf7_cf_conditions_for === 'any' ) {
     622                            break;
     623                        }
    589624                    }
    590                     // Condition for Greater than
    591                     else if ( $uacf7_cf_operator == 'greater_than' && $posted_value > $uacf7_cf_val ) {
    592                         $condition_status[] = 'true';
    593                     }
    594                     // Condition for Less than
    595                     else if ( $uacf7_cf_operator == 'less_than' && $posted_value < $uacf7_cf_val ) {
    596                         $condition_status[] = 'true';
    597                     }
    598                     // Condition for Greater than or equal to
    599                     else if ( $uacf7_cf_operator == 'greater_than_or_equal_to' && $posted_value >= $uacf7_cf_val ) {
    600                         $condition_status[] = 'true';
    601                     }
    602                     // Condition for Less than or equal to
    603                     else if ( $uacf7_cf_operator == 'less_than_or_equal_to' && $posted_value <= $uacf7_cf_val ) {
    604                         $condition_status[] = 'true';
    605                     }
    606                     // Condition for Starts With
    607                     else if ( $uacf7_cf_operator == 'starts_with' && substr( $posted_value, 0, strlen( $uacf7_cf_val ) ) === $uacf7_cf_val ) {
    608                         $condition_status[] = 'true';
    609                     }
    610                     // Condition for Ends With
    611                     else if ( $uacf7_cf_operator == 'ends_with' && substr( $posted_value, -strlen( $uacf7_cf_val ) ) === $uacf7_cf_val ) {
    612                         $condition_status[] = 'true';
    613                     }     
    614                     // Condition for Contains
    615                     else if ( $uacf7_cf_operator == 'contains' && strpos( $posted_value, $uacf7_cf_val ) !== false ) {
    616                         $condition_status[] = 'true';
    617                     }     
    618                     // Condition for Excludes (does not contain)
    619                     else if ( $uacf7_cf_operator == 'does_not_contain' && strpos( $posted_value, $uacf7_cf_val ) === false ) {
    620                         $condition_status[] = 'true';
    621                     }else {
    622                         $condition_status[] = 'false';
    623                     }
    624                 }
    625 
    626                 // Check if the conditions for all 
    627                 if ( $uacf7_cf_conditions_for == 'all' ) {
    628                     if ( ! in_array( 'false', $condition_status ) ) {
    629                         if ( $uacf7_cf_hs == 'show' ) {
    630                             $mail_body = preg_replace( '/\[' . $uacf7_cf_group . '\]/s', '', $mail_body );
    631                             $mail_body = preg_replace( '/\[\/' . $uacf7_cf_group . '\]/s', '', $mail_body );
    632 
    633                             // Mail 2
    634                             $mail_body_2 = preg_replace( '/\[' . $uacf7_cf_group . '\]/s', '', $mail_body_2 );
    635                             $mail_body_2 = preg_replace( '/\[\/' . $uacf7_cf_group . '\]/s', '', $mail_body_2 );
    636                         }else{
    637                             $mail_body = preg_replace( '/\[' . $uacf7_cf_group . '\].*?\[\/' . $uacf7_cf_group . '\]/s', '', $mail_body );
    638 
    639                             // Mail 2
    640                             $mail_body_2 = preg_replace( '/\[' . $uacf7_cf_group . '\].*?\[\/' . $uacf7_cf_group . '\]/s', '', $mail_body_2 );
    641                         }
    642                     }else if($uacf7_cf_hs == 'hide' ){
    643                         $mail_body = preg_replace( '/\[' . $uacf7_cf_group . '\]/s', '', $mail_body );
    644                         $mail_body = preg_replace( '/\[\/' . $uacf7_cf_group . '\]/s', '', $mail_body );
    645 
    646                         // Mail 2
    647                         $mail_body_2 = preg_replace( '/\[' . $uacf7_cf_group . '\]/s', '', $mail_body_2 );
    648                         $mail_body_2 = preg_replace( '/\[\/' . $uacf7_cf_group . '\]/s', '', $mail_body_2 );
    649                      }else {
    650                         $mail_body = preg_replace( '/\[' . $uacf7_cf_group . '\].*?\[\/' . $uacf7_cf_group . '\]/s', '', $mail_body );
    651 
    652                         // Mail 2
    653                         $mail_body_2 = preg_replace( '/\[' . $uacf7_cf_group . '\].*?\[\/' . $uacf7_cf_group . '\]/s', '', $mail_body_2 );
    654                     }
    655                 }
    656 
    657                 // Check if the conditions for any
    658                 if ( $uacf7_cf_conditions_for == 'any' ) {
    659                    
    660                     $normalized_conditions = array_map(fn($v) => $v === 'true', (array) $condition_status);
    661 
    662                     if ( in_array(true, $normalized_conditions, true) ) {
    663                         if ( $uacf7_cf_hs == 'show' ) {
    664                             $mail_body = preg_replace( '/\[' . $uacf7_cf_group . '\]/s', '', $mail_body );
    665                             $mail_body = preg_replace( '/\[\/' . $uacf7_cf_group . '\]/s', '', $mail_body );
    666 
    667                             // Mail 2
    668                             $mail_body_2 = preg_replace( '/\[' . $uacf7_cf_group . '\]/s', '', $mail_body_2 );
    669                             $mail_body_2 = preg_replace( '/\[\/' . $uacf7_cf_group . '\]/s', '', $mail_body_2 );
    670                         }else {
    671                             $mail_body = preg_replace( '/\[' . $uacf7_cf_group . '\].*?\[\/' . $uacf7_cf_group . '\]/s', '', $mail_body );
    672    
    673                             // Mail 2
    674                             $mail_body_2 = preg_replace( '/\[' . $uacf7_cf_group . '\].*?\[\/' . $uacf7_cf_group . '\]/s', '', $mail_body_2 );
    675                         }
    676                     }else if($uacf7_cf_hs == 'hide' ){
    677                         $mail_body = preg_replace( '/\[' . $uacf7_cf_group . '\]/s', '', $mail_body );
    678                         $mail_body = preg_replace( '/\[\/' . $uacf7_cf_group . '\]/s', '', $mail_body );
    679 
    680                         // Mail 2
    681                         $mail_body_2 = preg_replace( '/\[' . $uacf7_cf_group . '\]/s', '', $mail_body_2 );
    682                         $mail_body_2 = preg_replace( '/\[\/' . $uacf7_cf_group . '\]/s', '', $mail_body_2 );
    683                     } else {
    684                         $mail_body = preg_replace( '/\[' . $uacf7_cf_group . '\].*?\[\/' . $uacf7_cf_group . '\]/s', '', $mail_body );
    685 
    686                         // Mail 2
    687                         $mail_body_2 = preg_replace( '/\[' . $uacf7_cf_group . '\].*?\[\/' . $uacf7_cf_group . '\]/s', '', $mail_body_2 );
    688                     }
    689                 }
    690 
     625
     626                    $condition_status[] = $result ? 'true' : 'false';
     627                }
     628
     629                // Handle "all" vs "any"
     630                if ( $uacf7_cf_conditions_for === 'all' ) {
     631                    $match = ! in_array( 'false', $condition_status, true );
     632                } else {
     633                    $match = in_array( 'true', $condition_status, true );
     634                }
     635
     636                // Apply mail body replacements
     637                if ( $match && $uacf7_cf_hs === 'show' ) {
     638                    $mail_body   = preg_replace( '/\[' . $uacf7_cf_group . '\]/s', '', $mail_body );
     639                    $mail_body   = preg_replace( '/\[\/' . $uacf7_cf_group . '\]/s', '', $mail_body );
     640                    $mail_body_2 = preg_replace( '/\[' . $uacf7_cf_group . '\]/s', '', $mail_body_2 );
     641                    $mail_body_2 = preg_replace( '/\[\/' . $uacf7_cf_group . '\]/s', '', $mail_body_2 );
     642                } else if ( $match && $uacf7_cf_hs === 'hide' ) {
     643                    $mail_body   = preg_replace( '/\[' . $uacf7_cf_group . '\].*?\[\/' . $uacf7_cf_group . '\]/s', '', $mail_body );
     644                    $mail_body_2 = preg_replace( '/\[' . $uacf7_cf_group . '\].*?\[\/' . $uacf7_cf_group . '\]/s', '', $mail_body_2 );
     645                } else if ( ! $match ) {
     646                    // Default: remove group if condition fails
     647                    $mail_body   = preg_replace( '/\[' . $uacf7_cf_group . '\].*?\[\/' . $uacf7_cf_group . '\]/s', '', $mail_body );
     648                    $mail_body_2 = preg_replace( '/\[' . $uacf7_cf_group . '\].*?\[\/' . $uacf7_cf_group . '\]/s', '', $mail_body_2 );
     649                }
    691650            }
    692651
    693             // Set the email body in the mail properties
    694             $properties['mail']['body'] = $mail_body;
    695 
    696             // Mail 2
     652            // Save back
     653            $properties['mail']['body']   = $mail_body;
    697654            $properties['mail_2']['body'] = $mail_body_2;
    698 
    699655            $submission->get_contact_form()->set_properties( $properties );
    700 
    701         }
    702     }
     656        }
     657    }
     658
    703659
    704660    public function uacf7_condition_replace_pdf( $pdf_content, $id, $contact_form_data ) {
     
    706662        $conditional_repeater = isset( $uacf7_conditions['conditional_repeater'] ) ? $uacf7_conditions['conditional_repeater'] : array();
    707663
    708         // ✅ Use raw posted data from submission, not the normalized $contact_form_data
    709         $submission = WPCF7_Submission::get_instance();
    710         $posted_data = $submission ? $submission->get_posted_data() : (array) $contact_form_data;
     664        $submission   = WPCF7_Submission::get_instance();
     665        $posted_data  = $submission ? $submission->get_posted_data() : (array) $contact_form_data;
    711666
    712667        if ( is_array( $conditional_repeater ) && ! empty( $conditional_repeater ) ) {
    713             foreach ( $conditional_repeater as $key => $condition ) {
    714 
    715                 $uacf7_cf_hs = $condition['uacf7_cf_hs'];
    716                 $uacf7_cf_group = $condition['uacf7_cf_group'];
     668            foreach ( $conditional_repeater as $condition ) {
     669
     670                $uacf7_cf_hs            = $condition['uacf7_cf_hs'];
     671                $uacf7_cf_group         = $condition['uacf7_cf_group'];
    717672                $uacf7_cf_conditions_for = $condition['uacf7_cf_condition_for'];
    718                 $uacf7_cf_conditions = $condition['uacf7_cf_conditions'];
    719                 $condition_status = [];
     673                $uacf7_cf_conditions    = $condition['uacf7_cf_conditions'] ?? [];
     674                $condition_status       = [];
    720675
    721676                foreach ( $uacf7_cf_conditions as $c ) {
    722                     $uacf7_cf_val = $c['uacf7_cf_val'];
     677                    $uacf7_cf_val      = $c['uacf7_cf_val'];
    723678                    $uacf7_cf_operator = $c['uacf7_cf_operator'];
    724                     $uacf7_cf_tn = rtrim( $c['uacf7_cf_tn'], '[]' );
    725 
    726                     // ✅ Normalize posted value
    727                     $posted_value = isset($posted_data[$uacf7_cf_tn])
    728                         ? ( is_array($posted_data[$uacf7_cf_tn]) ? implode(',', $posted_data[$uacf7_cf_tn]) : $posted_data[$uacf7_cf_tn] )
    729                         : '';
    730 
    731                     // ✅ Same condition checks as your mail function
    732                     if ( $uacf7_cf_operator == 'equal' && $posted_value == $uacf7_cf_val ) {
    733                         $condition_status[] = 'true';
     679                    $uacf7_cf_tn       = rtrim( $c['uacf7_cf_tn'], '[]' );
     680
     681                    // Normalize posted value as array always
     682                    $raw_value   = $posted_data[$uacf7_cf_tn] ?? '';
     683                    $posted_vals = is_array( $raw_value ) ? $raw_value : ( $raw_value !== '' ? [ $raw_value ] : [] );
     684
     685                    // Loop through all posted values
     686                    $matched = false;
     687                    foreach ( $posted_vals as $posted_value ) {
     688                        switch ( $uacf7_cf_operator ) {
     689                            case 'equal':
     690                                if ( $posted_value == $uacf7_cf_val ) $matched = true;
     691                                break;
     692                            case 'not_equal':
     693                                if ( $posted_value != $uacf7_cf_val ) $matched = true;
     694                                break;
     695                            case 'greater_than':
     696                                if ( $posted_value > $uacf7_cf_val ) $matched = true;
     697                                break;
     698                            case 'less_than':
     699                                if ( $posted_value < $uacf7_cf_val ) $matched = true;
     700                                break;
     701                            case 'greater_than_or_equal_to':
     702                                if ( $posted_value >= $uacf7_cf_val ) $matched = true;
     703                                break;
     704                            case 'less_than_or_equal_to':
     705                                if ( $posted_value <= $uacf7_cf_val ) $matched = true;
     706                                break;
     707                            case 'starts_with':
     708                                if ( substr( $posted_value, 0, strlen( $uacf7_cf_val ) ) === $uacf7_cf_val ) $matched = true;
     709                                break;
     710                            case 'ends_with':
     711                                if ( substr( $posted_value, -strlen( $uacf7_cf_val ) ) === $uacf7_cf_val ) $matched = true;
     712                                break;
     713                            case 'contains':
     714                                if ( strpos( $posted_value, $uacf7_cf_val ) !== false ) $matched = true;
     715                                break;
     716                            case 'does_not_contain':
     717                                if ( strpos( $posted_value, $uacf7_cf_val ) === false ) $matched = true;
     718                                break;
     719                        }
     720                        if ( $matched ) break; // no need to check more values
    734721                    }
    735                     elseif ( $uacf7_cf_operator == 'not_equal' && $posted_value != $uacf7_cf_val ) {
    736                         $condition_status[] = 'true';
    737                     }
    738                     elseif ( $uacf7_cf_operator == 'contains' && strpos($posted_value, $uacf7_cf_val) !== false ) {
    739                         $condition_status[] = 'true';
    740                     }
    741                     elseif ( $uacf7_cf_operator == 'does_not_contain' && strpos($posted_value, $uacf7_cf_val) === false ) {
    742                         $condition_status[] = 'true';
    743                     }
    744                     else {
    745                         $condition_status[] = 'false';
    746                     }
    747                 }
    748 
    749                 // Replace content (same as your mail logic)
    750                 if ( $uacf7_cf_conditions_for == 'all' && ! in_array('false', $condition_status) ) {
     722
     723                    $condition_status[] = $matched ? 'true' : 'false';
     724                }
     725
     726                // ✅ Replace content like mail logic
     727                if ( $uacf7_cf_conditions_for == 'all' && ! in_array( 'false', $condition_status, true ) ) {
    751728                    if ( $uacf7_cf_hs == 'show' ) {
    752729                        $pdf_content = preg_replace( '/\['.$uacf7_cf_group.'\]/s', '', $pdf_content );
    753730                        $pdf_content = preg_replace( '/\[\/'.$uacf7_cf_group.'\]/s', '', $pdf_content );
    754731                    }
    755                 } elseif ( $uacf7_cf_conditions_for == 'any' && in_array('true', $condition_status) ) {
     732                }
     733                elseif ( $uacf7_cf_conditions_for == 'any' && in_array( 'true', $condition_status, true ) ) {
    756734                    if ( $uacf7_cf_hs == 'show' ) {
    757735                        $pdf_content = preg_replace( '/\['.$uacf7_cf_group.'\]/s', '', $pdf_content );
    758736                        $pdf_content = preg_replace( '/\[\/'.$uacf7_cf_group.'\]/s', '', $pdf_content );
    759737                    }
    760                 } else {
     738                }
     739                else {
    761740                    $pdf_content = preg_replace( '/\['.$uacf7_cf_group.'\].*?\[\/'.$uacf7_cf_group.'\]/s', '', $pdf_content );
    762741                }
     
    766745        return $pdf_content;
    767746    }
     747
    768748
    769749
  • ultimate-addons-for-contact-form-7/trunk/readme.txt

    r3353641 r3366254  
    55Tested up to: 6.8
    66Requires PHP: 7.4
    7 Stable tag: 3.5.27
     7Stable tag: 3.5.28
    88License: GPL-2.0+
    99License URI: http://www.gnu.org/licenses/gpl-2.0.txt
     
    482482== Changelog ==
    483483
    484 = 3.5.27 - 10/08/2025 =
    485 
    486 - Fixed: Multistep issue in Elementor Popup.
    487 - Fixed: Conditional field issue in PDF generator.
     484= 3.5.28 - 23/09/2025 =
     485
     486- Fixed: Conditional logic for multiple checkbox selection has been updated.
    488487
    489488**Old Changelog can be found [here](https://cf7addons.com/changelog/)**.
  • ultimate-addons-for-contact-form-7/trunk/ultimate-addons-for-contact-form-7.php

    r3353641 r3366254  
    44 * Plugin URI: https://cf7addons.com/
    55 * Description: 50+ Essential Addons for Contact Form 7 - Conditional Fields, Multi Step Forms, Redirection, Form Templates, Columns, WooCommerce, Mailchimp and more, all in one.
    6  * Version: 3.5.27
     6 * Version: 3.5.28
    77 * Author: Themefic
    88 * Author URI: https://themefic.com/
     
    3131        define( 'UACF7_PATH', plugin_dir_path( __FILE__ ) );
    3232
    33         define( 'UACF7_VERSION', '3.5.27' );
     33        define( 'UACF7_VERSION', '3.5.28' );
    3434
    3535        if ( ! class_exists( 'Appsero\Client' ) ) {
Note: See TracChangeset for help on using the changeset viewer.