WP_Http::_get_first_available_transport() WordPress Method

The WP_Http::_get_first_available_transport() method is used to get the first available transport method on the current system. This is useful for checking which transport methods are available and for choosing the best one for a particular request.

WP_Http::_get_first_available_transport( array $args, string $url = null ) #

Tests which transports are capable of supporting the request.


Parameters

$args

(array)(Required)Request arguments.

$url

(string)(Optional)URL to request.

Default value: null


Top ↑

Return

(string|false) Class name for the first transport that claims to support the request. False if no transport claims to support the request.


Top ↑

Source

File: wp-includes/class-wp-http.php

	public function _get_first_available_transport( $args, $url = null ) {
		$transports = array( 'curl', 'streams' );

		/**
		 * Filters which HTTP transports are available and in what order.
		 *
		 * @since 3.7.0
		 *
		 * @param string[] $transports Array of HTTP transports to check. Default array contains
		 *                             'curl' and 'streams', in that order.
		 * @param array    $args       HTTP request arguments.
		 * @param string   $url        The URL to request.
		 */
		$request_order = apply_filters( 'http_api_transports', $transports, $args, $url );

		// Loop over each transport on each HTTP request looking for one which will serve this request's needs.
		foreach ( $request_order as $transport ) {
			if ( in_array( $transport, $transports, true ) ) {
				$transport = ucfirst( $transport );
			}
			$class = 'WP_Http_' . $transport;

			// Check to see if this transport is a possibility, calls the transport statically.
			if ( ! call_user_func( array( $class, 'test' ), $args, $url ) ) {
				continue;
			}

			return $class;
		}

		return false;
	}


Top ↑

Changelog

Changelog
VersionDescription
3.2.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.