Plugin Directory

Changeset 3323842


Ignore:
Timestamp:
07/07/2025 05:59:20 PM (8 months ago)
Author:
checkview
Message:

Update to version 2.0.19 from GitHub

Location:
checkview
Files:
22 added
28 edited
1 copied

Legend:

Unmodified
Added
Removed
  • checkview/tags/2.0.19/README.txt

    r3303097 r3323842  
    88License: GPLv3
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html
    10 Stable tag: 2.0.18
     10Stable tag: 2.0.19
    1111
    1212[CheckView](https://checkview.io/) is the friendly WordPress automated testing platform for everyone, from developers, shop owners to agencies. 
     
    8686
    8787== Changelog ==
     88= 2.0.19 =
     89* Improve logging
     90* Add hooks for disabling WP Forms CAPTCHAs/Turnstiles for tests
     91* Disable test-related hooks on API requests
     92* Disable Fluent Forms token-based spam prevention for tests
     93* Remove Fluent Forms CAPTCHA/Turnstile key swap
     94* Disable Fluent Forms CAPTCHAs using newly provided hook
     95
    8896= 2.0.18 =
    8997* Improve logging when querying for available test results.
     
    360368
    361369== Upgrade Notice ==
     370= 2.0.19 =
     371* Improve logging
     372* Add hooks for disabling WP Forms CAPTCHAs/Turnstiles for tests
     373* Disable test-related hooks on API requests
     374* Disable Fluent Forms token-based spam prevention for tests
     375* Remove Fluent Forms CAPTCHA/Turnstile key swap
     376* Disable Fluent Forms CAPTCHAs using newly provided hook
     377
    362378= 2.0.18 =
    363379* Improve logging when querying for available test results.
  • checkview/tags/2.0.19/admin/class-checkview-admin.php

    r3283610 r3323842  
    6262
    6363        add_action(
    64             'checkview_options_cleanup_cron',
    65             'checkview_options_cleanup'
    66         );
    67 
    68         add_action(
    6964            'checkview_nonce_cleanup_cron',
    7065            array( $this, 'checkview_delete_expired_nonces' )
     
    122117        if ( ! wp_next_scheduled( 'checkview_nonce_cleanup_cron' ) ) {
    123118            wp_schedule_event( time(), 'hourly', 'checkview_nonce_cleanup_cron' );
    124         }
    125 
    126         if ( ! wp_next_scheduled( 'checkview_options_cleanup_cron' ) ) {
    127             wp_schedule_single_event( time() + 60, 'checkview_options_cleanup_cron' );
    128119        }
    129120    }
     
    216207     */
    217208    public function checkview_init_current_test() {
    218 
    219209        if ( ! function_exists( 'is_plugin_active' ) ) {
    220210            include_once ABSPATH . 'wp-admin/includes/plugin.php';
    221211        }
    222         // Current Vsitor IP.
     212
     213        $is_helper_api_request = isset( $_SERVER['REQUEST_URI'] ) && strpos( $_SERVER['REQUEST_URI'], '_checkview_timestamp' );
     214
     215        if ( $is_helper_api_request ) {
     216            return;
     217        }
     218
     219        // Current Visitor IP.
    223220        $visitor_ip = checkview_get_visitor_ip();
    224221        // Check view Bot IP.
     
    227224        // Skip if visitor ip not equal to CV Bot IP.
    228225        if ( is_array( $cv_bot_ip ) && ! in_array( $visitor_ip, $cv_bot_ip ) ) {
     226            if ( isset( $_REQUEST['checkview_test_id'] ) ) {
     227                Checkview_Admin_Logs::add( 'ip-logs', 'Although checkview_test_id is set in the request, exiting test init due to visitor IP [' . $visitor_ip . '] failing bot IP check [' . implode(', ', $cv_bot_ip) . '].' );
     228            }
     229
    229230            if ( 'true' !== get_option( 'cv_ff_keys_set_turnstile' ) ) {
    230231                return;
    231232            }
    232             if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) {
    233                 checkview_options_cleanup();
    234             }
     233
    235234            return;
    236235        }
    237236
    238         // If clean talk plugin active whitelist check form API IP.
     237        Checkview_Admin_Logs::add( 'ip-logs', 'Visitor IP [' . $visitor_ip . '] determined to be in bot IP list, continuing.' );
     238
    239239        if ( is_plugin_active( 'cleantalk-spam-protect/cleantalk.php' ) ) {
    240240            checkview_whitelist_api_ip();
     
    248248            $allowlist                  = Allow_List::get_ips();
    249249            $aiowps_firewall_allow_list = AIOS_Firewall_Resource::request( AIOS_Firewall_Resource::ALLOW_LIST );
     250
    250251            if ( ! empty( $allowlist ) ) {
    251252                $allowlist .= "\n" . $visitor_ip;
     
    253254                $allowlist = $visitor_ip;
    254255            }
    255             $ips                     = sanitize_textarea_field( wp_unslash( $allowlist ) );
    256             $ips                     = AIOWPSecurity_Utility_IP::create_ip_list_array_from_string_with_newline( $ips );
     256
     257            $ips = sanitize_textarea_field( wp_unslash( $allowlist ) );
     258            $ips = AIOWPSecurity_Utility_IP::create_ip_list_array_from_string_with_newline( $ips );
    257259            $validated_ip_list_array = AIOWPSecurity_Utility_IP::validate_ip_list( $ips, 'firewall_allowlist' );
     260
    258261            if ( is_wp_error( $validated_ip_list_array ) ) {
    259262                $success = false;
    260263                $message = nl2br( $validated_ip_list_array->get_error_message() );
     264
    261265                Checkview_Admin_Logs::add( 'ip-logs', 'Error ' . $message );
    262266            } else {
     
    267271        if ( is_plugin_active( 'defender-security/wp-defender.php' ) ) {
    268272            $data = array();
    269 
    270273            $data['allow_list'] = (array) $visitor_ip;
    271 
    272             $data['block_list']           = array();
    273             $data['last_update_time']     = '';
     274            $data['block_list'] = array();
     275            $data['last_update_time'] = '';
    274276            $data['last_update_time_utc'] = '';
    275277
    276278            $global_ip_component = wd_di()->get( Global_IP::class );
    277             $result              = $global_ip_component->set_global_ip_list( $data );
    278         }
     279            $result = $global_ip_component->set_global_ip_list( $data );
     280        }
     281
    279282        if ( is_plugin_active( 'enhanced-cloudflare-turnstile/enhanced-cloudflare-turnstile.php' ) ) {
    280             $ect_ip_address       = ecft_get_option( 'ecft_ip_address' );
     283            $ect_ip_address = ecft_get_option( 'ecft_ip_address' );
    281284            $ect_ip_address_array = explode( "\n", $ect_ip_address );
     285
    282286            if ( ! empty( $ect_ip_address_array ) && is_array( $ect_ip_address_array ) ) {
    283287                if ( ! in_array( $visitor_ip, $ect_ip_address_array ) ) {
    284288                    $ect_ip_address .= "\n" . $visitor_ip;
    285                     update_option( 'ecft_ip_address', $ect_ip_address );
     289
     290                    cv_update_option( 'ecft_ip_address', $ect_ip_address );
    286291                }
    287292            } else {
    288293                $ect_ip_address = $visitor_ip;
    289                 update_option( 'ecft_ip_address', $ect_ip_address );
     294
     295                cv_update_option( 'ecft_ip_address', $ect_ip_address );
    290296            }
    291297        }
     
    304310
    305311                // Save the updated list back to the database.
    306                 update_option( 'captcha_ip_range_opt', implode( ',', $captcha_ip_range ) );
    307             }
    308         }
     312                cv_update_option( 'captcha_ip_range_opt', implode( ',', $captcha_ip_range ) );
     313            }
     314        }
     315
    309316        if ( is_plugin_active( 'recaptcha-for-woocommerce/woo-recaptcha.php' ) ) {
    310             $captcha_ip_range     = '';
     317            $captcha_ip_range = '';
    311318            $captcha_ip_range_opt = '';
    312             $captcha_ip_range     = array();
     319            $captcha_ip_range = array();
     320
    313321            // Get the existing whitelist from the database.
    314322            $captcha_ip_range_opt = sanitize_text_field( wp_unslash( get_option( 'i13_recapcha_ip_to_skip_captcha' ) ) );
     
    323331                if ( count( $captcha_ip_range ) > 1 ) {
    324332                    // Save the updated list back to the database.
    325                     update_option( 'i13_recapcha_ip_to_skip_captcha', implode( ',', $captcha_ip_range ) );
     333                    cv_update_option( 'i13_recapcha_ip_to_skip_captcha', implode( ',', $captcha_ip_range ) );
    326334                } else {
    327                     update_option( 'i13_recapcha_ip_to_skip_captcha', $visitor_ip );
     335                    cv_update_option( 'i13_recapcha_ip_to_skip_captcha', $visitor_ip );
    328336                }
    329337            }
    330338        }
    331         // Gather test ID.
     339
    332340        $cv_test_id = isset( $_REQUEST['checkview_test_id'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['checkview_test_id'] ) ) : '';
    333 
    334         // Flag disabling of email receipts.
    335341        $disable_email_receipt = isset( $_REQUEST['disable_email_receipt'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['disable_email_receipt'] ) ) : false;
    336 
    337342        $disable_webhooks = isset( $_REQUEST['disable_webhooks'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['disable_webhooks'] ) ) : false;
    338 
    339343        $referrer_url = sanitize_url( wp_get_raw_referer(), array( 'http', 'https' ) );
    340344
     
    343347            // Create session for later use when form submit VIA AJAX.
    344348            checkview_create_cv_session( $visitor_ip, $cv_test_id );
    345             update_option( $visitor_ip, 'checkview-saas', true );
     349
     350            cv_update_option( $visitor_ip, 'checkview-saas', true);
    346351        }
    347352
     
    349354        if ( isset( $_SERVER['REQUEST_URI'] ) && strpos( sanitize_url( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'admin-ajax.php' ) !== false ) {
    350355            $referer_url_query = wp_parse_url( $referrer_url, PHP_URL_QUERY );
    351             $qry_str           = array();
     356            $qry_str = array();
     357
    352358            if ( $referer_url_query ) {
    353359                parse_str( $referer_url_query, $qry_str );
    354360            }
     361
    355362            if ( isset( $qry_str['checkview_test_id'] ) ) {
    356363                $cv_test_id = $qry_str['checkview_test_id'];
    357364            }
    358365        }
     366
    359367        if ( ! empty( $cv_test_id ) && ! checkview_is_valid_uuid( $cv_test_id ) ) {
    360             Checkview_Admin_Logs::add( 'ip-logs', 'Not Bypassed invalid test id. ' . $visitor_ip . '=> ' . $cv_test_id );
     368            Checkview_Admin_Logs::add( 'ip-logs', 'Test ID format failed to validate, exiting.' );
     369
    361370            return;
    362371        }
     372
    363373        if ( $cv_test_id && '' !== $cv_test_id ) {
    364374            setcookie( 'checkview_test_id', $cv_test_id, time() + 6600, COOKIEPATH, COOKIE_DOMAIN );
     
    381391            }
    382392        }
    383         if ( empty( $cv_test_id ) ) {
    384             Checkview_Admin_Logs::add( 'ip-logs', 'Not Bypassed missing test id. ' . $visitor_ip . '=> ' . $cv_test_id );
    385         } else {
    386             Checkview_Admin_Logs::add( 'ip-logs', 'Bypassed ' . $visitor_ip . '=> ' . $cv_test_id );
    387         }
     393
    388394        if ( ! empty( $cv_session ) ) {
    389 
    390395            $test_key = $cv_session[0]['test_key'];
    391 
    392396            $test_form = get_option( $test_key, '' );
    393397
     
    402406            if ( ! defined( 'CV_TEST_ID' ) ) {
    403407                define( 'CV_TEST_ID', $cv_test_id );
    404             }
    405         }
     408
     409                Checkview_Admin_Logs::add( 'ip-logs', 'Defined constant [CV_TEST_ID] as [ ' . CV_TEST_ID . ' ].' );
     410            }
     411        } else {
     412            Checkview_Admin_Logs::add( 'ip-logs', 'The CheckView session was empty, but continuing.' );
     413        }
     414
    406415        if ( ! defined( 'TEST_EMAIL' ) ) {
    407416            define( 'TEST_EMAIL', $send_to );
     417
     418            Checkview_Admin_Logs::add( 'ip-logs', 'Defined constant [TEST_EMAIL] as [ ' . TEST_EMAIL . ' ].' );
    408419        }
    409420
    410421        if ( ! defined( 'CV_DISABLE_EMAIL_RECEIPT' ) && $disable_email_receipt ) {
    411422            define( 'CV_DISABLE_EMAIL_RECEIPT', 'true' );
    412             update_option( 'disable_email_receipt', 'true', true );
     423
     424            Checkview_Admin_Logs::add( 'ip-logs', 'Defined constant [CV_DISABLE_EMAIL_RECEIPT] as [' . CV_DISABLE_EMAIL_RECEIPT . '].' );
     425
     426            cv_update_option('disable_email_receipt', 'true', true);
    413427        }
    414428
    415429        if ( ! defined( 'CV_DISABLE_WEBHOOKS' ) && $disable_webhooks ) {
    416430            define( 'CV_DISABLE_WEBHOOKS', 'true' );
    417             update_option( 'disable_webhooks', 'true', true );
     431
     432            Checkview_Admin_Logs::add( 'ip-logs', 'Defined constant [CV_DISABLE_WEBHOOKS] as [' . CV_DISABLE_WEBHOOKS . '].' );
     433
     434            cv_update_option('disable_webhooks', 'true', true);
    418435        }
    419436
    420437        delete_transient( 'checkview_forms_test_transient' );
    421438        delete_transient( 'checkview_store_orders_transient' );
     439
    422440        if ( is_plugin_active( 'gravityforms/gravityforms.php' ) ) {
     441            Checkview_Admin_Logs::add( 'ip-logs', 'Loading Gravity Forms helper.' );
     442
    423443            require_once CHECKVIEW_INC_DIR . 'formhelpers/class-checkview-gforms-helper.php';
    424444        }
     445
    425446        if ( is_plugin_active( 'fluentform/fluentform.php' ) ) {
     447            Checkview_Admin_Logs::add( 'ip-logs', 'Loading Fluent Forms helper.' );
     448
    426449            require_once CHECKVIEW_INC_DIR . 'formhelpers/class-checkview-fluent-forms-helper.php';
    427450        }
     451
    428452        if ( is_plugin_active( 'ninja-forms/ninja-forms.php' ) ) {
     453            Checkview_Admin_Logs::add( 'ip-logs', 'Loading Ninja Forms helper.' );
     454
    429455            require_once CHECKVIEW_INC_DIR . 'formhelpers/class-checkview-ninja-forms-helper.php';
    430456        }
     457
    431458        if ( function_exists( 'wpforms' ) && ( is_plugin_active( 'wpforms/wpforms.php' ) || is_plugin_active( 'wpforms-lite/wpforms.php' ) ) ) {
     459            Checkview_Admin_Logs::add( 'ip-logs', 'Loading WP Forms helper.' );
     460
    432461            require_once CHECKVIEW_INC_DIR . 'formhelpers/class-checkview-wpforms-helper.php';
    433462        }
     463
    434464        if ( is_plugin_active( 'formidable/formidable.php' ) ) {
     465            Checkview_Admin_Logs::add( 'ip-logs', 'Loading Formidable Forms helper.' );
     466
    435467            require_once CHECKVIEW_INC_DIR . 'formhelpers/class-checkview-formidable-helper.php';
    436468        }
    437469
    438470        if ( is_plugin_active( 'forminator/forminator.php' ) ) {
     471            Checkview_Admin_Logs::add( 'ip-logs', 'Loading Forminator helper.' );
     472
    439473            require_once CHECKVIEW_INC_DIR . 'formhelpers/class-checkview-forminator-helper.php';
    440474        }
    441475
    442476        if ( is_plugin_active( 'ws-form/ws-form.php' ) || is_plugin_active( 'ws-form-pro/ws-form.php' ) ) {
     477            Checkview_Admin_Logs::add( 'ip-logs', 'Loading WS Form helper.' );
     478
    443479            require_once CHECKVIEW_INC_DIR . 'formhelpers/class-checkview-wsf-helper.php';
    444480        }
     481
    445482        if ( is_plugin_active( 'contact-form-7/wp-contact-form-7.php' ) ) {
     483            Checkview_Admin_Logs::add( 'ip-logs', 'Loading Contact Form 7 helper.' );
     484
    446485            require_once CHECKVIEW_INC_DIR . 'formhelpers/class-checkview-cf7-helper.php';
    447486        }
  • checkview/tags/2.0.19/checkview.php

    r3303097 r3323842  
    1212 * Plugin URI:        https://checkview.io
    1313 * Description:       CheckView is the #1 fully automated solution to test your WordPress forms and detect form problems fast.  Automatically test your WordPress forms to ensure you never miss a lead again.
    14  * Version:           2.0.18
     14 * Version:           2.0.19
    1515 * Author:            CheckView
    1616 * Author URI:        https://checkview.io/
     
    3636 * @link https://semver.org
    3737 */
    38 define( 'CHECKVIEW_VERSION', '2.0.18' );
     38define( 'CHECKVIEW_VERSION', '2.0.19' );
    3939
    4040if ( ! defined( 'CHECKVIEW_BASE_DIR' ) ) {
  • checkview/tags/2.0.19/includes/checkview-functions.php

    r3303097 r3323842  
    144144    }
    145145}
     146
    146147if ( ! function_exists( 'complete_checkview_test' ) ) {
    147148    /**
     
    156157    function complete_checkview_test( $checkview_test_id = '' ) {
    157158        global $wpdb;
    158         global $CV_TEST_ID;
     159
     160        Checkview_Admin_Logs::add( 'ip-logs', 'Completing test...' );
     161
    159162        if ( ! defined( 'CV_TEST_ID' ) ) {
    160163            define( 'CV_TEST_ID', $checkview_test_id );
    161164        }
     165
    162166        $session_table = $wpdb->prefix . 'cv_session';
    163         $visitor_ip    = checkview_get_visitor_ip();
    164         $cv_session    = checkview_get_cv_session( $visitor_ip, CV_TEST_ID );
     167        $visitor_ip = checkview_get_visitor_ip();
     168        $cv_session = checkview_get_cv_session( $visitor_ip, CV_TEST_ID );
    165169
    166170        // Stop if session not found.
    167171        if ( ! empty( $cv_session ) ) {
    168172            $test_key = $cv_session[0]['test_key'];
    169             delete_option( $test_key );
    170         }
    171 
    172         $wpdb->delete(
     173
     174            cv_delete_option( $test_key );
     175        }
     176
     177        $result = $wpdb->delete(
    173178            $session_table,
    174179            array(
    175180                'visitor_ip' => $visitor_ip,
    176                 'test_id'    => $checkview_test_id,
     181                'test_id' => $checkview_test_id,
    177182            )
    178183        );
     184
     185        if ( false === $result ) {
     186            Checkview_Admin_Logs::add( 'ip-logs', 'Failed to delete rows from session table [' . $session_table . '].' );
     187        }
     188
    179189        $entry_id = get_option( $checkview_test_id . '_wsf_entry_id', '' );
    180190        $form_id  = get_option( $checkview_test_id . '_wsf_frm_id', '' );
     191
    181192        if ( ! empty( $form_id ) && ! empty( $entry_id ) ) {
    182             $ws_form_submit          = new WS_Form_Submit();
    183             $ws_form_submit->id      = $entry_id;
     193            $ws_form_submit = new WS_Form_Submit();
     194            $ws_form_submit->id = $entry_id;
    184195            $ws_form_submit->form_id = $form_id;
    185196            $ws_form_submit->db_delete( true, true, true );
    186197        }
    187         delete_option( $checkview_test_id . '_wsf_entry_id' );
    188         delete_option( $checkview_test_id . '_wsf_frm_id' );
    189         delete_option( $visitor_ip );
     198
     199        cv_delete_option( $checkview_test_id . '_wsf_entry_id' );
     200        cv_delete_option( $checkview_test_id . '_wsf_frm_id' );
     201        cv_delete_option( $visitor_ip );
     202
    190203        setcookie( 'checkview_test_id', '', time() - 6600, COOKIEPATH, COOKIE_DOMAIN );
    191204        setcookie( 'checkview_test_id' . $checkview_test_id, '', time() - 6600, COOKIEPATH, COOKIE_DOMAIN );
    192         delete_option( 'disable_email_receipt' );
    193         delete_option( 'disable_webhooks' );
    194     }
    195 }
     205
     206        cv_delete_option( 'disable_email_receipt' );
     207        cv_delete_option( 'disable_webhooks' );
     208
     209        Checkview_Admin_Logs::add( 'ip-logs', 'Test complete.' );
     210    }
     211}
     212
    196213if ( ! function_exists( 'checkview_get_publickey' ) ) {
    197214    /**
     
    235252     */
    236253    function checkview_get_api_ip() {
    237 
    238254        $ip_address = get_transient( 'checkview_saas_ip_address' ) ? get_transient( 'checkview_saas_ip_address' ) : array();
    239         if ( null === $ip_address || '' === $ip_address || empty( $ip_address ) ) {
     255
     256        if ( empty( $ip_address ) ) {
     257            Checkview_Admin_Logs::add( 'ip-logs', 'Bot IP address list transient empty, requesting new IP addresses.' );
     258
    240259            $request = wp_remote_get(
    241260                'https://verify.checkview.io/whitelist.json',
     
    245264                )
    246265            );
     266
    247267            if ( is_wp_error( $request ) ) {
     268                $code = $request->get_error_code();
     269                $message = $request->get_error_message();
     270
     271                Checkview_Admin_Logs::add( 'ip-logs', 'Request for new IP addresses failed with code [' . $code . ']. Message: ' . $message );
     272
    248273                return null;
    249274            }
    250275
    251276            $body = wp_remote_retrieve_body( $request );
    252 
    253277            $data = json_decode( $body, true );
     278
    254279            if ( ! empty( $data ) && ! empty( $data['ipAddresses'] ) ) {
    255280                $ip_address = $data['ipAddresses'];
     281
    256282                if ( ! empty( $ip_address ) && is_array( $ip_address ) ) {
    257283                    foreach ( $ip_address as $ip ) {
     
    264290                    return false;
    265291                }
     292
    266293                set_transient( 'checkview_saas_ip_address', $ip_address, 12 * HOUR_IN_SECONDS );
    267             }
    268         }
     294
     295                Checkview_Admin_Logs::add( 'ip-logs', 'Set bot IP address list transient to response data [' . wp_json_encode( $ip_address ) . ']' );
     296            } else {
     297                Checkview_Admin_Logs::add( 'ip-logs', 'IP addresses not found in request for new IP addresses.' );
     298            }
     299        }
     300
    269301        if ( ! is_array( $ip_address ) ) {
    270302            $ip_address = (array) $ip_address;
    271303        }
     304
    272305        if ( is_array( $ip_address ) ) {
    273306            $ip_address[] = '::1';
     
    275308            $ip_address[] = '2001:8a0:e5d0:a900:70a5:138a:d159:5054';
    276309        }
     310
    277311        return $ip_address;
    278312    }
     
    325359     * @since 1.0.0
    326360     *
    327      * @return string|false IP address of visitor, or `false` if determined to be
    328      *                      an invalid IP.
     361     * @return string IP address of visitor, or `false` if determined to be
     362     *                an invalid IP.
    329363     */
    330364    function checkview_get_visitor_ip() {
     
    332366        $cv_bot_ip  = checkview_get_api_ip();
    333367        $ip_options = checkview_get_custom_header_keys_for_ip();
    334         $ip         = '';
     368        $ip = '';
    335369
    336370        foreach ( $ip_options as $key ) {
     
    340374
    341375            $key = checkview_get_server_value( $key );
     376
    342377            foreach ( explode( ',', $key ) as $ip ) {
    343                 // Just to be safe.
    344378                $ip = trim( $ip );
    345379
    346380                if ( checkview_validate_ip( $ip ) && is_array( $cv_bot_ip ) && in_array( $ip, $cv_bot_ip ) ) {
    347                     Checkview_Admin_Logs::add( 'ip-logs', 'Bypassed ' . $ip );
    348381                    return sanitize_text_field( $ip );
    349382                }
     
    808841     */
    809842    function checkview_schedule_delete_orders( $order_id ) {
     843        Checkview_Admin_Logs::add( 'ip-logs', 'Scheduling order deletion.' );
     844
    810845        wp_schedule_single_event( time() + 1 * HOUR_IN_SECONDS, 'checkview_delete_orders_action', array( $order_id ) );
    811846    }
     
    888923    function checkview_is_valid_uuid( $uuid ) {
    889924        if ( empty( $uuid ) || is_wp_error( $uuid ) ) {
     925            Checkview_Admin_Logs::add( 'ip-logs', 'Invalid UUID [' . $uuid . '].' );
     926
    890927            return false;
    891928        }
    892         return preg_match( '/^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/i', $uuid );
     929
     930        $matches = preg_match( '/^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/i', $uuid );
     931
     932        if ( ! $matches ) {
     933            Checkview_Admin_Logs::add( 'ip-logs', 'Invalid UUID [' . $uuid . '].' );
     934
     935            return false;
     936        }
     937
     938        return true;
    893939    }
    894940}
     
    10741120        }
    10751121        return $updated;
    1076     }
    1077 }
    1078 if ( ! defined( 'checkview_options_cleanup' ) ) {
    1079     /**
    1080      * Cleans options for CV.
    1081      *
    1082      * @return void
    1083      */
    1084     function checkview_options_cleanup() {
    1085         $old_settings = array();
    1086         $old_settings = (array) get_option( '_fluentform_reCaptcha_details', array() );
    1087         if ( ! empty( $old_settings ) && null !== $old_settings['siteKey'] && null !== $old_settings['secretKey'] ) {
    1088             if ( '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI' === $old_settings['siteKey'] ) {
    1089                 $old_settings['siteKey']   = get_option( 'checkview_rc-site-key' );
    1090                 $old_settings['secretKey'] = get_option( 'checkview_rc-secret-key' );
    1091                 update_option( '_fluentform_reCaptcha_details', $old_settings );
    1092             }
    1093         }
    1094         $old_settings = array();
    1095         $old_settings = (array) get_option( '_fluentform_turnstile_details', array() );
    1096         if ( ! empty( $old_settings ) && null !== $old_settings['siteKey'] && null !== $old_settings['secretKey'] ) {
    1097             if ( '1x00000000000000000000AA' === $old_settings['siteKey'] ) {
    1098                 $old_settings['siteKey']   = get_option( 'checkview_ff_turnstile-site-key' );
    1099                 $old_settings['secretKey'] = get_option( 'checkview_ff_turnstile-secret-key' );
    1100                 update_option( '_fluentform_turnstile_details', $old_settings );
    1101             }
    1102         }
    1103         delete_option( 'cv_ff_keys_set_turnstile' );
    11041122    }
    11051123}
     
    11251143    }
    11261144}
     1145
     1146if ( ! function_exists( 'cv_update_option' ) ) {
     1147    /**
     1148     * Updates an option in WordPress.
     1149     *
     1150     * Wrapper for update_option() that also includes logging. Suppresses logs from
     1151     * failures due to option already existing with the same value.
     1152     *
     1153     * @see update_option()
     1154     * @see get_option()
     1155     *
     1156     * @param $option string Name of the option to update.
     1157     * @param $value mixed Option value.
     1158     * @param $autoload boolean|null Optional. Whether to load the option when WordPress starts up.
     1159     *
     1160     * @return boolean True if the value was updated, false otherwise.
     1161     */
     1162    function cv_update_option( $option, $value, $autoload = null ) {
     1163        $old_option = get_option( $option );
     1164        $result = update_option( $option, $value, $autoload );
     1165
     1166        if ( $result ) {
     1167            Checkview_Admin_Logs::add( 'ip-logs', 'Updated option [' . $option . '] with value [' . print_r( $value, true ) . '].' );
     1168        } else {
     1169            if ($old_option !== false && $old_option !== $value && maybe_serialize( $old_option ) !== maybe_serialize( $value ) ) {
     1170                Checkview_Admin_Logs::add( 'ip-logs', 'Failed updating option [' . $option . '] with value [' . print_r( $value, true ) . '].' );
     1171            }
     1172        }
     1173
     1174        return $result;
     1175    }
     1176}
     1177
     1178if ( ! function_exists( 'cv_delete_option' ) ) {
     1179    /**
     1180     * Deletes an option in WordPress.
     1181     *
     1182     * Wrapper for delete_option() that also includes logging. Only attempts
     1183     * deletion if the option is found in the database.
     1184     *
     1185     * @see delete_option()
     1186     * @see get_option()
     1187     *
     1188     * @param $option string Name of the option to delete.
     1189     *
     1190     * @return boolean True if the value was deleted, false otherwise.
     1191     */
     1192    function cv_delete_option( $option ) {
     1193        $current_option = get_option( $option );
     1194
     1195        if ( false !== $current_option ) {
     1196            $result = delete_option( $option );
     1197
     1198            if ( $result ) {
     1199                Checkview_Admin_Logs::add( 'ip-logs', 'Deleted option [' . $option . '].' );
     1200            } else {
     1201                Checkview_Admin_Logs::add( 'ip-logs', 'Failed deleting option [' . $option . '].' );
     1202            }
     1203
     1204            return $result;
     1205        }
     1206
     1207        return true;
     1208    }
     1209}
  • checkview/tags/2.0.19/includes/class-checkview.php

    r3303097 r3323842  
    7171            $this->version = CHECKVIEW_VERSION;
    7272        } else {
    73             $this->version = '2.0.18';
     73            $this->version = '2.0.19';
    7474        }
    7575        $this->plugin_name = 'checkview';
     
    202202     */
    203203    private function define_admin_hooks() {
    204 
    205204        $plugin_admin    = new Checkview_Admin( $this->get_plugin_name(), $this->get_version() );
    206205        $plugin_settings = new Checkview_Admin_Settings( $this->get_plugin_name(), $this->get_version() );
    207206        $plugin_logs     = new Checkview_Admin_Logs();
     207
    208208        if ( is_admin() ) {
    209209            // load backend hooks.
  • checkview/tags/2.0.19/includes/formhelpers/class-checkview-cf7-helper.php

    r3216431 r3323842  
    125125         */
    126126        public function checkview_cf7_before_send_mail( $form_tag ) {
    127 
    128127            global $wpdb;
    129128
    130             $form_id              = $form_tag->id();
     129            $form_id = $form_tag->id();
    131130            $wp_filesystem_direct = new WP_Filesystem_Direct( array() );
    132 
    133131            $checkview_test_id = get_checkview_test_id();
    134132
     
    137135            }
    138136
    139             $upload_dir     = wp_upload_dir();
     137            $upload_dir = wp_upload_dir();
    140138            $cv_cf7_dirname = $upload_dir['basedir'] . '/cv_cf7_uploads';
    141139
     
    145143
    146144            $time_now = time();
    147 
    148145            $submission = WPCF7_Submission::get_instance();
     146
    149147            if ( $submission ) {
    150148                $contact_form = $submission->get_contact_form();
    151149            }
     150
    152151            $tags_names = array();
    153152
    154153            if ( $submission ) {
    155 
    156                 $allowed_tags = array();
     154                Checkview_Admin_Logs::add( 'ip-logs', 'Cloning submission entry...' );
    157155
    158156                $tags = $contact_form->scan_form_tags();
     157
    159158                foreach ( $tags as $tag ) {
    160159                    if ( ! empty( $tag->name ) ) {
     
    162161                    }
    163162                }
     163
    164164                $allowed_tags = $tags_names;
    165 
    166165                $not_allowed_tags = array( 'g-recaptcha-response' );
    167 
    168                 $data           = $submission->get_posted_data();
    169                 $files          = $submission->uploaded_files();
     166                $data = $submission->get_posted_data();
     167                $files = $submission->uploaded_files();
    170168                $uploaded_files = array();
    171169
     
    173171                    array_push( $uploaded_files, $file_key );
    174172                }
     173
    175174                foreach ( $files as $file_key => $file ) {
    176175                    $file = is_array( $file ) ? reset( $file ) : $file;
     
    184183
    185184                foreach ( $data as $key => $d ) {
    186 
    187185                    if ( ! in_array( $key, $allowed_tags ) ) {
    188186                        continue;
     
    190188
    191189                    if ( ! in_array( $key, $not_allowed_tags ) && ! in_array( $key, $uploaded_files ) ) {
    192 
    193190                        $tmp_d = $d;
    194191
    195192                        if ( ! is_array( $d ) ) {
    196                             $bl    = array( '\"', "\'", '/', '\\', '"', "'" );
    197                             $wl    = array( '"', ''', '/', '\', '"', ''' );
     193                            $bl = array( '\"', "\'", '/', '\\', '"', "'" );
     194                            $wl = array( '"', ''', '/', '\', '"', ''' );
    198195                            $tmp_d = str_replace( $bl, $wl, $tmp_d );
    199196                        }
     197
    200198                        if ( is_array( $d ) ) {
    201199                            $tmp_d = serialize( $d );
     
    204202                        $form_data[ $key ] = $tmp_d;
    205203                    }
     204
    206205                    if ( in_array( $key, $uploaded_files ) ) {
    207                         $file                              = is_array( $files[ $key ] ) ? reset( $files[ $key ] ) : $files[ $key ];
    208                         $file_name                         = empty( $file ) ? '' : $time_now . '-' . $key . '-' . basename( $file );
     206                        $file = is_array( $files[ $key ] ) ? reset( $files[ $key ] ) : $files[ $key ];
     207                        $file_name = empty( $file ) ? '' : $time_now . '-' . $key . '-' . basename( $file );
    209208                        $form_data[ $key . 'cv_cf7_file' ] = $file_name;
    210209                    }
     
    213212                // insert entry.
    214213                $entry_data  = array(
    215                     'form_id'      => $form_id,
    216                     'status'       => 'publish',
    217                     'source_url'   => isset( $_SERVER['HTTP_REFERER'] ) ? sanitize_url( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '',
     214                    'form_id' => $form_id,
     215                    'status' => 'publish',
     216                    'source_url' => isset( $_SERVER['HTTP_REFERER'] ) ? sanitize_url( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '',
    218217                    'date_created' => current_time( 'mysql' ),
    219218                    'date_updated' => current_time( 'mysql' ),
    220                     'uid'          => $checkview_test_id,
    221                     'form_type'    => 'CF7',
     219                    'uid' => $checkview_test_id,
     220                    'form_type' => 'CF7',
    222221                );
    223222                $entry_table = $wpdb->prefix . 'cv_entry';
    224                 $wpdb->insert( $entry_table, $entry_data );
     223
     224                $result = $wpdb->insert( $entry_table, $entry_data );
     225
     226                if ( ! $result ) {
     227                    Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry data.' );
     228                } else {
     229                    Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry data (inserted ' . (int) $result . ' rows into ' . $entry_table . ').' );
     230                }
     231
    225232                $inserted_entry_id = $wpdb->insert_id;
    226 
    227233                $entry_meta_table = $wpdb->prefix . 'cv_entry_meta';
     234                $count = 0;
    228235
    229236                foreach ( $form_data as $key => $val ) {
    230 
    231237                    $entry_metadata = array(
    232                         'uid'        => $checkview_test_id,
    233                         'form_id'    => $form_id,
    234                         'entry_id'   => $inserted_entry_id,
    235                         'meta_key'   => $key,
     238                        'uid' => $checkview_test_id,
     239                        'form_id' => $form_id,
     240                        'entry_id' => $inserted_entry_id,
     241                        'meta_key' => $key,
    236242                        'meta_value' => $val,
    237243                    );
    238                     $wpdb->insert( $entry_meta_table, $entry_metadata );
     244
     245                    $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     246
     247                    if ( $result ) {
     248                        $count++;
     249                    }
     250                }
     251
     252                if ( $count > 0 ) {
     253                    Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry meta data (inserted ' . $count . ' rows into ' . $entry_meta_table . ').' );
     254                } else {
     255                    if ( count( $form_data ) > 0 ) {
     256                        Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry meta data.' );
     257                    }
    239258                }
    240259
  • checkview/tags/2.0.19/includes/formhelpers/class-checkview-fluent-forms-helper.php

    r3227063 r3323842  
    4747                add_filter(
    4848                    'fluentform/email_to',
    49                     array(
    50                         $this,
    51                         'checkview_remove_receipt',
    52                     ),
     49                    array( $this, 'checkview_remove_receipt' ),
    5350                    99,
    54                     4
     51                    4,
    5552                );
    5653
    5754                add_filter(
    5855                    'fluentform/email_template_header',
    59                     array(
    60                         $this,
    61                         'checkview_remove_email_header',
    62                     ),
     56                    array( $this, 'checkview_remove_email_header' ),
    6357                    99,
    64                     2
     58                    2,
    6559                );
    6660            }
     
    7064                add_filter(
    7165                    'fluentform/email_to',
    72                     array(
    73                         $this,
    74                         'checkview_inject_email',
    75                     ),
     66                    array( $this, 'checkview_inject_email' ),
    7667                    99,
    77                     4
     68                    4,
    7869                );
    7970            }
     
    8172            add_action(
    8273                'fluentform/submission_inserted',
    83                 array(
    84                     $this,
    85                     'checkview_clone_fluentform_entry',
    86                 ),
     74                array( $this, 'checkview_clone_fluentform_entry' ),
    8775                99,
    8876                3
    8977            );
     78
    9079            add_filter(
    9180                'fluentform/has_recaptcha',
    92                 function ( $isSpamCheck ) {
    93                     return false;
    94                 },
     81                '__return_false',
    9582                20,
    96                 1
    9783            );
    9884
    9985            add_filter(
    10086                'fluentform/has_hcaptcha',
    101                 function ( $status ) {
    102                     // Do your stuff here.
    103 
    104                     return false;
    105                 },
    106                 10,
    107                 1
     87                '__return_false',
    10888            );
    10989
    11090            add_filter(
    11191                'fluentform/has_turnstile',
    112                 function ( $status ) {
    113                     // Do your stuff here.
    114 
    115                     return false;
    116                 },
    117                 10,
    118                 1
    119             );
     92                '__return_false',
     93            );
     94
    12095            add_filter(
    12196                'fluentform/akismet_check_spam',
    122                 function ( $isSpamCheck, $form_id, $formData ) {
    123                     return false;
    124                 },
     97                '__return_false',
    12598                20,
    126                 3
    127             );
     99            );
     100
    128101            add_filter(
    129102                'cfturnstile_whitelisted',
    130103                '__return_true',
    131                 999
    132             );
    133 
    134             $old_settings = (array) get_option( '_fluentform_turnstile_details', array() );
    135             if ( ! empty( $old_settings['siteKey'] ) && null !== $old_settings['siteKey'] && null !== $old_settings['secretKey'] ) {
    136                 if ( '1x00000000000000000000AA' !== $old_settings['siteKey'] ) {
    137                     update_option( 'checkview_ff_turnstile-site-key', $old_settings['siteKey'], true );
    138                     update_option( 'checkview_ff_turnstile-secret-key', $old_settings['secretKey'], true );
    139                     $old_settings['siteKey']   = '1x00000000000000000000AA';
    140                     $old_settings['secretKey'] = '1x0000000000000000000000000000000AA';
    141                     update_option( '_fluentform_turnstile_details', $old_settings );
    142                 }
    143             }
    144             $old_settings = array();
    145             $old_settings = (array) get_option( '_fluentform_reCaptcha_details', array() );
    146             if ( null !== $old_settings['siteKey'] && null !== $old_settings['secretKey'] && strpos( $old_settings['api_version'], 'v3' ) === false ) {
    147                 if ( '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI' !== $old_settings['siteKey'] ) {
    148                     update_option( 'checkview_rc-site-key', $old_settings['siteKey'], true );
    149                     update_option( 'checkview_rc-secret-key', $old_settings['secretKey'], true );
    150                     $old_settings['siteKey']   = '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI';
    151                     $old_settings['secretKey'] = '6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe';
    152                     update_option( '_fluentform_reCaptcha_details', $old_settings );
    153                 }
    154             }
    155             update_option( 'cv_ff_keys_set_turnstile', 'true' );
     104                999,
     105            );
     106
    156107            add_filter(
    157108                'fluentform/recaptcha_v3_ref_score',
     
    160111                },
    161112                99,
    162                 1
    163113            );
    164114
     
    173123            );
    174124
    175             // Disbale feeds.
     125            // Disable feeds.
    176126            add_filter(
    177127                'fluentform/global_notification_active_types',
    178                 array(
    179                     $this,
    180                     'checkview_disable_form_actions',
    181                 ),
     128                array( $this, 'checkview_disable_form_actions' ),
    182129                99,
    183                 2
     130                2,
    184131            );
    185132
     
    187134            add_filter(
    188135                'fluentform/honeypot_status',
    189                 function ( $status, $form_id ) {
    190                     return false;
    191                 },
     136                '__return_false',
    192137                999,
    193                 2
     138            );
     139
     140            add_filter(
     141                'fluentform/token_based_spam_protection_status',
     142                '__return_false',
     143                999
     144            );
     145
     146            add_filter(
     147                'fluentform/disable_captcha',
     148                '__return_true',
     149                999
    194150            );
    195151        }
     
    260216            global $wpdb;
    261217
    262             $form_id           = $form->id;
     218            Checkview_Admin_Logs::add( 'ip-logs', 'Cloning submission entry [' . $entry_id . ']...' );
     219
     220            $form_id = $form->id;
    263221            $checkview_test_id = get_checkview_test_id();
    264222
     
    269227            // Clone entry to check view tables.
    270228            $tablename = $wpdb->prefix . 'fluentform_entry_details';
    271             $rows      = $wpdb->get_results( $wpdb->prepare( 'Select * from ' . $tablename . ' where submission_id=%d and form_id=%d order by id ASC', $entry_id, $form_id ) );
     229            $rows = $wpdb->get_results( $wpdb->prepare( 'Select * from ' . $tablename . ' where submission_id=%d and form_id=%d order by id ASC', $entry_id, $form_id ) );
     230            $count = 0;
     231            $entry_meta_table = $wpdb->prefix . 'cv_entry_meta';
     232
    272233            foreach ( $rows as $row ) {
    273234                $meta_key = 'ff_' . $form_id . '_' . $row->field_name;
     235
    274236                if ( '' !== $row->sub_field_name ) {
    275237                    $meta_key .= '_' . $row->sub_field_name . '_';
    276238                }
    277                 $table = $wpdb->prefix . 'cv_entry_meta';
     239
    278240                $data  = array(
    279241                    'uid'        => $checkview_test_id,
     
    283245                    'meta_value' => $row->field_value,
    284246                );
    285                 $wpdb->insert( $table, $data );
    286             }
     247
     248                $result = $wpdb->insert( $entry_meta_table, $data );
     249
     250                if ( $result ) {
     251                    $count++;
     252                }
     253            }
     254
     255            if ( $count > 0 ) {
     256                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry meta data (inserted ' . $count . ' rows into ' . $entry_meta_table . ').' );
     257            } else {
     258                if ( count( $rows ) > 0 ) {
     259                    Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry meta data.' );
     260                }
     261            }
     262
    287263            $tablename = $wpdb->prefix . 'fluentform_submissions';
    288             $row       = $wpdb->get_row( $wpdb->prepare( 'Select * from ' . $tablename . ' where id=%d and form_id=%d LIMIT 1', $entry_id, $form_id ), ARRAY_A );
    289             $table1    = $wpdb->prefix . 'cv_entry';
    290             $data      = array(
    291                 'uid'            => $checkview_test_id,
    292                 'form_type'      => 'FluentForms',
    293                 'form_id'        => $form_id,
    294                 'source_url'     => isset( $row['source_url'] ) ? $row['source_url'] : 'n/a',
    295                 'response'       => isset( $row['response'] ) ? $row['response'] : 'n/a',
    296                 'user_agent'     => isset( $row['browser'] ) ? $row['browser'] : 'n/a',
    297                 'ip'             => isset( $row['ip'] ) ? $row['ip'] : 'n/a',
    298                 'date_created'   => isset( $row['created_at'] ) ? $row['created_at'] : 'n/a',
    299                 'date_updated'   => isset( $row['updated_at'] ) ? $row['updated_at'] : 'n/a',
     264            $row = $wpdb->get_row( $wpdb->prepare( 'Select * from ' . $tablename . ' where id=%d and form_id=%d LIMIT 1', $entry_id, $form_id ), ARRAY_A );
     265            $entry_table = $wpdb->prefix . 'cv_entry';
     266            $data = array(
     267                'uid' => $checkview_test_id,
     268                'form_type' => 'FluentForms',
     269                'form_id' => $form_id,
     270                'source_url' => isset( $row['source_url'] ) ? $row['source_url'] : 'n/a',
     271                'response' => isset( $row['response'] ) ? $row['response'] : 'n/a',
     272                'user_agent' => isset( $row['browser'] ) ? $row['browser'] : 'n/a',
     273                'ip' => isset( $row['ip'] ) ? $row['ip'] : 'n/a',
     274                'date_created' => isset( $row['created_at'] ) ? $row['created_at'] : 'n/a',
     275                'date_updated' => isset( $row['updated_at'] ) ? $row['updated_at'] : 'n/a',
    300276                'payment_status' => isset( $row['payment_status'] ) ? $row['payment_status'] : 'n/a',
    301277                'payment_method' => isset( $row['payment_method'] ) ? $row['payment_payment'] : 'n/a',
    302278                'payment_amount' => isset( $row['payment_total'] ) ? $row['payment_total'] : 0,
    303279            );
    304             $wpdb->insert( $table1, $data );
     280
     281            $result = $wpdb->insert( $entry_table, $data );
     282
     283            if ( ! $result ) {
     284                Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry data.' );
     285            } else {
     286                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry data (inserted ' . (int) $result . ' rows into ' . $entry_table . ').' );
     287            }
    305288
    306289            // remove entry from Fluent forms tables.
  • checkview/tags/2.0.19/includes/formhelpers/class-checkview-formidable-helper.php

    r3247217 r3323842  
    4141        public function __construct() {
    4242            $this->loader = new Checkview_Loader();
     43
    4344            if ( defined( 'TEST_EMAIL' ) ) {
    4445                // update email to our test email.
     
    8384                2
    8485            );
     86
    8587            add_filter(
    8688                'akismet_get_api_key',
     
    8890                -10
    8991            );
     92
    9093            add_filter(
    9194                'frm_fields_to_validate',
     
    97100                2
    98101            );
     102
    99103            add_filter(
    100104                'cfturnstile_whitelisted',
     
    102106                999
    103107            );
     108
    104109            add_filter(
    105110                'frm_run_honeypot',
    106111                '__return_false'
    107112            );
     113
    108114            // Disbale form action.
    109115            add_filter(
     
    169175            global $wpdb;
    170176
     177            Checkview_Admin_Logs::add( 'ip-logs', 'Cloning submission entry [' . $entry_id . ']...' );
     178
    171179            $checkview_test_id = get_checkview_test_id();
    172180
     
    176184
    177185            // Insert entry.
    178             $entry_data  = array(
    179                 'form_id'      => $form_id,
    180                 'status'       => 'publish',
    181                 'source_url'   => isset( $_SERVER['HTTP_REFERER'] ) ? sanitize_url( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '',
     186            $entry_data = array(
     187                'form_id' => $form_id,
     188                'status' => 'publish',
     189                'source_url' => isset( $_SERVER['HTTP_REFERER'] ) ? sanitize_url( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '',
    182190                'date_created' => current_time( 'mysql' ),
    183191                'date_updated' => current_time( 'mysql' ),
    184                 'uid'          => $checkview_test_id,
    185                 'form_type'    => 'Formidable',
     192                'uid' => $checkview_test_id,
     193                'form_type' => 'Formidable',
    186194            );
    187195            $entry_table = $wpdb->prefix . 'cv_entry';
    188             $wpdb->insert( $entry_table, $entry_data );
    189             $inserted_entry_id = $wpdb->insert_id;
     196
     197            $result  = $wpdb->insert( $entry_table, $entry_data );
     198
     199            if ( ! $result ) {
     200                Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry data.' );
     201            } else {
     202                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry data (inserted ' . (int) $result . ' rows into ' . $entry_table . ').' );
     203            }
    190204
    191205            // Insert entry meta.
    192206            $entry_meta_table = $wpdb->prefix . 'cv_entry_meta';
    193             $fields           = $this->get_form_fields( $form_id );
     207            $fields = $this->get_form_fields( $form_id );
     208
    194209            if ( empty( $fields ) ) {
    195210                return;
    196211            }
    197             $tablename   = $wpdb->prefix . 'frm_item_metas';
     212
     213            $tablename = $wpdb->prefix . 'frm_item_metas';
    198214            $form_fields = $wpdb->get_results( $wpdb->prepare( 'Select * from ' . $tablename . ' where item_id=%d', $entry_id ) );
     215            $count = 0;
     216
    199217            foreach ( $form_fields as $field ) {
    200218                if ( empty( $field->field_id ) ) {
    201219                    continue;
    202220                }
     221
    203222                if ( 'name' === $fields[ $field->field_id ]['type'] ) {
    204 
    205223                    $field_values = maybe_unserialize( $field->meta_value );
    206 
    207224                    $name_format = $fields[ $field->field_id ]['name_layout'];
     225
    208226                    switch ( $name_format ) {
    209227                        case 'first_middle_last':
    210228                            // First.
    211229                            $entry_metadata = array(
    212                                 'uid'        => $checkview_test_id,
    213                                 'form_id'    => $form_id,
    214                                 'entry_id'   => $entry_id,
    215                                 'meta_key'   => $fields[ $field->field_id ]['sub_fields'][0]['field_id'],
     230                                'uid' => $checkview_test_id,
     231                                'form_id' => $form_id,
     232                                'entry_id' => $entry_id,
     233                                'meta_key' => $fields[ $field->field_id ]['sub_fields'][0]['field_id'],
    216234                                'meta_value' => $field_values['first'],
    217235                            );
    218                             $wpdb->insert( $entry_meta_table, $entry_metadata );
     236
     237                            $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     238
     239                            if ( $result ) {
     240                                $count++;
     241                            }
    219242
    220243                            // middle.
    221244                            $entry_metadata = array(
    222                                 'uid'        => $checkview_test_id,
    223                                 'form_id'    => $form_id,
    224                                 'entry_id'   => $entry_id,
    225                                 'meta_key'   => $fields[ $field->field_id ]['sub_fields'][1]['field_id'],
     245                                'uid' => $checkview_test_id,
     246                                'form_id' => $form_id,
     247                                'entry_id' => $entry_id,
     248                                'meta_key' => $fields[ $field->field_id ]['sub_fields'][1]['field_id'],
    226249                                'meta_value' => $field_values['middle'],
    227250                            );
    228                             $wpdb->insert( $entry_meta_table, $entry_metadata );
     251
     252                            $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     253
     254                            if ( $result ) {
     255                                $count++;
     256                            }
    229257
    230258                            // last.
    231259                            $entry_metadata = array(
    232                                 'uid'        => $checkview_test_id,
    233                                 'form_id'    => $form_id,
    234                                 'entry_id'   => $entry_id,
    235                                 'meta_key'   => $fields[ $field->field_id ]['sub_fields'][2]['field_id'],
     260                                'uid' => $checkview_test_id,
     261                                'form_id' => $form_id,
     262                                'entry_id' => $entry_id,
     263                                'meta_key' => $fields[ $field->field_id ]['sub_fields'][2]['field_id'],
    236264                                'meta_value' => $field_values['last'],
    237265                            );
    238                             $wpdb->insert( $entry_meta_table, $entry_metadata );
     266
     267                            $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     268
     269                            if ( $result ) {
     270                                $count++;
     271                            }
    239272
    240273                            break;
     
    242275                            // First.
    243276                            $entry_metadata = array(
    244                                 'uid'        => $checkview_test_id,
    245                                 'form_id'    => $form_id,
    246                                 'entry_id'   => $entry_id,
    247                                 'meta_key'   => $fields[ $field->field_id ]['sub_fields'][0]['field_id'],
     277                                'uid' => $checkview_test_id,
     278                                'form_id' => $form_id,
     279                                'entry_id' => $entry_id,
     280                                'meta_key' => $fields[ $field->field_id ]['sub_fields'][0]['field_id'],
    248281                                'meta_value' => $field_values['first'],
    249282                            );
    250                             $wpdb->insert( $entry_meta_table, $entry_metadata );
     283
     284                            $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     285
     286                            if ( $result ) {
     287                                $count++;
     288                            }
     289
    251290                            // last.
    252291                            $entry_metadata = array(
    253                                 'uid'        => $checkview_test_id,
    254                                 'form_id'    => $form_id,
    255                                 'entry_id'   => $entry_id,
    256                                 'meta_key'   => $fields[ $field->field_id ]['sub_fields'][1]['field_id'],
     292                                'uid' => $checkview_test_id,
     293                                'form_id' => $form_id,
     294                                'entry_id' => $entry_id,
     295                                'meta_key' => $fields[ $field->field_id ]['sub_fields'][1]['field_id'],
    257296                                'meta_value' => $field_values['last'],
    258297                            );
    259                             $wpdb->insert( $entry_meta_table, $entry_metadata );
     298
     299                            $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     300
     301                            if ( $result ) {
     302                                $count++;
     303                            }
     304
    260305                            break;
    261306                        case 'last_first':
    262307                            // First.
    263308                            $entry_metadata = array(
    264                                 'uid'        => $checkview_test_id,
    265                                 'form_id'    => $form_id,
    266                                 'entry_id'   => $entry_id,
    267                                 'meta_key'   => $fields[ $field->field_id ]['sub_fields'][1]['field_id'],
     309                                'uid' => $checkview_test_id,
     310                                'form_id' => $form_id,
     311                                'entry_id' => $entry_id,
     312                                'meta_key' => $fields[ $field->field_id ]['sub_fields'][1]['field_id'],
    268313                                'meta_value' => $field_values['first'],
    269314                            );
    270                             $wpdb->insert( $entry_meta_table, $entry_metadata );
     315
     316                            $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     317
     318                            if ( $result ) {
     319                                $count++;
     320                            }
     321
    271322                            // last.
    272323                            $entry_metadata = array(
    273                                 'uid'        => $checkview_test_id,
    274                                 'form_id'    => $form_id,
    275                                 'entry_id'   => $entry_id,
    276                                 'meta_key'   => $fields[ $field->field_id ]['sub_fields'][0]['field_id'],
     324                                'uid' => $checkview_test_id,
     325                                'form_id' => $form_id,
     326                                'entry_id' => $entry_id,
     327                                'meta_key' => $fields[ $field->field_id ]['sub_fields'][0]['field_id'],
    277328                                'meta_value' => $field_values['last'],
    278329                            );
    279                             $wpdb->insert( $entry_meta_table, $entry_metadata );
    280                             break;
    281 
     330
     331                            $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     332
     333                            if ( $result ) {
     334                                $count++;
     335                            }
     336
     337                            break;
    282338                    }
    283339                } else {
    284                     $field_value    = $field->meta_value;
     340                    $field_value = $field->meta_value;
    285341                    $entry_metadata = array(
    286                         'uid'        => $checkview_test_id,
    287                         'form_id'    => $form_id,
    288                         'entry_id'   => $entry_id,
    289                         'meta_key'   => $fields[ $field->field_id ]['field_id'],
     342                        'uid' => $checkview_test_id,
     343                        'form_id' => $form_id,
     344                        'entry_id' => $entry_id,
     345                        'meta_key' => $fields[ $field->field_id ]['field_id'],
    290346                        'meta_value' => $field_value,
    291347                    );
    292                     $wpdb->insert( $entry_meta_table, $entry_metadata );
     348
     349                    $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     350
     351                    if ( $result ) {
     352                        $count++;
     353                    }
     354                }
     355            }
     356
     357            if ( $count > 0 ) {
     358                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry meta data (inserted ' . $count . ' rows into ' . $entry_meta_table . ').' );
     359            } else {
     360                if ( count( $form_fields ) > 0 ) {
     361                    Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry meta data.' );
    293362                }
    294363            }
     
    296365            // Remove test entry form Formidable.
    297366            $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE item_id=%d', $entry_id ) );
    298             $result = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_items WHERE id=%d', $entry_id ) );
     367            $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_items WHERE id=%d', $entry_id ) );
    299368
    300369            complete_checkview_test( $checkview_test_id );
  • checkview/tags/2.0.19/includes/formhelpers/class-checkview-forminator-helper.php

    r3216431 r3323842  
    4141        public function __construct() {
    4242            $this->loader = new Checkview_Loader();
     43
    4344            if ( defined( 'TEST_EMAIL' ) ) {
    4445                // update email to our test email.
     
    9192                999
    9293            );
     94
    9395            add_filter(
    9496                'forminator_invalid_captcha_message',
    9597                '__return_null'
    9698            );
     99
    97100            // Disbale form action.
    98101            add_filter(
     
    151154         * @param object $entry entry object.
    152155         * @param int    $form_id Form entry ID.
    153          * @param int    $form_fields Form's fields.
     156         * @param array  $form_fields Form's fields.
    154157         * @return void
    155158         */
    156         public function checkview_log_form_test_entry(
    157             $entry,
    158             $form_id,
    159             $form_fields
    160         ) {
     159        public function checkview_log_form_test_entry($entry, $form_id, $form_fields) {
    161160            global $wpdb;
    162161
    163162            $checkview_test_id = get_checkview_test_id();
    164             $entry_id          = $entry->entry_id;
    165             $form_id           = $entry->form_id;
     163            $entry_id = $entry->entry_id;
     164            $form_id = $entry->form_id;
     165
     166            Checkview_Admin_Logs::add( 'ip-logs', 'Cloning submission entry [' . $entry_id . ']...' );
     167
    166168            if ( empty( $checkview_test_id ) ) {
    167169                $checkview_test_id = $form_id . gmdate( 'Ymd' );
     
    180182
    181183            $entry_table = $wpdb->prefix . 'cv_entry';
    182             $wpdb->insert( $entry_table, $entry_data );
    183             $inserted_entry_id = $wpdb->insert_id;
    184 
    185             // Insert entry meta.
     184            $result = $wpdb->insert( $entry_table, $entry_data );
     185
     186            if ( ! $result ) {
     187                Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry data.' );
     188            } else {
     189                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry data (inserted ' . (int) $result . ' rows into ' . $entry_table . ').' );
     190            }
     191
    186192            $entry_meta_table = $wpdb->prefix . 'cv_entry_meta';
     193            $count = 0;
    187194
    188195            foreach ( $form_fields as $field ) {
     
    190197                    continue;
    191198                }
     199
    192200                $field_value    = $field['value'];
    193201                $meta_key       = $field['name'];
     
    199207                    'meta_value' => $field_value,
    200208                );
    201                 $wpdb->insert( $entry_meta_table, $entry_metadata );
    202             }
    203 
    204             // Remove test entry form Forminator.
     209
     210                $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     211
     212                if ( $result ) {
     213                    $count++;
     214                }
     215            }
     216
     217            if ( $count > 0 ) {
     218                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry meta data (inserted ' . $count . ' rows into ' . $entry_meta_table . ').' );
     219            } else {
     220                if ( count( $form_fields ) > 0 ) {
     221                    Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry meta data.' );
     222                }
     223            }
    205224
    206225            complete_checkview_test( $checkview_test_id );
     226
    207227            // Delete entry.
    208228            Forminator_Form_Entry_Model::delete_by_entry( $entry_id );
  • checkview/tags/2.0.19/includes/formhelpers/class-checkview-gforms-helper.php

    r3216431 r3323842  
    168168            foreach ( $form['fields'] as $key => $field ) {
    169169                if ( 'captcha' === $field->type || 'hcaptcha' === $field->type || 'turnstile' === $field->type ) {
     170                    Checkview_Admin_Logs::add( 'ip-logs', 'Unset captcha field type [' . $field->type . '].' );
     171
    170172                    unset( $fields[ $key ] );
    171173                }
     
    173175
    174176            $form['fields'] = $fields;
     177
    175178            return $form;
    176179        }
     
    186189         */
    187190        public function checkview_clone_entry( $entry, $form ) {
    188             $form_id           = rgar( $form, 'id' );
     191            $form_id = rgar( $form, 'id' );
    189192            $checkview_test_id = get_checkview_test_id();
    190193
     
    192195                $checkview_test_id = $form_id . gmdate( 'Ymd' );
    193196            }
     197
    194198            self::checkview_clone_gf_entry( $entry['id'], $form_id, $checkview_test_id );
     199
    195200            if ( isset( $entry['id'] ) ) {
    196201                GFAPI::delete_entry( $entry['id'] );
     
    285290            global $wpdb;
    286291
     292            Checkview_Admin_Logs::add( 'ip-logs', 'Cloning submission entry [' . $entry_id . '] with unique ID [' . $uid . ']...' );
     293
    287294            $tablename = $wpdb->prefix . 'gf_entry_meta';
    288             $rows      = $wpdb->get_results( $wpdb->prepare( 'Select * from ' . $tablename . ' where entry_id=%d and form_id=%d order by id ASC', $entry_id, $form_id ) );
     295            $rows = $wpdb->get_results( $wpdb->prepare( 'Select * from ' . $tablename . ' where entry_id=%d and form_id=%d order by id ASC', $entry_id, $form_id ) );
     296            $entry_meta_table = $wpdb->prefix . 'cv_entry_meta';
     297            $count = 0;
     298
    289299            foreach ( $rows as $row ) {
    290                 $table = $wpdb->prefix . 'cv_entry_meta';
    291300                $data  = array(
    292                     'uid'        => $uid,
    293                     'form_id'    => $row->form_id,
    294                     'entry_id'   => $row->entry_id,
    295                     'meta_key'   => $row->meta_key,
     301                    'uid' => $uid,
     302                    'form_id' => $row->form_id,
     303                    'entry_id' => $row->entry_id,
     304                    'meta_key' => $row->meta_key,
    296305                    'meta_value' => $row->meta_value,
    297306                );
    298                 $wpdb->insert( $table, $data );
    299             }
     307
     308                $result = $wpdb->insert( $entry_meta_table, $data );
     309
     310                if ( $result ) {
     311                    $count++;
     312                }
     313            }
     314
     315            if ( $count > 0 ) {
     316                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry meta data (inserted ' . $count . ' rows into ' . $entry_meta_table . ').' );
     317            } else {
     318                if ( count( $rows ) > 0 ) {
     319                    Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry meta data.' );
     320                }
     321            }
     322
    300323            $tablename = $wpdb->prefix . 'gf_entry';
    301             $row       = $wpdb->get_row( $wpdb->prepare( 'Select * from ' . $tablename . ' where id=%d and form_id=%d LIMIT 1', $entry_id, $form_id ), ARRAY_A );
     324            $row = $wpdb->get_row( $wpdb->prepare( 'Select * from ' . $tablename . ' where id=%d and form_id=%d LIMIT 1', $entry_id, $form_id ), ARRAY_A );
     325
    302326            unset( $row['id'] );
    303327            unset( $row['source_id'] );
    304             $table1           = $wpdb->prefix . 'cv_entry';
    305             $row['uid']       = $uid;
     328
     329            $entry_table = $wpdb->prefix . 'cv_entry';
     330            $row['uid'] = $uid;
    306331            $row['form_type'] = 'GravityForms';
    307             $wpdb->insert( $table1, $row );
     332            $result = $wpdb->insert( $entry_table, $row );
     333
     334            if ( ! $result ) {
     335                Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry data.' );
     336            } else {
     337                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry data (inserted ' . (int) $result . ' rows into ' . $entry_table . ').' );
     338            }
    308339        }
    309340
  • checkview/tags/2.0.19/includes/formhelpers/class-checkview-ninja-forms-helper.php

    r3216431 r3323842  
    4242        public function __construct() {
    4343            $this->loader = new Checkview_Loader();
     44
    4445            add_action(
    4546                'ninja_forms_after_submission',
     
    5152                1
    5253            );
     54
    5355            add_filter(
    5456                'akismet_get_api_key',
     
    6567                20
    6668            );
     69
    6770            add_filter(
    6871                'ninja_forms_validate_fields',
     
    7982                999
    8083            );
     84
    8185            add_filter(
    8286                'ninja_forms_action_recaptcha__verify_response',
     
    8488                99
    8589            );
     90
    8691            if ( defined( 'TEST_EMAIL' ) ) {
    8792                add_filter(
     
    154159            $entry_id = isset( $form_data['actions']['save']['sub_id'] ) ? $form_data['actions']['save']['sub_id'] : 0;
    155160
     161            Checkview_Admin_Logs::add( 'ip-logs', 'Cloning submission entry [' . $entry_id . ']...' );
     162
    156163            $checkview_test_id = get_checkview_test_id();
    157164
     
    162169            // Insert Entry.
    163170            $entry_data  = array(
    164                 'form_id'      => $form_id,
    165                 'status'       => 'publish',
    166                 'source_url'   => isset( $_SERVER['HTTP_REFERER'] ) ? sanitize_url( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '',
     171                'form_id' => $form_id,
     172                'status' => 'publish',
     173                'source_url' => isset( $_SERVER['HTTP_REFERER'] ) ? sanitize_url( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '',
    167174                'date_created' => current_time( 'mysql' ),
    168175                'date_updated' => current_time( 'mysql' ),
    169                 'uid'          => $checkview_test_id,
    170                 'form_type'    => 'NinjaForms',
     176                'uid' => $checkview_test_id,
     177                'form_type' => 'NinjaForms',
    171178            );
    172179            $entry_table = $wpdb->prefix . 'cv_entry';
    173             $wpdb->insert( $entry_table, $entry_data );
    174             $inserted_entry_id = $wpdb->insert_id;
    175 
    176             // Insert entry meta.
     180
     181            $result = $wpdb->insert( $entry_table, $entry_data );
     182
     183            if ( ! $result ) {
     184                Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry data.' );
     185            } else {
     186                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry data (inserted ' . (int) $result . ' rows into ' . $entry_table . ').' );
     187            }
     188
    177189            $entry_meta_table = $wpdb->prefix . 'cv_entry_meta';
    178190            $field_id_prefix  = 'nf';
    179             $tablename        = $wpdb->prefix . 'postmeta';
    180             $form_fields      = $wpdb->get_results( $wpdb->prepare( 'Select * from ' . $tablename . ' where post_id=%d', $entry_id ) );
     191            $tablename = $wpdb->prefix . 'postmeta';
     192            $form_fields = $wpdb->get_results( $wpdb->prepare( 'Select * from ' . $tablename . ' where post_id=%d', $entry_id ) );
     193            $count = 0;
     194
    181195            foreach ( $form_fields as $field ) {
    182196                if ( ! in_array( $field->meta_key, array( '_form_id', '_seq_num' ) ) ) {
     
    188202                        'meta_value' => $field->meta_value,
    189203                    );
    190                     $wpdb->insert( $entry_meta_table, $entry_metadata );
     204
     205                    $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     206
     207                    if ( $result ) {
     208                        $count++;
     209                    }
     210                }
     211            }
     212
     213            if ( $count > 0 ) {
     214                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry meta data (inserted ' . $count . ' rows into ' . $entry_meta_table . ').' );
     215            } else {
     216                if ( count( $form_fields ) > 0 ) {
     217                    Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry meta data.' );
    191218                }
    192219            }
  • checkview/tags/2.0.19/includes/formhelpers/class-checkview-wpforms-helper.php

    r3247217 r3323842  
    4242        public function __construct() {
    4343            $this->loader = new Checkview_Loader();
     44
    4445            if ( ! is_admin() ) {
    4546                include_once ABSPATH . 'wp-admin/includes/plugin.php';
    4647            }
    4748
    48             $old_settings = (array) get_option( 'wpforms_settings', array() );
    49             if ( ! empty( $old_settings['turnstile-site-key'] ) && null !== $old_settings['turnstile-site-key'] && null !== $old_settings['turnstile-secret-key'] ) {
    50                 if ( '1x00000000000000000000AA' !== $old_settings['turnstile-site-key'] ) {
    51                     update_option( 'checkview_wpforms_turnstile-site-key', $old_settings['turnstile-site-key'], true );
    52                     update_option( 'checkview_wpforms_turnstile-secret-key', $old_settings['turnstile-secret-key'], true );
    53                     $old_settings['turnstile-site-key']   = '1x00000000000000000000AA';
    54                     $old_settings['turnstile-secret-key'] = '1x0000000000000000000000000000000AA';
    55                     update_option( 'wpforms_settings', $old_settings );
    56                 }
    57             } else {
    58                 // Disable reCAPTCHA assets and initialisation on the frontend.
    59                 add_filter(
    60                     'wpforms_frontend_recaptcha_disable',
    61                     '__return_true',
    62                     99
    63                 );
    64             }
     49            add_filter( 'wpforms_frontend_form_data', array( $this, 'checkview_disable_turnstile' ) );
     50
     51            add_filter( 'wpforms_process_before_form_data', array( $this, 'checkview_disable_turnstile' ) );
     52
     53            add_filter( 'wpforms_frontend_captcha_api', array( $this, 'checkview_disable_frontend_captcha_api' ) );
     54
     55            add_filter( 'wpforms_frontend_recaptcha_disable', '__return_true', 99 );
    6556
    6657            // Disable validation and verification on the backend.
     
    150141
    151142        /**
     143         * Disable Cloudflare Turnstile.
     144         *
     145         * @param array $form_data Form data.
     146         *
     147         * @return array Modified form data.
     148         *
     149         * @since 2.0.19
     150         */
     151        public function checkview_disable_turnstile( $form_data ) {
     152            $form_data['settings']['recaptcha'] = '0';
     153
     154            return $form_data;
     155        }
     156
     157        /**
     158         * Disable WP Forms frontend CAPTCHA API.
     159         *
     160         * @param $captcha_api string CAPTCHA API.
     161         *
     162         * @return string
     163         *
     164         * @since 2.0.19
     165         */
     166        public function checkview_disable_frontend_captcha_api( $captcha_api ) {
     167            $captcha_settings = wpforms_get_captcha_settings();
     168
     169            if ( $captcha_settings['provider'] === 'turnstile' ) {
     170                return '';
     171            }
     172
     173            return $captcha_api;
     174        }
     175
     176        /**
    152177         * Injects testing email address.
    153178         *
     
    182207        public function checkview_log_wpform_test_entry( $form_fields, $entry, $form_data, $entry_id ) {
    183208            global $wpdb;
     209
     210            Checkview_Admin_Logs::add( 'ip-logs', 'Cloning submission entry [' . $entry_id . ']...' );
     211
    184212            if ( ! function_exists( 'is_plugin_active' ) ) {
    185213                include_once ABSPATH . 'wp-admin/includes/plugin.php';
    186214            }
    187215
    188             $form_id           = $form_data['id'];
     216            $form_id = $form_data['id'];
    189217            $checkview_test_id = get_checkview_test_id();
    190218
     
    194222
    195223            $entry_data  = array(
    196                 'form_id'      => $form_id,
    197                 'status'       => 'publish',
    198                 'source_url'   => isset( $_SERVER['HTTP_REFERER'] ) ? sanitize_url( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '',
     224                'form_id' => $form_id,
     225                'status' => 'publish',
     226                'source_url' => isset( $_SERVER['HTTP_REFERER'] ) ? sanitize_url( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '',
    199227                'date_created' => current_time( 'mysql' ),
    200228                'date_updated' => current_time( 'mysql' ),
    201                 'uid'          => $checkview_test_id,
    202                 'form_type'    => 'WpForms',
     229                'uid' => $checkview_test_id,
     230                'form_type' => 'WpForms',
    203231            );
    204232            $entry_table = $wpdb->prefix . 'cv_entry';
    205             $wpdb->insert( $entry_table, $entry_data );
     233
     234            $result = $wpdb->insert( $entry_table, $entry_data );
     235
     236            if ( ! $result ) {
     237                Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry data.' );
     238            } else {
     239                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry data (inserted ' . (int) $result . ' rows into ' . $entry_table . ').' );
     240            }
     241
    206242            $inserted_entry_id = $wpdb->insert_id;
    207243            $entry_meta_table  = $wpdb->prefix . 'cv_entry_meta';
    208244            $field_id_prefix   = 'wpforms-' . $form_id . '-field_';
     245            $count = 0;
     246
    209247            foreach ( $form_fields as $field ) {
    210 
    211248                if ( ! isset( $field['value'] ) || '' === $field['value'] ) {
    212249                    continue;
    213250                }
     251
    214252                $field_value = is_array( $field['value'] ) ? serialize( $field['value'] ) : $field['value'];
    215                 $type        = isset( $field['type'] ) ? $field['type'] : '';
     253                $type = isset( $field['type'] ) ? $field['type'] : '';
     254
    216255                switch ( $type ) {
    217256                    case 'name':
     
    224263                                'meta_value' => $field['first'],
    225264                            );
    226                             $wpdb->insert( $entry_meta_table, $entry_metadata );
    227 
     265
     266                            $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     267
     268                            if ( $result ) {
     269                                $count++;
     270                            }
    228271                        } elseif ( '' === $field['middle'] ) {
    229272                            $entry_metadata = array(
     
    234277                                'meta_value' => $field['first'],
    235278                            );
    236                             $wpdb->insert( $entry_meta_table, $entry_metadata );
    237                             $entry_metadata = array(
    238                                 'uid'        => $checkview_test_id,
    239                                 'form_id'    => $form_id,
    240                                 'entry_id'   => $inserted_entry_id,
    241                                 'meta_key'   => $field_id_prefix . $field['id'] . '-last',
     279
     280                            $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     281
     282                            if ( $result ) {
     283                                $count++;
     284                            }
     285
     286                            $entry_metadata = array(
     287                                'uid' => $checkview_test_id,
     288                                'form_id' => $form_id,
     289                                'entry_id' => $inserted_entry_id,
     290                                'meta_key' => $field_id_prefix . $field['id'] . '-last',
    242291                                'meta_value' => $field['last'],
    243292                            );
    244                             $wpdb->insert( $entry_meta_table, $entry_metadata );
    245 
     293
     294                            $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     295
     296                            if ( $result ) {
     297                                $count++;
     298                            }
    246299                        } else {
    247300                            $entry_metadata = array(
    248                                 'uid'        => $checkview_test_id,
    249                                 'form_id'    => $form_id,
    250                                 'entry_id'   => $inserted_entry_id,
    251                                 'meta_key'   => $field_id_prefix . $field['id'],
     301                                'uid' => $checkview_test_id,
     302                                'form_id' => $form_id,
     303                                'entry_id' => $inserted_entry_id,
     304                                'meta_key' => $field_id_prefix . $field['id'],
    252305                                'meta_value' => $field['first'],
    253306                            );
    254                             $wpdb->insert( $entry_meta_table, $entry_metadata );
    255                             $entry_metadata = array(
    256                                 'uid'        => $checkview_test_id,
    257                                 'form_id'    => $form_id,
    258                                 'entry_id'   => $inserted_entry_id,
    259                                 'meta_key'   => $field_id_prefix . $field['id'] . '-middle',
     307
     308                            $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     309
     310                            if ( $result ) {
     311                                $count++;
     312                            }
     313
     314                            $entry_metadata = array(
     315                                'uid' => $checkview_test_id,
     316                                'form_id' => $form_id,
     317                                'entry_id' => $inserted_entry_id,
     318                                'meta_key' => $field_id_prefix . $field['id'] . '-middle',
    260319                                'meta_value' => $field['middle'],
    261320                            );
    262                             $wpdb->insert( $entry_meta_table, $entry_metadata );
    263                             $entry_metadata = array(
    264                                 'uid'        => $checkview_test_id,
    265                                 'form_id'    => $form_id,
    266                                 'entry_id'   => $inserted_entry_id,
    267                                 'meta_key'   => $field_id_prefix . $field['id'] . '-last',
     321
     322                            $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     323
     324                            if ( $result ) {
     325                                $count++;
     326                            }
     327
     328                            $entry_metadata = array(
     329                                'uid' => $checkview_test_id,
     330                                'form_id' => $form_id,
     331                                'entry_id' => $inserted_entry_id,
     332                                'meta_key' => $field_id_prefix . $field['id'] . '-last',
    268333                                'meta_value' => $field['last'],
    269334                            );
    270                             $wpdb->insert( $entry_meta_table, $entry_metadata );
    271 
     335
     336                            $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     337
     338                            if ( $result ) {
     339                                $count++;
     340                            }
    272341                        }
    273342                        break;
    274343                    default:
    275344                        $entry_metadata = array(
    276                             'uid'        => $checkview_test_id,
    277                             'form_id'    => $form_id,
    278                             'entry_id'   => $inserted_entry_id,
    279                             'meta_key'   => $field_id_prefix . $field['id'],
     345                            'uid' => $checkview_test_id,
     346                            'form_id' => $form_id,
     347                            'entry_id' => $inserted_entry_id,
     348                            'meta_key' => $field_id_prefix . $field['id'],
    280349                            'meta_value' => $field_value,
    281350                        );
    282                         $wpdb->insert( $entry_meta_table, $entry_metadata );
     351
     352                        $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     353
     354                        if ( $result ) {
     355                            $count++;
     356                        }
     357
    283358                        break;
     359                }
     360            }
     361
     362            if ( $count > 0 ) {
     363                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry meta data (inserted ' . $count . ' rows into ' . $entry_meta_table . ').' );
     364            } else {
     365                if ( count( $form_fields ) > 0 ) {
     366                    Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry meta data.' );
    284367                }
    285368            }
     
    295378                    )
    296379                );
     380
    297381                $wpdb->delete(
    298382                    $wpdb->prefix . 'wpforms_entry_fields',
     
    303387                );
    304388            }
    305             $old_settings = (array) get_option( 'wpforms_settings', array() );
    306             if ( ! empty( $old_settings['turnstile-site-key'] ) && null !== $old_settings['turnstile-site-key'] && null !== $old_settings['turnstile-secret-key'] ) {
    307                 if ( '1x00000000000000000000AA' === $old_settings['turnstile-site-key'] ) {
    308                     $old_settings['turnstile-site-key']   = get_option( 'checkview_wpforms_turnstile-site-key' );
    309                     $old_settings['turnstile-secret-key'] = get_option( 'checkview_wpforms_turnstile-secret-key' );
    310                     update_option( 'wpforms_settings', $old_settings );
    311                 }
    312             }
    313389
    314390            complete_checkview_test( $checkview_test_id );
  • checkview/tags/2.0.19/includes/formhelpers/class-checkview-wsf-helper.php

    r3216431 r3323842  
    4242        public function __construct() {
    4343            $this->loader = new Checkview_Loader();
     44
    4445            add_action(
    4546                'wsf_submit_post_complete',
     
    5152                1
    5253            );
     54
    5355            add_filter(
    5456                'akismet_get_api_key',
     
    6264                999
    6365            );
     66
    6467            if ( defined( 'TEST_EMAIL' ) ) {
    6568                add_filter(
     
    8386                2
    8487            );
     88
    8589            add_filter(
    8690                'wsf_config_meta_keys',
     
    96100                6
    97101            );
     102
    98103            add_filter(
    99104                'wsf_action_email_headers',
     
    157162                $headers = explode( "\r\n", $headers );
    158163            }
     164
    159165            $filtered_headers = array_filter(
    160166                $headers,
     
    164170                }
    165171            );
     172
    166173            return array_values( $filtered_headers );
    167174        }
     
    179186            $form_id  = $form_data->form_id;
    180187            $entry_id = $form_data->id;
    181 
    182188            $checkview_test_id = get_checkview_test_id();
     189
     190            Checkview_Admin_Logs::add( 'ip-logs', 'Cloning submission entry [' . $entry_id . ']...' );
    183191
    184192            if ( empty( $checkview_test_id ) ) {
    185193                $checkview_test_id = $form_id . gmdate( 'Ymd' );
    186194            }
     195
    187196            // Insert Entry.
    188197            $entry_data  = array(
    189                 'form_id'      => $form_id,
    190                 'status'       => 'publish',
    191                 'source_url'   => isset( $_SERVER['HTTP_REFERER'] ) ? sanitize_url( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '',
     198                'form_id' => $form_id,
     199                'status' => 'publish',
     200                'source_url' => isset( $_SERVER['HTTP_REFERER'] ) ? sanitize_url( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '',
    192201                'date_created' => current_time( 'mysql' ),
    193202                'date_updated' => current_time( 'mysql' ),
    194                 'uid'          => $checkview_test_id,
    195                 'form_type'    => 'WSForms',
     203                'uid' => $checkview_test_id,
     204                'form_type' => 'WSForms',
    196205            );
    197206            $entry_table = $wpdb->prefix . 'cv_entry';
    198             $wpdb->insert( $entry_table, $entry_data );
    199             $inserted_entry_id = $wpdb->insert_id;
    200 
    201             // Insert entry meta.
     207
     208            $result = $wpdb->insert( $entry_table, $entry_data );
     209
     210            if ( ! $result ) {
     211                Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry data.' );
     212            } else {
     213                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry data (inserted ' . (int) $result . ' rows into ' . $entry_table . ').' );
     214            }
     215
    202216            $entry_meta_table = $wpdb->prefix . 'cv_entry_meta';
    203217            $field_id_prefix  = 'wsf';
    204             $tablename        = $wpdb->prefix . 'wsf_submit_meta';
    205             $form_fields      = $wpdb->get_results( $wpdb->prepare( 'Select * from ' . $tablename . ' where parent_id=%d', $entry_id ) );
     218            $tablename = $wpdb->prefix . 'wsf_submit_meta';
     219            $form_fields = $wpdb->get_results( $wpdb->prepare( 'Select * from ' . $tablename . ' where parent_id=%d', $entry_id ) );
     220            $count = 0;
     221
    206222            foreach ( $form_fields as $field ) {
    207223                if ( ! in_array( $field->meta_key, array( '_form_id', 'post_id', 'wsf_meta_key_hidden' ) ) ) {
    208224                    $entry_metadata = array(
    209                         'uid'        => $checkview_test_id,
    210                         'form_id'    => $form_id,
    211                         'entry_id'   => $entry_id,
    212                         'meta_key'   => $field_id_prefix . str_replace( '_', '-', $field->meta_key ),
     225                        'uid' => $checkview_test_id,
     226                        'form_id' => $form_id,
     227                        'entry_id' => $entry_id,
     228                        'meta_key' => $field_id_prefix . str_replace( '_', '-', $field->meta_key ),
    213229                        'meta_value' => $field->meta_value,
    214230                    );
    215                     $wpdb->insert( $entry_meta_table, $entry_metadata );
    216                 }
    217             }
    218             update_option( $checkview_test_id . '_wsf_entry_id', $entry_id );
    219             update_option( $checkview_test_id . '_wsf_frm_id', $form_id );
     231
     232                    $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     233
     234                    if ( $result ) {
     235                        $count++;
     236                    }
     237                }
     238            }
     239
     240            if ( $count > 0 ) {
     241                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry meta data (inserted ' . $count . ' rows into ' . $entry_meta_table . ').' );
     242            } else {
     243                if ( count( $form_fields ) > 0 ) {
     244                    Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry meta data.' );
     245                }
     246            }
     247
     248            cv_update_option( $checkview_test_id . '_wsf_entry_id', $entry_id );
     249            cv_update_option( $checkview_test_id . '_wsf_frm_id', $form_id );
     250
    220251            complete_checkview_test( $checkview_test_id );
    221252        }
  • checkview/tags/2.0.19/includes/woocommercehelper/class-checkview-woo-automated-testing.php

    r3303097 r3323842  
    564564     */
    565565    public function checkview_test_mode() {
    566 
    567         // Current Vsitor IP.
    568566        $visitor_ip = checkview_get_visitor_ip();
    569         // Check view Bot IP.
    570567        $cv_bot_ip = checkview_get_api_ip();
     568
    571569        if ( ! is_array( $cv_bot_ip ) || ! in_array( $visitor_ip, $cv_bot_ip ) ) {
    572 
    573570            return;
    574571        }
    575         Checkview_Admin_Logs::add( 'ip-logs', wp_json_encode( $cv_bot_ip ) . 'bot IP' );
    576         Checkview_Admin_Logs::add( 'ip-logs', wp_json_encode( $visitor_ip ) . 'visitor IP' );
     572
     573        Checkview_Admin_Logs::add( 'ip-logs', 'Running Woo test mode hooks, visitor IP [' . $visitor_ip . '] matched a bot IP.' );
     574
    577575        if ( ! is_admin() && class_exists( 'WooCommerce' ) ) {
    578576            // Always use Stripe test mode when on dev or staging.
     
    580578                'option_woocommerce_stripe_settings',
    581579                function ( $value ) {
     580                    Checkview_Admin_Logs::add( 'ip-logs', 'Setting Woo test mode to true for hook [option_woocommerce_stripe_settings].' );
    582581
    583582                    $value['testmode'] = 'yes';
     
    586585                }
    587586            );
     587
    588588            // Turn test mode on for stripe payments.
    589589            add_filter(
    590590                'wc_stripe_mode',
    591591                function ( $mode ) {
     592                    Checkview_Admin_Logs::add( 'ip-logs', 'Setting Woo test mode to true for hook [wc_stripe_mode].' );
    592593
    593594                    $mode = 'test';
     
    615616                'checkview_woocommerce_block_support',
    616617            );
     618
    617619            add_filter(
    618620                'cfturnstile_whitelisted',
     
    620622                999
    621623            );
     624
    622625            // Make the test product visible in the catalog.
    623626            add_filter(
    624627                'woocommerce_product_is_visible',
    625                 function ( $visible, $product_id ) {
     628                function ( bool $visible, $product_id ) {
    626629                    $product = $this->checkview_get_test_product();
    627630
     
    630633                    }
    631634
    632                     return $product_id === $product->get_id() ? true : $visible;
     635                    $is_visible = $product_id === $product->get_id() ? true : $visible;
     636
     637                    if ($is_visible) {
     638                        Checkview_Admin_Logs::add( 'ip-logs', 'Setting Woo test product visibility to true.' );
     639
     640                        return true;
     641                    }
     642
     643                    return false;
    633644                },
    634645                9999,
    635646                2
    636647            );
     648
    637649            $this->loader->add_action(
    638650                'woocommerce_order_status_changed',
     
    642654                3
    643655            );
    644         }
    645     }
     656        } else {
     657            Checkview_Admin_Logs::add( 'ip-logs', 'No Woo hooks were ran (WooCommerce was not found or client is requesting admin area).' );
     658        }
     659    }
     660
    646661    /**
    647662     * Returns false.
     
    729744     * Adds CheckView dummy payment gateway to Woo.
    730745     *
    731      * @param string $methods Methods to add payments.
    732      * @return array
     746     * @param string[] $methods Methods to add payments.
     747     * @return string[]
    733748     */
    734749    public function checkview_add_payment_gateway( $methods ) {
    735         $methods[] = 'Checkview_Payment_Gateway';
     750        $gateway = 'Checkview_Payment_Gateway';
     751
     752        Checkview_Admin_Logs::add( 'ip-logs', 'Adding Woo payment gateway [' . $gateway . '].' );
     753
     754        $methods[] = $gateway;
     755
    736756        return $methods;
    737757    }
     
    749769                'woocommerce_blocks_payment_method_type_registration',
    750770                function ( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     771                    Checkview_Admin_Logs::add( 'ip-logs', 'Added Woo Blocks payment gateway.' );
     772
    751773                    $payment_method_registry->register( new Checkview_Blocks_Payment_Gateway() );
    752774                }
     
    767789            return;
    768790        }
     791
    769792        return $this->checkview_delete_orders();
    770793    }
     
    777800     */
    778801    public function checkview_delete_orders( $order_id = '' ) {
    779 
    780         global $wpdb;
     802        Checkview_Admin_Logs::add( 'ip-logs', 'Deleting CheckView orders from the database...' );
     803
    781804        $orders = array();
    782         // WPDBPREPARE.
    783         if ( empty( $orders ) || false === $orders ) {
    784             $args = array(
    785                 'limit'        => -1,
    786                 'type'         => 'shop_order',
    787                 'meta_key'     => 'payment_made_by', // Postmeta key field.
    788                 'meta_value'   => 'checkview', // Postmeta value field.
    789                 'meta_compare' => '=',
    790                 'return'       => 'ids',
    791             );
    792             if ( function_exists( 'wc_get_orders' ) ) {
    793                 $orders = wc_get_orders( $args );
    794             }
    795             $orders_cv = array();
    796             $args      = array(
    797                 'limit'          => -1,
    798                 'type'           => 'shop_order',
    799                 'payment_method' => 'checkview',
    800                 'return'         => 'ids',
    801             );
    802             if ( function_exists( 'wc_get_orders' ) ) {
    803                 $orders_cv = wc_get_orders( $args );
    804             }
    805             $orders = array_unique( array_merge( $orders, $orders_cv ) );
    806 
    807         }
     805        $args = array(
     806            'limit' => -1,
     807            'type' => 'shop_order',
     808            'meta_key' => 'payment_made_by', // Postmeta key field.
     809            'meta_value' => 'checkview', // Postmeta value field.
     810            'meta_compare' => '=',
     811            'return' => 'ids',
     812        );
     813
     814        if ( function_exists( 'wc_get_orders' ) ) {
     815            $orders = wc_get_orders( $args );
     816        }
     817
     818        $orders_cv = array();
     819        $args = array(
     820            'limit' => -1,
     821            'type' => 'shop_order',
     822            'payment_method' => 'checkview',
     823            'return' => 'ids',
     824        );
     825
     826        if ( function_exists( 'wc_get_orders' ) ) {
     827            $orders_cv = wc_get_orders( $args );
     828        }
     829
     830        $orders = array_unique( array_merge( $orders, $orders_cv ) );
     831
     832        Checkview_Admin_Logs::add( 'cron-logs', 'Found ' . count( $orders ) . ' CheckView orders to delete.' );
     833
    808834        // Delete orders.
    809835        if ( ! empty( $orders ) ) {
    810836            foreach ( $orders as $order ) {
    811 
     837                $order_object = wc_get_order( $order );
     838
     839                // Delete order.
    812840                try {
    813                     $order_object = wc_get_order( $order );
    814                     // Delete order.
    815841                    if ( $order_object && method_exists( $order_object, 'get_customer_id' ) ) {
    816842                        if ( $order_object->get_meta( 'payment_made_by' ) !== 'checkview' && 'checkview' !== $order_object->get_payment_method() ) {
    817843                            continue;
    818844                        }
     845
    819846                        $customer_id = $order_object->get_customer_id();
    820847                        $order_object->delete( true );
     848
    821849                        delete_transient( 'checkview_store_orders_transient' );
    822850
    823851                        $order_object = null;
    824852                        $current_user = get_user_by( 'id', $customer_id );
     853
    825854                        // Delete customer if available.
    826855                        if ( $customer_id && isset( $current_user->roles ) && isset( $current_user->roles ) && ! in_array( 'administrator', $current_user->roles, true ) ) {
     
    831860                            }
    832861
    833                             $res      = $customer->delete( true );
     862                            $res = $customer->delete( true );
    834863                            $customer = null;
    835864                        }
     
    839868                        require_once CHECKVIEW_ADMIN_DIR . '/class-checkview-admin-logs.php';
    840869                    }
    841                     Checkview_Admin_Logs::add( 'cron-logs', 'Crone job failed.' );
     870
     871                    if ($order_object) {
     872                        Checkview_Admin_Logs::add( 'cron-logs', 'Failed to delete CheckView order [' . $order_object->get_id() . '] from the database.' );
     873                    } else {
     874                        Checkview_Admin_Logs::add( 'cron-logs', 'Failed to delete CheckView order from the database.' );
     875                    }
     876
    842877                }
    843878            }
     879
    844880            return true;
    845881        }
     
    858894            $order = new WC_Order( $order_id );
    859895            $order->update_meta_data( 'payment_made_by', 'checkview' );
    860 
    861896            $order->update_meta_data( 'checkview_test_id', sanitize_text_field( wp_unslash( $_COOKIE['checkview_test_id'] ) ) );
     897
     898            Checkview_Admin_Logs::add( 'ip-logs', 'Added meta data to test order.' );
     899
    862900            complete_checkview_test( sanitize_text_field( wp_unslash( $_COOKIE['checkview_test_id'] ) ) );
    863901
    864902            $order->save();
     903
     904            Checkview_Admin_Logs::add( 'ip-logs', 'Saved new order [' . $order->get_id() . '].' );
     905
    865906            unset( $_COOKIE['checkview_test_id'] );
    866907            setcookie( 'checkview_test_id', '', time() - 6600, COOKIEPATH, COOKIE_DOMAIN );
  • checkview/trunk/README.txt

    r3303097 r3323842  
    88License: GPLv3
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html
    10 Stable tag: 2.0.18
     10Stable tag: 2.0.19
    1111
    1212[CheckView](https://checkview.io/) is the friendly WordPress automated testing platform for everyone, from developers, shop owners to agencies. 
     
    8686
    8787== Changelog ==
     88= 2.0.19 =
     89* Improve logging
     90* Add hooks for disabling WP Forms CAPTCHAs/Turnstiles for tests
     91* Disable test-related hooks on API requests
     92* Disable Fluent Forms token-based spam prevention for tests
     93* Remove Fluent Forms CAPTCHA/Turnstile key swap
     94* Disable Fluent Forms CAPTCHAs using newly provided hook
     95
    8896= 2.0.18 =
    8997* Improve logging when querying for available test results.
     
    360368
    361369== Upgrade Notice ==
     370= 2.0.19 =
     371* Improve logging
     372* Add hooks for disabling WP Forms CAPTCHAs/Turnstiles for tests
     373* Disable test-related hooks on API requests
     374* Disable Fluent Forms token-based spam prevention for tests
     375* Remove Fluent Forms CAPTCHA/Turnstile key swap
     376* Disable Fluent Forms CAPTCHAs using newly provided hook
     377
    362378= 2.0.18 =
    363379* Improve logging when querying for available test results.
  • checkview/trunk/admin/class-checkview-admin.php

    r3283610 r3323842  
    6262
    6363        add_action(
    64             'checkview_options_cleanup_cron',
    65             'checkview_options_cleanup'
    66         );
    67 
    68         add_action(
    6964            'checkview_nonce_cleanup_cron',
    7065            array( $this, 'checkview_delete_expired_nonces' )
     
    122117        if ( ! wp_next_scheduled( 'checkview_nonce_cleanup_cron' ) ) {
    123118            wp_schedule_event( time(), 'hourly', 'checkview_nonce_cleanup_cron' );
    124         }
    125 
    126         if ( ! wp_next_scheduled( 'checkview_options_cleanup_cron' ) ) {
    127             wp_schedule_single_event( time() + 60, 'checkview_options_cleanup_cron' );
    128119        }
    129120    }
     
    216207     */
    217208    public function checkview_init_current_test() {
    218 
    219209        if ( ! function_exists( 'is_plugin_active' ) ) {
    220210            include_once ABSPATH . 'wp-admin/includes/plugin.php';
    221211        }
    222         // Current Vsitor IP.
     212
     213        $is_helper_api_request = isset( $_SERVER['REQUEST_URI'] ) && strpos( $_SERVER['REQUEST_URI'], '_checkview_timestamp' );
     214
     215        if ( $is_helper_api_request ) {
     216            return;
     217        }
     218
     219        // Current Visitor IP.
    223220        $visitor_ip = checkview_get_visitor_ip();
    224221        // Check view Bot IP.
     
    227224        // Skip if visitor ip not equal to CV Bot IP.
    228225        if ( is_array( $cv_bot_ip ) && ! in_array( $visitor_ip, $cv_bot_ip ) ) {
     226            if ( isset( $_REQUEST['checkview_test_id'] ) ) {
     227                Checkview_Admin_Logs::add( 'ip-logs', 'Although checkview_test_id is set in the request, exiting test init due to visitor IP [' . $visitor_ip . '] failing bot IP check [' . implode(', ', $cv_bot_ip) . '].' );
     228            }
     229
    229230            if ( 'true' !== get_option( 'cv_ff_keys_set_turnstile' ) ) {
    230231                return;
    231232            }
    232             if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) {
    233                 checkview_options_cleanup();
    234             }
     233
    235234            return;
    236235        }
    237236
    238         // If clean talk plugin active whitelist check form API IP.
     237        Checkview_Admin_Logs::add( 'ip-logs', 'Visitor IP [' . $visitor_ip . '] determined to be in bot IP list, continuing.' );
     238
    239239        if ( is_plugin_active( 'cleantalk-spam-protect/cleantalk.php' ) ) {
    240240            checkview_whitelist_api_ip();
     
    248248            $allowlist                  = Allow_List::get_ips();
    249249            $aiowps_firewall_allow_list = AIOS_Firewall_Resource::request( AIOS_Firewall_Resource::ALLOW_LIST );
     250
    250251            if ( ! empty( $allowlist ) ) {
    251252                $allowlist .= "\n" . $visitor_ip;
     
    253254                $allowlist = $visitor_ip;
    254255            }
    255             $ips                     = sanitize_textarea_field( wp_unslash( $allowlist ) );
    256             $ips                     = AIOWPSecurity_Utility_IP::create_ip_list_array_from_string_with_newline( $ips );
     256
     257            $ips = sanitize_textarea_field( wp_unslash( $allowlist ) );
     258            $ips = AIOWPSecurity_Utility_IP::create_ip_list_array_from_string_with_newline( $ips );
    257259            $validated_ip_list_array = AIOWPSecurity_Utility_IP::validate_ip_list( $ips, 'firewall_allowlist' );
     260
    258261            if ( is_wp_error( $validated_ip_list_array ) ) {
    259262                $success = false;
    260263                $message = nl2br( $validated_ip_list_array->get_error_message() );
     264
    261265                Checkview_Admin_Logs::add( 'ip-logs', 'Error ' . $message );
    262266            } else {
     
    267271        if ( is_plugin_active( 'defender-security/wp-defender.php' ) ) {
    268272            $data = array();
    269 
    270273            $data['allow_list'] = (array) $visitor_ip;
    271 
    272             $data['block_list']           = array();
    273             $data['last_update_time']     = '';
     274            $data['block_list'] = array();
     275            $data['last_update_time'] = '';
    274276            $data['last_update_time_utc'] = '';
    275277
    276278            $global_ip_component = wd_di()->get( Global_IP::class );
    277             $result              = $global_ip_component->set_global_ip_list( $data );
    278         }
     279            $result = $global_ip_component->set_global_ip_list( $data );
     280        }
     281
    279282        if ( is_plugin_active( 'enhanced-cloudflare-turnstile/enhanced-cloudflare-turnstile.php' ) ) {
    280             $ect_ip_address       = ecft_get_option( 'ecft_ip_address' );
     283            $ect_ip_address = ecft_get_option( 'ecft_ip_address' );
    281284            $ect_ip_address_array = explode( "\n", $ect_ip_address );
     285
    282286            if ( ! empty( $ect_ip_address_array ) && is_array( $ect_ip_address_array ) ) {
    283287                if ( ! in_array( $visitor_ip, $ect_ip_address_array ) ) {
    284288                    $ect_ip_address .= "\n" . $visitor_ip;
    285                     update_option( 'ecft_ip_address', $ect_ip_address );
     289
     290                    cv_update_option( 'ecft_ip_address', $ect_ip_address );
    286291                }
    287292            } else {
    288293                $ect_ip_address = $visitor_ip;
    289                 update_option( 'ecft_ip_address', $ect_ip_address );
     294
     295                cv_update_option( 'ecft_ip_address', $ect_ip_address );
    290296            }
    291297        }
     
    304310
    305311                // Save the updated list back to the database.
    306                 update_option( 'captcha_ip_range_opt', implode( ',', $captcha_ip_range ) );
    307             }
    308         }
     312                cv_update_option( 'captcha_ip_range_opt', implode( ',', $captcha_ip_range ) );
     313            }
     314        }
     315
    309316        if ( is_plugin_active( 'recaptcha-for-woocommerce/woo-recaptcha.php' ) ) {
    310             $captcha_ip_range     = '';
     317            $captcha_ip_range = '';
    311318            $captcha_ip_range_opt = '';
    312             $captcha_ip_range     = array();
     319            $captcha_ip_range = array();
     320
    313321            // Get the existing whitelist from the database.
    314322            $captcha_ip_range_opt = sanitize_text_field( wp_unslash( get_option( 'i13_recapcha_ip_to_skip_captcha' ) ) );
     
    323331                if ( count( $captcha_ip_range ) > 1 ) {
    324332                    // Save the updated list back to the database.
    325                     update_option( 'i13_recapcha_ip_to_skip_captcha', implode( ',', $captcha_ip_range ) );
     333                    cv_update_option( 'i13_recapcha_ip_to_skip_captcha', implode( ',', $captcha_ip_range ) );
    326334                } else {
    327                     update_option( 'i13_recapcha_ip_to_skip_captcha', $visitor_ip );
     335                    cv_update_option( 'i13_recapcha_ip_to_skip_captcha', $visitor_ip );
    328336                }
    329337            }
    330338        }
    331         // Gather test ID.
     339
    332340        $cv_test_id = isset( $_REQUEST['checkview_test_id'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['checkview_test_id'] ) ) : '';
    333 
    334         // Flag disabling of email receipts.
    335341        $disable_email_receipt = isset( $_REQUEST['disable_email_receipt'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['disable_email_receipt'] ) ) : false;
    336 
    337342        $disable_webhooks = isset( $_REQUEST['disable_webhooks'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['disable_webhooks'] ) ) : false;
    338 
    339343        $referrer_url = sanitize_url( wp_get_raw_referer(), array( 'http', 'https' ) );
    340344
     
    343347            // Create session for later use when form submit VIA AJAX.
    344348            checkview_create_cv_session( $visitor_ip, $cv_test_id );
    345             update_option( $visitor_ip, 'checkview-saas', true );
     349
     350            cv_update_option( $visitor_ip, 'checkview-saas', true);
    346351        }
    347352
     
    349354        if ( isset( $_SERVER['REQUEST_URI'] ) && strpos( sanitize_url( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'admin-ajax.php' ) !== false ) {
    350355            $referer_url_query = wp_parse_url( $referrer_url, PHP_URL_QUERY );
    351             $qry_str           = array();
     356            $qry_str = array();
     357
    352358            if ( $referer_url_query ) {
    353359                parse_str( $referer_url_query, $qry_str );
    354360            }
     361
    355362            if ( isset( $qry_str['checkview_test_id'] ) ) {
    356363                $cv_test_id = $qry_str['checkview_test_id'];
    357364            }
    358365        }
     366
    359367        if ( ! empty( $cv_test_id ) && ! checkview_is_valid_uuid( $cv_test_id ) ) {
    360             Checkview_Admin_Logs::add( 'ip-logs', 'Not Bypassed invalid test id. ' . $visitor_ip . '=> ' . $cv_test_id );
     368            Checkview_Admin_Logs::add( 'ip-logs', 'Test ID format failed to validate, exiting.' );
     369
    361370            return;
    362371        }
     372
    363373        if ( $cv_test_id && '' !== $cv_test_id ) {
    364374            setcookie( 'checkview_test_id', $cv_test_id, time() + 6600, COOKIEPATH, COOKIE_DOMAIN );
     
    381391            }
    382392        }
    383         if ( empty( $cv_test_id ) ) {
    384             Checkview_Admin_Logs::add( 'ip-logs', 'Not Bypassed missing test id. ' . $visitor_ip . '=> ' . $cv_test_id );
    385         } else {
    386             Checkview_Admin_Logs::add( 'ip-logs', 'Bypassed ' . $visitor_ip . '=> ' . $cv_test_id );
    387         }
     393
    388394        if ( ! empty( $cv_session ) ) {
    389 
    390395            $test_key = $cv_session[0]['test_key'];
    391 
    392396            $test_form = get_option( $test_key, '' );
    393397
     
    402406            if ( ! defined( 'CV_TEST_ID' ) ) {
    403407                define( 'CV_TEST_ID', $cv_test_id );
    404             }
    405         }
     408
     409                Checkview_Admin_Logs::add( 'ip-logs', 'Defined constant [CV_TEST_ID] as [ ' . CV_TEST_ID . ' ].' );
     410            }
     411        } else {
     412            Checkview_Admin_Logs::add( 'ip-logs', 'The CheckView session was empty, but continuing.' );
     413        }
     414
    406415        if ( ! defined( 'TEST_EMAIL' ) ) {
    407416            define( 'TEST_EMAIL', $send_to );
     417
     418            Checkview_Admin_Logs::add( 'ip-logs', 'Defined constant [TEST_EMAIL] as [ ' . TEST_EMAIL . ' ].' );
    408419        }
    409420
    410421        if ( ! defined( 'CV_DISABLE_EMAIL_RECEIPT' ) && $disable_email_receipt ) {
    411422            define( 'CV_DISABLE_EMAIL_RECEIPT', 'true' );
    412             update_option( 'disable_email_receipt', 'true', true );
     423
     424            Checkview_Admin_Logs::add( 'ip-logs', 'Defined constant [CV_DISABLE_EMAIL_RECEIPT] as [' . CV_DISABLE_EMAIL_RECEIPT . '].' );
     425
     426            cv_update_option('disable_email_receipt', 'true', true);
    413427        }
    414428
    415429        if ( ! defined( 'CV_DISABLE_WEBHOOKS' ) && $disable_webhooks ) {
    416430            define( 'CV_DISABLE_WEBHOOKS', 'true' );
    417             update_option( 'disable_webhooks', 'true', true );
     431
     432            Checkview_Admin_Logs::add( 'ip-logs', 'Defined constant [CV_DISABLE_WEBHOOKS] as [' . CV_DISABLE_WEBHOOKS . '].' );
     433
     434            cv_update_option('disable_webhooks', 'true', true);
    418435        }
    419436
    420437        delete_transient( 'checkview_forms_test_transient' );
    421438        delete_transient( 'checkview_store_orders_transient' );
     439
    422440        if ( is_plugin_active( 'gravityforms/gravityforms.php' ) ) {
     441            Checkview_Admin_Logs::add( 'ip-logs', 'Loading Gravity Forms helper.' );
     442
    423443            require_once CHECKVIEW_INC_DIR . 'formhelpers/class-checkview-gforms-helper.php';
    424444        }
     445
    425446        if ( is_plugin_active( 'fluentform/fluentform.php' ) ) {
     447            Checkview_Admin_Logs::add( 'ip-logs', 'Loading Fluent Forms helper.' );
     448
    426449            require_once CHECKVIEW_INC_DIR . 'formhelpers/class-checkview-fluent-forms-helper.php';
    427450        }
     451
    428452        if ( is_plugin_active( 'ninja-forms/ninja-forms.php' ) ) {
     453            Checkview_Admin_Logs::add( 'ip-logs', 'Loading Ninja Forms helper.' );
     454
    429455            require_once CHECKVIEW_INC_DIR . 'formhelpers/class-checkview-ninja-forms-helper.php';
    430456        }
     457
    431458        if ( function_exists( 'wpforms' ) && ( is_plugin_active( 'wpforms/wpforms.php' ) || is_plugin_active( 'wpforms-lite/wpforms.php' ) ) ) {
     459            Checkview_Admin_Logs::add( 'ip-logs', 'Loading WP Forms helper.' );
     460
    432461            require_once CHECKVIEW_INC_DIR . 'formhelpers/class-checkview-wpforms-helper.php';
    433462        }
     463
    434464        if ( is_plugin_active( 'formidable/formidable.php' ) ) {
     465            Checkview_Admin_Logs::add( 'ip-logs', 'Loading Formidable Forms helper.' );
     466
    435467            require_once CHECKVIEW_INC_DIR . 'formhelpers/class-checkview-formidable-helper.php';
    436468        }
    437469
    438470        if ( is_plugin_active( 'forminator/forminator.php' ) ) {
     471            Checkview_Admin_Logs::add( 'ip-logs', 'Loading Forminator helper.' );
     472
    439473            require_once CHECKVIEW_INC_DIR . 'formhelpers/class-checkview-forminator-helper.php';
    440474        }
    441475
    442476        if ( is_plugin_active( 'ws-form/ws-form.php' ) || is_plugin_active( 'ws-form-pro/ws-form.php' ) ) {
     477            Checkview_Admin_Logs::add( 'ip-logs', 'Loading WS Form helper.' );
     478
    443479            require_once CHECKVIEW_INC_DIR . 'formhelpers/class-checkview-wsf-helper.php';
    444480        }
     481
    445482        if ( is_plugin_active( 'contact-form-7/wp-contact-form-7.php' ) ) {
     483            Checkview_Admin_Logs::add( 'ip-logs', 'Loading Contact Form 7 helper.' );
     484
    446485            require_once CHECKVIEW_INC_DIR . 'formhelpers/class-checkview-cf7-helper.php';
    447486        }
  • checkview/trunk/checkview.php

    r3303097 r3323842  
    1212 * Plugin URI:        https://checkview.io
    1313 * Description:       CheckView is the #1 fully automated solution to test your WordPress forms and detect form problems fast.  Automatically test your WordPress forms to ensure you never miss a lead again.
    14  * Version:           2.0.18
     14 * Version:           2.0.19
    1515 * Author:            CheckView
    1616 * Author URI:        https://checkview.io/
     
    3636 * @link https://semver.org
    3737 */
    38 define( 'CHECKVIEW_VERSION', '2.0.18' );
     38define( 'CHECKVIEW_VERSION', '2.0.19' );
    3939
    4040if ( ! defined( 'CHECKVIEW_BASE_DIR' ) ) {
  • checkview/trunk/includes/checkview-functions.php

    r3303097 r3323842  
    144144    }
    145145}
     146
    146147if ( ! function_exists( 'complete_checkview_test' ) ) {
    147148    /**
     
    156157    function complete_checkview_test( $checkview_test_id = '' ) {
    157158        global $wpdb;
    158         global $CV_TEST_ID;
     159
     160        Checkview_Admin_Logs::add( 'ip-logs', 'Completing test...' );
     161
    159162        if ( ! defined( 'CV_TEST_ID' ) ) {
    160163            define( 'CV_TEST_ID', $checkview_test_id );
    161164        }
     165
    162166        $session_table = $wpdb->prefix . 'cv_session';
    163         $visitor_ip    = checkview_get_visitor_ip();
    164         $cv_session    = checkview_get_cv_session( $visitor_ip, CV_TEST_ID );
     167        $visitor_ip = checkview_get_visitor_ip();
     168        $cv_session = checkview_get_cv_session( $visitor_ip, CV_TEST_ID );
    165169
    166170        // Stop if session not found.
    167171        if ( ! empty( $cv_session ) ) {
    168172            $test_key = $cv_session[0]['test_key'];
    169             delete_option( $test_key );
    170         }
    171 
    172         $wpdb->delete(
     173
     174            cv_delete_option( $test_key );
     175        }
     176
     177        $result = $wpdb->delete(
    173178            $session_table,
    174179            array(
    175180                'visitor_ip' => $visitor_ip,
    176                 'test_id'    => $checkview_test_id,
     181                'test_id' => $checkview_test_id,
    177182            )
    178183        );
     184
     185        if ( false === $result ) {
     186            Checkview_Admin_Logs::add( 'ip-logs', 'Failed to delete rows from session table [' . $session_table . '].' );
     187        }
     188
    179189        $entry_id = get_option( $checkview_test_id . '_wsf_entry_id', '' );
    180190        $form_id  = get_option( $checkview_test_id . '_wsf_frm_id', '' );
     191
    181192        if ( ! empty( $form_id ) && ! empty( $entry_id ) ) {
    182             $ws_form_submit          = new WS_Form_Submit();
    183             $ws_form_submit->id      = $entry_id;
     193            $ws_form_submit = new WS_Form_Submit();
     194            $ws_form_submit->id = $entry_id;
    184195            $ws_form_submit->form_id = $form_id;
    185196            $ws_form_submit->db_delete( true, true, true );
    186197        }
    187         delete_option( $checkview_test_id . '_wsf_entry_id' );
    188         delete_option( $checkview_test_id . '_wsf_frm_id' );
    189         delete_option( $visitor_ip );
     198
     199        cv_delete_option( $checkview_test_id . '_wsf_entry_id' );
     200        cv_delete_option( $checkview_test_id . '_wsf_frm_id' );
     201        cv_delete_option( $visitor_ip );
     202
    190203        setcookie( 'checkview_test_id', '', time() - 6600, COOKIEPATH, COOKIE_DOMAIN );
    191204        setcookie( 'checkview_test_id' . $checkview_test_id, '', time() - 6600, COOKIEPATH, COOKIE_DOMAIN );
    192         delete_option( 'disable_email_receipt' );
    193         delete_option( 'disable_webhooks' );
    194     }
    195 }
     205
     206        cv_delete_option( 'disable_email_receipt' );
     207        cv_delete_option( 'disable_webhooks' );
     208
     209        Checkview_Admin_Logs::add( 'ip-logs', 'Test complete.' );
     210    }
     211}
     212
    196213if ( ! function_exists( 'checkview_get_publickey' ) ) {
    197214    /**
     
    235252     */
    236253    function checkview_get_api_ip() {
    237 
    238254        $ip_address = get_transient( 'checkview_saas_ip_address' ) ? get_transient( 'checkview_saas_ip_address' ) : array();
    239         if ( null === $ip_address || '' === $ip_address || empty( $ip_address ) ) {
     255
     256        if ( empty( $ip_address ) ) {
     257            Checkview_Admin_Logs::add( 'ip-logs', 'Bot IP address list transient empty, requesting new IP addresses.' );
     258
    240259            $request = wp_remote_get(
    241260                'https://verify.checkview.io/whitelist.json',
     
    245264                )
    246265            );
     266
    247267            if ( is_wp_error( $request ) ) {
     268                $code = $request->get_error_code();
     269                $message = $request->get_error_message();
     270
     271                Checkview_Admin_Logs::add( 'ip-logs', 'Request for new IP addresses failed with code [' . $code . ']. Message: ' . $message );
     272
    248273                return null;
    249274            }
    250275
    251276            $body = wp_remote_retrieve_body( $request );
    252 
    253277            $data = json_decode( $body, true );
     278
    254279            if ( ! empty( $data ) && ! empty( $data['ipAddresses'] ) ) {
    255280                $ip_address = $data['ipAddresses'];
     281
    256282                if ( ! empty( $ip_address ) && is_array( $ip_address ) ) {
    257283                    foreach ( $ip_address as $ip ) {
     
    264290                    return false;
    265291                }
     292
    266293                set_transient( 'checkview_saas_ip_address', $ip_address, 12 * HOUR_IN_SECONDS );
    267             }
    268         }
     294
     295                Checkview_Admin_Logs::add( 'ip-logs', 'Set bot IP address list transient to response data [' . wp_json_encode( $ip_address ) . ']' );
     296            } else {
     297                Checkview_Admin_Logs::add( 'ip-logs', 'IP addresses not found in request for new IP addresses.' );
     298            }
     299        }
     300
    269301        if ( ! is_array( $ip_address ) ) {
    270302            $ip_address = (array) $ip_address;
    271303        }
     304
    272305        if ( is_array( $ip_address ) ) {
    273306            $ip_address[] = '::1';
     
    275308            $ip_address[] = '2001:8a0:e5d0:a900:70a5:138a:d159:5054';
    276309        }
     310
    277311        return $ip_address;
    278312    }
     
    325359     * @since 1.0.0
    326360     *
    327      * @return string|false IP address of visitor, or `false` if determined to be
    328      *                      an invalid IP.
     361     * @return string IP address of visitor, or `false` if determined to be
     362     *                an invalid IP.
    329363     */
    330364    function checkview_get_visitor_ip() {
     
    332366        $cv_bot_ip  = checkview_get_api_ip();
    333367        $ip_options = checkview_get_custom_header_keys_for_ip();
    334         $ip         = '';
     368        $ip = '';
    335369
    336370        foreach ( $ip_options as $key ) {
     
    340374
    341375            $key = checkview_get_server_value( $key );
     376
    342377            foreach ( explode( ',', $key ) as $ip ) {
    343                 // Just to be safe.
    344378                $ip = trim( $ip );
    345379
    346380                if ( checkview_validate_ip( $ip ) && is_array( $cv_bot_ip ) && in_array( $ip, $cv_bot_ip ) ) {
    347                     Checkview_Admin_Logs::add( 'ip-logs', 'Bypassed ' . $ip );
    348381                    return sanitize_text_field( $ip );
    349382                }
     
    808841     */
    809842    function checkview_schedule_delete_orders( $order_id ) {
     843        Checkview_Admin_Logs::add( 'ip-logs', 'Scheduling order deletion.' );
     844
    810845        wp_schedule_single_event( time() + 1 * HOUR_IN_SECONDS, 'checkview_delete_orders_action', array( $order_id ) );
    811846    }
     
    888923    function checkview_is_valid_uuid( $uuid ) {
    889924        if ( empty( $uuid ) || is_wp_error( $uuid ) ) {
     925            Checkview_Admin_Logs::add( 'ip-logs', 'Invalid UUID [' . $uuid . '].' );
     926
    890927            return false;
    891928        }
    892         return preg_match( '/^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/i', $uuid );
     929
     930        $matches = preg_match( '/^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/i', $uuid );
     931
     932        if ( ! $matches ) {
     933            Checkview_Admin_Logs::add( 'ip-logs', 'Invalid UUID [' . $uuid . '].' );
     934
     935            return false;
     936        }
     937
     938        return true;
    893939    }
    894940}
     
    10741120        }
    10751121        return $updated;
    1076     }
    1077 }
    1078 if ( ! defined( 'checkview_options_cleanup' ) ) {
    1079     /**
    1080      * Cleans options for CV.
    1081      *
    1082      * @return void
    1083      */
    1084     function checkview_options_cleanup() {
    1085         $old_settings = array();
    1086         $old_settings = (array) get_option( '_fluentform_reCaptcha_details', array() );
    1087         if ( ! empty( $old_settings ) && null !== $old_settings['siteKey'] && null !== $old_settings['secretKey'] ) {
    1088             if ( '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI' === $old_settings['siteKey'] ) {
    1089                 $old_settings['siteKey']   = get_option( 'checkview_rc-site-key' );
    1090                 $old_settings['secretKey'] = get_option( 'checkview_rc-secret-key' );
    1091                 update_option( '_fluentform_reCaptcha_details', $old_settings );
    1092             }
    1093         }
    1094         $old_settings = array();
    1095         $old_settings = (array) get_option( '_fluentform_turnstile_details', array() );
    1096         if ( ! empty( $old_settings ) && null !== $old_settings['siteKey'] && null !== $old_settings['secretKey'] ) {
    1097             if ( '1x00000000000000000000AA' === $old_settings['siteKey'] ) {
    1098                 $old_settings['siteKey']   = get_option( 'checkview_ff_turnstile-site-key' );
    1099                 $old_settings['secretKey'] = get_option( 'checkview_ff_turnstile-secret-key' );
    1100                 update_option( '_fluentform_turnstile_details', $old_settings );
    1101             }
    1102         }
    1103         delete_option( 'cv_ff_keys_set_turnstile' );
    11041122    }
    11051123}
     
    11251143    }
    11261144}
     1145
     1146if ( ! function_exists( 'cv_update_option' ) ) {
     1147    /**
     1148     * Updates an option in WordPress.
     1149     *
     1150     * Wrapper for update_option() that also includes logging. Suppresses logs from
     1151     * failures due to option already existing with the same value.
     1152     *
     1153     * @see update_option()
     1154     * @see get_option()
     1155     *
     1156     * @param $option string Name of the option to update.
     1157     * @param $value mixed Option value.
     1158     * @param $autoload boolean|null Optional. Whether to load the option when WordPress starts up.
     1159     *
     1160     * @return boolean True if the value was updated, false otherwise.
     1161     */
     1162    function cv_update_option( $option, $value, $autoload = null ) {
     1163        $old_option = get_option( $option );
     1164        $result = update_option( $option, $value, $autoload );
     1165
     1166        if ( $result ) {
     1167            Checkview_Admin_Logs::add( 'ip-logs', 'Updated option [' . $option . '] with value [' . print_r( $value, true ) . '].' );
     1168        } else {
     1169            if ($old_option !== false && $old_option !== $value && maybe_serialize( $old_option ) !== maybe_serialize( $value ) ) {
     1170                Checkview_Admin_Logs::add( 'ip-logs', 'Failed updating option [' . $option . '] with value [' . print_r( $value, true ) . '].' );
     1171            }
     1172        }
     1173
     1174        return $result;
     1175    }
     1176}
     1177
     1178if ( ! function_exists( 'cv_delete_option' ) ) {
     1179    /**
     1180     * Deletes an option in WordPress.
     1181     *
     1182     * Wrapper for delete_option() that also includes logging. Only attempts
     1183     * deletion if the option is found in the database.
     1184     *
     1185     * @see delete_option()
     1186     * @see get_option()
     1187     *
     1188     * @param $option string Name of the option to delete.
     1189     *
     1190     * @return boolean True if the value was deleted, false otherwise.
     1191     */
     1192    function cv_delete_option( $option ) {
     1193        $current_option = get_option( $option );
     1194
     1195        if ( false !== $current_option ) {
     1196            $result = delete_option( $option );
     1197
     1198            if ( $result ) {
     1199                Checkview_Admin_Logs::add( 'ip-logs', 'Deleted option [' . $option . '].' );
     1200            } else {
     1201                Checkview_Admin_Logs::add( 'ip-logs', 'Failed deleting option [' . $option . '].' );
     1202            }
     1203
     1204            return $result;
     1205        }
     1206
     1207        return true;
     1208    }
     1209}
  • checkview/trunk/includes/class-checkview.php

    r3303097 r3323842  
    7171            $this->version = CHECKVIEW_VERSION;
    7272        } else {
    73             $this->version = '2.0.18';
     73            $this->version = '2.0.19';
    7474        }
    7575        $this->plugin_name = 'checkview';
     
    202202     */
    203203    private function define_admin_hooks() {
    204 
    205204        $plugin_admin    = new Checkview_Admin( $this->get_plugin_name(), $this->get_version() );
    206205        $plugin_settings = new Checkview_Admin_Settings( $this->get_plugin_name(), $this->get_version() );
    207206        $plugin_logs     = new Checkview_Admin_Logs();
     207
    208208        if ( is_admin() ) {
    209209            // load backend hooks.
  • checkview/trunk/includes/formhelpers/class-checkview-cf7-helper.php

    r3216431 r3323842  
    125125         */
    126126        public function checkview_cf7_before_send_mail( $form_tag ) {
    127 
    128127            global $wpdb;
    129128
    130             $form_id              = $form_tag->id();
     129            $form_id = $form_tag->id();
    131130            $wp_filesystem_direct = new WP_Filesystem_Direct( array() );
    132 
    133131            $checkview_test_id = get_checkview_test_id();
    134132
     
    137135            }
    138136
    139             $upload_dir     = wp_upload_dir();
     137            $upload_dir = wp_upload_dir();
    140138            $cv_cf7_dirname = $upload_dir['basedir'] . '/cv_cf7_uploads';
    141139
     
    145143
    146144            $time_now = time();
    147 
    148145            $submission = WPCF7_Submission::get_instance();
     146
    149147            if ( $submission ) {
    150148                $contact_form = $submission->get_contact_form();
    151149            }
     150
    152151            $tags_names = array();
    153152
    154153            if ( $submission ) {
    155 
    156                 $allowed_tags = array();
     154                Checkview_Admin_Logs::add( 'ip-logs', 'Cloning submission entry...' );
    157155
    158156                $tags = $contact_form->scan_form_tags();
     157
    159158                foreach ( $tags as $tag ) {
    160159                    if ( ! empty( $tag->name ) ) {
     
    162161                    }
    163162                }
     163
    164164                $allowed_tags = $tags_names;
    165 
    166165                $not_allowed_tags = array( 'g-recaptcha-response' );
    167 
    168                 $data           = $submission->get_posted_data();
    169                 $files          = $submission->uploaded_files();
     166                $data = $submission->get_posted_data();
     167                $files = $submission->uploaded_files();
    170168                $uploaded_files = array();
    171169
     
    173171                    array_push( $uploaded_files, $file_key );
    174172                }
     173
    175174                foreach ( $files as $file_key => $file ) {
    176175                    $file = is_array( $file ) ? reset( $file ) : $file;
     
    184183
    185184                foreach ( $data as $key => $d ) {
    186 
    187185                    if ( ! in_array( $key, $allowed_tags ) ) {
    188186                        continue;
     
    190188
    191189                    if ( ! in_array( $key, $not_allowed_tags ) && ! in_array( $key, $uploaded_files ) ) {
    192 
    193190                        $tmp_d = $d;
    194191
    195192                        if ( ! is_array( $d ) ) {
    196                             $bl    = array( '\"', "\'", '/', '\\', '"', "'" );
    197                             $wl    = array( '"', ''', '/', '\', '"', ''' );
     193                            $bl = array( '\"', "\'", '/', '\\', '"', "'" );
     194                            $wl = array( '"', ''', '/', '\', '"', ''' );
    198195                            $tmp_d = str_replace( $bl, $wl, $tmp_d );
    199196                        }
     197
    200198                        if ( is_array( $d ) ) {
    201199                            $tmp_d = serialize( $d );
     
    204202                        $form_data[ $key ] = $tmp_d;
    205203                    }
     204
    206205                    if ( in_array( $key, $uploaded_files ) ) {
    207                         $file                              = is_array( $files[ $key ] ) ? reset( $files[ $key ] ) : $files[ $key ];
    208                         $file_name                         = empty( $file ) ? '' : $time_now . '-' . $key . '-' . basename( $file );
     206                        $file = is_array( $files[ $key ] ) ? reset( $files[ $key ] ) : $files[ $key ];
     207                        $file_name = empty( $file ) ? '' : $time_now . '-' . $key . '-' . basename( $file );
    209208                        $form_data[ $key . 'cv_cf7_file' ] = $file_name;
    210209                    }
     
    213212                // insert entry.
    214213                $entry_data  = array(
    215                     'form_id'      => $form_id,
    216                     'status'       => 'publish',
    217                     'source_url'   => isset( $_SERVER['HTTP_REFERER'] ) ? sanitize_url( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '',
     214                    'form_id' => $form_id,
     215                    'status' => 'publish',
     216                    'source_url' => isset( $_SERVER['HTTP_REFERER'] ) ? sanitize_url( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '',
    218217                    'date_created' => current_time( 'mysql' ),
    219218                    'date_updated' => current_time( 'mysql' ),
    220                     'uid'          => $checkview_test_id,
    221                     'form_type'    => 'CF7',
     219                    'uid' => $checkview_test_id,
     220                    'form_type' => 'CF7',
    222221                );
    223222                $entry_table = $wpdb->prefix . 'cv_entry';
    224                 $wpdb->insert( $entry_table, $entry_data );
     223
     224                $result = $wpdb->insert( $entry_table, $entry_data );
     225
     226                if ( ! $result ) {
     227                    Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry data.' );
     228                } else {
     229                    Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry data (inserted ' . (int) $result . ' rows into ' . $entry_table . ').' );
     230                }
     231
    225232                $inserted_entry_id = $wpdb->insert_id;
    226 
    227233                $entry_meta_table = $wpdb->prefix . 'cv_entry_meta';
     234                $count = 0;
    228235
    229236                foreach ( $form_data as $key => $val ) {
    230 
    231237                    $entry_metadata = array(
    232                         'uid'        => $checkview_test_id,
    233                         'form_id'    => $form_id,
    234                         'entry_id'   => $inserted_entry_id,
    235                         'meta_key'   => $key,
     238                        'uid' => $checkview_test_id,
     239                        'form_id' => $form_id,
     240                        'entry_id' => $inserted_entry_id,
     241                        'meta_key' => $key,
    236242                        'meta_value' => $val,
    237243                    );
    238                     $wpdb->insert( $entry_meta_table, $entry_metadata );
     244
     245                    $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     246
     247                    if ( $result ) {
     248                        $count++;
     249                    }
     250                }
     251
     252                if ( $count > 0 ) {
     253                    Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry meta data (inserted ' . $count . ' rows into ' . $entry_meta_table . ').' );
     254                } else {
     255                    if ( count( $form_data ) > 0 ) {
     256                        Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry meta data.' );
     257                    }
    239258                }
    240259
  • checkview/trunk/includes/formhelpers/class-checkview-fluent-forms-helper.php

    r3227063 r3323842  
    4747                add_filter(
    4848                    'fluentform/email_to',
    49                     array(
    50                         $this,
    51                         'checkview_remove_receipt',
    52                     ),
     49                    array( $this, 'checkview_remove_receipt' ),
    5350                    99,
    54                     4
     51                    4,
    5552                );
    5653
    5754                add_filter(
    5855                    'fluentform/email_template_header',
    59                     array(
    60                         $this,
    61                         'checkview_remove_email_header',
    62                     ),
     56                    array( $this, 'checkview_remove_email_header' ),
    6357                    99,
    64                     2
     58                    2,
    6559                );
    6660            }
     
    7064                add_filter(
    7165                    'fluentform/email_to',
    72                     array(
    73                         $this,
    74                         'checkview_inject_email',
    75                     ),
     66                    array( $this, 'checkview_inject_email' ),
    7667                    99,
    77                     4
     68                    4,
    7869                );
    7970            }
     
    8172            add_action(
    8273                'fluentform/submission_inserted',
    83                 array(
    84                     $this,
    85                     'checkview_clone_fluentform_entry',
    86                 ),
     74                array( $this, 'checkview_clone_fluentform_entry' ),
    8775                99,
    8876                3
    8977            );
     78
    9079            add_filter(
    9180                'fluentform/has_recaptcha',
    92                 function ( $isSpamCheck ) {
    93                     return false;
    94                 },
     81                '__return_false',
    9582                20,
    96                 1
    9783            );
    9884
    9985            add_filter(
    10086                'fluentform/has_hcaptcha',
    101                 function ( $status ) {
    102                     // Do your stuff here.
    103 
    104                     return false;
    105                 },
    106                 10,
    107                 1
     87                '__return_false',
    10888            );
    10989
    11090            add_filter(
    11191                'fluentform/has_turnstile',
    112                 function ( $status ) {
    113                     // Do your stuff here.
    114 
    115                     return false;
    116                 },
    117                 10,
    118                 1
    119             );
     92                '__return_false',
     93            );
     94
    12095            add_filter(
    12196                'fluentform/akismet_check_spam',
    122                 function ( $isSpamCheck, $form_id, $formData ) {
    123                     return false;
    124                 },
     97                '__return_false',
    12598                20,
    126                 3
    127             );
     99            );
     100
    128101            add_filter(
    129102                'cfturnstile_whitelisted',
    130103                '__return_true',
    131                 999
    132             );
    133 
    134             $old_settings = (array) get_option( '_fluentform_turnstile_details', array() );
    135             if ( ! empty( $old_settings['siteKey'] ) && null !== $old_settings['siteKey'] && null !== $old_settings['secretKey'] ) {
    136                 if ( '1x00000000000000000000AA' !== $old_settings['siteKey'] ) {
    137                     update_option( 'checkview_ff_turnstile-site-key', $old_settings['siteKey'], true );
    138                     update_option( 'checkview_ff_turnstile-secret-key', $old_settings['secretKey'], true );
    139                     $old_settings['siteKey']   = '1x00000000000000000000AA';
    140                     $old_settings['secretKey'] = '1x0000000000000000000000000000000AA';
    141                     update_option( '_fluentform_turnstile_details', $old_settings );
    142                 }
    143             }
    144             $old_settings = array();
    145             $old_settings = (array) get_option( '_fluentform_reCaptcha_details', array() );
    146             if ( null !== $old_settings['siteKey'] && null !== $old_settings['secretKey'] && strpos( $old_settings['api_version'], 'v3' ) === false ) {
    147                 if ( '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI' !== $old_settings['siteKey'] ) {
    148                     update_option( 'checkview_rc-site-key', $old_settings['siteKey'], true );
    149                     update_option( 'checkview_rc-secret-key', $old_settings['secretKey'], true );
    150                     $old_settings['siteKey']   = '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI';
    151                     $old_settings['secretKey'] = '6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe';
    152                     update_option( '_fluentform_reCaptcha_details', $old_settings );
    153                 }
    154             }
    155             update_option( 'cv_ff_keys_set_turnstile', 'true' );
     104                999,
     105            );
     106
    156107            add_filter(
    157108                'fluentform/recaptcha_v3_ref_score',
     
    160111                },
    161112                99,
    162                 1
    163113            );
    164114
     
    173123            );
    174124
    175             // Disbale feeds.
     125            // Disable feeds.
    176126            add_filter(
    177127                'fluentform/global_notification_active_types',
    178                 array(
    179                     $this,
    180                     'checkview_disable_form_actions',
    181                 ),
     128                array( $this, 'checkview_disable_form_actions' ),
    182129                99,
    183                 2
     130                2,
    184131            );
    185132
     
    187134            add_filter(
    188135                'fluentform/honeypot_status',
    189                 function ( $status, $form_id ) {
    190                     return false;
    191                 },
     136                '__return_false',
    192137                999,
    193                 2
     138            );
     139
     140            add_filter(
     141                'fluentform/token_based_spam_protection_status',
     142                '__return_false',
     143                999
     144            );
     145
     146            add_filter(
     147                'fluentform/disable_captcha',
     148                '__return_true',
     149                999
    194150            );
    195151        }
     
    260216            global $wpdb;
    261217
    262             $form_id           = $form->id;
     218            Checkview_Admin_Logs::add( 'ip-logs', 'Cloning submission entry [' . $entry_id . ']...' );
     219
     220            $form_id = $form->id;
    263221            $checkview_test_id = get_checkview_test_id();
    264222
     
    269227            // Clone entry to check view tables.
    270228            $tablename = $wpdb->prefix . 'fluentform_entry_details';
    271             $rows      = $wpdb->get_results( $wpdb->prepare( 'Select * from ' . $tablename . ' where submission_id=%d and form_id=%d order by id ASC', $entry_id, $form_id ) );
     229            $rows = $wpdb->get_results( $wpdb->prepare( 'Select * from ' . $tablename . ' where submission_id=%d and form_id=%d order by id ASC', $entry_id, $form_id ) );
     230            $count = 0;
     231            $entry_meta_table = $wpdb->prefix . 'cv_entry_meta';
     232
    272233            foreach ( $rows as $row ) {
    273234                $meta_key = 'ff_' . $form_id . '_' . $row->field_name;
     235
    274236                if ( '' !== $row->sub_field_name ) {
    275237                    $meta_key .= '_' . $row->sub_field_name . '_';
    276238                }
    277                 $table = $wpdb->prefix . 'cv_entry_meta';
     239
    278240                $data  = array(
    279241                    'uid'        => $checkview_test_id,
     
    283245                    'meta_value' => $row->field_value,
    284246                );
    285                 $wpdb->insert( $table, $data );
    286             }
     247
     248                $result = $wpdb->insert( $entry_meta_table, $data );
     249
     250                if ( $result ) {
     251                    $count++;
     252                }
     253            }
     254
     255            if ( $count > 0 ) {
     256                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry meta data (inserted ' . $count . ' rows into ' . $entry_meta_table . ').' );
     257            } else {
     258                if ( count( $rows ) > 0 ) {
     259                    Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry meta data.' );
     260                }
     261            }
     262
    287263            $tablename = $wpdb->prefix . 'fluentform_submissions';
    288             $row       = $wpdb->get_row( $wpdb->prepare( 'Select * from ' . $tablename . ' where id=%d and form_id=%d LIMIT 1', $entry_id, $form_id ), ARRAY_A );
    289             $table1    = $wpdb->prefix . 'cv_entry';
    290             $data      = array(
    291                 'uid'            => $checkview_test_id,
    292                 'form_type'      => 'FluentForms',
    293                 'form_id'        => $form_id,
    294                 'source_url'     => isset( $row['source_url'] ) ? $row['source_url'] : 'n/a',
    295                 'response'       => isset( $row['response'] ) ? $row['response'] : 'n/a',
    296                 'user_agent'     => isset( $row['browser'] ) ? $row['browser'] : 'n/a',
    297                 'ip'             => isset( $row['ip'] ) ? $row['ip'] : 'n/a',
    298                 'date_created'   => isset( $row['created_at'] ) ? $row['created_at'] : 'n/a',
    299                 'date_updated'   => isset( $row['updated_at'] ) ? $row['updated_at'] : 'n/a',
     264            $row = $wpdb->get_row( $wpdb->prepare( 'Select * from ' . $tablename . ' where id=%d and form_id=%d LIMIT 1', $entry_id, $form_id ), ARRAY_A );
     265            $entry_table = $wpdb->prefix . 'cv_entry';
     266            $data = array(
     267                'uid' => $checkview_test_id,
     268                'form_type' => 'FluentForms',
     269                'form_id' => $form_id,
     270                'source_url' => isset( $row['source_url'] ) ? $row['source_url'] : 'n/a',
     271                'response' => isset( $row['response'] ) ? $row['response'] : 'n/a',
     272                'user_agent' => isset( $row['browser'] ) ? $row['browser'] : 'n/a',
     273                'ip' => isset( $row['ip'] ) ? $row['ip'] : 'n/a',
     274                'date_created' => isset( $row['created_at'] ) ? $row['created_at'] : 'n/a',
     275                'date_updated' => isset( $row['updated_at'] ) ? $row['updated_at'] : 'n/a',
    300276                'payment_status' => isset( $row['payment_status'] ) ? $row['payment_status'] : 'n/a',
    301277                'payment_method' => isset( $row['payment_method'] ) ? $row['payment_payment'] : 'n/a',
    302278                'payment_amount' => isset( $row['payment_total'] ) ? $row['payment_total'] : 0,
    303279            );
    304             $wpdb->insert( $table1, $data );
     280
     281            $result = $wpdb->insert( $entry_table, $data );
     282
     283            if ( ! $result ) {
     284                Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry data.' );
     285            } else {
     286                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry data (inserted ' . (int) $result . ' rows into ' . $entry_table . ').' );
     287            }
    305288
    306289            // remove entry from Fluent forms tables.
  • checkview/trunk/includes/formhelpers/class-checkview-formidable-helper.php

    r3247217 r3323842  
    4141        public function __construct() {
    4242            $this->loader = new Checkview_Loader();
     43
    4344            if ( defined( 'TEST_EMAIL' ) ) {
    4445                // update email to our test email.
     
    8384                2
    8485            );
     86
    8587            add_filter(
    8688                'akismet_get_api_key',
     
    8890                -10
    8991            );
     92
    9093            add_filter(
    9194                'frm_fields_to_validate',
     
    97100                2
    98101            );
     102
    99103            add_filter(
    100104                'cfturnstile_whitelisted',
     
    102106                999
    103107            );
     108
    104109            add_filter(
    105110                'frm_run_honeypot',
    106111                '__return_false'
    107112            );
     113
    108114            // Disbale form action.
    109115            add_filter(
     
    169175            global $wpdb;
    170176
     177            Checkview_Admin_Logs::add( 'ip-logs', 'Cloning submission entry [' . $entry_id . ']...' );
     178
    171179            $checkview_test_id = get_checkview_test_id();
    172180
     
    176184
    177185            // Insert entry.
    178             $entry_data  = array(
    179                 'form_id'      => $form_id,
    180                 'status'       => 'publish',
    181                 'source_url'   => isset( $_SERVER['HTTP_REFERER'] ) ? sanitize_url( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '',
     186            $entry_data = array(
     187                'form_id' => $form_id,
     188                'status' => 'publish',
     189                'source_url' => isset( $_SERVER['HTTP_REFERER'] ) ? sanitize_url( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '',
    182190                'date_created' => current_time( 'mysql' ),
    183191                'date_updated' => current_time( 'mysql' ),
    184                 'uid'          => $checkview_test_id,
    185                 'form_type'    => 'Formidable',
     192                'uid' => $checkview_test_id,
     193                'form_type' => 'Formidable',
    186194            );
    187195            $entry_table = $wpdb->prefix . 'cv_entry';
    188             $wpdb->insert( $entry_table, $entry_data );
    189             $inserted_entry_id = $wpdb->insert_id;
     196
     197            $result  = $wpdb->insert( $entry_table, $entry_data );
     198
     199            if ( ! $result ) {
     200                Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry data.' );
     201            } else {
     202                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry data (inserted ' . (int) $result . ' rows into ' . $entry_table . ').' );
     203            }
    190204
    191205            // Insert entry meta.
    192206            $entry_meta_table = $wpdb->prefix . 'cv_entry_meta';
    193             $fields           = $this->get_form_fields( $form_id );
     207            $fields = $this->get_form_fields( $form_id );
     208
    194209            if ( empty( $fields ) ) {
    195210                return;
    196211            }
    197             $tablename   = $wpdb->prefix . 'frm_item_metas';
     212
     213            $tablename = $wpdb->prefix . 'frm_item_metas';
    198214            $form_fields = $wpdb->get_results( $wpdb->prepare( 'Select * from ' . $tablename . ' where item_id=%d', $entry_id ) );
     215            $count = 0;
     216
    199217            foreach ( $form_fields as $field ) {
    200218                if ( empty( $field->field_id ) ) {
    201219                    continue;
    202220                }
     221
    203222                if ( 'name' === $fields[ $field->field_id ]['type'] ) {
    204 
    205223                    $field_values = maybe_unserialize( $field->meta_value );
    206 
    207224                    $name_format = $fields[ $field->field_id ]['name_layout'];
     225
    208226                    switch ( $name_format ) {
    209227                        case 'first_middle_last':
    210228                            // First.
    211229                            $entry_metadata = array(
    212                                 'uid'        => $checkview_test_id,
    213                                 'form_id'    => $form_id,
    214                                 'entry_id'   => $entry_id,
    215                                 'meta_key'   => $fields[ $field->field_id ]['sub_fields'][0]['field_id'],
     230                                'uid' => $checkview_test_id,
     231                                'form_id' => $form_id,
     232                                'entry_id' => $entry_id,
     233                                'meta_key' => $fields[ $field->field_id ]['sub_fields'][0]['field_id'],
    216234                                'meta_value' => $field_values['first'],
    217235                            );
    218                             $wpdb->insert( $entry_meta_table, $entry_metadata );
     236
     237                            $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     238
     239                            if ( $result ) {
     240                                $count++;
     241                            }
    219242
    220243                            // middle.
    221244                            $entry_metadata = array(
    222                                 'uid'        => $checkview_test_id,
    223                                 'form_id'    => $form_id,
    224                                 'entry_id'   => $entry_id,
    225                                 'meta_key'   => $fields[ $field->field_id ]['sub_fields'][1]['field_id'],
     245                                'uid' => $checkview_test_id,
     246                                'form_id' => $form_id,
     247                                'entry_id' => $entry_id,
     248                                'meta_key' => $fields[ $field->field_id ]['sub_fields'][1]['field_id'],
    226249                                'meta_value' => $field_values['middle'],
    227250                            );
    228                             $wpdb->insert( $entry_meta_table, $entry_metadata );
     251
     252                            $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     253
     254                            if ( $result ) {
     255                                $count++;
     256                            }
    229257
    230258                            // last.
    231259                            $entry_metadata = array(
    232                                 'uid'        => $checkview_test_id,
    233                                 'form_id'    => $form_id,
    234                                 'entry_id'   => $entry_id,
    235                                 'meta_key'   => $fields[ $field->field_id ]['sub_fields'][2]['field_id'],
     260                                'uid' => $checkview_test_id,
     261                                'form_id' => $form_id,
     262                                'entry_id' => $entry_id,
     263                                'meta_key' => $fields[ $field->field_id ]['sub_fields'][2]['field_id'],
    236264                                'meta_value' => $field_values['last'],
    237265                            );
    238                             $wpdb->insert( $entry_meta_table, $entry_metadata );
     266
     267                            $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     268
     269                            if ( $result ) {
     270                                $count++;
     271                            }
    239272
    240273                            break;
     
    242275                            // First.
    243276                            $entry_metadata = array(
    244                                 'uid'        => $checkview_test_id,
    245                                 'form_id'    => $form_id,
    246                                 'entry_id'   => $entry_id,
    247                                 'meta_key'   => $fields[ $field->field_id ]['sub_fields'][0]['field_id'],
     277                                'uid' => $checkview_test_id,
     278                                'form_id' => $form_id,
     279                                'entry_id' => $entry_id,
     280                                'meta_key' => $fields[ $field->field_id ]['sub_fields'][0]['field_id'],
    248281                                'meta_value' => $field_values['first'],
    249282                            );
    250                             $wpdb->insert( $entry_meta_table, $entry_metadata );
     283
     284                            $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     285
     286                            if ( $result ) {
     287                                $count++;
     288                            }
     289
    251290                            // last.
    252291                            $entry_metadata = array(
    253                                 'uid'        => $checkview_test_id,
    254                                 'form_id'    => $form_id,
    255                                 'entry_id'   => $entry_id,
    256                                 'meta_key'   => $fields[ $field->field_id ]['sub_fields'][1]['field_id'],
     292                                'uid' => $checkview_test_id,
     293                                'form_id' => $form_id,
     294                                'entry_id' => $entry_id,
     295                                'meta_key' => $fields[ $field->field_id ]['sub_fields'][1]['field_id'],
    257296                                'meta_value' => $field_values['last'],
    258297                            );
    259                             $wpdb->insert( $entry_meta_table, $entry_metadata );
     298
     299                            $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     300
     301                            if ( $result ) {
     302                                $count++;
     303                            }
     304
    260305                            break;
    261306                        case 'last_first':
    262307                            // First.
    263308                            $entry_metadata = array(
    264                                 'uid'        => $checkview_test_id,
    265                                 'form_id'    => $form_id,
    266                                 'entry_id'   => $entry_id,
    267                                 'meta_key'   => $fields[ $field->field_id ]['sub_fields'][1]['field_id'],
     309                                'uid' => $checkview_test_id,
     310                                'form_id' => $form_id,
     311                                'entry_id' => $entry_id,
     312                                'meta_key' => $fields[ $field->field_id ]['sub_fields'][1]['field_id'],
    268313                                'meta_value' => $field_values['first'],
    269314                            );
    270                             $wpdb->insert( $entry_meta_table, $entry_metadata );
     315
     316                            $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     317
     318                            if ( $result ) {
     319                                $count++;
     320                            }
     321
    271322                            // last.
    272323                            $entry_metadata = array(
    273                                 'uid'        => $checkview_test_id,
    274                                 'form_id'    => $form_id,
    275                                 'entry_id'   => $entry_id,
    276                                 'meta_key'   => $fields[ $field->field_id ]['sub_fields'][0]['field_id'],
     324                                'uid' => $checkview_test_id,
     325                                'form_id' => $form_id,
     326                                'entry_id' => $entry_id,
     327                                'meta_key' => $fields[ $field->field_id ]['sub_fields'][0]['field_id'],
    277328                                'meta_value' => $field_values['last'],
    278329                            );
    279                             $wpdb->insert( $entry_meta_table, $entry_metadata );
    280                             break;
    281 
     330
     331                            $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     332
     333                            if ( $result ) {
     334                                $count++;
     335                            }
     336
     337                            break;
    282338                    }
    283339                } else {
    284                     $field_value    = $field->meta_value;
     340                    $field_value = $field->meta_value;
    285341                    $entry_metadata = array(
    286                         'uid'        => $checkview_test_id,
    287                         'form_id'    => $form_id,
    288                         'entry_id'   => $entry_id,
    289                         'meta_key'   => $fields[ $field->field_id ]['field_id'],
     342                        'uid' => $checkview_test_id,
     343                        'form_id' => $form_id,
     344                        'entry_id' => $entry_id,
     345                        'meta_key' => $fields[ $field->field_id ]['field_id'],
    290346                        'meta_value' => $field_value,
    291347                    );
    292                     $wpdb->insert( $entry_meta_table, $entry_metadata );
     348
     349                    $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     350
     351                    if ( $result ) {
     352                        $count++;
     353                    }
     354                }
     355            }
     356
     357            if ( $count > 0 ) {
     358                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry meta data (inserted ' . $count . ' rows into ' . $entry_meta_table . ').' );
     359            } else {
     360                if ( count( $form_fields ) > 0 ) {
     361                    Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry meta data.' );
    293362                }
    294363            }
     
    296365            // Remove test entry form Formidable.
    297366            $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE item_id=%d', $entry_id ) );
    298             $result = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_items WHERE id=%d', $entry_id ) );
     367            $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_items WHERE id=%d', $entry_id ) );
    299368
    300369            complete_checkview_test( $checkview_test_id );
  • checkview/trunk/includes/formhelpers/class-checkview-forminator-helper.php

    r3216431 r3323842  
    4141        public function __construct() {
    4242            $this->loader = new Checkview_Loader();
     43
    4344            if ( defined( 'TEST_EMAIL' ) ) {
    4445                // update email to our test email.
     
    9192                999
    9293            );
     94
    9395            add_filter(
    9496                'forminator_invalid_captcha_message',
    9597                '__return_null'
    9698            );
     99
    97100            // Disbale form action.
    98101            add_filter(
     
    151154         * @param object $entry entry object.
    152155         * @param int    $form_id Form entry ID.
    153          * @param int    $form_fields Form's fields.
     156         * @param array  $form_fields Form's fields.
    154157         * @return void
    155158         */
    156         public function checkview_log_form_test_entry(
    157             $entry,
    158             $form_id,
    159             $form_fields
    160         ) {
     159        public function checkview_log_form_test_entry($entry, $form_id, $form_fields) {
    161160            global $wpdb;
    162161
    163162            $checkview_test_id = get_checkview_test_id();
    164             $entry_id          = $entry->entry_id;
    165             $form_id           = $entry->form_id;
     163            $entry_id = $entry->entry_id;
     164            $form_id = $entry->form_id;
     165
     166            Checkview_Admin_Logs::add( 'ip-logs', 'Cloning submission entry [' . $entry_id . ']...' );
     167
    166168            if ( empty( $checkview_test_id ) ) {
    167169                $checkview_test_id = $form_id . gmdate( 'Ymd' );
     
    180182
    181183            $entry_table = $wpdb->prefix . 'cv_entry';
    182             $wpdb->insert( $entry_table, $entry_data );
    183             $inserted_entry_id = $wpdb->insert_id;
    184 
    185             // Insert entry meta.
     184            $result = $wpdb->insert( $entry_table, $entry_data );
     185
     186            if ( ! $result ) {
     187                Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry data.' );
     188            } else {
     189                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry data (inserted ' . (int) $result . ' rows into ' . $entry_table . ').' );
     190            }
     191
    186192            $entry_meta_table = $wpdb->prefix . 'cv_entry_meta';
     193            $count = 0;
    187194
    188195            foreach ( $form_fields as $field ) {
     
    190197                    continue;
    191198                }
     199
    192200                $field_value    = $field['value'];
    193201                $meta_key       = $field['name'];
     
    199207                    'meta_value' => $field_value,
    200208                );
    201                 $wpdb->insert( $entry_meta_table, $entry_metadata );
    202             }
    203 
    204             // Remove test entry form Forminator.
     209
     210                $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     211
     212                if ( $result ) {
     213                    $count++;
     214                }
     215            }
     216
     217            if ( $count > 0 ) {
     218                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry meta data (inserted ' . $count . ' rows into ' . $entry_meta_table . ').' );
     219            } else {
     220                if ( count( $form_fields ) > 0 ) {
     221                    Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry meta data.' );
     222                }
     223            }
    205224
    206225            complete_checkview_test( $checkview_test_id );
     226
    207227            // Delete entry.
    208228            Forminator_Form_Entry_Model::delete_by_entry( $entry_id );
  • checkview/trunk/includes/formhelpers/class-checkview-gforms-helper.php

    r3216431 r3323842  
    168168            foreach ( $form['fields'] as $key => $field ) {
    169169                if ( 'captcha' === $field->type || 'hcaptcha' === $field->type || 'turnstile' === $field->type ) {
     170                    Checkview_Admin_Logs::add( 'ip-logs', 'Unset captcha field type [' . $field->type . '].' );
     171
    170172                    unset( $fields[ $key ] );
    171173                }
     
    173175
    174176            $form['fields'] = $fields;
     177
    175178            return $form;
    176179        }
     
    186189         */
    187190        public function checkview_clone_entry( $entry, $form ) {
    188             $form_id           = rgar( $form, 'id' );
     191            $form_id = rgar( $form, 'id' );
    189192            $checkview_test_id = get_checkview_test_id();
    190193
     
    192195                $checkview_test_id = $form_id . gmdate( 'Ymd' );
    193196            }
     197
    194198            self::checkview_clone_gf_entry( $entry['id'], $form_id, $checkview_test_id );
     199
    195200            if ( isset( $entry['id'] ) ) {
    196201                GFAPI::delete_entry( $entry['id'] );
     
    285290            global $wpdb;
    286291
     292            Checkview_Admin_Logs::add( 'ip-logs', 'Cloning submission entry [' . $entry_id . '] with unique ID [' . $uid . ']...' );
     293
    287294            $tablename = $wpdb->prefix . 'gf_entry_meta';
    288             $rows      = $wpdb->get_results( $wpdb->prepare( 'Select * from ' . $tablename . ' where entry_id=%d and form_id=%d order by id ASC', $entry_id, $form_id ) );
     295            $rows = $wpdb->get_results( $wpdb->prepare( 'Select * from ' . $tablename . ' where entry_id=%d and form_id=%d order by id ASC', $entry_id, $form_id ) );
     296            $entry_meta_table = $wpdb->prefix . 'cv_entry_meta';
     297            $count = 0;
     298
    289299            foreach ( $rows as $row ) {
    290                 $table = $wpdb->prefix . 'cv_entry_meta';
    291300                $data  = array(
    292                     'uid'        => $uid,
    293                     'form_id'    => $row->form_id,
    294                     'entry_id'   => $row->entry_id,
    295                     'meta_key'   => $row->meta_key,
     301                    'uid' => $uid,
     302                    'form_id' => $row->form_id,
     303                    'entry_id' => $row->entry_id,
     304                    'meta_key' => $row->meta_key,
    296305                    'meta_value' => $row->meta_value,
    297306                );
    298                 $wpdb->insert( $table, $data );
    299             }
     307
     308                $result = $wpdb->insert( $entry_meta_table, $data );
     309
     310                if ( $result ) {
     311                    $count++;
     312                }
     313            }
     314
     315            if ( $count > 0 ) {
     316                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry meta data (inserted ' . $count . ' rows into ' . $entry_meta_table . ').' );
     317            } else {
     318                if ( count( $rows ) > 0 ) {
     319                    Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry meta data.' );
     320                }
     321            }
     322
    300323            $tablename = $wpdb->prefix . 'gf_entry';
    301             $row       = $wpdb->get_row( $wpdb->prepare( 'Select * from ' . $tablename . ' where id=%d and form_id=%d LIMIT 1', $entry_id, $form_id ), ARRAY_A );
     324            $row = $wpdb->get_row( $wpdb->prepare( 'Select * from ' . $tablename . ' where id=%d and form_id=%d LIMIT 1', $entry_id, $form_id ), ARRAY_A );
     325
    302326            unset( $row['id'] );
    303327            unset( $row['source_id'] );
    304             $table1           = $wpdb->prefix . 'cv_entry';
    305             $row['uid']       = $uid;
     328
     329            $entry_table = $wpdb->prefix . 'cv_entry';
     330            $row['uid'] = $uid;
    306331            $row['form_type'] = 'GravityForms';
    307             $wpdb->insert( $table1, $row );
     332            $result = $wpdb->insert( $entry_table, $row );
     333
     334            if ( ! $result ) {
     335                Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry data.' );
     336            } else {
     337                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry data (inserted ' . (int) $result . ' rows into ' . $entry_table . ').' );
     338            }
    308339        }
    309340
  • checkview/trunk/includes/formhelpers/class-checkview-ninja-forms-helper.php

    r3216431 r3323842  
    4242        public function __construct() {
    4343            $this->loader = new Checkview_Loader();
     44
    4445            add_action(
    4546                'ninja_forms_after_submission',
     
    5152                1
    5253            );
     54
    5355            add_filter(
    5456                'akismet_get_api_key',
     
    6567                20
    6668            );
     69
    6770            add_filter(
    6871                'ninja_forms_validate_fields',
     
    7982                999
    8083            );
     84
    8185            add_filter(
    8286                'ninja_forms_action_recaptcha__verify_response',
     
    8488                99
    8589            );
     90
    8691            if ( defined( 'TEST_EMAIL' ) ) {
    8792                add_filter(
     
    154159            $entry_id = isset( $form_data['actions']['save']['sub_id'] ) ? $form_data['actions']['save']['sub_id'] : 0;
    155160
     161            Checkview_Admin_Logs::add( 'ip-logs', 'Cloning submission entry [' . $entry_id . ']...' );
     162
    156163            $checkview_test_id = get_checkview_test_id();
    157164
     
    162169            // Insert Entry.
    163170            $entry_data  = array(
    164                 'form_id'      => $form_id,
    165                 'status'       => 'publish',
    166                 'source_url'   => isset( $_SERVER['HTTP_REFERER'] ) ? sanitize_url( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '',
     171                'form_id' => $form_id,
     172                'status' => 'publish',
     173                'source_url' => isset( $_SERVER['HTTP_REFERER'] ) ? sanitize_url( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '',
    167174                'date_created' => current_time( 'mysql' ),
    168175                'date_updated' => current_time( 'mysql' ),
    169                 'uid'          => $checkview_test_id,
    170                 'form_type'    => 'NinjaForms',
     176                'uid' => $checkview_test_id,
     177                'form_type' => 'NinjaForms',
    171178            );
    172179            $entry_table = $wpdb->prefix . 'cv_entry';
    173             $wpdb->insert( $entry_table, $entry_data );
    174             $inserted_entry_id = $wpdb->insert_id;
    175 
    176             // Insert entry meta.
     180
     181            $result = $wpdb->insert( $entry_table, $entry_data );
     182
     183            if ( ! $result ) {
     184                Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry data.' );
     185            } else {
     186                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry data (inserted ' . (int) $result . ' rows into ' . $entry_table . ').' );
     187            }
     188
    177189            $entry_meta_table = $wpdb->prefix . 'cv_entry_meta';
    178190            $field_id_prefix  = 'nf';
    179             $tablename        = $wpdb->prefix . 'postmeta';
    180             $form_fields      = $wpdb->get_results( $wpdb->prepare( 'Select * from ' . $tablename . ' where post_id=%d', $entry_id ) );
     191            $tablename = $wpdb->prefix . 'postmeta';
     192            $form_fields = $wpdb->get_results( $wpdb->prepare( 'Select * from ' . $tablename . ' where post_id=%d', $entry_id ) );
     193            $count = 0;
     194
    181195            foreach ( $form_fields as $field ) {
    182196                if ( ! in_array( $field->meta_key, array( '_form_id', '_seq_num' ) ) ) {
     
    188202                        'meta_value' => $field->meta_value,
    189203                    );
    190                     $wpdb->insert( $entry_meta_table, $entry_metadata );
     204
     205                    $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     206
     207                    if ( $result ) {
     208                        $count++;
     209                    }
     210                }
     211            }
     212
     213            if ( $count > 0 ) {
     214                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry meta data (inserted ' . $count . ' rows into ' . $entry_meta_table . ').' );
     215            } else {
     216                if ( count( $form_fields ) > 0 ) {
     217                    Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry meta data.' );
    191218                }
    192219            }
  • checkview/trunk/includes/formhelpers/class-checkview-wpforms-helper.php

    r3247217 r3323842  
    4242        public function __construct() {
    4343            $this->loader = new Checkview_Loader();
     44
    4445            if ( ! is_admin() ) {
    4546                include_once ABSPATH . 'wp-admin/includes/plugin.php';
    4647            }
    4748
    48             $old_settings = (array) get_option( 'wpforms_settings', array() );
    49             if ( ! empty( $old_settings['turnstile-site-key'] ) && null !== $old_settings['turnstile-site-key'] && null !== $old_settings['turnstile-secret-key'] ) {
    50                 if ( '1x00000000000000000000AA' !== $old_settings['turnstile-site-key'] ) {
    51                     update_option( 'checkview_wpforms_turnstile-site-key', $old_settings['turnstile-site-key'], true );
    52                     update_option( 'checkview_wpforms_turnstile-secret-key', $old_settings['turnstile-secret-key'], true );
    53                     $old_settings['turnstile-site-key']   = '1x00000000000000000000AA';
    54                     $old_settings['turnstile-secret-key'] = '1x0000000000000000000000000000000AA';
    55                     update_option( 'wpforms_settings', $old_settings );
    56                 }
    57             } else {
    58                 // Disable reCAPTCHA assets and initialisation on the frontend.
    59                 add_filter(
    60                     'wpforms_frontend_recaptcha_disable',
    61                     '__return_true',
    62                     99
    63                 );
    64             }
     49            add_filter( 'wpforms_frontend_form_data', array( $this, 'checkview_disable_turnstile' ) );
     50
     51            add_filter( 'wpforms_process_before_form_data', array( $this, 'checkview_disable_turnstile' ) );
     52
     53            add_filter( 'wpforms_frontend_captcha_api', array( $this, 'checkview_disable_frontend_captcha_api' ) );
     54
     55            add_filter( 'wpforms_frontend_recaptcha_disable', '__return_true', 99 );
    6556
    6657            // Disable validation and verification on the backend.
     
    150141
    151142        /**
     143         * Disable Cloudflare Turnstile.
     144         *
     145         * @param array $form_data Form data.
     146         *
     147         * @return array Modified form data.
     148         *
     149         * @since 2.0.19
     150         */
     151        public function checkview_disable_turnstile( $form_data ) {
     152            $form_data['settings']['recaptcha'] = '0';
     153
     154            return $form_data;
     155        }
     156
     157        /**
     158         * Disable WP Forms frontend CAPTCHA API.
     159         *
     160         * @param $captcha_api string CAPTCHA API.
     161         *
     162         * @return string
     163         *
     164         * @since 2.0.19
     165         */
     166        public function checkview_disable_frontend_captcha_api( $captcha_api ) {
     167            $captcha_settings = wpforms_get_captcha_settings();
     168
     169            if ( $captcha_settings['provider'] === 'turnstile' ) {
     170                return '';
     171            }
     172
     173            return $captcha_api;
     174        }
     175
     176        /**
    152177         * Injects testing email address.
    153178         *
     
    182207        public function checkview_log_wpform_test_entry( $form_fields, $entry, $form_data, $entry_id ) {
    183208            global $wpdb;
     209
     210            Checkview_Admin_Logs::add( 'ip-logs', 'Cloning submission entry [' . $entry_id . ']...' );
     211
    184212            if ( ! function_exists( 'is_plugin_active' ) ) {
    185213                include_once ABSPATH . 'wp-admin/includes/plugin.php';
    186214            }
    187215
    188             $form_id           = $form_data['id'];
     216            $form_id = $form_data['id'];
    189217            $checkview_test_id = get_checkview_test_id();
    190218
     
    194222
    195223            $entry_data  = array(
    196                 'form_id'      => $form_id,
    197                 'status'       => 'publish',
    198                 'source_url'   => isset( $_SERVER['HTTP_REFERER'] ) ? sanitize_url( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '',
     224                'form_id' => $form_id,
     225                'status' => 'publish',
     226                'source_url' => isset( $_SERVER['HTTP_REFERER'] ) ? sanitize_url( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '',
    199227                'date_created' => current_time( 'mysql' ),
    200228                'date_updated' => current_time( 'mysql' ),
    201                 'uid'          => $checkview_test_id,
    202                 'form_type'    => 'WpForms',
     229                'uid' => $checkview_test_id,
     230                'form_type' => 'WpForms',
    203231            );
    204232            $entry_table = $wpdb->prefix . 'cv_entry';
    205             $wpdb->insert( $entry_table, $entry_data );
     233
     234            $result = $wpdb->insert( $entry_table, $entry_data );
     235
     236            if ( ! $result ) {
     237                Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry data.' );
     238            } else {
     239                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry data (inserted ' . (int) $result . ' rows into ' . $entry_table . ').' );
     240            }
     241
    206242            $inserted_entry_id = $wpdb->insert_id;
    207243            $entry_meta_table  = $wpdb->prefix . 'cv_entry_meta';
    208244            $field_id_prefix   = 'wpforms-' . $form_id . '-field_';
     245            $count = 0;
     246
    209247            foreach ( $form_fields as $field ) {
    210 
    211248                if ( ! isset( $field['value'] ) || '' === $field['value'] ) {
    212249                    continue;
    213250                }
     251
    214252                $field_value = is_array( $field['value'] ) ? serialize( $field['value'] ) : $field['value'];
    215                 $type        = isset( $field['type'] ) ? $field['type'] : '';
     253                $type = isset( $field['type'] ) ? $field['type'] : '';
     254
    216255                switch ( $type ) {
    217256                    case 'name':
     
    224263                                'meta_value' => $field['first'],
    225264                            );
    226                             $wpdb->insert( $entry_meta_table, $entry_metadata );
    227 
     265
     266                            $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     267
     268                            if ( $result ) {
     269                                $count++;
     270                            }
    228271                        } elseif ( '' === $field['middle'] ) {
    229272                            $entry_metadata = array(
     
    234277                                'meta_value' => $field['first'],
    235278                            );
    236                             $wpdb->insert( $entry_meta_table, $entry_metadata );
    237                             $entry_metadata = array(
    238                                 'uid'        => $checkview_test_id,
    239                                 'form_id'    => $form_id,
    240                                 'entry_id'   => $inserted_entry_id,
    241                                 'meta_key'   => $field_id_prefix . $field['id'] . '-last',
     279
     280                            $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     281
     282                            if ( $result ) {
     283                                $count++;
     284                            }
     285
     286                            $entry_metadata = array(
     287                                'uid' => $checkview_test_id,
     288                                'form_id' => $form_id,
     289                                'entry_id' => $inserted_entry_id,
     290                                'meta_key' => $field_id_prefix . $field['id'] . '-last',
    242291                                'meta_value' => $field['last'],
    243292                            );
    244                             $wpdb->insert( $entry_meta_table, $entry_metadata );
    245 
     293
     294                            $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     295
     296                            if ( $result ) {
     297                                $count++;
     298                            }
    246299                        } else {
    247300                            $entry_metadata = array(
    248                                 'uid'        => $checkview_test_id,
    249                                 'form_id'    => $form_id,
    250                                 'entry_id'   => $inserted_entry_id,
    251                                 'meta_key'   => $field_id_prefix . $field['id'],
     301                                'uid' => $checkview_test_id,
     302                                'form_id' => $form_id,
     303                                'entry_id' => $inserted_entry_id,
     304                                'meta_key' => $field_id_prefix . $field['id'],
    252305                                'meta_value' => $field['first'],
    253306                            );
    254                             $wpdb->insert( $entry_meta_table, $entry_metadata );
    255                             $entry_metadata = array(
    256                                 'uid'        => $checkview_test_id,
    257                                 'form_id'    => $form_id,
    258                                 'entry_id'   => $inserted_entry_id,
    259                                 'meta_key'   => $field_id_prefix . $field['id'] . '-middle',
     307
     308                            $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     309
     310                            if ( $result ) {
     311                                $count++;
     312                            }
     313
     314                            $entry_metadata = array(
     315                                'uid' => $checkview_test_id,
     316                                'form_id' => $form_id,
     317                                'entry_id' => $inserted_entry_id,
     318                                'meta_key' => $field_id_prefix . $field['id'] . '-middle',
    260319                                'meta_value' => $field['middle'],
    261320                            );
    262                             $wpdb->insert( $entry_meta_table, $entry_metadata );
    263                             $entry_metadata = array(
    264                                 'uid'        => $checkview_test_id,
    265                                 'form_id'    => $form_id,
    266                                 'entry_id'   => $inserted_entry_id,
    267                                 'meta_key'   => $field_id_prefix . $field['id'] . '-last',
     321
     322                            $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     323
     324                            if ( $result ) {
     325                                $count++;
     326                            }
     327
     328                            $entry_metadata = array(
     329                                'uid' => $checkview_test_id,
     330                                'form_id' => $form_id,
     331                                'entry_id' => $inserted_entry_id,
     332                                'meta_key' => $field_id_prefix . $field['id'] . '-last',
    268333                                'meta_value' => $field['last'],
    269334                            );
    270                             $wpdb->insert( $entry_meta_table, $entry_metadata );
    271 
     335
     336                            $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     337
     338                            if ( $result ) {
     339                                $count++;
     340                            }
    272341                        }
    273342                        break;
    274343                    default:
    275344                        $entry_metadata = array(
    276                             'uid'        => $checkview_test_id,
    277                             'form_id'    => $form_id,
    278                             'entry_id'   => $inserted_entry_id,
    279                             'meta_key'   => $field_id_prefix . $field['id'],
     345                            'uid' => $checkview_test_id,
     346                            'form_id' => $form_id,
     347                            'entry_id' => $inserted_entry_id,
     348                            'meta_key' => $field_id_prefix . $field['id'],
    280349                            'meta_value' => $field_value,
    281350                        );
    282                         $wpdb->insert( $entry_meta_table, $entry_metadata );
     351
     352                        $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     353
     354                        if ( $result ) {
     355                            $count++;
     356                        }
     357
    283358                        break;
     359                }
     360            }
     361
     362            if ( $count > 0 ) {
     363                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry meta data (inserted ' . $count . ' rows into ' . $entry_meta_table . ').' );
     364            } else {
     365                if ( count( $form_fields ) > 0 ) {
     366                    Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry meta data.' );
    284367                }
    285368            }
     
    295378                    )
    296379                );
     380
    297381                $wpdb->delete(
    298382                    $wpdb->prefix . 'wpforms_entry_fields',
     
    303387                );
    304388            }
    305             $old_settings = (array) get_option( 'wpforms_settings', array() );
    306             if ( ! empty( $old_settings['turnstile-site-key'] ) && null !== $old_settings['turnstile-site-key'] && null !== $old_settings['turnstile-secret-key'] ) {
    307                 if ( '1x00000000000000000000AA' === $old_settings['turnstile-site-key'] ) {
    308                     $old_settings['turnstile-site-key']   = get_option( 'checkview_wpforms_turnstile-site-key' );
    309                     $old_settings['turnstile-secret-key'] = get_option( 'checkview_wpforms_turnstile-secret-key' );
    310                     update_option( 'wpforms_settings', $old_settings );
    311                 }
    312             }
    313389
    314390            complete_checkview_test( $checkview_test_id );
  • checkview/trunk/includes/formhelpers/class-checkview-wsf-helper.php

    r3216431 r3323842  
    4242        public function __construct() {
    4343            $this->loader = new Checkview_Loader();
     44
    4445            add_action(
    4546                'wsf_submit_post_complete',
     
    5152                1
    5253            );
     54
    5355            add_filter(
    5456                'akismet_get_api_key',
     
    6264                999
    6365            );
     66
    6467            if ( defined( 'TEST_EMAIL' ) ) {
    6568                add_filter(
     
    8386                2
    8487            );
     88
    8589            add_filter(
    8690                'wsf_config_meta_keys',
     
    96100                6
    97101            );
     102
    98103            add_filter(
    99104                'wsf_action_email_headers',
     
    157162                $headers = explode( "\r\n", $headers );
    158163            }
     164
    159165            $filtered_headers = array_filter(
    160166                $headers,
     
    164170                }
    165171            );
     172
    166173            return array_values( $filtered_headers );
    167174        }
     
    179186            $form_id  = $form_data->form_id;
    180187            $entry_id = $form_data->id;
    181 
    182188            $checkview_test_id = get_checkview_test_id();
     189
     190            Checkview_Admin_Logs::add( 'ip-logs', 'Cloning submission entry [' . $entry_id . ']...' );
    183191
    184192            if ( empty( $checkview_test_id ) ) {
    185193                $checkview_test_id = $form_id . gmdate( 'Ymd' );
    186194            }
     195
    187196            // Insert Entry.
    188197            $entry_data  = array(
    189                 'form_id'      => $form_id,
    190                 'status'       => 'publish',
    191                 'source_url'   => isset( $_SERVER['HTTP_REFERER'] ) ? sanitize_url( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '',
     198                'form_id' => $form_id,
     199                'status' => 'publish',
     200                'source_url' => isset( $_SERVER['HTTP_REFERER'] ) ? sanitize_url( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '',
    192201                'date_created' => current_time( 'mysql' ),
    193202                'date_updated' => current_time( 'mysql' ),
    194                 'uid'          => $checkview_test_id,
    195                 'form_type'    => 'WSForms',
     203                'uid' => $checkview_test_id,
     204                'form_type' => 'WSForms',
    196205            );
    197206            $entry_table = $wpdb->prefix . 'cv_entry';
    198             $wpdb->insert( $entry_table, $entry_data );
    199             $inserted_entry_id = $wpdb->insert_id;
    200 
    201             // Insert entry meta.
     207
     208            $result = $wpdb->insert( $entry_table, $entry_data );
     209
     210            if ( ! $result ) {
     211                Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry data.' );
     212            } else {
     213                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry data (inserted ' . (int) $result . ' rows into ' . $entry_table . ').' );
     214            }
     215
    202216            $entry_meta_table = $wpdb->prefix . 'cv_entry_meta';
    203217            $field_id_prefix  = 'wsf';
    204             $tablename        = $wpdb->prefix . 'wsf_submit_meta';
    205             $form_fields      = $wpdb->get_results( $wpdb->prepare( 'Select * from ' . $tablename . ' where parent_id=%d', $entry_id ) );
     218            $tablename = $wpdb->prefix . 'wsf_submit_meta';
     219            $form_fields = $wpdb->get_results( $wpdb->prepare( 'Select * from ' . $tablename . ' where parent_id=%d', $entry_id ) );
     220            $count = 0;
     221
    206222            foreach ( $form_fields as $field ) {
    207223                if ( ! in_array( $field->meta_key, array( '_form_id', 'post_id', 'wsf_meta_key_hidden' ) ) ) {
    208224                    $entry_metadata = array(
    209                         'uid'        => $checkview_test_id,
    210                         'form_id'    => $form_id,
    211                         'entry_id'   => $entry_id,
    212                         'meta_key'   => $field_id_prefix . str_replace( '_', '-', $field->meta_key ),
     225                        'uid' => $checkview_test_id,
     226                        'form_id' => $form_id,
     227                        'entry_id' => $entry_id,
     228                        'meta_key' => $field_id_prefix . str_replace( '_', '-', $field->meta_key ),
    213229                        'meta_value' => $field->meta_value,
    214230                    );
    215                     $wpdb->insert( $entry_meta_table, $entry_metadata );
    216                 }
    217             }
    218             update_option( $checkview_test_id . '_wsf_entry_id', $entry_id );
    219             update_option( $checkview_test_id . '_wsf_frm_id', $form_id );
     231
     232                    $result = $wpdb->insert( $entry_meta_table, $entry_metadata );
     233
     234                    if ( $result ) {
     235                        $count++;
     236                    }
     237                }
     238            }
     239
     240            if ( $count > 0 ) {
     241                Checkview_Admin_Logs::add( 'ip-logs', 'Cloned submission entry meta data (inserted ' . $count . ' rows into ' . $entry_meta_table . ').' );
     242            } else {
     243                if ( count( $form_fields ) > 0 ) {
     244                    Checkview_Admin_Logs::add( 'ip-logs', 'Failed to clone submission entry meta data.' );
     245                }
     246            }
     247
     248            cv_update_option( $checkview_test_id . '_wsf_entry_id', $entry_id );
     249            cv_update_option( $checkview_test_id . '_wsf_frm_id', $form_id );
     250
    220251            complete_checkview_test( $checkview_test_id );
    221252        }
  • checkview/trunk/includes/woocommercehelper/class-checkview-woo-automated-testing.php

    r3303097 r3323842  
    564564     */
    565565    public function checkview_test_mode() {
    566 
    567         // Current Vsitor IP.
    568566        $visitor_ip = checkview_get_visitor_ip();
    569         // Check view Bot IP.
    570567        $cv_bot_ip = checkview_get_api_ip();
     568
    571569        if ( ! is_array( $cv_bot_ip ) || ! in_array( $visitor_ip, $cv_bot_ip ) ) {
    572 
    573570            return;
    574571        }
    575         Checkview_Admin_Logs::add( 'ip-logs', wp_json_encode( $cv_bot_ip ) . 'bot IP' );
    576         Checkview_Admin_Logs::add( 'ip-logs', wp_json_encode( $visitor_ip ) . 'visitor IP' );
     572
     573        Checkview_Admin_Logs::add( 'ip-logs', 'Running Woo test mode hooks, visitor IP [' . $visitor_ip . '] matched a bot IP.' );
     574
    577575        if ( ! is_admin() && class_exists( 'WooCommerce' ) ) {
    578576            // Always use Stripe test mode when on dev or staging.
     
    580578                'option_woocommerce_stripe_settings',
    581579                function ( $value ) {
     580                    Checkview_Admin_Logs::add( 'ip-logs', 'Setting Woo test mode to true for hook [option_woocommerce_stripe_settings].' );
    582581
    583582                    $value['testmode'] = 'yes';
     
    586585                }
    587586            );
     587
    588588            // Turn test mode on for stripe payments.
    589589            add_filter(
    590590                'wc_stripe_mode',
    591591                function ( $mode ) {
     592                    Checkview_Admin_Logs::add( 'ip-logs', 'Setting Woo test mode to true for hook [wc_stripe_mode].' );
    592593
    593594                    $mode = 'test';
     
    615616                'checkview_woocommerce_block_support',
    616617            );
     618
    617619            add_filter(
    618620                'cfturnstile_whitelisted',
     
    620622                999
    621623            );
     624
    622625            // Make the test product visible in the catalog.
    623626            add_filter(
    624627                'woocommerce_product_is_visible',
    625                 function ( $visible, $product_id ) {
     628                function ( bool $visible, $product_id ) {
    626629                    $product = $this->checkview_get_test_product();
    627630
     
    630633                    }
    631634
    632                     return $product_id === $product->get_id() ? true : $visible;
     635                    $is_visible = $product_id === $product->get_id() ? true : $visible;
     636
     637                    if ($is_visible) {
     638                        Checkview_Admin_Logs::add( 'ip-logs', 'Setting Woo test product visibility to true.' );
     639
     640                        return true;
     641                    }
     642
     643                    return false;
    633644                },
    634645                9999,
    635646                2
    636647            );
     648
    637649            $this->loader->add_action(
    638650                'woocommerce_order_status_changed',
     
    642654                3
    643655            );
    644         }
    645     }
     656        } else {
     657            Checkview_Admin_Logs::add( 'ip-logs', 'No Woo hooks were ran (WooCommerce was not found or client is requesting admin area).' );
     658        }
     659    }
     660
    646661    /**
    647662     * Returns false.
     
    729744     * Adds CheckView dummy payment gateway to Woo.
    730745     *
    731      * @param string $methods Methods to add payments.
    732      * @return array
     746     * @param string[] $methods Methods to add payments.
     747     * @return string[]
    733748     */
    734749    public function checkview_add_payment_gateway( $methods ) {
    735         $methods[] = 'Checkview_Payment_Gateway';
     750        $gateway = 'Checkview_Payment_Gateway';
     751
     752        Checkview_Admin_Logs::add( 'ip-logs', 'Adding Woo payment gateway [' . $gateway . '].' );
     753
     754        $methods[] = $gateway;
     755
    736756        return $methods;
    737757    }
     
    749769                'woocommerce_blocks_payment_method_type_registration',
    750770                function ( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     771                    Checkview_Admin_Logs::add( 'ip-logs', 'Added Woo Blocks payment gateway.' );
     772
    751773                    $payment_method_registry->register( new Checkview_Blocks_Payment_Gateway() );
    752774                }
     
    767789            return;
    768790        }
     791
    769792        return $this->checkview_delete_orders();
    770793    }
     
    777800     */
    778801    public function checkview_delete_orders( $order_id = '' ) {
    779 
    780         global $wpdb;
     802        Checkview_Admin_Logs::add( 'ip-logs', 'Deleting CheckView orders from the database...' );
     803
    781804        $orders = array();
    782         // WPDBPREPARE.
    783         if ( empty( $orders ) || false === $orders ) {
    784             $args = array(
    785                 'limit'        => -1,
    786                 'type'         => 'shop_order',
    787                 'meta_key'     => 'payment_made_by', // Postmeta key field.
    788                 'meta_value'   => 'checkview', // Postmeta value field.
    789                 'meta_compare' => '=',
    790                 'return'       => 'ids',
    791             );
    792             if ( function_exists( 'wc_get_orders' ) ) {
    793                 $orders = wc_get_orders( $args );
    794             }
    795             $orders_cv = array();
    796             $args      = array(
    797                 'limit'          => -1,
    798                 'type'           => 'shop_order',
    799                 'payment_method' => 'checkview',
    800                 'return'         => 'ids',
    801             );
    802             if ( function_exists( 'wc_get_orders' ) ) {
    803                 $orders_cv = wc_get_orders( $args );
    804             }
    805             $orders = array_unique( array_merge( $orders, $orders_cv ) );
    806 
    807         }
     805        $args = array(
     806            'limit' => -1,
     807            'type' => 'shop_order',
     808            'meta_key' => 'payment_made_by', // Postmeta key field.
     809            'meta_value' => 'checkview', // Postmeta value field.
     810            'meta_compare' => '=',
     811            'return' => 'ids',
     812        );
     813
     814        if ( function_exists( 'wc_get_orders' ) ) {
     815            $orders = wc_get_orders( $args );
     816        }
     817
     818        $orders_cv = array();
     819        $args = array(
     820            'limit' => -1,
     821            'type' => 'shop_order',
     822            'payment_method' => 'checkview',
     823            'return' => 'ids',
     824        );
     825
     826        if ( function_exists( 'wc_get_orders' ) ) {
     827            $orders_cv = wc_get_orders( $args );
     828        }
     829
     830        $orders = array_unique( array_merge( $orders, $orders_cv ) );
     831
     832        Checkview_Admin_Logs::add( 'cron-logs', 'Found ' . count( $orders ) . ' CheckView orders to delete.' );
     833
    808834        // Delete orders.
    809835        if ( ! empty( $orders ) ) {
    810836            foreach ( $orders as $order ) {
    811 
     837                $order_object = wc_get_order( $order );
     838
     839                // Delete order.
    812840                try {
    813                     $order_object = wc_get_order( $order );
    814                     // Delete order.
    815841                    if ( $order_object && method_exists( $order_object, 'get_customer_id' ) ) {
    816842                        if ( $order_object->get_meta( 'payment_made_by' ) !== 'checkview' && 'checkview' !== $order_object->get_payment_method() ) {
    817843                            continue;
    818844                        }
     845
    819846                        $customer_id = $order_object->get_customer_id();
    820847                        $order_object->delete( true );
     848
    821849                        delete_transient( 'checkview_store_orders_transient' );
    822850
    823851                        $order_object = null;
    824852                        $current_user = get_user_by( 'id', $customer_id );
     853
    825854                        // Delete customer if available.
    826855                        if ( $customer_id && isset( $current_user->roles ) && isset( $current_user->roles ) && ! in_array( 'administrator', $current_user->roles, true ) ) {
     
    831860                            }
    832861
    833                             $res      = $customer->delete( true );
     862                            $res = $customer->delete( true );
    834863                            $customer = null;
    835864                        }
     
    839868                        require_once CHECKVIEW_ADMIN_DIR . '/class-checkview-admin-logs.php';
    840869                    }
    841                     Checkview_Admin_Logs::add( 'cron-logs', 'Crone job failed.' );
     870
     871                    if ($order_object) {
     872                        Checkview_Admin_Logs::add( 'cron-logs', 'Failed to delete CheckView order [' . $order_object->get_id() . '] from the database.' );
     873                    } else {
     874                        Checkview_Admin_Logs::add( 'cron-logs', 'Failed to delete CheckView order from the database.' );
     875                    }
     876
    842877                }
    843878            }
     879
    844880            return true;
    845881        }
     
    858894            $order = new WC_Order( $order_id );
    859895            $order->update_meta_data( 'payment_made_by', 'checkview' );
    860 
    861896            $order->update_meta_data( 'checkview_test_id', sanitize_text_field( wp_unslash( $_COOKIE['checkview_test_id'] ) ) );
     897
     898            Checkview_Admin_Logs::add( 'ip-logs', 'Added meta data to test order.' );
     899
    862900            complete_checkview_test( sanitize_text_field( wp_unslash( $_COOKIE['checkview_test_id'] ) ) );
    863901
    864902            $order->save();
     903
     904            Checkview_Admin_Logs::add( 'ip-logs', 'Saved new order [' . $order->get_id() . '].' );
     905
    865906            unset( $_COOKIE['checkview_test_id'] );
    866907            setcookie( 'checkview_test_id', '', time() - 6600, COOKIEPATH, COOKIE_DOMAIN );
Note: See TracChangeset for help on using the changeset viewer.