[wp-trac] [WordPress Trac] #36931: wp_upload_dir caches calls with default arguments separately from their explicit equivalent
WordPress Trac
noreply at wordpress.org
Tue May 24 09:55:07 UTC 2016
#36931: wp_upload_dir caches calls with default arguments separately from their
explicit equivalent
---------------------------+-----------------------------
Reporter: stephenharris | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version: 4.5.2
Severity: normal | Keywords:
Focuses: |
---------------------------+-----------------------------
This a fairly minor bug. Prior to [36565] the following were equivalent
{{{#!php
$upload = wp_upload_dir();
$upload2 = wp_upload_dir( gmstrftime('%Y/%m') );
}}}
(In deed, even `$upload3 = wp_upload_dir( gmstrftime('%Y/%m yabadabadoo')
);` is equivalent, but that behaviour is undocumented.)
Since caching has been introduced the first call to `wp_upload_dir()` is
stored separately in the cache to the second call, despite the fact that
they are otherwise interpreted the same.
This causes a disparity in behaviour when one of the caches is cleared
after a setting has been changed:
{{{#!php
$upload = wp_upload_dir();
$upload2 = wp_upload_dir( gmstrftime('%Y/%m') );
// $upload == $upload2
//Disable year/month folders and clear the cache
add_filter( 'pre_option_uploads_use_yearmonth_folders', '__return_null' );
wp_upload_dir( null, false, true );
$upload = wp_upload_dir( null );
$upload2 = wp_upload_dir( gmstrftime('%Y/%m') );
//$upload != $upload2
remove_filter( 'pre_option_uploads_use_yearmonth_folders', '__return_null'
);
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/36931>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list