• Skip to primary navigation
  • Skip to main content

RocketGeek

Home of WP-Members, The Original WordPress Membership Plugin

  • WordPress Plugins
    • WP-Members
      • FAQs
      • Quick Start
      • Documentation
      • Extensions
    • Advanced Options
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Download Protect
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Invite Codes
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • MailChimp Integration
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • PayPal Subscriptions
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Salesforce Web-to-Lead
    • Security
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Text Editor
      • Purchase the Plugin
      • Get the Pro Bundle
    • User List
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • User Tracking
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Memberships for WooCommerce
    • WordPass
  • Blog
    • Basics
    • Tips and Tricks
    • Filters
    • Actions
    • Code Snippets
    • Shortcodes
    • Design
    • Release Announcements
  • Store
    • Cart
    • Checkout
  • Contact
  • Log In
  • Show Search
Hide Search
Home » Filters » Add an avatar to the sidebar login

Add an avatar to the sidebar login

Chad Butler · Mar 22, 2012 ·

This article is provided free. Find out how you can get full access to premium content, including how-to articles and support forums, as well as priority email support and member exclusive plugin extensions..

 

In this is example of the wpmem_sidebar_status filter hook we will add a gravatar image to the user’s sidebar login status.
The hook brings in the html $string generated by the plugin. You may use that, filter it, append to it, or anything.

This example adds a gravatar to the front of the generated $string using the WP function get_avatar. (Learn more about get_avatar in the WordPress Codex.)

Whatever you do, the filter should return what you wish to display as a string. DO NOT echo.

/**
* WP-Members sidebar status filter hook
* puts a gravatar in the sidebar status
*/
add_filter( 'wpmem_sidebar_status', 'my_sidebar_status' );
function my_sidebar_status( $string )
{
	// The $user_ID is needed for the get_avatar function
	$user_ID = get_current_user_id();

	// We are floating the gravatar to the left and a 4 pixel padding.
	// The get_avatar function can define the size in pixels
	$gravatar = '<div style="padding:4px 4px 0 0;float:left;">'
		. get_avatar( $user_ID, '46' )
		. '</div>';

	// The unedited html for the login status was passed
	// in $string. We are adding the above html to the
	// beginning of that string.
	$string = $gravatar . $string;

	// Return the new string
	return $string;
}

Filters demo, filters, free, get_avatar, hooks, wpmem_sidebar_status

Ready to get started?

Join Today!

© 2025 · butlerblog.com · RocketGeek is built using WordPress, WP-Members, and the Genesis Framework

  • butlerblog.com
  • WP-Members Support Subscription
  • Terms of Service
  • Privacy Policy
  • Refund Policy