| | 82 | * Tests through all WP_Http objects and stores the first match |
| | 83 | * and returns. |
| | 84 | * |
| | 85 | * Test Order: |
| | 86 | * |
| | 87 | * 1. exthttp : WP_Http_Exthttp |
| | 88 | * 2. curl : WP_Http_Curl |
| | 89 | * 3. streams : WP_Http_Streams |
| | 90 | * 4. fopen : WP_Http_Fopen |
| | 91 | * 5. fsockopen: WP_Http_Fsockopen |
| | 92 | * |
| | 93 | * @since 3.1.0 |
| | 94 | * @access private |
| | 95 | * @param string $context named context |
| | 96 | * @param array $args (optional) Request arguments |
| | 97 | * @return object|null Concrete HTTP Transport Object; Null if no transport was found. |
| | 98 | */ |
| | 99 | function &_namedTransport( $context, $args = array() ) { |
| | 100 | static $working, $blocking, $nonblocking; |
| | 101 | |
| | 102 | if ( !isset( $working[$context] ) ) { |
| | 103 | $transports = apply_filters( 'http_transport_available_transports', $this->transports, $context, $args ); |
| | 104 | |
| | 105 | foreach ( $transports as $name ) { |
| | 106 | false === class_exists( ( $class = $name ) ) |
| | 107 | && ( $class = 'WP_Http_' . ucfirst( $name ) ); |
| | 108 | |
| | 109 | if ( !call_user_func( array( $class, 'test' ), $args ) ) |
| | 110 | continue; |
| | 111 | |
| | 112 | $wp_http = new $class(); |
| | 113 | |
| | 114 | $working[$context][$name] = &$wp_http; |
| | 115 | $blocking[$context][] = &$wp_http; |
| | 116 | $nonblocking[$context][] = &$wp_http; |
| | 117 | |
| | 118 | break; |
| | 119 | } |
| | 120 | } |
| | 121 | |
| | 122 | do_action( 'http_transport_get_debug', $working[$context], $blocking[$context], $nonblocking[$context] ); |
| | 123 | |
| | 124 | if ( isset( $args['blocking'] ) && !$args['blocking'] ) |
| | 125 | return $nonblocking[$context]; |
| | 126 | else |
| | 127 | return $blocking[$context]; |
| | 128 | |
| | 129 | } |
| | 130 | |
| | 131 | /** |
| 89 | | static $working_transport, $blocking_transport, $nonblocking_transport; |
| 90 | | |
| 91 | | if ( is_null($working_transport) ) { |
| 92 | | if ( true === WP_Http_ExtHttp::test($args) ) { |
| 93 | | $working_transport['exthttp'] = new WP_Http_ExtHttp(); |
| 94 | | $blocking_transport[] = &$working_transport['exthttp']; |
| 95 | | } else if ( true === WP_Http_Curl::test($args) ) { |
| 96 | | $working_transport['curl'] = new WP_Http_Curl(); |
| 97 | | $blocking_transport[] = &$working_transport['curl']; |
| 98 | | } else if ( true === WP_Http_Streams::test($args) ) { |
| 99 | | $working_transport['streams'] = new WP_Http_Streams(); |
| 100 | | $blocking_transport[] = &$working_transport['streams']; |
| 101 | | } else if ( true === WP_Http_Fopen::test($args) ) { |
| 102 | | $working_transport['fopen'] = new WP_Http_Fopen(); |
| 103 | | $blocking_transport[] = &$working_transport['fopen']; |
| 104 | | } else if ( true === WP_Http_Fsockopen::test($args) ) { |
| 105 | | $working_transport['fsockopen'] = new WP_Http_Fsockopen(); |
| 106 | | $blocking_transport[] = &$working_transport['fsockopen']; |
| 107 | | } |
| 108 | | |
| 109 | | foreach ( array('curl', 'streams', 'fopen', 'fsockopen', 'exthttp') as $transport ) { |
| 110 | | if ( isset($working_transport[$transport]) ) |
| 111 | | $nonblocking_transport[] = &$working_transport[$transport]; |
| 112 | | } |
| 113 | | } |
| 114 | | |
| 115 | | do_action( 'http_transport_get_debug', $working_transport, $blocking_transport, $nonblocking_transport ); |
| 116 | | |
| 117 | | if ( isset($args['blocking']) && !$args['blocking'] ) |
| 118 | | return $nonblocking_transport; |
| 119 | | else |
| 120 | | return $blocking_transport; |
| | 154 | return $this->_namedTransport( 'get', $args ); |
| 139 | | static $working_transport, $blocking_transport, $nonblocking_transport; |
| 140 | | |
| 141 | | if ( is_null($working_transport) ) { |
| 142 | | if ( true === WP_Http_ExtHttp::test($args) ) { |
| 143 | | $working_transport['exthttp'] = new WP_Http_ExtHttp(); |
| 144 | | $blocking_transport[] = &$working_transport['exthttp']; |
| 145 | | } else if ( true === WP_Http_Curl::test($args) ) { |
| 146 | | $working_transport['curl'] = new WP_Http_Curl(); |
| 147 | | $blocking_transport[] = &$working_transport['curl']; |
| 148 | | } else if ( true === WP_Http_Streams::test($args) ) { |
| 149 | | $working_transport['streams'] = new WP_Http_Streams(); |
| 150 | | $blocking_transport[] = &$working_transport['streams']; |
| 151 | | } else if ( true === WP_Http_Fsockopen::test($args) ) { |
| 152 | | $working_transport['fsockopen'] = new WP_Http_Fsockopen(); |
| 153 | | $blocking_transport[] = &$working_transport['fsockopen']; |
| 154 | | } |
| 155 | | |
| 156 | | foreach ( array('curl', 'streams', 'fsockopen', 'exthttp') as $transport ) { |
| 157 | | if ( isset($working_transport[$transport]) ) |
| 158 | | $nonblocking_transport[] = &$working_transport[$transport]; |
| 159 | | } |
| 160 | | } |
| 161 | | |
| 162 | | do_action( 'http_transport_post_debug', $working_transport, $blocking_transport, $nonblocking_transport ); |
| 163 | | |
| 164 | | if ( isset($args['blocking']) && !$args['blocking'] ) |
| 165 | | return $nonblocking_transport; |
| 166 | | else |
| 167 | | return $blocking_transport; |
| | 173 | return $this->_namedTransport( 'post', $args ); |