Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: Birthday Notification with thumbnail

@danbp

Participant

hi @escudero95

here are 2 function you can use for do what you need. The first add Happy birthday on the Toolbar, near the Howdy.

The second will add the same thing on the profile header, above @username at the right of the avatar.

These function can be used from within bp-custom.php or theme’s functions.php

You have to create a date type profile field and set it to be viewed by friends only.

Naturally this is intended to be an example of use. It’s certainly perfectible. Also take care of the different comments inside the code. Have fun !


function bpfr_happybirthday( $wp_admin_bar ) {
	global $bp;
	
	// if user is not logged in, we show nothing
	if ( !is_user_logged_in() )
	return false;
	
	// is xprofile component active ?
	if ( bp_is_active( 'xprofile' ) )	
		   // fetch the birthdate
		   // as the function should work outside of the profile loop, we first need the user_id
		$user_id = bp_get_activity_user_id();
			
			// now we get the birthdate and our text to show (text | username). 53 is the field id.
			// depending your theme, this may be adjusted by css as it goes probably on two lines
		$birthdate = xprofile_get_field_data('53', $user_id ) ? __( 'Happy Birthday ' ) . bp_core_get_username( bp_displayed_user_id() ) : '';	
		
		// building the output and adding some css	 
		$user_id = bp_displayed_user_id();

		// condition for the greating on the toolbar
		if (!is_user_logged_in( $user_id ) ) { 		
		
		$my_title = '<span style="float: left; width: 16px;	height: 16px; margin: 5px 5px 0 -1px; display: block; background-color: green; border-radius: 16px;"></span> '.$birthdate.' ';
		
			$args = array(
			'parent'    => 'top-secondary', // position
			'id'		=> 'birthday_item', // unique identifier
			'title' 	=> $my_title, // the name who appears on the bar
			);
		
	
			$wp_admin_bar->add_node($args);
		}
	
}
add_action( 'admin_bar_menu', 'bpfr_happybirthday', 90 );

function bpfr_happybirthday2u() {
	global $bp;
	
	// if user is not logged in, we show nothing
	if ( !is_user_logged_in() )
	return false;
	
	if( bp_is_user() && ! bp_get_member_user_id() ) {
        $user_id = 'displayed: '. bp_displayed_user_id();
    } else {
        $user_id = 'get_member_user: '. bp_get_member_user_id();
    }
	
	// is xprofile components active ?
	if ( bp_is_active( 'xprofile' ) )
	
	// fetch the birthdate
	// as the function should work outside of the profile loop, we first need the user_id
	$user_id = bp_get_activity_user_id();
	
	// now we get the birthdate and our text to show (text | username). 53 is the field id.
	// depending your theme, this may be adjusted by css as it goes probably on two lines
	$birthdate = xprofile_get_field_data('53', $user_id ) ? __( 'Happy Birthday ' ) . bp_core_get_username( bp_displayed_user_id() ) : '';	
	
	// building the output and adding some css
	$my_title = '<div style="margin: 5px 5px 20px 5px; border:1px solid red; min-height:18px;"><div style="float: left; width: 16px; height: 16px; margin: 5px 5px 0 -1px; display: block; background-color: green; border-radius: 16px;"></div> '.$birthdate.' </div>';
	
	echo $birthdate;	
	
}
add_action( 'bp_before_member_header_meta', 'bpfr_happybirthday2u' );

Codex references:
https://codex.wordpress.org/Class_Reference/WP_Admin_Bar

Developer Resources

Playing with the toolbar (in french but code is in english)
http://www.geekpress.fr/wordpress/tutoriel/modifier-howdy-admin-bar-1102/

Skip to toolbar