home *** CD-ROM | disk | FTP | other *** search
/ HTML Examples / WP.iso / wordpress2 / wp-includes / class-wp-http-requests-hooks.php < prev    next >
Encoding:
PHP Script  |  2017-07-01  |  1.8 KB  |  77 lines

  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.  * @since 4.7.0
  14.  *
  15.  * @see Requests_Hooks
  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.     /**
  44.      * Dispatch a Requests hook to a native WordPress action.
  45.      *
  46.      * @param string $hook Hook name.
  47.      * @param array $parameters Parameters to pass to callbacks.
  48.      * @return boolean True if hooks were run, false if nothing was hooked.
  49.      */
  50.     public function dispatch( $hook, $parameters = array() ) {
  51.         $result = parent::dispatch( $hook, $parameters );
  52.  
  53.         // Handle back-compat actions
  54.         switch ( $hook ) {
  55.             case 'curl.before_send':
  56.                 /** This action is documented in wp-includes/class-wp-http-curl.php */
  57.                 do_action_ref_array( 'http_api_curl', array( &$parameters[0], $this->request, $this->url ) );
  58.                 break;
  59.         }
  60.  
  61.         /**
  62.          * Transforms a native Request hook to a WordPress actions.
  63.          *
  64.          * This action maps Requests internal hook to a native WordPress action.
  65.          *
  66.          * @see https://github.com/rmccue/Requests/blob/master/docs/hooks.md
  67.          *
  68.          * @param array $parameters Parameters from Requests internal hook.
  69.          * @param array $request Request data in WP_Http format.
  70.          * @param string $url URL to request.
  71.          */
  72.         do_action_ref_array( "requests-{$hook}", $parameters, $this->request, $this->url );
  73.  
  74.         return $result;
  75.     }
  76. }
  77.