BuddyDev

Search

[Resolved] BuddyPress Avatar Moderator – Profile Pic Disappears After Approval

Tagged: 

  • Participant
    Level: Enlightened
    Posts: 41
    Mic on #22603

    Hello,

    I have the following custom code in my functions file that assigns a random “Mystery Man” profile pic from a folder of avatar pictures that I define. I have hundred of legacy users with no profile pictures and I wanted some variety instead of them all being the same default “Mystery Man”.

    Unfortunately, the code I have does not assign a default avatar to the profile pic. Instead it cycles the “Mystery Man” to a different image on every page load. While this was not ideal, it does give the effect I was looking for of more variety in the profile pictures of users that have not defined an avatar.

    
    /* RANDOM MYSTERY MAN
    ================================================== */
    // Random Mystery Man avatar for everyone who doesn't have an avatar assigned. - Mic
    
    function avatar_photo_random_default() {
    
        //pick random number
        $random_num	 = rand( 1, 424 ); //currently we have 424 images.
        $random_num	 = apply_filters( "avatar_photo_random_num", $random_num );
    
        //pick the random image
        $dir_avatar = get_stylesheet_directory_uri();
        $filename = $dir_avatar."/images/avatars/".$random_num.".png";
        $filename = apply_filters( "avatar_photo_default_pick_filename", $filename );
    
        return $filename;
    }
    add_filter( "bp_core_mysteryman_src", "avatar_photo_random_default" )
    

    If a user uploads an avatar, their profile picture will be replaced with whatever they uploaded and will no longer use a random “Mystery Man” picture. However, after activating the BuddyPress Avatar Moderator plugin the image they upload is not used and the “Mystery Man” image continues to display.

    I’m pretty sure that the custom code I have in my functions file is interfering with the way the BuddyPress Avatar Moderator plugin works. I would really like to have a random avatar chosen from a collection I define assigned to all users that have not updated their profile picture, and still be able to moderate the avatars that are uploaded.

    Do you have any suggestions?

    Sincerely,
    Mic

  • Keymaster
    (BuddyDev Team)
    Posts: 24190
    Brajesh Singh on #22605

    Hi Mic,
    My apologies for the inconvenience.

    Please allow us to check it tomorrow and get back to you.

    Thank you
    Brajesh

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2934
    Ravi on #22613

    Hello Mic,

    I have tested the plugin and it is working for me. But with your custom code, no random image is showing for the user who has not uploaded the avatar. I just modified the filter and it is working for me. Try the following code and let me know if it works or not.

    
    Replace the following 
    add_filter( "bp_core_mysteryman_src", "avatar_photo_random_default" )
    
    with
    add_filter( "bp_core_default_avatar_user", "avatar_photo_random_default" )
    

    Regards
    Ravi

  • Participant
    Level: Enlightened
    Posts: 41
    Mic on #22636

    Thank you for the quick response guys!

    I will go try that code and update this thread with my results.

    -Mic

  • Participant
    Level: Enlightened
    Posts: 41
    Mic on #22644

    Thanks for the help. The filter “bp_core_default_avatar_user” led me to additional resources that stated you have to disable Gravatar for that filter to activate.

    My final code looks like this:

    
    /* RANDOM MYSTERY MAN
    ================================================== */
    // Random Mystery Man avatar for everyone who doesn't have an avatar assigned. - Mic
    
    add_filter( 'bp_core_fetch_avatar_no_grav', '__return_true' );
    
    function avatar_photo_random_default() {
    
        //pick random number
        $random_num	 = rand( 1, 424 ); //currently we have 424 images.
        $random_num	 = apply_filters( "avatar_photo_random_num", $random_num );
    
        //pick the random image
        $dir_avatar = get_stylesheet_directory_uri();
        $filename = $dir_avatar."/images/avatars/".$random_num.".png";
        $filename = apply_filters( "avatar_photo_default_pick_filename", $filename );
    
        return $filename;
    }
    add_filter( "bp_core_default_avatar_user", "avatar_photo_random_default", 10, 2);
    

    Now I am able to have random avatars and moderate them when a user chooses to upload a new one!

    -Mic

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2934
    Ravi on #22647

    Hello Mic,

    Thank you for the acknowledgement. I am glad that problem is resolved.

    Regards
    Ravi

The topic ‘ [Resolved] BuddyPress Avatar Moderator – Profile Pic Disappears After Approval’ is closed to new replies.

This topic is: resolved