/wp-includes/class-wp-http-requests-hooks.php

  1. <?php 
  2. /** 
  3. * HTTP API: Requests hook bridge class 
  4. * 
  5. * @package WordPress 
  6. * @subpackage HTTP 
  7. * @since 4.7.0 
  8. */ 
  9.  
  10. /** 
  11. * Bridge to connect Requests internal hooks to WordPress actions. 
  12. * 
  13. * @package WordPress 
  14. * @subpackage HTTP 
  15. * @since 4.7.0 
  16. */ 
  17. class WP_HTTP_Requests_Hooks extends Requests_Hooks { 
  18. /** 
  19. * Requested URL. 
  20. * 
  21. * @var string Requested URL. 
  22. */ 
  23. protected $url; 
  24.  
  25. /** 
  26. * WordPress WP_HTTP request data. 
  27. * 
  28. * @var array Request data in WP_Http format. 
  29. */ 
  30. protected $request = array(); 
  31.  
  32. /** 
  33. * Constructor. 
  34. * 
  35. * @param string $url URL to request. 
  36. * @param array $request Request data in WP_Http format. 
  37. */ 
  38. public function __construct( $url, $request ) { 
  39. $this->url = $url; 
  40. $this->request = $request; 
  41.  
  42. /** 
  43. * Dispatch a Requests hook to a native WordPress action. 
  44. * 
  45. * @param string $hook Hook name. 
  46. * @param array $parameters Parameters to pass to callbacks. 
  47. * @return boolean True if hooks were run, false if nothing was hooked. 
  48. */ 
  49. public function dispatch( $hook, $parameters = array() ) { 
  50. $result = parent::dispatch( $hook, $parameters ); 
  51.  
  52. // Handle back-compat actions 
  53. switch ( $hook ) { 
  54. case 'curl.before_send': 
  55. /** This action is documented in wp-includes/class-wp-http-curl.php */ 
  56. do_action_ref_array( 'http_api_curl', array( &$parameters[0], $this->request, $this->url ) ); 
  57. break; 
  58.  
  59. /** 
  60. * Transforms a native Request hook to a WordPress actions. 
  61. * 
  62. * This action maps Requests internal hook to a native WordPress action. 
  63. * 
  64. * @see https://github.com/rmccue/Requests/blob/master/docs/hooks.md 
  65. * 
  66. * @param array $parameters Parameters from Requests internal hook. 
  67. * @param array $request Request data in WP_Http format. 
  68. * @param string $url URL to request. 
  69. */ 
  70. do_action_ref_array( "requests-{$hook}", $parameters, $this->request, $this->url ); 
  71.  
  72. return $result; 
.