WordPress.org

Make WordPress Core

Ticket #20778: 20778.diff

File 20778.diff, 1.9 KB (added by dd32, 6 years ago)
  • wp-includes/functions.php

     
    13671367
    13681368/**
    13691369 * Determines a writable directory for temporary files.
    1370  * Function's preference is to WP_CONTENT_DIR followed by the return value of <code>sys_get_temp_dir()</code>, before finally defaulting to /tmp/
     1370 * Function's preference is the return value of <code>sys_get_temp_dir()</code>,
     1371 * followed by your PHP temporary upload directory, followed by WP_CONTENT_DIR,
     1372 * before finally defaulting to /tmp/
    13711373 *
    1372  * In the event that this function does not find a writable location, It may be overridden by the <code>WP_TEMP_DIR</code> constant in your <code>wp-config.php</code> file.
     1374 * In the event that this function does not find a writable location,
     1375 * It may be overridden by the <code>WP_TEMP_DIR</code> constant in
     1376 * your <code>wp-config.php</code> file.
    13731377 *
    13741378 * @since 2.5.0
    13751379 *
     
    13831387        if ( $temp )
    13841388                return trailingslashit($temp);
    13851389
    1386         $temp = WP_CONTENT_DIR . '/';
    1387         if ( is_dir($temp) && @is_writable($temp) )
    1388                 return $temp;
     1390        $is_win = ( 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) );
    13891391
    13901392        if  ( function_exists('sys_get_temp_dir') ) {
    13911393                $temp = sys_get_temp_dir();
    1392                 if ( @is_writable($temp) )
    1393                         return trailingslashit($temp);
     1394                if ( is_dir( $temp ) && ( $is_win ? win_is_writable( $temp ) : @is_writable( $temp ) ) ) {
     1395                        return trailingslashit( $temp );
     1396                }
    13941397        }
    13951398
    13961399        $temp = ini_get('upload_tmp_dir');
    1397         if ( is_dir($temp) && @is_writable($temp) )
     1400        if ( is_dir( $temp ) && ( $is_win ? win_is_writable( $temp ) : @is_writable( $temp ) ) )
    13981401                return trailingslashit($temp);
    13991402
     1403        $temp = WP_CONTENT_DIR . '/';
     1404        if ( is_dir( $temp ) && ( $is_win ? win_is_writable( $temp ) : @is_writable( $temp ) ) )
     1405                return $temp;
     1406
    14001407        $temp = '/tmp/';
    14011408        return $temp;
    14021409}