function protect_call($action = 'check_ip', $request = array())
{
global $wp_version, $wpdb, $current_user;
$api_key = $this->maybe_get_protect_key();
$user_agent = "WordPress/{$wp_version} | Jetpack/" . constant('JETPACK__VERSION');
$request['action'] = $action;
$request['ip'] = jetpack_protect_get_ip();
$request['host'] = $this->get_local_host();
$request['headers'] = json_encode($this->get_headers());
$request['jetpack_version'] = constant('JETPACK__VERSION');
$request['wordpress_version'] = strval($wp_version);
$request['api_key'] = $api_key;
$request['multisite'] = "0";
if (is_multisite()) {
$request['multisite'] = get_blog_count();
}
/**
* Filter controls maximum timeout in waiting for reponse from Protect servers.
*
* @module protect
*
* @since 4.0.4
*
* @param int $timeout Max time (in seconds) to wait for a response.
*/
$timeout = apply_filters('jetpack_protect_connect_timeout', 30);
$args = array('body' => $request, 'user-agent' => $user_agent, 'httpversion' => '1.0', 'timeout' => absint($timeout));
$response_json = wp_remote_post($this->get_api_host(), $args);
$this->last_response_raw = $response_json;
$headers = $this->get_headers();
$header_hash = md5(json_encode($headers));
$transient_name = 'jpp_li_' . $header_hash;
$this->delete_transient($transient_name);
if (is_array($response_json)) {
$response = json_decode($response_json['body'], true);
}
if (isset($response['blocked_attempts']) && $response['blocked_attempts']) {
update_site_option('jetpack_protect_blocked_attempts', $response['blocked_attempts']);
}
if (isset($response['status']) && !isset($response['error'])) {
$response['expire'] = time() + $response['seconds_remaining'];
$this->set_transient($transient_name, $response, $response['seconds_remaining']);
$this->delete_transient('brute_use_math');
} else {
// Fallback to Math Captcha if no response from API host
$this->set_transient('brute_use_math', 1, 600);
$response['status'] = 'ok';
$response['math'] = true;
}
if (isset($response['error'])) {
update_site_option('jetpack_protect_error', $response['error']);
} else {
delete_site_option('jetpack_protect_error');
}
return $response;
}