blob: 80e4eb7ef4b9f58c77f4c2a82f49b312d221d2f5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
<?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 WpOrg\Requests\Hooks
*/
#[AllowDynamicProperties]
class WP_HTTP_Requests_Hooks extends WpOrg\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.
*
* @param string $url URL to request.
* @param array $request Request data in WP_Http format.
*/
public function __construct( $url, $request ) {
$this->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 bool 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 action.
*
* This action maps Requests internal hook to a native WordPress action.
*
* @see https://github.com/WordPress/Requests/blob/master/docs/hooks.md
*
* @since 4.7.0
*
* @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 ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
return $result;
}
}
|