Skip to:
Content
Pages
Categories
Search
Top
Bottom

Birthday Notification with thumbnail


  • escudero95
    Participant

    @escudero95

    Hello! First off, just wanted to say how impressed I am with buddypress’ functionality so far. I have freelanced web design for a while and have never found anything so handy.

    My question relates to the primary notification area in the top bar and/or activity stream. I was seeking a way to have friends’ birthdays appear there with a small thumbnail like a little candle or something of that nature but was unable to find a plugin or internet search solution for that topic. Anyone have any insight?

    Question answers:
    1. Which version of WordPress are you running? 3.9.1

    2. Did you install WordPress as a directory or subdomain install? Directory

    3. If a directory install, is it in root or in a subdirectory? Root

    4. Did you upgrade from a previous version of WordPress? If so, from which version? No

    5. Was WordPress functioning properly before installing/upgrading BuddyPress (BP)? e.g. permalinks, creating a new post, commenting. Yes

    6. Which version of BP are you running? 2.0.1

    7. Did you upgraded from a previous version of BP? If so, from which version? No

    8. Do you have any plugins other than BuddyPress installed and activated? If so, which ones?
    bbPress, buddypics, CNN News, frontend uploader, site offline mode, video conference, buddypress like

    9. Are you using the standard BuddyPress themes or customized themes? Aggregate (from eleganthemes)

    10. Have you modified the core files in any way? no

    11. Do you have any custom functions in bp-custom.php? no

    12. If running bbPress, which version? Or did your BuddyPress install come with a copy of bbPress built-in? 2.5.4

    13. Please provide a list of any errors in your server’s log files.

    14. Which company provides your hosting? register.com

    15. Is your server running Windows, or if Linux; Apache, nginx or something else?
    Linux

Viewing 2 replies - 1 through 2 (of 2 total)

  • danbp
    Moderator

    @danbp

    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/


    escudero95
    Participant

    @escudero95

    Hi danbp,

    I put the code you posted into functions.php but it didn’t seem to have any effect. I made the visibility of the date of birth field to ‘friends only’ first via the user selection, then via the profile fields settings area and ‘enforced default’. Is there a different way you mean for me to do that?

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Birthday Notification with thumbnail’ is closed to new replies.
Skip to toolbar