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
|
|
|
*
|
2021-12-06 22:30:03 +01:00
|
|
|
* @see Requests_Hooks
|
2016-11-13 11:36:29 +01:00
|
|
|
*/
|
2021-12-06 22:30:03 +01:00
|
|
|
class WP_HTTP_Requests_Hooks extends Requests_Hooks {
|
2016-11-13 11:36:29 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
2020-10-10 22:02:05 +02:00
|
|
|
* @return bool True if hooks were run, false if nothing was hooked.
|
2016-11-13 11:36:29 +01:00
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-19 18:54:05 +01:00
|
|
|
* Transforms a native Request hook to a WordPress action.
|
2016-11-13 11:36:29 +01:00
|
|
|
*
|
|
|
|
* This action maps Requests internal hook to a native WordPress action.
|
|
|
|
*
|
2021-07-01 23:12:58 +02:00
|
|
|
* @see https://github.com/WordPress/Requests/blob/master/docs/hooks.md
|
2016-11-13 11:36:29 +01:00
|
|
|
*
|
2020-11-19 18:54:05 +01:00
|
|
|
* @since 4.7.0
|
|
|
|
*
|
2016-11-13 11:36:29 +01:00
|
|
|
* @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;
|
|
|
|
}
|
|
|
|
}
|