ether the token was revoked successfully. */ public function revoke_token() { Authentication::tokens( false ); delete_option( 'rank_math_google_analytic_profile' ); delete_option( 'rank_math_google_analytic_options' ); delete_option( 'rankmath_google_api_failed_attempts_data' ); delete_option( 'rankmath_google_api_reconnect' ); return $this->is_success(); } /** * Log every failed API call. * And kill all next scheduled event if failed count is more then three. * * @param array $response Response from api. * @param string $action Action performing. * @param string $start_date Start date fetching for (or page URI for inspections). * @param array $args Array of arguments. */ public function log_failed_request( $response, $action, $start_date, $args ) { if ( $this->is_success() ) { return; } $option_key = 'rankmath_google_api_failed_attempts_data'; $reconnect_google_option_key = 'rankmath_google_api_reconnect'; if ( empty( $response['error'] ) || ! is_array( $response['error'] ) ) { delete_option( $option_key ); delete_option( $reconnect_google_option_key ); return; } // Limit maximum 10 failed attempt data to log. $failed_attempts = get_option( $option_key, [] ); $failed_attempts = ( ! empty( $failed_attempts ) && is_array( $failed_attempts ) ) ? array_slice( $failed_attempts, -9, 9 ) : []; $failed_attempts[] = [ 'action' => $action, 'args' => $args, 'error' => $response['error'], ]; update_option( $option_key, $failed_attempts, false ); // Number of allowed attempt. if ( 3 < count( $failed_attempts ) ) { update_option( $reconnect_google_option_key, 'search_analytics_query' ); return; } as_schedule_single_action( time() + 60, "rank_math/analytics/get_{$action}_data", [ $start_date ], 'rank-math' ); } }