From 35a0240fb2df290e86157d1d44aa1ccdfb92e228 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Sun, 13 Nov 2016 10:36:29 +0000 Subject: [PATCH] WP_HTTP: Map internal Requests hooks to WordPress actions. This change introduces a `requests-{$hook}` action which can be used to hook into Requests hooks, and restores the `http_api_curl` action. Props rmccue. Fixes #37843. Built from https://develop.svn.wordpress.org/trunk@39212 git-svn-id: http://core.svn.wordpress.org/trunk@39152 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-http.php | 2 +- wp-includes/class-wp-http-requests-hooks.php | 76 ++++++++++++++++++++ wp-includes/version.php | 2 +- wp-settings.php | 1 + 4 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 wp-includes/class-wp-http-requests-hooks.php diff --git a/wp-includes/class-http.php b/wp-includes/class-http.php index 45eeeaf1a1..b9f5ab50fb 100644 --- a/wp-includes/class-http.php +++ b/wp-includes/class-http.php @@ -300,7 +300,7 @@ class WP_Http { 'timeout' => $r['timeout'], 'useragent' => $r['user-agent'], 'blocking' => $r['blocking'], - 'hooks' => new Requests_Hooks(), + 'hooks' => new WP_HTTP_Requests_Hooks( $url, $r ), ); // Ensure redirects follow browser behaviour. diff --git a/wp-includes/class-wp-http-requests-hooks.php b/wp-includes/class-wp-http-requests-hooks.php new file mode 100644 index 0000000000..108fae8c10 --- /dev/null +++ b/wp-includes/class-wp-http-requests-hooks.php @@ -0,0 +1,76 @@ +url = $url; + $this->request = $request; + } + + /** + * Dispatch a Requests hook to a native WordPress action. + * + * @param string $hook Hook name. + * @param array $parameters Parameters to pass to callbacks. + * @return boolean True if hooks were run, false if nothing was hooked. + */ + public function dispatch( $hook, $parameters = array() ) { + $result = parent::dispatch( $hook, $parameters ); + + // Handle back-compat actions + switch ( $hook ) { + case 'curl.before_send': + /** This action is documented in wp-includes/class-wp-http-curl.php */ + do_action_ref_array( 'http_api_curl', array( $parameters[0], $this->request, $this->url ) ); + break; + } + + /** + * Transforms a native Request hook to a WordPress actions. + * + * This action maps Requests internal hook to a native WordPress action. + * + * @see https://github.com/rmccue/Requests/blob/master/docs/hooks.md + * + * @param array $parameters Parameters from Requests internal hook. + * @param array $request Request data in WP_Http format. + * @param string $url URL to request. + */ + do_action_ref_array( "requests-{$hook}", $parameters, $this->request, $this->url ); + + return $result; + } +} diff --git a/wp-includes/version.php b/wp-includes/version.php index 4d3bc11775..f542270a4d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.7-beta3-39211'; +$wp_version = '4.7-beta3-39212'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. diff --git a/wp-settings.php b/wp-settings.php index c592bab6e5..9fe4080f3f 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -208,6 +208,7 @@ require( ABSPATH . WPINC . '/class-wp-http-cookie.php' ); require( ABSPATH . WPINC . '/class-wp-http-encoding.php' ); require( ABSPATH . WPINC . '/class-wp-http-response.php' ); require( ABSPATH . WPINC . '/class-wp-http-requests-response.php' ); +require( ABSPATH . WPINC . '/class-wp-http-requests-hooks.php' ); require( ABSPATH . WPINC . '/widgets.php' ); require( ABSPATH . WPINC . '/class-wp-widget.php' ); require( ABSPATH . WPINC . '/class-wp-widget-factory.php' );