2016-11-13 05:36:29 -05: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
|
2017-07-01 12:58:42 -04:00
|
|
|
*
|
External Libraries: Update the Requests library to version 2.0.0.
This is a major release and contains breaking changes.
Most important changes to be aware of for this release:
* All code is now namespaced. Though there is a full backward compatibility layer available and the old class names are still supported, using them will generate a deprecation notice (which can be silenced by plugins if they'd need to support multiple WP versions). See the [https://requests.ryanmccue.info/docs/upgrading.html upgrade guide] for more details.
* A lot of classes have been marked `final`. This should generally not affect userland code as care has been taken to not apply the `final` keyword to classes which are known to be extended in userland code.
* Extensive input validation has been added to Requests. When Requests is used as documented though, this will be unnoticable.
* A new `WpOrg\Requests\Requests::has_capabilities()` method has been introduced which can be used to address #37708.
* A new `WpOrg\Requests\Response::decode_body()` method has been introduced which may be usable to simplify some of the WP native wrapper code.
* Remaining PHP 8.0 compatibility fixed (support for named parameters).
* PHP 8.1 compatibility.
Release notes: https://github.com/WordPress/Requests/releases/tag/v2.0.0
For a full list of changes in this update, see the Requests GitHub:
https://github.com/WordPress/Requests/compare/v1.8.1...v2.0.0
Follow-up to [50842], [51078].
Props jrf, schlessera, datagutten, wojsmol, dd32, dustinrue, soulseekah, costdev, szepeviktor.
Fixes #54504.
Built from https://develop.svn.wordpress.org/trunk@52244
git-svn-id: http://core.svn.wordpress.org/trunk@51836 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-24 20:12:02 -05:00
|
|
|
* @see WpOrg\Requests\Hooks
|
2016-11-13 05:36:29 -05:00
|
|
|
*/
|
External Libraries: Update the Requests library to version 2.0.0.
This is a major release and contains breaking changes.
Most important changes to be aware of for this release:
* All code is now namespaced. Though there is a full backward compatibility layer available and the old class names are still supported, using them will generate a deprecation notice (which can be silenced by plugins if they'd need to support multiple WP versions). See the [https://requests.ryanmccue.info/docs/upgrading.html upgrade guide] for more details.
* A lot of classes have been marked `final`. This should generally not affect userland code as care has been taken to not apply the `final` keyword to classes which are known to be extended in userland code.
* Extensive input validation has been added to Requests. When Requests is used as documented though, this will be unnoticable.
* A new `WpOrg\Requests\Requests::has_capabilities()` method has been introduced which can be used to address #37708.
* A new `WpOrg\Requests\Response::decode_body()` method has been introduced which may be usable to simplify some of the WP native wrapper code.
* Remaining PHP 8.0 compatibility fixed (support for named parameters).
* PHP 8.1 compatibility.
Release notes: https://github.com/WordPress/Requests/releases/tag/v2.0.0
For a full list of changes in this update, see the Requests GitHub:
https://github.com/WordPress/Requests/compare/v1.8.1...v2.0.0
Follow-up to [50842], [51078].
Props jrf, schlessera, datagutten, wojsmol, dd32, dustinrue, soulseekah, costdev, szepeviktor.
Fixes #54504.
Built from https://develop.svn.wordpress.org/trunk@52244
git-svn-id: http://core.svn.wordpress.org/trunk@51836 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-24 20:12:02 -05:00
|
|
|
class WP_HTTP_Requests_Hooks extends WpOrg\Requests\Hooks {
|
2016-11-13 05:36:29 -05:00
|
|
|
/**
|
|
|
|
* 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-07-23 16:01:04 -04:00
|
|
|
* @param string $url URL to request.
|
|
|
|
* @param array $request Request data in WP_Http format.
|
2016-11-13 05:36:29 -05:00
|
|
|
*/
|
|
|
|
public function __construct( $url, $request ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
$this->url = $url;
|
2016-11-13 05:36:29 -05:00
|
|
|
$this->request = $request;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispatch a Requests hook to a native WordPress action.
|
|
|
|
*
|
2020-07-23 16:01:04 -04:00
|
|
|
* @param string $hook Hook name.
|
|
|
|
* @param array $parameters Parameters to pass to callbacks.
|
2020-10-10 16:02:05 -04:00
|
|
|
* @return bool True if hooks were run, false if nothing was hooked.
|
2016-11-13 05:36:29 -05:00
|
|
|
*/
|
|
|
|
public function dispatch( $hook, $parameters = array() ) {
|
|
|
|
$result = parent::dispatch( $hook, $parameters );
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Handle back-compat actions.
|
2016-11-13 05:36:29 -05:00
|
|
|
switch ( $hook ) {
|
|
|
|
case 'curl.before_send':
|
|
|
|
/** This action is documented in wp-includes/class-wp-http-curl.php */
|
2017-02-17 00:06:44 -05:00
|
|
|
do_action_ref_array( 'http_api_curl', array( &$parameters[0], $this->request, $this->url ) );
|
2016-11-13 05:36:29 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-19 12:54:05 -05:00
|
|
|
* Transforms a native Request hook to a WordPress action.
|
2016-11-13 05:36:29 -05:00
|
|
|
*
|
|
|
|
* This action maps Requests internal hook to a native WordPress action.
|
|
|
|
*
|
2021-07-01 17:12:58 -04:00
|
|
|
* @see https://github.com/WordPress/Requests/blob/master/docs/hooks.md
|
2016-11-13 05:36:29 -05:00
|
|
|
*
|
2020-11-19 12:54:05 -05:00
|
|
|
* @since 4.7.0
|
|
|
|
*
|
2016-11-13 05:36:29 -05: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-07-04 21:45:56 -04:00
|
|
|
do_action_ref_array( "requests-{$hook}", $parameters, $this->request, $this->url ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
|
2016-11-13 05:36:29 -05:00
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|