diff options
author | Yury German <blueknight@gentoo.org> | 2016-02-12 22:22:00 -0500 |
---|---|---|
committer | Yury German <blueknight@gentoo.org> | 2016-02-12 22:22:00 -0500 |
commit | 657cafe0e955cf88033597f131aa50835140c617 (patch) | |
tree | cf21a30d319cb2a238a6cfb8b4eb3b20b1b5dcff /plugins/jetpack/class.jetpack-client.php | |
parent | Adding New Mantra version 2.4.1.1 - Bug 574468 (diff) | |
download | blogs-gentoo-657cafe0e955cf88033597f131aa50835140c617.tar.gz blogs-gentoo-657cafe0e955cf88033597f131aa50835140c617.tar.bz2 blogs-gentoo-657cafe0e955cf88033597f131aa50835140c617.zip |
Updating plugins easy-table, jetpack, openid, public-post preview, talbe-of-contents-plus, wordress-mobile-pack - Bug 574468
Diffstat (limited to 'plugins/jetpack/class.jetpack-client.php')
-rw-r--r-- | plugins/jetpack/class.jetpack-client.php | 65 |
1 files changed, 64 insertions, 1 deletions
diff --git a/plugins/jetpack/class.jetpack-client.php b/plugins/jetpack/class.jetpack-client.php index 669ccba7..df1c4c07 100644 --- a/plugins/jetpack/class.jetpack-client.php +++ b/plugins/jetpack/class.jetpack-client.php @@ -1,6 +1,9 @@ <?php class Jetpack_Client { + const WPCOM_JSON_API_HOST = 'public-api.wordpress.com'; + const WPCOM_JSON_API_VERSION = '1.1'; + /** * Makes an authorized remote request using Jetpack_Signature * @@ -51,7 +54,7 @@ class Jetpack_Client { $jetpack_signature = new Jetpack_Signature( $token->secret, $time_diff ); $timestamp = time() + $time_diff; - + if( function_exists( 'wp_generate_password' ) ) { $nonce = wp_generate_password( 10, false ); } else { @@ -131,6 +134,21 @@ class Jetpack_Client { * @return array|WP_Error WP HTTP response on success */ public static function _wp_remote_request( $url, $args, $set_fallback = false ) { + /** + * SSL verification (`sslverify`) for the JetpackClient remote request + * defaults to off, use this filter to force it on. + * + * Return `true` to ENABLE SSL verification, return `false` + * to DISABLE SSL verification. + * + * @since 3.6.0 + * + * @param bool Whether to force `sslverify` or not. + */ + if ( apply_filters( 'jetpack_client_verify_ssl_certs', false ) ) { + return wp_remote_request( $url, $args ); + } + $fallback = Jetpack_Options::get_option( 'fallback_no_verify_ssl_certs' ); if ( false === $fallback ) { Jetpack_Options::update_option( 'fallback_no_verify_ssl_certs', 0 ); @@ -216,4 +234,49 @@ class Jetpack_Client { } } } + + /** + * Query the WordPress.com REST API using the blog token + * + * @param string $path + * @param string $version + * @param array $args + * @param string $body + * @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', + ) ); + + /** + * 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, self::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 ); + } + } |