Skip to:
Content
Pages
Categories
Search
Top
Bottom

Changing avatar images and profile links


  • jimme595
    Participant

    @jimme595

    Wordpress: 4.3.1
    BP: 2.4.0

    Hi, I have a slightly unusual setup that I’m trying to get working.

    I run a site for kids and as such I have created profile images that they can choose from which are stored as user-meta in wp. I also have my own user profiles basaed on the wp author.php located at /profiles/(nickname). I want to integrate buddypress in to my site as it uses Learndash and this integrates with bp to give an activity feed to the LMS.

    So the two things I would like to achieve are to change the user profile links on bp features such as the activity feed and online members widget etc from the buddypress profiles to links to my profiles at /profiles/. Secondly I need to change the avatar images that come up in activity feed and member widges from the buddypress ones to my custom meta.

    I’ve been working away on this all day and can’t quite get it. I’ve placed teh following code in my bp-custom.php and had some success but it is not yet working. If someone could take a look and help me out or point me in the right direction i’d really appreciate it!

    Here is the first code to try and get the profile links to redirect:

    function _bp_core_get_user_domain($domain) {
    		$url = get_home_url();
    		$user_id = bp_get_member_user_id();
    		$link = bp_core_get_username( $user_id ); 
            $domain = '' . $url . '/profiles/' . $link . '';
            return $domain;
        }
    add_filter('bp_core_get_user_domain', '_bp_core_get_user_domain', 10, 4);

    And here is the second to try and change the profile pics:

    function my_default_avatar_url() {
    	$url = get_site_url();
    	$user_id = bp_get_member_user_id();
    	$profile_image = get_the_author_meta( my_avatar, $user_id );
    	if (empty($profile_image)) {
    	$profile_image = '' . $url . '/wp-content/uploads/avatars/avatar.png';
    }
        $image = '<img src="' . $profile_image . '" width="50px" height="50px" />';
    	return $image;
    }
    
    add_filter( 'bp_core_default_avatar_user', 'my_default_avatar_url' );
    add_filter( 'bp_core_fetch_avatar', 'my_default_avatar_url');

    Thanks!

Viewing 13 replies - 1 through 13 (of 13 total)

  • Henry Wright
    Moderator

    @henrywright

    bp_core_default_avatar_user will fire only if you have disabled Gravatar via the bp_core_fetch_avatar_no_grav hook.


    jimme595
    Participant

    @jimme595

    Hi, thanks for the heads up, have got fetch avatar no grav disabled now and my filter on bp_core_default_avatar_user is now working! However it is only working for things like members list and and ‘who’s online’ widget. In the activity feed the avatar is always my admin avatar… is there a different filter for avatars fetched during activity feeds?

    BEst, James


    jimme595
    Participant

    @jimme595

    I think I have this working now by including get_activity_user_id:

    function my_default_avatar_url() {
    	$url = get_site_url();
    	$user_id = bp_get_member_user_id();
    	if (empty($user_id)) {
    		$user_id = bp_get_activity_user_id();
    	}
    	$profile_image = get_the_author_meta( my_avatar, $user_id );
    	if (empty($profile_image)) {
    	$profile_image = '' . $url . '/wp-content/uploads/avatars/avatar.png';
    }
    	return $profile_image;
    }
    add_filter( 'bp_core_default_avatar_user', 'my_default_avatar_url' );

    jimme595
    Participant

    @jimme595

    So i’ve had some success trying to change the profile links with this code:

    function _bp_core_get_user_domain($domain) {
    	$url = get_home_url();
    	$user_id = bp_get_member_user_id();
    	if (empty($user_id)) {
    		$user_id = bp_get_activity_user_id();
    	}
    	if (empty($user_id)) {
    		//$user_id = bp_displayed_user_id();
    	}
    	$user_info = get_userdata($user_id);
    	$link = $user_info->display_name;
    	$domain = '' . $url . '/profiles/' . $link . '';
    	return $domain;
        }
    add_filter('bp_core_get_user_domain', '_bp_core_get_user_domain', 10, 4);
    apply_filters( 'bp_get_activity_user_link', '_bp_core_get_user_domain', 15, 1);

    This seems to work on every profile link except the one in the activity header section. This link is being changed but just to /profiles/. The display name is not being added to the end… so looking at my code this means i’m not retrieving the user id in the activity. Strangely enough though the user avatar next to the post has the correct link applied to it with the above filter! Any ideas?

    My other option is to use the buddypress member profile location but replace it with my profile templates. I tried to implement this by creaing a members/single/home.php in my wordpress custom theme folder… but the profile loads inside another page, i get a page within a page type effect with the username above the inner page… not sure what is going on there? If anyone can help with either of these solutions i’d really appreciate it!

    James


    Henry Wright
    Moderator

    @henrywright

    You’re not quite using the bp_core_default_avatar_user filter properly. The function you hook to it can take 2 parameters, the 2nd of which is $params.

    function _bp_core_get_user_domain( $avatar_default, $params ) {
        // You get the user ID here with $params['item_id']
    }
    add_filter( 'bp_core_default_avatar_user', '_bp_core_get_user_domain', 10, 2 );

    jimme595
    Participant

    @jimme595

    Great, thank you, that is working well now. I’m also trying to change the link to the user profile and have managed to do it everywhere except in the activity header bit where, with my filter posted above I return just /profiles/ but not the users display name.


    Henry Wright
    Moderator

    @henrywright

    You’ll need to use a different filter hook to change the user profile links. The bp_core_default_avatar_user filter is just for changing the image src attribute.


    jimme595
    Participant

    @jimme595

    Yes I get that, I think my two initial issues got confused in to one! The second bit of code i’m trying to use to change the profile links is this:

    `function _bp_core_get_user_domain($domain) {
    $url = get_home_url();
    $user_id = bp_get_member_user_id();
    if (empty($user_id)) {
    $user_id = bp_get_activity_user_id();
    }
    $user_info = get_userdata($user_id);
    $link = $user_info->display_name;
    $domain = ” . $url . ‘/profiles/’ . $link . ”;
    return $domain;
    }
    add_filter(‘bp_core_get_user_domain’, ‘_bp_core_get_user_domain’, 10, 4);

    This works for everything as far as I can see except for the link in the activity feed header where the username is posted ‘admin created the group…’ The link wrapped around ‘admin’ I’m struggling to change.


    Henry Wright
    Moderator

    @henrywright

    Right, I see! Sorry about that.

    The X created the group X text (and link around the first X) can be changed via the groups_activity_created_group_action filter.


    jimme595
    Participant

    @jimme595

    Ah ok, so there isn’t a more generic way to change all the links in the activity feed of the type ‘x joined x’, ‘x posted x’? I’ll have to filter each one separately?


    Henry Wright
    Moderator

    @henrywright

    Not that I’m aware of. As far as I know you have to filter each type of action individually. The best way to do that is to go through your activity stream and list all of the different types of action. I doubt there will be many, perhaps ~10. Then search the codebase for the static portion of the string to find the right hook.

    Anyone else here know of generic way?


    jimme595
    Participant

    @jimme595

    function get_my_link ($string, $user_id) {
    	$url = get_home_url();
    	$user_info = get_userdata($user_id);
    	$name = $user_info->display_name;
    	$link = '<a href =' . $url . '/profiles/' . $name . '>' . $name . '</a>';
    	return $link;
    }
    add_filter ('bp_core_get_userlink', 'get_my_link', 10, 2);

    I think I’ve got it, the bp_core_get_userlink function generates the links for all the header action username bits so I filtered that with the above code and seems to be working. Phew, got there in the end! Thanks for the help Henry!


    Henry Wright
    Moderator

    @henrywright

    Thanks for sharing @jimme595. bp_core_get_userlink is useful to know!

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Changing avatar images and profile links’ is closed to new replies.
Skip to toolbar