Skip to:
Content

BuddyPress.org

Opened 12 years ago

Closed 11 years ago

Last modified 7 years ago

#4252 closed defect (bug) (duplicate)

Avatars are (erroneously) stored locally when running BP_ENABLE_MULTIBLOG

Reported by: douglance's profile douglance Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Core Keywords: reporter-feedback has-patch
Cc: rachelbaker, lrv

Description

When BP_ENABLE_MULTIBLOG is activated, the avatars of sub-directory sites are pointing to the wrong location. Either old avatars are displayed or the images are broken.

Change History (15)

#1 follow-up: @boonebgorges
12 years ago

  • Keywords reporter-feedback added

Can you say more about how to reproduce the problem? What are "the avatars of sub-directory sites"? Does that mean: user avatars on blogs other than blog #1? Or does it mean the avatars that appear in the Sites directory? And what do you mean by "old avatars"?

#2 in reply to: ↑ 1 ; follow-up: @douglance
12 years ago

Replying to boonebgorges:

Can you say more about how to reproduce the problem? What are "the avatars of sub-directory sites"? Does that mean: user avatars on blogs other than blog #1? Or does it mean the avatars that appear in the Sites directory? And what do you mean by "old avatars"?

I installed Multisite, then enabled BP_ENABLE_MULTIBLOG, then created sub-directory sites.

Both the group avatars and the user avatars are not functioning correctly. The group avatars are displaying as default. The user avatars are either displayed as default or as avatars that the user had used in the past.

All avatars function correctly on main site.

#3 in reply to: ↑ 2 @rachelbaker
12 years ago

  • Cc rachelbaker added

Replying to douglance:

Both the group avatars and the user avatars are not functioning correctly. The group avatars are displaying as default. The user avatars are either displayed as default or as avatars that the user had used in the past.

All avatars function correctly on main site.

Doug,

What are you using as the upload directories for the sub-directory sites? Something like: wp-content/blogs.dir/2/files ?

#4 follow-up: @boonebgorges
12 years ago

  • Milestone changed from Awaiting Review to Future Release
  • Summary changed from Avatar errors with Buddypress + Multisite to Avatars are (erroneously) stored locally when running BP_ENABLE_MULTIBLOG

The problem is BP_ENABLE_MULTIBLOG. When you're running BP_ENABLE_MULTIBLOG, your avatars are stored *locally* by design, which is to say that they're stored on each individual site. So changing your avatar on one of the sites will not change it elsewhere. On reflection, I'm not sure whether this makes sense, though the fact is that it's in place right now, and we can't easily change it anytime very soon.

In the meantime, you can easily override this default behavior by defining your own custom avatar constants. Select the blog where you want custom avatars to live (doesn't matter which if you're starting from scratch; if users have already been actively creating content in one site, you should use that one), and define the following constants in wp-config.php:

// This assumes that the blog in question is #1. If it's not, the path will 
// have blogs.dir in it
define( 'BP_AVATAR_UPLOAD_PATH', '/var/www/html/example/wp-content/uploads' );

// Again, assuming you're coming from #1. To pull from a different blog, 
// it'll be example.com/secondaryblog/files or something like that
define( 'BP_AVATAR_URL', 'http://example.com/wp-content/uploads' );

I'm putting this into Future Release for consideration by the rest of the core devs. Team: do you think it makes sense to have per-site avatars as the default, given that no other BP data is per-site in multiblog mode?

#5 @luisrosario
12 years ago

To expand on this issue. We are currently using sub domain install and running a Multisite with BP_ENABLE_MULTIBLOG enabled. What we are finding to support the above, yes, avatars on sub sites are not displaying at all. Additionally, if trying to upload a new avatar on a sub site, avatars don't upload properly and ajax cropping is errored. The result is an image with a question mark. When checking the /files folder for uploads on sub sites, wordpress has successfully uploaded the image, but for some reason doesn't display correctly. So even if I wanted to upload a new avatar on a sub site, I can't. I have been able to upload normal images to sub site with no problem using media.php One more note. What seems like is happening, is if there's no avatar present on a sub site, it's looks to gravatars for an avatar for the user, if there's none, then it uses default gravatars. I've found that there's a handful of profiles who do use gravatars and so their thumbnails displays on the sub sites.

#6 @luisrosario
12 years ago

Tried the constant, not working on our site.

#7 @boonebgorges
12 years ago

Tried the constant, not working on our site.

You will have to give more details for me to actually be able to help with this. Which constant are you talking about? (I described two.) In what sense is it not working? Can you give more details about what URLs are actually being put into the 'src' attribute of the avatars that wrongly show up on the secondary sites?

#8 @luisrosario
12 years ago

I used the second constant and below is what one of the avatar links point to on our secondary site ... It goes to gravatar.com for the an avatar..

http://www.gravatar.com/avatar/604ecd8081a9416c0f672796173a093a?d=wavatar&s=50

#9 @douglance
12 years ago

This is issue has re-arisen since the new BP update. I've tried modifying the constants above to no avail. Please help Boone!

Not sure what more info I can provide. My site: http://www.efictionmag.com/activity/ and a subsite that isn't displaying properly: http://www.efictionmag.com/india/activity/

Version 0, edited 12 years ago by douglance (next)

#10 follow-up: @lrv
12 years ago

  • Cc lrv added
  • Keywords has-patch added

Here is the code fixed for me avatar and group avatar problem that appeared after BP_ENABLE_MULTIBLOG had been activated.

/* This fixes the BP_ENABLE_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);

#11 in reply to: ↑ 4 @needle
12 years ago

Replying to boonebgorges:

you can easily override this default behavior by defining your own custom avatar constants

@boonebgorges: This may be a solution for some, but I'm not persuaded that this issue is entirely related to the BP_ENABLE_MULTIBLOG constant. When BP is intsalled in a Multisite environment, any site that is not the root site can suffer from broken avatar urls - see, for example, the issue of group avatars that you highlight in the readme for the bp-groupblog plugin.

It seems to me that this issue can move closer to being resolved by making the code in function bp_core_avatar_url() consistent with the way that bp_core_avatar_upload_path() gets the upload basedir.

At present, bp_core_avatar_url() reconstructs the baseurl - when the site in question is not the root site - using:

$baseurl = trailingslashit( get_blog_option( bp_get_root_blog_id(), 'home' ) ) . get_blog_option( bp_get_root_blog_id(), 'upload_path' );

But in most cases, get_blog_option( bp_get_root_blog_id(), 'upload_path' ) returns an empty string, which is why Irv's filter works for him. However, Irv's filter is not generic enough and will only work if no custom path has been defined.

If bp_core_avatar_url retrieved the baseurl from wp_upload_dir() after switching to the root blog, I think all would be well. In the meantime, a filter such as the following works reliably for me:

function my_bp_avatar_upload_url( $url ) {
	if ( is_multisite() && !bp_is_root_blog() ) {
		switch_to_blog( bp_get_root_blog_id() );
		$upload_dir = wp_upload_dir();
		$url = $upload_dir['baseurl'];
		restore_current_blog();
	}
	return $url;
}
add_filter( 'bp_core_avatar_url', 'my_bp_avatar_upload_url', 10, 1 );

I'm not going to add a patch because these two related functions (bp_core_avatar_url() and bp_core_avatar_upload_path()) would then both be calling switch_to_blog() and it may be that you want to restructure them to switch only once, or only switch after testing for the existence of a local avatar.

Cheers,

Christian

#12 @luccame
11 years ago

While testing BP 1.7 on multisite I noticed missing avatars on sites other than root.
I'm NOT using BP_ENABLE_MULTIBLOG but I found this ticket and the previous comment helped solve the problem. I was able to fix it by putting the code provided by needle in a mu-plugin.

Other people have reported this bug on the forum:
http://buddypress.org/support/topic/avatar-uploads-fail-on-buddypress-multisite/#post-153826

#13 @r-a-y
11 years ago

  • Resolution set to duplicate
  • Status changed from new to closed

Thanks for the feedback everyone. needle is right on the money.

I missed this ticket and opened a new one. See #4948 instead. Thanks to luccame for pointing me here.

#14 @DJPaul
11 years ago

  • Milestone Future Release deleted

#15 in reply to: ↑ 10 @nanaboakye
7 years ago

Replying to lrv:

Here is the code fixed for me avatar and group avatar problem that appeared after BP_ENABLE_MULTIBLOG had been activated.

/* This fixes the BP_ENABLE_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);

In which file do I place this code?

Note: See TracTickets for help on using tickets.