I am trying to update the value of an option in the DB for all sites within my multisite, but no success here is the code, been pulling my hair out for the last 2 hours:

function simplifyit_upload_folder($blog_id){
      update_option('uploads_use_yearmonth_folders', false);      
      add_action( 'update_wpmu_options', 'simplifyit_upload_folder' );

Thanks to @TheDeadMedic who gave me the answer for filtering but I am looking to update the value in the DB:

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

Sorry for not being clearer I want to make sure that all blogs in the network are set by default to 0 for YYYYMM upload option but would like to have the possibility to let the Network administrator override it via the WP Network panel should he /she wish to do so for individual sites

  • Have you tried 0 instead of false? – fuxia Jun 26 '13 at 13:06
  • Yes I did unfortunately it does not work either! – TARMAK Jun 26 '13 at 13:13
  • The field just ends up with an empty value :-( – TARMAK Jun 26 '13 at 13:18

Well, "update_wpmu_options" is certainly the wrong hook. It doesn't send the blog_id as a parameter, so your code won't ever work with that hook and use of the blog_id parameter.

If you just wanted to update the value on each site, then I would just put update_option('uploads_use_yearmonth_folders', 0); on the init hook, and wait for each site to be visited once.

  • What about wpmu_update_blog_options? There are so many hooks without documentation do you recommend a good site which list them all and their usage, I have been to adambrown.info/p/wp_hooks but still I am a bit of a novice when it comes to WP – TARMAK Jun 26 '13 at 13:59
  • Could be a problem there must be a hook that lets you pass that value straight to the DB without any prior user action! Have updated what I am looking to accomplish above – TARMAK Jun 26 '13 at 14:17
  • Yes, there is such a hook: init, like I stated in the answer above. – Otto Jun 27 '13 at 13:49

The field just ends up with an empty value :-(

If what you want to do is remove the value, as it seems you do from that comment, then you need delete_option, or delete_site_option. The latter seems most appropriate.

function simplifyit_upload_folder(){
    $current_site = get_current_site();
add_action( 'update_wpmu_options', 'simplifyit_upload_folder' );

I used get_current_site to get the blog ID, as that hook does not pass the value.

I am not completely sure that the hook you want though. It runs in the admin and only when there is POST data-- http://core.trac.wordpress.org/browser/trunk/wp-admin/network/settings.php#L69

Based on an edit to the question, it sounds like you want the wpmu_new_blog hook, so that your value is set on blog creation. After which blog admins could alter it, and your code would not interfere.

Untested (I don't have MU on a dev server right now) but...

function simplifyit_upload_folder($blog_id){
    // not 100% sure exactly what you need here; caveat emptor :)
    update_option('uploads_use_yearmonth_folders', false);      
add_action( 'wpmu_new_blog', 'simplifyit_upload_folder' );
  • Ok this would not work unless someone updates any settings on the blog in question! The filter above still seems the safest option then! – TARMAK Jun 26 '13 at 14:04
  • That is what it looks like, yes. I haven't done anything to explicitly verify that though. – s_ha_dum Jun 26 '13 at 14:05
  • As far as the filter being the "safest", I'm not completely sure what you want to accomplish. – s_ha_dum Jun 26 '13 at 14:07
  • There seems to be tone of other Wpmu option related hooks though none of which I am familiar with another one being wpmu_update_blog_options – TARMAK Jun 26 '13 at 14:07
  • 1
    Individual blog admins on multisite don't have the ability to alter the "uploads_use_yearmonth_folders" option at all. That's a per-site setting that is in the network admin area. So I'm thinking there's some other kind of underlying problem here that isn't being clarified properly. – Otto Jun 26 '13 at 15:39

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.