Share the same uploads dir for a BuddyPress multiblog set up
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
@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?
thanks, thought I'd just mention this still works
Just chiming in to say this worked like a charm. Thank you!!
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:
- Activated Multiblog with define( 'BP_ENABLE_MULTIBLOG', true );
- Made a new directory in main directory>Plugins>bp-custom
- 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
Hi @imath,
That worked just fine.
Thank you again,