= 1 ) { $remaining_tests -= $number; update_option( 'vrts_remaining_tests', max( 0, $remaining_tests ) ); } } /** * Drop the keys for subscription. */ public static function delete_options() { delete_option( 'vrts_email_notification_address' ); delete_option( 'vrts_email_notification_cc_address' ); delete_option( 'vrts_email_update_notification_address' ); delete_option( 'vrts_email_api_notification_address' ); delete_option( 'vrts_email_manual_notification_address' ); delete_option( 'vrts_click_selectors' ); delete_option( 'vrts_license_key' ); delete_option( 'vrts_automatic_comparison' ); delete_option( 'vrts_updates_comparison' ); delete_option( 'vrts_remaining_tests' ); delete_option( 'vrts_total_tests' ); delete_option( 'vrts_has_subscription' ); delete_option( 'vrts_tier_id' ); } /** * Send request to server to get the subscription and tests status. */ public static function get_latest_status() { $local_test_ids = Test::get_all_service_test_ids(); $service_project_id = get_option( 'vrts_project_id' ); $service_api_route = 'sites/' . $service_project_id; $response = Service::rest_service_request( $service_api_route, [], 'get' ); $remaining_credits = $response['response']['remaining_credits']; $total_credits = $response['response']['total_credits']; $has_subscription = $response['response']['has_subscription']; $tier_id = $response['response']['tier_id']; // Active test ids returned by service. $active_test_ids = $response['response']['active_test_ids']; $paused_test_ids = $response['response']['paused_test_ids']; $local_only_test_ids = []; foreach ( $local_test_ids as $test_id ) { if ( ! $has_subscription ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict -- This is a loose comparison by design. if ( ! in_array( $test_id, $active_test_ids ) && in_array( $test_id, $paused_test_ids ) ) { Test::pause( $test_id ); } // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict -- This is a loose comparison by design. } elseif ( in_array( $test_id, $paused_test_ids ) ) { $service_api_route = 'tests/' . $test_id . '/resume'; $response = Service::rest_service_request( $service_api_route, [], 'post' ); Test::unpause( $test_id ); } // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict -- This is a loose comparison by design. if ( $test_id && ! in_array( $test_id, $active_test_ids ) && ! in_array( $test_id, $paused_test_ids ) ) { $local_only_test_ids[] = $test_id; } } if ( ! empty( $local_only_test_ids ) ) { Test::clear_remote_test_ids( $local_only_test_ids ); } if ( array_key_exists( 'status_code', $response ) && 200 === $response['status_code'] ) { if ( array_key_exists( 'response', $response ) ) { self::update_available_tests( $remaining_credits, $total_credits, $has_subscription, $tier_id ); } } } }