2016-11-13 11:36:29 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* HTTP API: Requests hook bridge class
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage HTTP
|
|
|
|
* @since 4.7.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bridge to connect Requests internal hooks to WordPress actions.
|
|
|
|
*
|
|
|
|
* @since 4.7.0
|
2017-07-01 18:58:42 +02:00
|
|
|
*
|
|
|
|
* @see Requests_Hooks
|
2016-11-13 11:36:29 +01:00
|
|
|
*/
|
|
|
|
class WP_HTTP_Requests_Hooks extends Requests_Hooks {
|
|
|
|
/**
|
|
|
|
* Requested URL.
|
|
|
|
*
|
|
|
|
* @var string Requested URL.
|
|
|
|
*/
|
|
|
|
protected $url;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WordPress WP_HTTP request data.
|
|
|
|
*
|
|
|
|
* @var array Request data in WP_Http format.
|
|
|
|
*/
|
|
|
|
protected $request = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
2020-07-23 22:01:04 +02:00
|
|
|
* @param string $url URL to request.
|
|
|
|
* @param array $request Request data in WP_Http format.
|
2016-11-13 11:36:29 +01:00
|
|
|
*/
|
|
|
|
public function __construct( $url, $request ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
$this->url = $url;
|
2016-11-13 11:36:29 +01:00
|
|
|
$this->request = $request;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispatch a Requests hook to a native WordPress action.
|
|
|
|
*
|
2020-07-23 22:01:04 +02:00
|
|
|
* @param string $hook Hook name.
|
|
|
|
* @param array $parameters Parameters to pass to callbacks.
|
2016-11-13 11:36:29 +01:00
|
|
|
* @return boolean True if hooks were run, false if nothing was hooked.
|
|
|
|
*/
|
|
|
|
public function dispatch( $hook, $parameters = array() ) {
|
|
|
|
$result = parent::dispatch( $hook, $parameters );
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Handle back-compat actions.
|
2016-11-13 11:36:29 +01:00
|
|
|
switch ( $hook ) {
|
|
|
|
case 'curl.before_send':
|
|
|
|
/** This action is documented in wp-includes/class-wp-http-curl.php */
|
2017-02-17 06:06:44 +01:00
|
|
|
do_action_ref_array( 'http_api_curl', array( &$parameters[0], $this->request, $this->url ) );
|
2016-11-13 11:36:29 +01:00
|
|
|
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.
|
|
|
|
*/
|
2019-07-05 03:45:56 +02:00
|
|
|
do_action_ref_array( "requests-{$hook}", $parameters, $this->request, $this->url ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
|
2016-11-13 11:36:29 +01:00
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|