* @return array See above for description.
*/
function wp_upload_dir( $time = null, $create_dir = true, $refresh_cache = false ) {
- static $cache = array();
+ static $cache = array(), $tested_paths = array();
$key = sprintf( '%d-%s', get_current_blog_id(), (string) $time );
if ( $create_dir ) {
$path = $uploads['path'];
- $tested_paths = wp_cache_get( 'upload_dir_tested_paths' );
- if ( ! is_array( $tested_paths ) ) {
- $tested_paths = array();
- }
-
- if ( ! in_array( $path, $tested_paths, true ) ) {
+ if ( array_key_exists( $path, $tested_paths ) ) {
+ $uploads['error'] = $tested_paths[ $path ];
+ } else {
if ( ! wp_mkdir_p( $path ) ) {
if ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) {
$error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir'];
}
$uploads['error'] = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), esc_html( $error_path ) );
- } else {
- $tested_paths[] = $path;
- wp_cache_set( 'upload_dir_tested_paths', $tested_paths );
}
+
+ $tested_paths[ $path ] = $uploads['error'];
}
}