BuddyDev

Search

[Resolved] BuddyPress Xprofile Custom Field Types Age

  • Participant
    Level: Enlightened
    Posts: 38
    Keith on #15457

    I just installed BuddyPress Xprofile Custom Field Types to replace the old BuddyPress Xprofile Custom Fields Type, but I noticed that the months are displayed when show age is selected. So for instance I’m 35 years old and my profile says I’m 35 years and 3 months. I don’t want the 3 months to show. Is there a way to get rid of that? BTW thanks for creating a replacement to the old plugin. I knew the old plugin was not compatible with Buddypress 3.0 and it prevented me from updating.

    • This topic was modified 5 years, 10 months ago by Keith.
  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2908
    Ravi on #15461

    Hello Keith,

    Thank you for posting. Please try the following code in your bp-custom.php file and let me know if it works or not.

    
    /**
     * Modify birth date output
     *
     * @param string $age Age.
     * @param int    $field_id Field id.
     *
     * @return array
     */
    function buddydev_modify_birth_date_data( $age, $field_id ) {
    
    	if ( ! bp_is_user() || ! bp_xprofile_get_meta( $field_id, 'field', 'show_age', true ) ) {
    		return $age;
    	}
    
    	if ( strpos( $age, ',' ) != false ) {
    		$age = explode( ',', $age );
    
    		return $age[0];
    	};
    
    	return $age;
    }
    add_filter( 'bpxcftr_birthdate_age_display_data', 'buddydev_modify_birth_date_data', 10, 2 );
    
    

    Thank You
    Ravi

  • Participant
    Level: Enlightened
    Posts: 38
    Keith on #15464

    That worked thanks.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2908
    Ravi on #15467

    Thank you for the acknowledgement.

    Thank You
    Ravi

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #15469

    Thank you Ravi.

    In future, I am adding the option in the field settings to ask the admins if they want to show the month or not. That way, It will be much simpler.

    Bets regards
    Brajesh

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #15477

    Hi Keith,
    You may remove the code after upgrading to 1.0.1

    BuddyPress Xprofile Custom Field Types 1.0.1 is available and it provides you an option on the Admin edit field page to show/hide month.

    Best Regards
    Brajesh

The topic ‘ [Resolved] BuddyPress Xprofile Custom Field Types Age’ is closed to new replies.

This topic is: resolved