[buddypress-trac] [BuddyPress] #4252: Avatars are (erroneously) stored locally when running BP_ENABLE_MULTIBLOG
buddypress-trac
noreply at wordpress.org
Tue Feb 19 18:26:14 UTC 2013
#4252: Avatars are (erroneously) stored locally when running BP_ENABLE_MULTIBLOG
-----------------------------------------+-----------------------------
Reporter: douglance | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Future Release
Component: Core | Version:
Severity: normal | Resolution:
Keywords: reporter-feedback has-patch |
-----------------------------------------+-----------------------------
Comment (by needle):
Replying to [comment:4 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 [https://github.com/boonebgorges
/bp-groupblog/blob/master/readme.txt 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
--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/4252#comment:11>
BuddyPress <http://buddypress.org/>
BuddyPress
More information about the buddypress-trac
mailing list