Changeset 33969 for trunk/src/wp-includes/functions.php
- Timestamp:
- 09/09/2015 04:25:24 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/functions.php
r33849 r33969 562 562 } 563 563 } 564 }565 566 /**567 * Perform a HTTP HEAD or GET request.568 *569 * If $file_path is a writable filename, this will do a GET request and write570 * the file to that path.571 *572 * @since 2.5.0573 *574 * @param string $url URL to fetch.575 * @param string|bool $file_path Optional. File path to write request to. Default false.576 * @param int $red Optional. The number of Redirects followed, Upon 5 being hit,577 * returns false. Default 1.578 * @return bool|string False on failure and string of headers if HEAD request.579 */580 function wp_get_http( $url, $file_path = false, $red = 1 ) {581 @set_time_limit( 60 );582 583 if ( $red > 5 )584 return false;585 586 $options = array();587 $options['redirection'] = 5;588 589 if ( false == $file_path )590 $options['method'] = 'HEAD';591 else592 $options['method'] = 'GET';593 594 $response = wp_safe_remote_request( $url, $options );595 596 if ( is_wp_error( $response ) )597 return false;598 599 $headers = wp_remote_retrieve_headers( $response );600 $headers['response'] = wp_remote_retrieve_response_code( $response );601 602 // WP_HTTP no longer follows redirects for HEAD requests.603 if ( 'HEAD' == $options['method'] && in_array($headers['response'], array(301, 302)) && isset( $headers['location'] ) ) {604 return wp_get_http( $headers['location'], $file_path, ++$red );605 }606 607 if ( false == $file_path )608 return $headers;609 610 // GET request - write it to the supplied filename611 $out_fp = fopen($file_path, 'w');612 if ( !$out_fp )613 return $headers;614 615 fwrite( $out_fp, wp_remote_retrieve_body( $response ) );616 fclose($out_fp);617 clearstatcache();618 619 return $headers;620 564 } 621 565
Note: See TracChangeset
for help on using the changeset viewer.