Make WordPress Core


Ignore:
Timestamp:
02/17/2016 10:51:01 PM (9 years ago)
Author:
azaozz
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/functions.php

    r32139 r36565  
    116116    update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
    117117}
     118
     119/**
     120 * Helper used with the `upload_dir` filter to remove the /year/month sub directories from the uploads path and URL.
     121 */
     122function _upload_dir_no_subdir( $uploads ) {
     123    $subdir = $uploads['subdir'];
     124
     125    $uploads['subdir'] = '';
     126    $uploads['path'] = str_replace( $subdir, '', $uploads['path'] );
     127    $uploads['url'] = str_replace( $subdir, '', $uploads['url'] );
     128
     129    return $uploads;
     130}
     131
     132/**
     133 * Helper used with the `upload_dir` filter to set https upload URL.
     134 */
     135function _upload_dir_https( $uploads ) {
     136    $uploads['url'] = str_replace( 'http://', 'https://', $uploads['url'] );
     137    $uploads['baseurl'] = str_replace( 'http://', 'https://', $uploads['baseurl'] );
     138
     139    return $uploads;
     140}
Note: See TracChangeset for help on using the changeset viewer.