Make WordPress Core


Ignore:
Timestamp:
04/05/2011 06:09:43 AM (15 years ago)
Author:
dd32
Message:

Streamline WP_Http_*::test() methods: Check basic SSL requirements, only allow filters to disable transports, not enable them after ::test() has failed. Props mdawaffe for the initial patch. See #16606

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-http.php

    r17597 r17598  
    743743         */
    744744        function test( $args = array() ) {
     745                if ( ! function_exists( 'fsockopen' ) )
     746                        return false;
     747
    745748                if ( false !== ($option = get_option( 'disable_fsockopen' )) && time()-$option < 43200 ) // 12 hours
    746749                        return false;
    747750
    748                 $is_ssl = isset($args['ssl']) && $args['ssl'];
    749 
    750                 if ( ! $is_ssl && function_exists( 'fsockopen' ) )
    751                         $use = true;
    752                 elseif ( $is_ssl && extension_loaded('openssl') && function_exists( 'fsockopen' ) )
    753                         $use = true;
    754                 else
    755                         $use = false;
    756 
    757                 return apply_filters('use_fsockopen_transport', $use, $args);
     751                $is_ssl = isset( $args['ssl'] ) && $args['ssl'];
     752
     753                if ( $is_ssl && ! extension_loaded( 'openssl' ) )
     754                        return false;
     755
     756                return apply_filters( 'use_fsockopen_transport', true, $args );
    758757        }
    759758}
     
    926925         * @return boolean False means this class can not be used, true means it can.
    927926         */
    928         function test($args = array()) {
    929                 if ( ! function_exists('fopen') || (function_exists('ini_get') && true != ini_get('allow_url_fopen')) )
     927        function test( $args = array() ) {
     928                if ( ! function_exists( 'fopen' ) )
    930929                        return false;
    931930
    932                 return apply_filters('use_streams_transport', true, $args);
     931                if ( ! function_exists( 'ini_get' ) || true != ini_get( 'allow_url_fopen' ) )
     932                        return false;
     933
     934                $is_ssl = isset( $args['ssl'] ) && $args['ssl'];
     935
     936                if ( $is_ssl && ! extension_loaded( 'openssl' ) )
     937                        return false;
     938
     939                return apply_filters( 'use_streams_transport', true, $args );
    933940        }
    934941}
     
    13091316         * @return boolean False means this class can not be used, true means it can.
    13101317         */
    1311         function test($args = array()) {
    1312                 if ( function_exists('curl_init') && function_exists('curl_exec') )
    1313                         return apply_filters('use_curl_transport', true, $args);
    1314 
    1315                 return false;
     1318        function test( $args = array() ) {
     1319                if ( ! function_exists( 'curl_init' ) || ! function_exists( 'curl_exec' ) )
     1320                        return false;
     1321
     1322                $is_ssl = isset( $args['ssl'] ) && $args['ssl'];
     1323
     1324                if ( $is_ssl ) {
     1325                        $curl_version = curl_version();
     1326                        if ( ! (CURL_VERSION_SSL & $curl_version['features']) ) // Does this cURL version support SSL requests?
     1327                                return false;
     1328                }
     1329
     1330                return apply_filters( 'use_curl_transport', true, $args );
    13161331        }
    13171332}
Note: See TracChangeset for help on using the changeset viewer.