kollapsminoriteten/wp-includes/class-wp-http-requests-hook...

79 lines
1.9 KiB
PHP
Raw Normal View History

2019-11-02 10:38:58 +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
*
* @see Requests_Hooks
*/
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-09-15 14:29:22 +02:00
* @param string $url URL to request.
* @param array $request Request data in WP_Http format.
2019-11-02 10:38:58 +01:00
*/
public function __construct( $url, $request ) {
$this->url = $url;
$this->request = $request;
}
/**
* Dispatch a Requests hook to a native WordPress action.
*
2020-09-15 14:29:22 +02:00
* @param string $hook Hook name.
* @param array $parameters Parameters to pass to callbacks.
2020-12-10 14:06:04 +01:00
* @return bool True if hooks were run, false if nothing was hooked.
2019-11-02 10:38:58 +01:00
*/
public function dispatch( $hook, $parameters = array() ) {
$result = parent::dispatch( $hook, $parameters );
2020-05-06 17:23:38 +02:00
// Handle back-compat actions.
2019-11-02 10:38:58 +01:00
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;
}
/**
2021-04-27 08:32:47 +02:00
* Transforms a native Request hook to a WordPress action.
2019-11-02 10:38:58 +01:00
*
* This action maps Requests internal hook to a native WordPress action.
*
2022-04-02 10:26:41 +02:00
* @see https://github.com/WordPress/Requests/blob/master/docs/hooks.md
2019-11-02 10:38:58 +01:00
*
2021-04-27 08:32:47 +02:00
* @since 4.7.0
*
2019-11-02 10:38:58 +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-11-15 22:59:44 +01:00
do_action_ref_array( "requests-{$hook}", $parameters, $this->request, $this->url ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
2019-11-02 10:38:58 +01:00
return $result;
}
}