Ticket #16606: 16606.5.diff

File 16606.5.diff, 3.8 KB (added by mdawaffe, 2 years ago)
Line 
1Index: wp-includes/class-http.php
2===================================================================
3--- wp-includes/class-http.php  (revision 17587)
4+++ wp-includes/class-http.php  (working copy)
5@@ -746,19 +746,23 @@
6         * @return boolean False means this class can not be used, true means it can.
7         */
8        function test( $args = array() ) {
9-               if ( false !== ($option = get_option( 'disable_fsockopen' )) && time()-$option < 43200 ) // 12 hours
10+               // Doesn't exist
11+               if ( !function_exists( 'fsockopen' ) )
12                        return false;
13 
14-               $is_ssl = isset($args['ssl']) && $args['ssl'];
15+               // We disabled fsockopen because it's too slow
16+               if ( false !== ( $option = get_option( 'disable_fsockopen' ) ) && time() - $option < 43200 ) // 12 hours
17+                       return false;
18 
19-               if ( ! $is_ssl && function_exists( 'fsockopen' ) )
20+               if ( isset( $args['ssl'] ) && $args['ssl'] ) {
21+                       // We need SSL.  Check if it's available.
22+                       $use = extension_loaded( 'openssl' );
23+               } else {
24+                       // No SSL needed
25                        $use = true;
26-               elseif ( $is_ssl && extension_loaded('openssl') && function_exists( 'fsockopen' ) )
27-                       $use = true;
28-               else
29-                       $use = false;
30+               }
31 
32-               return apply_filters('use_fsockopen_transport', $use, $args);
33+               return apply_filters( 'use_fsockopen_transport', $use, $args );
34        }
35 }
36 
37@@ -929,11 +933,20 @@
38         *
39         * @return boolean False means this class can not be used, true means it can.
40         */
41-       function test($args = array()) {
42-               if ( ! function_exists('fopen') || (function_exists('ini_get') && true != ini_get('allow_url_fopen')) )
43+       function test( $args = array() ) {
44+               // Doesn't exist
45+               if ( !function_exists( 'fopen' ) || ( function_exists( 'ini_get' ) && !ini_get( 'allow_url_fopen' ) ) )
46                        return false;
47 
48-               return apply_filters('use_streams_transport', true, $args);
49+               if ( isset( $args['ssl'] ) && $args['ssl'] ) {
50+                       // We need SSL.  Check if it's available.
51+                       $use = extension_loaded( 'openssl' );
52+               } else {
53+                       // No SSL needed
54+                       $use = true;
55+               }
56+
57+               return apply_filters( 'use_streams_transport', $use, $args );
58        }
59 }
60 
61@@ -1096,8 +1109,25 @@
62         *
63         * @return boolean False means this class can not be used, true means it can.
64         */
65-       function test($args = array()) {
66-               return apply_filters('use_http_extension_transport', function_exists('http_request'), $args );
67+       function test( $args = array() ) {
68+               // Doesn't exist
69+               if ( !function_exists( 'http_request' ) )
70+                       return false;
71+
72+               if ( isset( $args['ssl'] ) && $args['ssl'] ) {
73+                       // We need SSL.  Check if it's available.
74+                       if ( is_callable( 'curl_version' ) && $curl_version = curl_version() ) {
75+                               // The HTTP Extensions is ultimately cURL based.  See if we can detect the cURL SSL capability.
76+                               $use = CURL_VERSION_SSL & $curl_version['features']; // bitwise
77+                       } else {
78+                               $use = extension_loaded( 'openssl' );
79+                       }
80+               } else {
81+                       // No SSL needed
82+                       $use = true;
83+               }
84+
85+               return apply_filters( 'use_http_extension_transport', (bool) $use, $args );
86        }
87 }
88 
89@@ -1312,11 +1342,24 @@
90         *
91         * @return boolean False means this class can not be used, true means it can.
92         */
93-       function test($args = array()) {
94-               if ( function_exists('curl_init') && function_exists('curl_exec') )
95-                       return apply_filters('use_curl_transport', true, $args);
96+       function test( $args = array() ) {
97+               // Doesn't exist
98+               if ( !function_exists( 'curl_init' ) || !function_exists( 'curl_exec' ) )
99+                       return false;
100 
101-               return false;
102+               if ( isset( $args['ssl'] ) && $args['ssl'] ) {
103+                       // We need SSL.  Check if it's available.
104+                       if ( is_callable( 'curl_version' ) && $curl_version = curl_version() ) {
105+                               $use = CURL_VERSION_SSL & $curl_version['features']; // bitwise
106+                       } else {
107+                               $use = extension_loaded( 'openssl' );
108+                       }
109+               } else {
110+                       // No SSL needed
111+                       $use = true;
112+               }
113+
114+               return apply_filters( 'use_curl_transport', (bool) $use, $args );
115        }
116 }
117