Jetpack_Client::wpcom_json_api_request_as_blog PHP Method

wpcom_json_api_request_as_blog() static public method

Query the WordPress.com REST API using the blog token
static public wpcom_json_api_request_as_blog ( string $path, string $version = self::WPCOM_JSON_API_VERSION, array $args = [], string $body = null ) : array | WP_Error
$path string
$version string
$args array
$body string
return array | WP_Error $response Data.
    static function wpcom_json_api_request_as_blog($path, $version = self::WPCOM_JSON_API_VERSION, $args = array(), $body = null)
    {
        $filtered_args = array_intersect_key($args, array('method' => 'string', 'timeout' => 'int', 'redirection' => 'int', 'stream' => 'boolean', 'filename' => 'string'));
        /**
         * Determines whether Jetpack can send outbound https requests to the WPCOM api.
         *
         * @since 3.6.0
         *
         * @param bool $proto Defaults to true.
         */
        $proto = apply_filters('jetpack_can_make_outbound_https', true) ? 'https' : 'http';
        // unprecedingslashit
        $_path = preg_replace('/^\\//', '', $path);
        // Use GET by default whereas `remote_request` uses POST
        if (isset($filtered_args['method']) && strtoupper($filtered_args['method'] === 'POST')) {
            $request_method = 'POST';
        } else {
            $request_method = 'GET';
        }
        $validated_args = array_merge($filtered_args, array('url' => sprintf('%s://%s/rest/v%s/%s', $proto, JETPACK__WPCOM_JSON_API_HOST, $version, $_path), 'blog_id' => (int) Jetpack_Options::get_option('id'), 'method' => $request_method));
        return Jetpack_Client::remote_request($validated_args, $body);
    }

Usage Example

 protected static function download_wpcom_theme_to_file($theme)
 {
     $wpcom_theme_slug = preg_replace('/-wpcom$/', '', $theme);
     $file = wp_tempnam('theme');
     if (!$file) {
         return new WP_Error('problem_creating_theme_file', __('Problem creating file for theme download', 'jetpack'));
     }
     $url = "themes/download/{$theme}.zip";
     $args = array('stream' => true, 'filename' => $file);
     $result = Jetpack_Client::wpcom_json_api_request_as_blog($url, '1.1', $args);
     $response = $result['response'];
     if ($response['code'] !== 200) {
         unlink($file);
         return new WP_Error('problem_fetching_theme', __('Problem downloading theme', 'jetpack'));
     }
     return $file;
 }
All Usage Examples Of Jetpack_Client::wpcom_json_api_request_as_blog