Avatars Not Showing with define( ‘BP_ENABLE_MULTIBLOG’, true );
-
Hey Guys, so I’ve searched google and forums and found no real answers to this issue.. I’m running multisite with define( ‘BP_ENABLE_MULTIBLOG’, true ); WP version 3.2.2 and latest of BP. Avatars seem to work fine on the home site, but on my test site no love. I’ve found that were some issues with this in the past. Can anyone assist with leading me to the right direction on resolving this? Thank you.
-Luis
-
Looks like i have the same problem. Do you know any solutions?
As of writing this, my understanding of the avatar-loading-code-in-question (bp_core_avatars.php) is:
IF in a multisite environment AND current blog is not the root blog THEN grab the upload path from the root blog and store it in the global bp_core_avatar_url variable.
If coding isn’t your thing (like it isn’t mine), the main thing you should take away from this is that you have to define your root blog. This is where I was failing. To set root blog, add
define( 'BP_ROOT_BLOG', 1 );
to wp-config. 1 is the ID of the domain that you installed buddypress on. To find that ID, navigate to My Sites–>Network Admin–>Sites, then hover over the domain URL that you installed buddypress on and look at the URL path in the bottom left of your screen. The end of the path will look something like …/site-info.php?id=1.Give that a go and see what happens. If you’re still SOL, right click on the broken avatar and click “Copy Image URL” and include that URL in your reply back to this thread.
You can not use define(‘BP_ENABLE_MULTIBLOG’, true); and define(‘BP_ROOT_BLOG’, 1), at the same time.
Good call, @Roman. Defining both fixed one problem, but introduced many more.
Delving deeper, I believe that multisite is designed, on purpose, to keep things separate amongst network sites. That includes avatars, group avatars, etc. That is why each site has a separate upload directory (wp-content/blogs.dir/3/files/avatars, wp-content/blogs.dir/4/files/group-avatars and so on…).
By default, each subsite’s upload path is something like wp-content/blogs.dir/5/files. And the home site’s upload path is wp-content/uploads. If no root blog is set (which @Roman pointed out that we can’t set a root blog AND enable multiblog), then the code will set the current site as the root blog and grab that site’s upload path. For example, if I’m on site 5 of a WPmultisite/BPmultiblog install, the site will look to pull files from the wp-content/blogs.dir/5/files folder. Accordingly, it will find any files that were uploaded to that directory, from site 5. It won’t find your avatar, because you likely uploaded them via the home site, and those avatars reside in the wp-content/uploads folder.
While this design probably works for most implementations, it does not suit my purposes. I need to show avatars and group avatars across all sites (sounds like you both do as well). With that in mind, here is the path I’m heading down:
The Network Admin Sites/Settings page (accessible via wp-admin dashboard at wp-admin/network/site-settings.php?id=4) allows you to update the “Upload Path”, “Upload URL Path”, and “Fileupload URL”. For my project, I modified all subsites to be the same as the home site upload path: “wp-content/uploads”, “http://example.com/wp-content/uploads”, and “http://example.com/wp-content/uploads”, respectively. HOWEVER, you can update them until you are blue in the face, but you will never successfully upload to the directory you update to. This is because WP overwrites these custom upload paths with the default upload paths mentioned above. This is done on the last line of wp-includes/ms-settings.php. As @Andrea Rennick points out on wordpress.org, this was done to protect ourselves from…ourselves by hosing things up in a multisite environment. On that same WP thread, @cooliojones proposed the fix of commenting out the last line in wp-includes/ms-settings.php, which is ms_upload_constants();.
YES, it’s a core hack, and NO it’s not the ideal solution, but I’m plowing forward with it anyway because I don’t want my project to die while I throw on my One Love cape and try to solve all the BP/WP integration problems of the world. I guess you have to ask yourself which is more important to you: common avatars across sites OR maintaining separate upload directories across sites?
Hope that helps.
As a last second, chuck it into the end zone and pray…Since I only need group/avatars to display across the multisites, I’m thinking it would be ideal if there way some way to define separate upload paths for group/avatars from all other uploads. Anyone have the golden ticket for that?
Hi @fivehead
I had already found decision for me. This small hack completely fixed avatar and group avatar problem for my site in MULTIBLOG mode:`
/* This fixes the MULTIBLOG avatar problem */
function nfm_bp_avtar_upload_path_correct($path){
if ( bp_core_is_multisite() ){
// $path = ABSPATH . get_blog_option( BP_ROOT_BLOG, ‘upload_path’ );
$path = ABSPATH . ‘wp-content/uploads/’;
}
return $path;
}
add_filter(‘bp_core_avatar_upload_path’, ‘nfm_bp_avtar_upload_path_correct’, 1);function nfm_bp_avatar_upload_url_correct($url){
if ( bp_core_is_multisite() ){
$url = get_blog_option( BP_ROOT_BLOG, ‘siteurl’ ) . “/wp-content/uploads”;
}
return $url;
}
add_filter(‘bp_core_avatar_url’, ‘nfm_bp_avatar_upload_url_correct’, 1);
`@Roman, I’ve seen a similar fix out there on the interwebs, but it didn’t work for me. Yours looks to be tweaked a bit from what I’ve seen, so I’ll give it a go. Where did you put this bit of code?
You are should add it to bp-custom.php
If you don’t have this file:
https://codex.buddypress.org/developer/customizing/bp-custom-php/Thank you!!!
I just tried @lrv ‘s code and it works like charm.
Even 9 months later ( uptade-wise ).
- The topic ‘Avatars Not Showing with define( ‘BP_ENABLE_MULTIBLOG’, true );’ is closed to new replies.