Jetpack::api_url PHP Method

api_url() public static method

Returns the requested Jetpack API URL
public static api_url ( $relative_url ) : string
return string
    public static function api_url($relative_url)
    {
        return trailingslashit(JETPACK__API_BASE . $relative_url) . JETPACK__API_VERSION . '/';
    }

Usage Example

コード例 #1
0
 /**
  * @return bool|WP_Error
  */
 public static function register()
 {
     add_action('pre_update_jetpack_option_register', array('Jetpack_Options', 'delete_option'));
     $secrets = Jetpack::init()->generate_secrets();
     Jetpack_Options::update_option('register', $secrets[0] . ':' . $secrets[1] . ':' . $secrets[2]);
     @(list($secret_1, $secret_2, $secret_eol) = explode(':', Jetpack_Options::get_option('register')));
     if (empty($secret_1) || empty($secret_2) || empty($secret_eol) || $secret_eol < time()) {
         return new Jetpack_Error('missing_secrets');
     }
     $timeout = Jetpack::init()->get_remote_query_timeout_limit();
     $gmt_offset = get_option('gmt_offset');
     if (!$gmt_offset) {
         $gmt_offset = 0;
     }
     $stats_options = get_option('stats_options');
     $stats_id = isset($stats_options['blog_id']) ? $stats_options['blog_id'] : null;
     $args = array('method' => 'POST', 'body' => array('siteurl' => site_url(), 'home' => home_url(), 'gmt_offset' => $gmt_offset, 'timezone_string' => (string) get_option('timezone_string'), 'site_name' => (string) get_option('blogname'), 'secret_1' => $secret_1, 'secret_2' => $secret_2, 'site_lang' => get_locale(), 'timeout' => $timeout, 'stats_id' => $stats_id), 'headers' => array('Accept' => 'application/json'), 'timeout' => $timeout);
     $response = Jetpack_Client::_wp_remote_request(Jetpack::fix_url_for_bad_hosts(Jetpack::api_url('register')), $args, true);
     // Make sure the response is valid and does not contain any Jetpack errors
     $valid_response = Jetpack::init()->validate_remote_register_response($response);
     if (is_wp_error($valid_response) || !$valid_response) {
         return $valid_response;
     }
     // Grab the response values to work with
     $code = wp_remote_retrieve_response_code($response);
     $entity = wp_remote_retrieve_body($response);
     if ($entity) {
         $json = json_decode($entity);
     } else {
         $json = false;
     }
     if (empty($json->jetpack_secret) || !is_string($json->jetpack_secret)) {
         return new Jetpack_Error('jetpack_secret', '', $code);
     }
     if (isset($json->jetpack_public)) {
         $jetpack_public = (int) $json->jetpack_public;
     } else {
         $jetpack_public = false;
     }
     Jetpack_Options::update_options(array('id' => (int) $json->jetpack_id, 'blog_token' => (string) $json->jetpack_secret, 'public' => $jetpack_public));
     return true;
 }
All Usage Examples Of Jetpack::api_url
Jetpack