Improve the performance of wp_upload_dir():

- Cache the output in non-persistent cache.
- Cache the result from `wp_mkdir_p()` in persistent cache (when present).
- Introduce `wp_get_upload_dir()` for use when not uploading files. It is equivalent to `wp_upload_dir()` but does not check for the existence or create the upload directory.
- Change tests to use the non-cached `_wp_upload_dir()`. They change options on the fly (should never be used in production) to simulate different environments.
- Introduce `_upload_dir_no_subdir()` and `_upload_dir_https()` to facilitate testing. These use the proper `upload_dir` filter to simulate different environments.

Props kovshenin, azaozz.
See #34359.

git-svn-id: https://develop.svn.wordpress.org/trunk@36565 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz
2016-02-17 22:51:01 +00:00
parent 1afe1da216
commit c7936b8785
5 changed files with 159 additions and 70 deletions
+2 -7
View File
@@ -895,11 +895,8 @@ EOF;
function test_wp_calculate_image_srcset_no_date_uploads() {
global $_wp_additional_image_sizes;
// Save the current setting for uploads folders
$uploads_use_yearmonth_folders = get_option( 'uploads_use_yearmonth_folders' );
// Disable date organized uploads
update_option( 'uploads_use_yearmonth_folders', 0 );
add_filter( 'upload_dir', '_upload_dir_no_subdir' );
// Make an image.
$filename = DIR_TESTDATA . '/images/test-image-large.png';
@@ -937,9 +934,7 @@ EOF;
// Remove the attachment
wp_delete_attachment( $id );
// Leave the uploads option the way you found it.
update_option( 'uploads_use_yearmonth_folders', $uploads_use_yearmonth_folders );
remove_filter( 'upload_dir', '_upload_dir_no_subdir' );
}
/**