Plugin Directory

Changeset 3296764


Ignore:
Timestamp:
05/19/2025 07:12:10 PM (10 months ago)
Author:
checkview
Message:

Update to version 2.0.16 from GitHub

Location:
checkview
Files:
8 edited
1 copied

Legend:

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

    r3294839 r3296764  
    88License: GPLv3
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html
    10 Stable tag: 2.0.15
     10Stable tag: 2.0.16
    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.16 =
     89* Check status of CleanTalk token before attempting API requests.
     90* Separate transients for CleanTalk Antispam and CleanTalk Spam Firewall IPs.
     91* Improve validation and handling of data from CleanTalk requests.
     92* Utilize CleanTalk service ID for requests, greatly reducing CleanTalk API response times.
     93* Lower CleanTalk API timeout errors.
     94* Correct record types in CleanTalk POST requests.
     95* Loosen checks for IPs/domains in CleanTalk responses.
     96* Improve logging.
     97
    8898= 2.0.15 =
    8999* Fixed an issue where CleanTalk requests were not properly being requested and cached.
     
    341351
    342352== Upgrade Notice ==
     353= 2.0.16 =
     354* Check status of CleanTalk token before attempting API requests.
     355* Separate transients for CleanTalk Antispam and CleanTalk Spam Firewall IPs.
     356* Improve validation and handling of data from CleanTalk requests.
     357* Utilize CleanTalk service ID for requests, greatly reducing CleanTalk API response times.
     358* Lower CleanTalk API timeout errors.
     359* Correct record types in CleanTalk POST requests.
     360* Loosen checks for IPs/domains in CleanTalk responses.
     361* Improve logging.
     362
    343363= 2.0.15 =
    344364* Fixed an issue where CleanTalk requests were not properly being requested and cached.
  • checkview/tags/2.0.16/checkview.php

    r3294839 r3296764  
    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.15
     14 * Version:           2.0.16
    1515 * Author:            CheckView
    1616 * Author URI:        https://checkview.io/
     
    3636 * @link https://semver.org
    3737 */
    38 define( 'CHECKVIEW_VERSION', '2.0.15' );
     38define( 'CHECKVIEW_VERSION', '2.0.16' );
    3939
    4040if ( ! defined( 'CHECKVIEW_BASE_DIR' ) ) {
  • checkview/tags/2.0.16/includes/checkview-functions.php

    r3294839 r3296764  
    360360     *
    361361     * @param string $service_type Service type.
    362      * @return array List of whitelisted IPs.
    363      */
    364     function checkview_get_cleantalk_whitelisted_ips( $service_type = 'antispam' ) {
    365         $ip_array = get_transient( 'checkview_whitelisted_ips' );
     362     * @param string $service_id Service ID.
     363     * @return array|false List of whitelisted IPs, false on error.
     364     */
     365    function checkview_get_cleantalk_whitelisted_ips( $service_type = 'antispam', $service_id = 'all' ) {
     366        $ip_array = get_transient( 'checkview_whitelisted_ips_' . $service_type );
     367
    366368        if ( ! empty( $ip_array ) && is_array( $ip_array ) ) {
    367369            return $ip_array;
    368370        }
     371
    369372        $spbc_data  = get_option( 'cleantalk_data', array() );
    370373        $user_token = $spbc_data['user_token'];
    371 
    372         // CleanTalk API endpoint to get whitelisted IPs.
    373         $api_url = "https://api.cleantalk.org/?method_name=private_list_get&user_token=$user_token&service_type=" . $service_type . '&product_id=1';
    374 
    375         // Perform a remote GET request using WordPress' wp_remote_get() function.
    376         $response = wp_remote_get( $api_url );
     374        $api_url = "https://api.cleantalk.org/?method_name=private_list_get&user_token=$user_token&service_type=" . $service_type . '&product_id=1&service_id=' . $service_id;
     375
     376        $response = wp_remote_get( $api_url, array(
     377            'timeout' => 20,
     378        ) );
    377379
    378380        if ( is_wp_error( $response ) ) {
     
    380382            Checkview_Admin_Logs::add( 'ip-logs', esc_html__( 'Error fetching whitelisted IPs: ' . $response->get_error_message(), 'checkview' ) );
    381383
    382             return array();
     384            return false;
    383385        }
    384386
     
    393395
    394396        // Check if we have valid data.
    395         if ( isset( $whitelisted_ips['data'] ) && ! empty( $whitelisted_ips['data'] ) ) {
     397        if ( isset( $whitelisted_ips['data'] ) && is_array( $whitelisted_ips['data'] ) && ! empty( $whitelisted_ips['data'] ) ) {
    396398            // Loop through and add IPs to the array.
    397399            foreach ( $whitelisted_ips['data'] as $entry ) {
     
    402404            }
    403405        }
    404         set_transient( 'checkview_whitelisted_ips', $ip_array, 12 * HOUR_IN_SECONDS );
     406
     407        set_transient( 'checkview_whitelisted_ips_' . $service_type, $ip_array, 12 * HOUR_IN_SECONDS );
     408
    405409        return $ip_array;
    406410    }
     
    412416     *
    413417     * @since 1.0.0
    414      *
    415      * @modified 2.0.13
    416      * @updated  2.0.14
    417      * @return mixed
     418     *
     419     * @return null
    418420     */
    419421    function checkview_whitelist_api_ip() {
     422        global $apbct;
     423
     424        if ( ! isset($apbct->data['service_id'] ) ) {
     425            error_log( 'CleanTalk service ID could not be found.' );
     426        }
     427
     428        $service_id = $apbct->data['service_id'];
    420429        $spbc_data  = get_option( 'cleantalk_data', array() );
    421430        $user_token = $spbc_data['user_token'];
     431
     432        if ( empty( $user_token ) || ( function_exists('apbct_api_key__is_correct') && ! apbct_api_key__is_correct() ) ) {
     433            return null;
     434        }
     435
    422436        $current_ip = checkview_get_visitor_ip();
    423437        $api_ip     = checkview_get_api_ip();
    424438
    425439        if ( is_array( $api_ip ) && in_array( $current_ip, $api_ip ) ) {
    426             $host_name = parse_url( home_url(), PHP_URL_HOST );
     440            $home_url = parse_url( home_url() ); // Returns `false`, `null`, or an assosiative array.
     441
     442            if ( $home_url === false || $home_url === null ) {
     443                error_log( sprintf( 'Error parsing the home url [%1$s].', home_url() ) );
     444                Checkview_Admin_Logs::add( 'ip-logs', sprintf( 'Error parsing the home url [%1$s].', home_url() ) );
     445
     446                return null;
     447            }
     448
     449            if ( is_array( $home_url ) && ! isset( $home_url[ 'host' ] ) ) {
     450                error_log( sprintf( 'Cannot determine host when parsing URL [%1$s].', json_encode( $home_url ) ) );
     451                Checkview_Admin_Logs::add( 'ip-logs', sprintf( 'Cannot determine host when parsing URL [%1$s].', json_encode( $home_url ) ) );
     452
     453                return null;
     454            }
     455
     456            $host_name = $home_url['host'];
    427457
    428458            // Check antispam whitelist.
    429             $antispam_ips = checkview_get_cleantalk_whitelisted_ips( 'antispam' );
    430 
    431             if ( ! in_array( $current_ip, $antispam_ips[ $host_name ] ) ) {
    432                 checkview_add_to_cleantalk( $user_token, 'antispam', $current_ip, 1 );
    433             }
    434 
    435             if ( ! in_array( 'checkview.io', $antispam_ips[ $host_name ] ) ) {
    436                 checkview_add_to_cleantalk( $user_token, 'antispam', 'checkview.io', 1 );
    437             }
    438 
    439             if ( ! in_array( 'test-mail.checkview.io', $antispam_ips[ $host_name ] ) ) {
    440                 checkview_add_to_cleantalk( $user_token, 'antispam', 'test-mail.checkview.io', 4 );
     459            $antispam_ips = checkview_get_cleantalk_whitelisted_ips( 'antispam', $service_id );
     460
     461            if ( is_array( $antispam_ips ) ) {
     462                if ( ! isset( $antispam_ips[ $host_name ] ) ) {
     463                    error_log( 'No host name found in Antispam IP list.' );
     464
     465                    // If the host name is not in the whitelist, request to add our IPs/hosts.
     466                    checkview_add_to_cleantalk( $user_token, 'antispam', $current_ip, 1, $service_id );
     467                    checkview_add_to_cleantalk( $user_token, 'antispam', 'checkview.io', 4, $service_id );
     468                    checkview_add_to_cleantalk( $user_token, 'antispam', 'test-mail.checkview.io', 4, $service_id );
     469                } else {
     470                    // Otherwise, check for our IPs/hosts individually, and request to add them if needed.
     471                    if ( is_array( $antispam_ips[ $host_name ] ) ) {
     472                        $has_current_ip = array_find( $antispam_ips[ $host_name ], function( $value, $key ) use ($current_ip) {
     473                            $position = strpos( $value, $current_ip );
     474
     475                            return $position === false ? false : true;
     476                        });
     477
     478                        if ( ! $has_current_ip ) {
     479                            checkview_add_to_cleantalk( $user_token, 'antispam', $current_ip, 1, $service_id );
     480                        }
     481
     482                        $has_checkview_hostname = array_find( $antispam_ips[ $host_name ], function( $value, $key ) {
     483                            $position = strpos( $value, 'checkview.io' );
     484
     485                            // Skip test-mail domain
     486                            if ($value === 'test-mail.checkview.io') {
     487                                return false;
     488                            }
     489
     490                            return $position === false ? false : true;
     491                        });
     492
     493                        if ( ! $has_checkview_hostname ) {
     494                            checkview_add_to_cleantalk( $user_token, 'antispam', 'checkview.io', 4, $service_id );
     495                        }
     496
     497                        $has_mail_hostname = array_find( $antispam_ips[ $host_name ], function( $value, $key ) {
     498                            $position = strpos( $value, 'test-mail.checkview.io' );
     499
     500                            return $position === false ? false : true;
     501                        });
     502
     503                        if ( ! $has_mail_hostname ) {
     504                            checkview_add_to_cleantalk( $user_token, 'antispam', 'test-mail.checkview.io', 4, $service_id );
     505                        }
     506                    } else {
     507                        error_log( sprintf( 'The value for antispam IPs at hostname [%1$s] is not an array.', $host_name ) );
     508                        Checkview_Admin_Logs::add( 'ip-logs', sprintf( 'The value for antispam IPs at hostname [%1$s] is not an array.', $host_name ) );
     509                    }
     510                }
    441511            }
    442512
    443513            // Check spamfirewall whitelist.
    444             $spamfirewall_ips = checkview_get_cleantalk_whitelisted_ips( 'spamfirewall' );
    445 
    446             if ( empty( $spamfirewall_ips[ $host_name ] ) || ! in_array( $current_ip, $spamfirewall_ips[ $host_name ] ) ) {
    447                 checkview_add_to_cleantalk( $user_token, 'spamfirewall', $current_ip . '/32', 6 );
    448             }
    449         }
     514            $spamfirewall_ips = checkview_get_cleantalk_whitelisted_ips( 'spamfirewall', $service_id );
     515
     516            if ( is_array( $spamfirewall_ips ) ) {
     517                if ( ! isset( $spamfirewall_ips[ $host_name ] ) ) {
     518                    error_log( 'No host name found in Spam Firewall IP list.' );
     519
     520                    // If host name is not set, request to add it.
     521                    checkview_add_to_cleantalk( $user_token, 'spamfirewall', $current_ip . '/32', 6, $service_id );
     522                } else {
     523                    if ( is_array( $spamfirewall_ips[ $host_name ] ) ) {
     524                        $has_current_ip = array_find( $spamfirewall_ips[ $host_name ], function( $value, $key ) use ($current_ip) {
     525                            $position = strpos( $value, $current_ip );
     526
     527                            return $position === false ? false : true;
     528                        });
     529
     530                        if ( ! $has_current_ip ) {
     531                            checkview_add_to_cleantalk( $user_token, 'spamfirewall', $current_ip, 6, $service_id );
     532                        }
     533                    } else {
     534                        error_log( sprintf( 'Value for spam firewall IPs at hostname [%1$s] is unexpected type [%2$s], expected array.', $host_name, gettype( $antispam_ips[ $host_name ] ) ) );
     535                        Checkview_Admin_Logs::add( 'ip-logs', sprintf( 'Value for spam firewall IPs at hostname [%1$s] is unexpected type [%2$s], expected array.', $host_name, gettype( $antispam_ips[ $host_name ] ) ) );
     536                    }
     537                }
     538            }
     539        }
     540
    450541        return null;
    451542    }
     
    461552     * @param string $record Record.
    462553     * @param string $record_type Record type.
     554     * @param string $service_id Service ID.
    463555     * @return mixed
    464556     */
    465     function checkview_add_to_cleantalk( $user_token, $service_type, $record, $record_type ) {
     557    function checkview_add_to_cleantalk( $user_token, $service_type, $record, $record_type, $service_id ) {
     558        error_log( sprintf(
     559            'Adding record [%1$s] with type [%2$s] and service type [%3$s] to CleanTalk\'s API with service id [%4$s]',
     560            $record,
     561            $record_type,
     562            $service_type,
     563            $service_id,
     564        ) );
     565
    466566        $response = wp_remote_get(
    467567            'https://api.cleantalk.org/?method_name=private_list_add&user_token=' . $user_token .
    468             '&service_id=all&service_type=' . $service_type .
     568            '&service_id=' . $service_id . '&service_type=' . $service_type .
    469569            '&product_id=1&record_type=' . $record_type .
    470570            '&status=allow&note=Checkview Bot&records=' . $record,
    471571            array(
    472572                'method'  => 'POST',
    473                 'timeout' => 30,
     573                'timeout' => 20,
    474574            )
    475575        );
     576
     577        delete_transient('checkview_whitelisted_ips_' . $service_type);
    476578
    477579        if ( is_wp_error( $response ) ) {
     
    638740        delete_transient( 'checkview_store_products_transient' );
    639741        delete_transient( 'checkview_store_shipping_transient' );
    640         delete_transient( 'checkview_whitelisted_ips' );
     742        delete_transient( 'checkview_whitelisted_ips_spamfirewall' );
     743        delete_transient( 'checkview_whitelisted_ips_antispam' );
    641744        $sync = true;
    642745        return $sync;
  • checkview/tags/2.0.16/includes/class-checkview.php

    r3294839 r3296764  
    7171            $this->version = CHECKVIEW_VERSION;
    7272        } else {
    73             $this->version = '2.0.15';
     73            $this->version = '2.0.16';
    7474        }
    7575        $this->plugin_name = 'checkview';
  • checkview/trunk/README.txt

    r3294839 r3296764  
    88License: GPLv3
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html
    10 Stable tag: 2.0.15
     10Stable tag: 2.0.16
    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.16 =
     89* Check status of CleanTalk token before attempting API requests.
     90* Separate transients for CleanTalk Antispam and CleanTalk Spam Firewall IPs.
     91* Improve validation and handling of data from CleanTalk requests.
     92* Utilize CleanTalk service ID for requests, greatly reducing CleanTalk API response times.
     93* Lower CleanTalk API timeout errors.
     94* Correct record types in CleanTalk POST requests.
     95* Loosen checks for IPs/domains in CleanTalk responses.
     96* Improve logging.
     97
    8898= 2.0.15 =
    8999* Fixed an issue where CleanTalk requests were not properly being requested and cached.
     
    341351
    342352== Upgrade Notice ==
     353= 2.0.16 =
     354* Check status of CleanTalk token before attempting API requests.
     355* Separate transients for CleanTalk Antispam and CleanTalk Spam Firewall IPs.
     356* Improve validation and handling of data from CleanTalk requests.
     357* Utilize CleanTalk service ID for requests, greatly reducing CleanTalk API response times.
     358* Lower CleanTalk API timeout errors.
     359* Correct record types in CleanTalk POST requests.
     360* Loosen checks for IPs/domains in CleanTalk responses.
     361* Improve logging.
     362
    343363= 2.0.15 =
    344364* Fixed an issue where CleanTalk requests were not properly being requested and cached.
  • checkview/trunk/checkview.php

    r3294839 r3296764  
    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.15
     14 * Version:           2.0.16
    1515 * Author:            CheckView
    1616 * Author URI:        https://checkview.io/
     
    3636 * @link https://semver.org
    3737 */
    38 define( 'CHECKVIEW_VERSION', '2.0.15' );
     38define( 'CHECKVIEW_VERSION', '2.0.16' );
    3939
    4040if ( ! defined( 'CHECKVIEW_BASE_DIR' ) ) {
  • checkview/trunk/includes/checkview-functions.php

    r3294839 r3296764  
    360360     *
    361361     * @param string $service_type Service type.
    362      * @return array List of whitelisted IPs.
    363      */
    364     function checkview_get_cleantalk_whitelisted_ips( $service_type = 'antispam' ) {
    365         $ip_array = get_transient( 'checkview_whitelisted_ips' );
     362     * @param string $service_id Service ID.
     363     * @return array|false List of whitelisted IPs, false on error.
     364     */
     365    function checkview_get_cleantalk_whitelisted_ips( $service_type = 'antispam', $service_id = 'all' ) {
     366        $ip_array = get_transient( 'checkview_whitelisted_ips_' . $service_type );
     367
    366368        if ( ! empty( $ip_array ) && is_array( $ip_array ) ) {
    367369            return $ip_array;
    368370        }
     371
    369372        $spbc_data  = get_option( 'cleantalk_data', array() );
    370373        $user_token = $spbc_data['user_token'];
    371 
    372         // CleanTalk API endpoint to get whitelisted IPs.
    373         $api_url = "https://api.cleantalk.org/?method_name=private_list_get&user_token=$user_token&service_type=" . $service_type . '&product_id=1';
    374 
    375         // Perform a remote GET request using WordPress' wp_remote_get() function.
    376         $response = wp_remote_get( $api_url );
     374        $api_url = "https://api.cleantalk.org/?method_name=private_list_get&user_token=$user_token&service_type=" . $service_type . '&product_id=1&service_id=' . $service_id;
     375
     376        $response = wp_remote_get( $api_url, array(
     377            'timeout' => 20,
     378        ) );
    377379
    378380        if ( is_wp_error( $response ) ) {
     
    380382            Checkview_Admin_Logs::add( 'ip-logs', esc_html__( 'Error fetching whitelisted IPs: ' . $response->get_error_message(), 'checkview' ) );
    381383
    382             return array();
     384            return false;
    383385        }
    384386
     
    393395
    394396        // Check if we have valid data.
    395         if ( isset( $whitelisted_ips['data'] ) && ! empty( $whitelisted_ips['data'] ) ) {
     397        if ( isset( $whitelisted_ips['data'] ) && is_array( $whitelisted_ips['data'] ) && ! empty( $whitelisted_ips['data'] ) ) {
    396398            // Loop through and add IPs to the array.
    397399            foreach ( $whitelisted_ips['data'] as $entry ) {
     
    402404            }
    403405        }
    404         set_transient( 'checkview_whitelisted_ips', $ip_array, 12 * HOUR_IN_SECONDS );
     406
     407        set_transient( 'checkview_whitelisted_ips_' . $service_type, $ip_array, 12 * HOUR_IN_SECONDS );
     408
    405409        return $ip_array;
    406410    }
     
    412416     *
    413417     * @since 1.0.0
    414      *
    415      * @modified 2.0.13
    416      * @updated  2.0.14
    417      * @return mixed
     418     *
     419     * @return null
    418420     */
    419421    function checkview_whitelist_api_ip() {
     422        global $apbct;
     423
     424        if ( ! isset($apbct->data['service_id'] ) ) {
     425            error_log( 'CleanTalk service ID could not be found.' );
     426        }
     427
     428        $service_id = $apbct->data['service_id'];
    420429        $spbc_data  = get_option( 'cleantalk_data', array() );
    421430        $user_token = $spbc_data['user_token'];
     431
     432        if ( empty( $user_token ) || ( function_exists('apbct_api_key__is_correct') && ! apbct_api_key__is_correct() ) ) {
     433            return null;
     434        }
     435
    422436        $current_ip = checkview_get_visitor_ip();
    423437        $api_ip     = checkview_get_api_ip();
    424438
    425439        if ( is_array( $api_ip ) && in_array( $current_ip, $api_ip ) ) {
    426             $host_name = parse_url( home_url(), PHP_URL_HOST );
     440            $home_url = parse_url( home_url() ); // Returns `false`, `null`, or an assosiative array.
     441
     442            if ( $home_url === false || $home_url === null ) {
     443                error_log( sprintf( 'Error parsing the home url [%1$s].', home_url() ) );
     444                Checkview_Admin_Logs::add( 'ip-logs', sprintf( 'Error parsing the home url [%1$s].', home_url() ) );
     445
     446                return null;
     447            }
     448
     449            if ( is_array( $home_url ) && ! isset( $home_url[ 'host' ] ) ) {
     450                error_log( sprintf( 'Cannot determine host when parsing URL [%1$s].', json_encode( $home_url ) ) );
     451                Checkview_Admin_Logs::add( 'ip-logs', sprintf( 'Cannot determine host when parsing URL [%1$s].', json_encode( $home_url ) ) );
     452
     453                return null;
     454            }
     455
     456            $host_name = $home_url['host'];
    427457
    428458            // Check antispam whitelist.
    429             $antispam_ips = checkview_get_cleantalk_whitelisted_ips( 'antispam' );
    430 
    431             if ( ! in_array( $current_ip, $antispam_ips[ $host_name ] ) ) {
    432                 checkview_add_to_cleantalk( $user_token, 'antispam', $current_ip, 1 );
    433             }
    434 
    435             if ( ! in_array( 'checkview.io', $antispam_ips[ $host_name ] ) ) {
    436                 checkview_add_to_cleantalk( $user_token, 'antispam', 'checkview.io', 1 );
    437             }
    438 
    439             if ( ! in_array( 'test-mail.checkview.io', $antispam_ips[ $host_name ] ) ) {
    440                 checkview_add_to_cleantalk( $user_token, 'antispam', 'test-mail.checkview.io', 4 );
     459            $antispam_ips = checkview_get_cleantalk_whitelisted_ips( 'antispam', $service_id );
     460
     461            if ( is_array( $antispam_ips ) ) {
     462                if ( ! isset( $antispam_ips[ $host_name ] ) ) {
     463                    error_log( 'No host name found in Antispam IP list.' );
     464
     465                    // If the host name is not in the whitelist, request to add our IPs/hosts.
     466                    checkview_add_to_cleantalk( $user_token, 'antispam', $current_ip, 1, $service_id );
     467                    checkview_add_to_cleantalk( $user_token, 'antispam', 'checkview.io', 4, $service_id );
     468                    checkview_add_to_cleantalk( $user_token, 'antispam', 'test-mail.checkview.io', 4, $service_id );
     469                } else {
     470                    // Otherwise, check for our IPs/hosts individually, and request to add them if needed.
     471                    if ( is_array( $antispam_ips[ $host_name ] ) ) {
     472                        $has_current_ip = array_find( $antispam_ips[ $host_name ], function( $value, $key ) use ($current_ip) {
     473                            $position = strpos( $value, $current_ip );
     474
     475                            return $position === false ? false : true;
     476                        });
     477
     478                        if ( ! $has_current_ip ) {
     479                            checkview_add_to_cleantalk( $user_token, 'antispam', $current_ip, 1, $service_id );
     480                        }
     481
     482                        $has_checkview_hostname = array_find( $antispam_ips[ $host_name ], function( $value, $key ) {
     483                            $position = strpos( $value, 'checkview.io' );
     484
     485                            // Skip test-mail domain
     486                            if ($value === 'test-mail.checkview.io') {
     487                                return false;
     488                            }
     489
     490                            return $position === false ? false : true;
     491                        });
     492
     493                        if ( ! $has_checkview_hostname ) {
     494                            checkview_add_to_cleantalk( $user_token, 'antispam', 'checkview.io', 4, $service_id );
     495                        }
     496
     497                        $has_mail_hostname = array_find( $antispam_ips[ $host_name ], function( $value, $key ) {
     498                            $position = strpos( $value, 'test-mail.checkview.io' );
     499
     500                            return $position === false ? false : true;
     501                        });
     502
     503                        if ( ! $has_mail_hostname ) {
     504                            checkview_add_to_cleantalk( $user_token, 'antispam', 'test-mail.checkview.io', 4, $service_id );
     505                        }
     506                    } else {
     507                        error_log( sprintf( 'The value for antispam IPs at hostname [%1$s] is not an array.', $host_name ) );
     508                        Checkview_Admin_Logs::add( 'ip-logs', sprintf( 'The value for antispam IPs at hostname [%1$s] is not an array.', $host_name ) );
     509                    }
     510                }
    441511            }
    442512
    443513            // Check spamfirewall whitelist.
    444             $spamfirewall_ips = checkview_get_cleantalk_whitelisted_ips( 'spamfirewall' );
    445 
    446             if ( empty( $spamfirewall_ips[ $host_name ] ) || ! in_array( $current_ip, $spamfirewall_ips[ $host_name ] ) ) {
    447                 checkview_add_to_cleantalk( $user_token, 'spamfirewall', $current_ip . '/32', 6 );
    448             }
    449         }
     514            $spamfirewall_ips = checkview_get_cleantalk_whitelisted_ips( 'spamfirewall', $service_id );
     515
     516            if ( is_array( $spamfirewall_ips ) ) {
     517                if ( ! isset( $spamfirewall_ips[ $host_name ] ) ) {
     518                    error_log( 'No host name found in Spam Firewall IP list.' );
     519
     520                    // If host name is not set, request to add it.
     521                    checkview_add_to_cleantalk( $user_token, 'spamfirewall', $current_ip . '/32', 6, $service_id );
     522                } else {
     523                    if ( is_array( $spamfirewall_ips[ $host_name ] ) ) {
     524                        $has_current_ip = array_find( $spamfirewall_ips[ $host_name ], function( $value, $key ) use ($current_ip) {
     525                            $position = strpos( $value, $current_ip );
     526
     527                            return $position === false ? false : true;
     528                        });
     529
     530                        if ( ! $has_current_ip ) {
     531                            checkview_add_to_cleantalk( $user_token, 'spamfirewall', $current_ip, 6, $service_id );
     532                        }
     533                    } else {
     534                        error_log( sprintf( 'Value for spam firewall IPs at hostname [%1$s] is unexpected type [%2$s], expected array.', $host_name, gettype( $antispam_ips[ $host_name ] ) ) );
     535                        Checkview_Admin_Logs::add( 'ip-logs', sprintf( 'Value for spam firewall IPs at hostname [%1$s] is unexpected type [%2$s], expected array.', $host_name, gettype( $antispam_ips[ $host_name ] ) ) );
     536                    }
     537                }
     538            }
     539        }
     540
    450541        return null;
    451542    }
     
    461552     * @param string $record Record.
    462553     * @param string $record_type Record type.
     554     * @param string $service_id Service ID.
    463555     * @return mixed
    464556     */
    465     function checkview_add_to_cleantalk( $user_token, $service_type, $record, $record_type ) {
     557    function checkview_add_to_cleantalk( $user_token, $service_type, $record, $record_type, $service_id ) {
     558        error_log( sprintf(
     559            'Adding record [%1$s] with type [%2$s] and service type [%3$s] to CleanTalk\'s API with service id [%4$s]',
     560            $record,
     561            $record_type,
     562            $service_type,
     563            $service_id,
     564        ) );
     565
    466566        $response = wp_remote_get(
    467567            'https://api.cleantalk.org/?method_name=private_list_add&user_token=' . $user_token .
    468             '&service_id=all&service_type=' . $service_type .
     568            '&service_id=' . $service_id . '&service_type=' . $service_type .
    469569            '&product_id=1&record_type=' . $record_type .
    470570            '&status=allow&note=Checkview Bot&records=' . $record,
    471571            array(
    472572                'method'  => 'POST',
    473                 'timeout' => 30,
     573                'timeout' => 20,
    474574            )
    475575        );
     576
     577        delete_transient('checkview_whitelisted_ips_' . $service_type);
    476578
    477579        if ( is_wp_error( $response ) ) {
     
    638740        delete_transient( 'checkview_store_products_transient' );
    639741        delete_transient( 'checkview_store_shipping_transient' );
    640         delete_transient( 'checkview_whitelisted_ips' );
     742        delete_transient( 'checkview_whitelisted_ips_spamfirewall' );
     743        delete_transient( 'checkview_whitelisted_ips_antispam' );
    641744        $sync = true;
    642745        return $sync;
  • checkview/trunk/includes/class-checkview.php

    r3294839 r3296764  
    7171            $this->version = CHECKVIEW_VERSION;
    7272        } else {
    73             $this->version = '2.0.15';
     73            $this->version = '2.0.16';
    7474        }
    7575        $this->plugin_name = 'checkview';
Note: See TracChangeset for help on using the changeset viewer.