WordPress.org

Make WordPress Core

Ticket #36931: 36931.diff

File 36931.diff, 1.4 KB (added by stephenharris, 5 years ago)
  • src/wp-includes/functions.php

     
    18571857function wp_upload_dir( $time = null, $create_dir = true, $refresh_cache = false ) {
    18581858        static $cache = array(), $tested_paths = array();
    18591859
     1860        if ( ! $time ) {
     1861                $time = gmstrftime( '%Y/%m' );
     1862        }
     1863
    18601864        $key = sprintf( '%d-%s', get_current_blog_id(), (string) $time );
    18611865
    18621866        if ( $refresh_cache || empty( $cache[ $key ] ) ) {
  • tests/phpunit/tests/upload.php

     
    110110                $this->assertEquals( false, $info['error'] );
    111111        }
    112112
     113        /**
     114         * @ticket 36931
     115         */
     116        function test_upload_cache() {
     117                //These two should behave identically
     118                $upload = wp_upload_dir();
     119                $upload2 = wp_upload_dir( gmstrftime('%Y/%m') );
     120
     121                $this->assertEquals( $upload, $upload2 );
     122
     123                //Disable year/month folders and clear cache
     124                add_filter( 'pre_option_uploads_use_yearmonth_folders', '__return_null' );
     125                wp_upload_dir( null, false, true );
     126
     127                $upload = wp_upload_dir();
     128                $upload2 = wp_upload_dir( gmstrftime('%Y/%m') );
     129
     130                $this->assertEquals( $upload, $upload2 );
     131
     132                remove_filter( 'pre_option_uploads_use_yearmonth_folders', '__return_null' );
     133        }
     134
    113135}