You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

77 lines
1.8 KiB

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