Exemplo n.º 1
0
 /**
  * Perform a HEAD request to the specified URL.
  * 
  * Note : 
  * 
  * Since the MediaFire checker works by parsing the "Location" header, redirect following
  * _must_ be disabled. This can become a problem on servers where WP is forced to fall back
  * on using WP_Http_Fopen which ignores the 'redirection' flag. WP_Http_Fsockopen would work, 
  * but it has the lowest priority of all transports. 
  * 
  * Alas, there is no way to reliably influence which transport is chosen - the WP_Http::_getTransport
  * function caches the available choices, so plugins can disable individual transports only during
  * its first run. Therefore, we must pick the best transport manually.
  * 
  * @param string $url
  * @return array|WP_Error
  */
 function head($url)
 {
     //Only consider transports that allow redirection to be disabled.
     $args = array();
     if (class_exists('WP_Http_ExtHttp') && true === WP_Http_ExtHttp::test($args)) {
         $transport = new WP_Http_ExtHttp();
     } else {
         if (class_exists('WP_Http_Curl') && true === WP_Http_Curl::test($args)) {
             $transport = new WP_Http_Curl();
         } else {
             if (class_exists('WP_Http_Curl') && true === WP_Http_Fsockopen::test($args)) {
                 $transport = new WP_Http_Fsockopen();
             } else {
                 return new WP_Error('no_suitable_transport', "No suitable HTTP transport found. Please upgrade to a more recent version of PHP or install the CURL extension.");
             }
         }
     }
     $conf = blc_get_configuration();
     $args = array('timeout' => $conf->options['timeout'], 'redirection' => 0, 'method' => 'HEAD');
     return $transport->request($url, $args);
 }