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){
    switch_to_blog($blog_id);
    update_option('uploads_use_yearmonth_folders', false);
    restore_current_blog();
}
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' ) == '' ) {
      switch_to_blog($blog_id);
      update_option('uploads_use_yearmonth_folders', false);
      restore_current_blog();
}

1 Answer
1

add_filter( 'option_uploads_use_yearmonth_folders', '__return_false', 100 );

That’s all you need, seriously!

Leave a Reply

Your email address will not be published. Required fields are marked *