PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

Add members username/profile pic in header

s2Member Plugin. A Membership plugin for WordPress®.

Add members username/profile pic in header

Postby wesleysoccer » March 18th, 2011, 9:13 am

Is it possible to add members username and profile pic after login to my header? Any help would be awesome.

I would love to see a login link in the my header and then after successful login username and small profile pic...is this possible?

Thanks in advance.
User avatar
wesleysoccer
Registered User
Registered User
 
Posts: 83
Joined: January 31, 2011

Re: Add members username/profile pic in header

Postby Cristián Lávaque » March 18th, 2011, 11:43 am

Did you try s2Member Pro's Login Widget? After login it'll display the user's avatar and some links.

If you want the logged in/out stuff displayed in different places, you could look at the widget's code and use it in your theme with a conditional depending on whether the person is logged in or out.
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Add members username/profile pic in header

Postby wesleysoccer » March 18th, 2011, 12:45 pm

Any suggestion on what code to use for just adding username and small profile pic after login in my header
User avatar
wesleysoccer
Registered User
Registered User
 
Posts: 83
Joined: January 31, 2011

Re: Add members username/profile pic in header

Postby Cristián Lávaque » March 18th, 2011, 1:32 pm

This may help you:

https://codex.wordpress.org/Using_Gravatars
Theme Support for WordPress 2.5+

The function to add Gravatars to your theme is called: get_avatar. The function returns a complete image HTML tag of the Avatar.

The function is called as follows:

Code: Select all
<?php 
    echo get_avatar
( $id_or_email, $size = '96', $default = '<path_to_url>' ); 
?>


The parameters are:

  • id_or_email (required): Author’s User ID (an integer or string), an E-mail Address (a string) or the comment object from the comment loop. Note: with most comment templates you can use $comment here, in order to display the gravatar of the commenter. In other templates within The Loop (for WordPress 2.7 and lower), you can use get_the_author_id() (deprecated in WordPress 2.8). For WordPress 2.8, please use get_the_author_meta('user_email').
  • size (optional): Avatar display size (max is 512).
  • default (optional): Absolute location of the default avatar to use (used when the person has no email address associated with them). If this is left blank then the gravatar you see here will be used as the default avatar.

Some things to note here:

  • The default Avatar size is 96x96 if you do not set the size using the size paramater.
  • The default Avatar is Gravatar
  • The Avatars will show only if the user allows them in the WP Admin Panel (enabled by default).
  • The Avatars will only show based on the rating the user has selected in the WordPress Administration Panels.

Code output:

The default output is when using the above function is listed below. Various classes are applied to img element to help you with element styling.

Code: Select all
<img alt='' src='http://gravatarurl_or_default' class='avatar avatar-$size' height='$size' width='$size' /> 


If the gravatar reverts to the default image due to a lack of an e-mail address (i.e. a pingback or trackback), whether you have specified a default or not, the img element will also be given a CSS class of avatar-default.


See also:
https://codex.wordpress.org/Function_Re ... get_avatar


Now, for the user's name, this may be what you need:

https://codex.wordpress.org/Function_Re ... rrent_user
Examples

E.g.: To determine if there is a user currently logged in, do this:
Code: Select all
<?php
    wp_get_current_user
();
    if ( 0 == $current_user->ID ) {
        // Not logged in.
    } else {
        // Logged in.
    }
?>


Default Usage

The call to wp_get_current_user() return WP_User object.

Code: Select all
<?php
    wp_get_current_user
();
    /**
     * @example Safe usage: $current_user = wp_get_current_user();
     * if ( !($current_user instanceof WP_User) )
     *     return;
     */
    echo 'Username: ' . $current_user->user_login . '<br />';
    echo 'User email: ' . $current_user->user_email . '<br />';
    echo 'User first name: ' . $current_user->user_firstname . '<br />';
    echo 'User last name: ' . $current_user->user_lastname . '<br />';
    echo 'User display name: ' . $current_user->display_name . '<br />';
    echo 'User ID: ' . $current_user->ID . '<br />';
?>


Let me know if that helps. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Add members username/profile pic in header

Postby wesleysoccer » March 18th, 2011, 2:14 pm

Thanks....I added the first bit of code and it added the the default avatar...where should I add each bit of code to my wp files? thanks
User avatar
wesleysoccer
Registered User
Registered User
 
Posts: 83
Joined: January 31, 2011

Re: Add members username/profile pic in header

Postby Cristián Lávaque » March 18th, 2011, 3:26 pm

To your theme file that has the header.
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010


Return to s2Member Plugin

Who is online

Users browsing this forum: No registered users and 1 guest

cron