• Resolved AM77

    (@andy277)


    I have worked out how to add a default avatar like so:

    add_filter( 'avatar_defaults', 'custom_avatar' );
    function custom_avatar ($avatar_defaults) {
    $myavatar = ('http://mysite.com/wp-content/mydirectory/image.jpg');
    $avatar_defaults[$myavatar] = "New Avatar";
    return $avatar_defaults;
    }

    This makes the avatar selectable in settings>discussions. Does anyone know how to make this avatar the main default avatar when users sign up?

    Any help appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    If that code works, put it in an mu-plugin file and it’ll be called for all users on all sites.

    Thread Starter AM77

    (@andy277)

    Thanks for your reply Mika.

    I put pretty much all my codes in an mu plugin.

    This code works, and sets up the avatar ready to be selected, however, I would like my new default avatar to display as soon as users sign up. Also, I will be using a plugin that allows users to also upload a local avatar, this is in the user>profile in the admin area, so I will be removing the whole, unneeded avatar table in settings>discussions to avoid users getting confused「(°ヘ°).

    So I am looking for a code that is rather the direct replacement for the mystery man avatar. So when a user first signs up, or they remove there own uploaded local avatar, it will go back to my custom avatar, not the mysteryman.

    I have just found these codes that is more what I am looking for, but it only works for buddypress:

    define ( 'BP_AVATAR_DEFAULT', 'http://mysite.com/wp-content/folder/image.jpg' );

    I think that is a wp-config code, for the direct replacement of the buddypress mystery man.

    and:

    function myavatar_add_default_avatar( $url ){
    return ('http://mysitite.com/path-to-default-avatar');
    }
    add_filter( 'bp_core_mysteryman_src', 'myavatar_add_default_avatar' );

    I think the ‘bp_core_mysteryman_src’ will also be the direct replacement for the buddypress mystery man.

    Is there a wordpress equivalant for the following:
    Filter hook: ‘bp_core_mysteryman_src’
    and
    wp-config name: ‘BP_AVATAR_DEFAULT’

    I will then give those two codes a try to see if it works.

    Thread Starter AM77

    (@andy277)

    Great news, I just discovered how to do it, I’ll leave this here for a reference.

    I found these wordpress websites about updating options:
    http://codex.wordpress.org/WPMU_Functions/update_site_option
    http://codex.wordpress.org/Option_Reference

    and found this:

    avatar_default
    mystery : (default) Mystery Man
    blank : Blank
    gravatar_default : Gravatar Logo
    identicon : Identicon (Generated)
    wavatar : Wavatar (Generated)
    monsterid : MonsterID (Generated)

    So after adding the avatar to the avatar list by doing:

    add_filter( 'avatar_defaults', 'custom_avatar' );
    function custom_avatar ($avatar_defaults) {
    $myavatar = ('http://mysite.com/wp-content/mydirectory/image.jpg');
    $avatar_defaults[$myavatar] = "New Avatar";
    return $avatar_defaults;
    }

    I just added this to set it to main default:

    update_option( avatar_default, 'http://mysite.com/wp-content/mydirectory/image.jpg' );

    I wanted my own default avatar because I have created all my themes to also have a large avatar in the sidebars, and have designed my own default avatar that is better than the default mystery man.

    And the avatar plugin overwrites it too :), I was a little worried that it wouldn’t because I think that update option seems to force the value and stops from changing it.

    I also have one more question. Is it possible to add a value to my custom avatar because my value is the image url ‘http://mysite.com/wp-content/mydirectory/image.jpg;?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Default avatar’ is closed to new replies.