Skip to content

Instantly share code, notes, and snippets.

@imath
Created March 3, 2016 17:18
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save imath/91d56292673e6de61597 to your computer and use it in GitHub Desktop.
Share the same uploads dir for a BuddyPress multiblog set up
<?php
/**
* Multiblog must have been set for it to work :)
*
* eg: define( 'BP_ENABLE_MULTIBLOG', true );
*/
function rbaccaro_set_multiblog_shared_upload_dir() {
if ( ! bp_is_multiblog_mode() ) {
return;
}
$current_site = get_current_site();
if ( (int) bp_get_root_blog_id() !== (int) $current_site->blog_id ) {
$switched = true;
switch_to_blog( $current_site->blog_id );
}
buddypress()->upload_dir = wp_upload_dir();
if ( ! empty( $switched ) ) {
restore_current_blog();
}
}
add_action( 'bp_init', 'rbaccaro_set_multiblog_shared_upload_dir', 1 );
@rbaccaro
Copy link

rbaccaro commented Mar 3, 2016

Hi @imath,

That worked just fine.

Thank you again,

@eskadesign
Copy link

@imath I've tried this great looking piece of code on my multiblog but it does not work, it shows a grey area on the main site and subsite after uploading an image.

Is there a fix for this?

@trivendor
Copy link

thanks, thought I'd just mention this still works

@alex-abell
Copy link

Just chiming in to say this worked like a charm. Thank you!!

@scratchmasterp
Copy link

Hello,

Thanks so much for creating this plugin. Can I get a couple of tips please to get it working? So far, I have done the following, but Cover Photos and Avatar images are still not syncing for the Groups and Members.

Here is what I've tried so far:

  1. Activated Multiblog with define( 'BP_ENABLE_MULTIBLOG', true );
  2. Made a new directory in main directory>Plugins>bp-custom
  3. Created a new text file and pasted your code above.

However the solution is not working at the moment. Any ideas how to fix? I would really appreciate your guidance on this.

Thanks very much. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment