In WordPress Multisite, by default the site option Uploads Use Yearmonth Folders is on (set to 1). Is it possible to force this value for all existing sites in the Network?

Perhaps a hook?
I know that for new sites created one can use:

function simplify_upload_folder($blog_id){
    update_option('uploads_use_yearmonth_folders', false);
add_action('wpmu_new_blog', 'simplify_upload_folder');

But what about already existing sites can one force this value via an action or filter?

As an alternative to using a filter, I have written up the following to toggle the value in the DB but for some reason the field remains empty. Not sure where I am going wrong here:

if ( get_option( 'uploads_use_yearmonth_folders' ) == true || get_option( 'uploads_use_yearmonth_folders' ) == '' ) {
      update_option('uploads_use_yearmonth_folders', false);
add_filter( 'option_uploads_use_yearmonth_folders', '__return_false', 100 );

That's all you need, seriously!

  • You mean just that line? I tried it and the value is still set to 1? This should work on a single install although I have not tried it. What about multisite? – TARMAK Jun 26 '13 at 10:54
  • When you say the value is still set to 1, do you mean in the database? Because that's fine, the filter will always override it, and so is effective site-wide immediately. – TheDeadMedic Jun 26 '13 at 10:57
  • Correct @TheDeadMedic you are totally right. You rock! How does that affect loading performance. I mean filtering versus DB query? I guess this also removes the possibility of some sites keeping the YYMM structure? – TARMAK Jun 26 '13 at 11:03
  • What I mean is that if you wanted to not force it for future sites created one would have to write the value to DB. – TARMAK Jun 26 '13 at 11:10
  • Zero impact. The filter will always override the user-saved setting. You'd need to write some additional checking logic to factor in future sites. – TheDeadMedic Jun 26 '13 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.