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/tests/post/attachments.php

    r35479 r36565  
    442442     */
    443443    public function test_wp_get_attachment_url_should_force_https_when_administering_over_https_and_siteurl_is_https() {
    444         // Must set the upload_url_path to fake out `wp_upload_dir()`.
    445         $siteurl = get_option( 'siteurl' );
    446         update_option( 'upload_url_path', set_url_scheme( $siteurl, 'https' ) . '/uploads' );
     444        // Set https upload URL
     445        add_filter( 'upload_dir', '_upload_dir_https' );
    447446
    448447        $filename = ( DIR_TESTDATA . '/images/test-image.jpg' );
     
    464463        $_SERVER['HTTPS'] = $is_ssl ? 'on' : 'off';
    465464        set_current_screen( 'front' );
     465        remove_filter( 'upload_dir', '_upload_dir_https' );
    466466
    467467        $this->assertSame( set_url_scheme( $url, 'https' ), $url );
Note: See TracChangeset for help on using the changeset viewer.