Allow for the callee of download_url() to specify a different timeout if they want to - maybe they don't want to wait that long.
git-svn-id: https://develop.svn.wordpress.org/trunk@16763 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
af3222dc7e
commit
0485062f5d
@ -507,9 +507,10 @@ function wp_handle_sideload( &$file, $overrides = false ) {
|
|||||||
* @since 2.5.0
|
* @since 2.5.0
|
||||||
*
|
*
|
||||||
* @param string $url the URL of the file to download
|
* @param string $url the URL of the file to download
|
||||||
|
* @param int $timeout The timeout for the request to download the file default 300 seconds
|
||||||
* @return mixed WP_Error on failure, string Filename on success.
|
* @return mixed WP_Error on failure, string Filename on success.
|
||||||
*/
|
*/
|
||||||
function download_url( $url ) {
|
function download_url( $url, $timeout = 300 ) {
|
||||||
//WARNING: The file is not automatically deleted, The script must unlink() the file.
|
//WARNING: The file is not automatically deleted, The script must unlink() the file.
|
||||||
if ( ! $url )
|
if ( ! $url )
|
||||||
return new WP_Error('http_no_url', __('Invalid URL Provided.'));
|
return new WP_Error('http_no_url', __('Invalid URL Provided.'));
|
||||||
@ -522,7 +523,7 @@ function download_url( $url ) {
|
|||||||
if ( ! $handle )
|
if ( ! $handle )
|
||||||
return new WP_Error('http_no_file', __('Could not create Temporary file.'));
|
return new WP_Error('http_no_file', __('Could not create Temporary file.'));
|
||||||
|
|
||||||
$response = wp_remote_get($url, array('timeout' => 300));
|
$response = wp_remote_get($url, array('timeout' => $timeout));
|
||||||
|
|
||||||
if ( is_wp_error($response) ) {
|
if ( is_wp_error($response) ) {
|
||||||
fclose($handle);
|
fclose($handle);
|
||||||
|
Loading…
Reference in New Issue
Block a user