From 079afa8ce25c1597eba9bdde601a61df46ba570f Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Wed, 26 Sep 2012 05:02:58 +0000 Subject: [PATCH] Rearrange the order that we check for temporary directories in get_temp_dir(). This change causes us to use System temporary directories in preference to WP_CONTENT_DIR, for better windows compatibility, we use win_is_writable() as well. Props simonwheatley and kurtpayne for initial patches, See #20778 git-svn-id: http://core.svn.wordpress.org/trunk@22008 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 404367168a..f541c787b4 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1367,9 +1367,13 @@ function path_join( $base, $path ) { /** * Determines a writable directory for temporary files. - * Function's preference is to WP_CONTENT_DIR followed by the return value of sys_get_temp_dir(), before finally defaulting to /tmp/ + * Function's preference is the return value of sys_get_temp_dir(), + * followed by your PHP temporary upload directory, followed by WP_CONTENT_DIR, + * before finally defaulting to /tmp/ * - * In the event that this function does not find a writable location, It may be overridden by the WP_TEMP_DIR constant in your wp-config.php file. + * In the event that this function does not find a writable location, + * It may be overridden by the WP_TEMP_DIR constant in + * your wp-config.php file. * * @since 2.5.0 * @@ -1383,20 +1387,23 @@ function get_temp_dir() { if ( $temp ) return trailingslashit($temp); - $temp = WP_CONTENT_DIR . '/'; - if ( is_dir($temp) && @is_writable($temp) ) - return $temp; + $is_win = ( 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) ); - if ( function_exists('sys_get_temp_dir') ) { + if ( function_exists('sys_get_temp_dir') ) { $temp = sys_get_temp_dir(); - if ( @is_writable($temp) ) - return trailingslashit($temp); + if ( is_dir( $temp ) && ( $is_win ? win_is_writable( $temp ) : @is_writable( $temp ) ) ) { + return trailingslashit( $temp ); + } } $temp = ini_get('upload_tmp_dir'); - if ( is_dir($temp) && @is_writable($temp) ) + if ( is_dir( $temp ) && ( $is_win ? win_is_writable( $temp ) : @is_writable( $temp ) ) ) return trailingslashit($temp); + $temp = WP_CONTENT_DIR . '/'; + if ( is_dir( $temp ) && ( $is_win ? win_is_writable( $temp ) : @is_writable( $temp ) ) ) + return $temp; + $temp = '/tmp/'; return $temp; }