Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Gender to determine default avatar

Hello all!,

I've created default avatar images for male and female gender so it can be assigned for their default avatar upon choosing their gender at the sign up.

I'm thinking to modify the gravatar plugin, but how to pull the data as if they are male and female?

or is there any other plugin exist that I wasn't able to find.

Tagged:
«1

Comments

  • peregrineperegrine MVP
    edited April 2014

    make a defaultu.png defaultm.png and a defaultf.png

    e.g.

    //  $Url .= '&default='.urlencode(Asset(C('Plugins.Gravatar.DefaultAvatar', 'plugins/Gravatar/default.png'), TRUE));
               $webroot = Gdn_Url::WebRoot();
              $webhost = $_SERVER["HTTP_HOST"];
             $Gender = GetValue('Gender', $User); 
            $Url = "http://$webhost/$webroot/plugins/Gravatar/default$Gender.png";
    

    the key parts are

    $Gender = GetValue('Gender', $User);

    you may need this.
    if ($Gender == "" ) $Gender = "u" // to default undefined gender to "u" depending on vanilla version.

    builld gender into the name of the image. (m , f , u)

    "default" . "$Gender" . ".png";

    to evaluate to defaultm.png, defaultf.png and defaultu.png

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Welcome to the community!

    What version number of Vanilla are you running?

    Gender is a property of the User object. You can easily get the currently logged in user via the session object.

    $Session = Gdn::Session();
    $User = $Session->User;
    switch($User->Gender) {
      case 'm':
        echo 'logged in user is male';
        break;
      case 'f':
        echo 'logged in user is female';
        break;
      default:
        echo 'logged in user is an unspecified gender';
        break;
    }
    

    I would suggest you hook into the user creation process and specify the photo based on the gender info entered. Something like the following could be put in your plugin or themehooks:

    public function UserModel_BeforeInsertUser_Handler($Sender) {
      $Gender = $Sender->EventArguments['InsertFields']['Gender'];
    
      switch($Gender) {
          case 'm':
            $Sender->EventArguments['InsertFields']['Photo'] = '/path/to/default/avatar/male.png';
            break;
          case 'f':
            $Sender->EventArguments['InsertFields']['Photo'] = '/path/to/default/avatar/female.png';
            break;
          default:
            break;
        }
    }
    

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • R_JR_J Admin

    Great solution by peregrine, but to answer your question on how to get the gender information more detailed: the function already has the user (object) as its argument. You can access every column of the User table with simply $User->ColumnName

  • Awesome!

  • peregrineperegrine MVP
    edited April 2014

    @gohunter

    edited:

    if you use the solution and modify a plugin that is NOT a core add-on

    you can help the community. by posting a link to this discussion under the appropriate plugin.

    the key to helping people with plugins is to post your question under the plugin you are asking about.

    that way the disucussion is associated with the plugin.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • great to know, I will do that in the future!

    How can I move this discussion under Gravatar plugin?

  • peregrineperegrine MVP
    edited April 2014

    edited out.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • @peregrine said:
    you can help the community. by posting a link to this discussion under the gravatar plugin.

    I couldn't find gravatar plugin under add ons.

    Sorry!

  • peregrineperegrine MVP
    edited April 2014

    I'm sorry. You are correct, gravatar add-on is in the core. never mind my ranting.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Perhaps thats why I didn't create this post under plugin... :) indeed I searched quite a bit about this avatar gender stuff.

    Good excuse ain't it?

  • peregrineperegrine MVP
    edited April 2014

    I was trying to think of a good idea around this predicament.

    • 1 Add core add-ons to the add-ons section.

      -pluses
      - easier to find mods and solutions.
      - easier to report problems to the community

      -minuses
      - it would need to be associated to with vanilla version (and make it easier for users who don't pay attention to download the wrong version associated with add-on.

    or

    • 2 Add mods to gihub.
      - fork the add-on (only minus there is some people don't fork.

    I suppose a moderator could edit and tag this discussion with "gravatar" and "gender"

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • R_JR_J Admin

    @gohunter said:
    Perhaps thats why I didn't create this post under plugin... :) indeed I searched quite a bit about this avatar gender stuff.

    Good excuse ain't it?

    But what you can do is to modify the plugin, give it a shiny new name, add a credit to the original plugin in a readme file and add that plugin here to the addons.

  • I bet @vrijvlinder could easily add a gender specific avatar to the

    http://vanillaforums.org/addon/defaultavatar-plugin

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • peregrineperegrine MVP
    edited April 2014

    @R_J said:
    But what you can do is to modify the plugin, give it a shiny new name, add a credit to the original plugin in a readme file and add that plugin here to the addons.

    OTOH, does a two line change warrant a new plugin (rhetorical question). A change so small, might lead to a pethora of one line modded plugins. And of course it would be advisable to ask the author of the original plugin first.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • R_JR_J Admin

    The plugin is bundled with GPLv2, so there is no need for asking. Since Gravatar is not in the addons section, I wouldn't see any chance of putting this modification on an appropriate place here at vf.org, so why not uploading it - slightly modified - with an informative credit? <- also rhetorical :D

  • Lol, I didn't expect this would expand into this much conversation!

  • peregrineperegrine MVP
    edited April 2014

    Some of us probably have OCD issues, otherwise we wouldn't be here posting all the time >:)

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Maybe this could be an extension of R_J gender plugin, or the force gender plugin could work to make sure they not only pick a gender but also get that specific avatar. . You can take any plugins I made to make you own if any one is useful .

    They are all under Gplv2 ...

  • Are there any "Pick a default avatar" plugins?

    Basically have a mini gallery of 16 default pics?

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Yea peregrine gave me that proposition when I was making default avatar.
    Tama's plugin custom default avatar has a settings page to add url of avatar.

    That works better than mine. no surprise there...

Sign In or Register to comment.