Introduce wp_http_supports as a much less hacky replacement for the http_transport_(get|post)_debug hooks that plugins could have

been using to detect if things like ssl requests were working.
See #17251 props mdawaffe


git-svn-id: https://develop.svn.wordpress.org/trunk@17914 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Peter Westwood
2011-05-13 09:56:59 +00:00
parent e2738c27c7
commit c30cd0193d
2 changed files with 71 additions and 26 deletions

View File

@@ -191,4 +191,34 @@ function wp_remote_retrieve_body(&$response) {
return $response['body'];
}
?>
/**
* Determins if there is an HTTP Transport that can process this request.
*
* @since 3.2.0
*
* @param array $capabilities Array of capabilities to test or a wp_remote_request() $args array.
* @param string $url Optional. If given, will check if the URL requires SSL and adds that requirement to the capabilities array.
*
* @return bool
*/
function wp_http_supports( $capabilities = array(), $url = null ) {
$objFetchSite = _wp_http_get_object();
$capabilities = wp_parse_args( $capabilities );
$count = count( $capabilities );
// If we have a numeric $capabilities array, spoof a wp_remote_request() associative $args array
if ( $count && count( array_filter( array_keys( $capabilities ), 'is_numeric' ) ) == $count ) {
$capabilities = array_combine( array_values( $capabilities ), array_fill( 0, $count, true ) );
}
if ( $url && !isset( $capabilities['ssl'] ) ) {
$scheme = parse_url( $url, PHP_URL_SCHEME );
if ( 'https' == $scheme || 'ssl' == $scheme ) {
$capabilities['ssl'] = true;
}
}
return (bool) $objFetchSite->_get_first_available_transport( $capabilities );
}