• Okay, what I’m trying to do sounds simple in theory, but has turned out to be ridiculously difficult in practice, as I am throwing in the towel after three hours of hard effort and asking for help here.

    What I would like is for all registered members of my blog to have a gray icon displayed next to their name in comments. This icon should be not associated to each member individually, or to their email address or URL, but to their registration status. Then, I would like to have myself, the admin, be distinguished with the same icon – only colorized (in this case, pink).

    I have tried out three different plugins (comvatars, author highlight and official comments), and only managed to assign myself an icon, or assign a registered user AND me the gray icon, or given everyone BUT me icons.

    The code I have been using, along with the official comments plugin, which should work in theory, but in actuality isn’t:

    <?php
        if(comment_wpusername() != admin)
          echo "<img src='https://www.jenn.nu/wp-content/themes/nov07/images/member.gif'
                height='16' width='16' alt='Registered member' title='Registered member' class='commentsbyadmin' /> ";
    
    else
    
        if(comment_wpusername() == admin )
          echo "<img src='https://www.jenn.nu/wp-content/themes/nov07/images/admin.png'
                height='16' width='16' alt='Registered member' title='Registered member' class='commentsbyadmin' /> ";
    ?>

    To reiterate what I am trying to do in simple terms:
    – All registered users will be marked with a gray icon next to their name
    – Myself, the blog administrator, will be distinguished from the rest of the registered users with a pink icon next to my name
    – Non-registered commenters will not have any type of icon next to their name

    If it helps, since I know how it is to try and explain something at 4am and make sense ?? , here is a visual example of what I am trying to accomplish:

    https://farm3.static.flickr.com/2211/2142847205_f014f33fbd_o.gif

    Thank you very much in advance for any assistance!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The following code might be of use to you. It retrieves the user level of a user when you supply the user’s display name.

    global $wpdb;
    $user = 'admin'; //The name of the user as in display name
    
    $userdata = $wpdb->get_results("SELECT ID, user_email, user_url, user_registered FROM $wpdb->users WHERE display_name = '".$user."'", ARRAY_N);
    $user_ID = $userdata[0][0]; //Get the ID of the user
    $userwpleveldata = $wpdb->get_results("SELECT meta_value FROM $wpdb->usermeta WHERE meta_key = 'wp_user_level' AND user_id = '".$user_ID."'", ARRAY_N);
    $userwplevel = $userwpleveldata[0][0];

    $userwplevel will be the user level. If it contains a number (i.e. not empty text), it means that the user is registered. If it is more than 7, it means that the user is an administrator.

    using what multipot gave us, you could make an if else statement, and depending on which number it spits out, you can choose to echo:

    echo "<img src='https://www.jenn.nu/wp-content/themes/nov07/images/member.gif'
                height='16' width='16' alt='Registered member' title='Registered member' class='commentsbyadmin' /> ";
    Thread Starter kissmykitty

    (@xoxo)

    Thank you both for your help. But I must admit, I am not very good at writing functions and the like on my own. How would I go about putting all of this together?

    I was looking on the blog entry of the official comments plugin, and it looks as though someone else wanted to use the plugin to do what I’d like to do. They asked the author about it, and he replied with:
    “If official user, then find out what their user level is.
    … If admin, echo .commentAdmin
    … else echo .commentMember
    else echo .commentAnonymous”

    Going on the plugin, his suggestion, and yours, how would I make all of this work?

    (I’m willing to make a Paypal donation to anyone who can help me get this working!)

    Using the above code I’ve mentioned, it can be modified to a function:

    function GetUserLevel($user) {
    global $wpdb;
    //$user is the display name
    if ($user != '') {
    $userdata = $wpdb->get_results("SELECT ID, user_email, user_url, user_registered FROM $wpdb->users WHERE display_name = '".$user."'", ARRAY_N);
    $user_ID = $userdata[0][0]; //Get the ID of the user
    $userwpleveldata = $wpdb->get_results("SELECT meta_value FROM $wpdb->usermeta WHERE meta_key = 'wp_user_level' AND user_id = '".$user_ID."'", ARRAY_N);
    return $userwpleveldata[0][0];
    } else {
    return '';
    }
    }

    Then, you call out to that function whenever you want the user level. In your case, it can be made to:

    //Assuming comment_wpusername() gives the user display name
    $wpuserlevel = GetUserLevel(comment_wpusername());
    if ($wpuserlevel != '') {
    //User is registered
    $wpuserlevel = (int) $wpuserlevel; //convert to number
    if ($wpuserlevel > 7) {
    //User in question is administrator
    echo "<img src='https://www.jenn.nu/wp-content/themes/nov07/images/admin.png' height='16' width='16' alt='Registered member' title='Registered member' class='commentsbyadmin' />";
    } else {
    //User in question is not an administrator but is a registered member
    echo "<img src='https://www.jenn.nu/wp-content/themes/nov07/images/member.gif' height='16' width='16' alt='Registered member' title='Registered member' class='commentsbyadmin' />";
    }
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Assigning icons to registered users and admin’ is closed to new replies.