Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
433 views
in Plugins by
How can I enforce the use of gravatars for everyone? When I enable gravatars, it seems like it will show only for users who have enabled them in their profile. Additionally, q2a's gravatar urls apparently do not pass in a variable like d=identicon (from their guide at http://en.gravatar.com/site/implement/images/) so the default gravatar is not unique.

I want to force all users to use a gravatar, and if they do not have their own, then for it to be generated from a unique hash. Any help to achieve this is appreciated.

I can look at editing the theme or create a custom plugin. I just don't know where to start. Thanks!
Q2A version: 1.7

1 Answer

0 votes
by
 
Best answer

Despite being a relative noobie I was able to solve this creating a plugin in qa-plugin/avatar as follows. Basically it forces gravatars on for new users, and also changes the img url used for gravatars to include : I also incremented the flags field in the user database by 8 for each existing avatar who I wanted to turn gravatars on. Hope this is all reasonable.

qa-plugin.php

if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
    header('Location: ../../');
    exit;
}

qa_register_plugin_overrides('qa-avatar-users-edit.php');
qa_register_plugin_overrides('qa-avatar-format.php');

qa-avatar-format.php

    if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
        header('Location: ../');
        exit;
    }

          function qa_get_gravatar_html($email, $size)
    {
        if ($size>0)
            return '<IMG SRC="'.(qa_is_https_probably() ? 'https' : 'http').
                '://www.gravatar.com/avatar/'.md5(strtolower(trim($email))).'?d=identicon&s='.(int)$size.
                '" WIDTH="'.(int)$size.'" HEIGHT="'.(int)$size.'" CLASS="qa-avatar-image" ALT=""/>';
        else
            return null;
    }

qa-avatar-users-edit.php

    if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
        header('Location: ../');
        exit;
    }

    function qa_create_new_user($email, $password, $handle, $level=QA_USER_LEVEL_BASIC, $confirmed=false) {
        $userid = qa_create_new_user_base($email, $password, $handle, $level, $confirmed);
        if (qa_opt('avatar_allow_gravatar'))
            qa_db_user_set_flag($userid, QA_USER_FLAGS_SHOW_GRAVATAR, true);
        return $userid;
    }

...