/** * Calculate member age based on date of birth * * @param int $id User id to get the age for * * @return string */ function get_member_age_r_sq( $id , $birthday_field_name) { $default_age_field = get_profile_id_by_name( $birthday_field_name ); $age_field = sq_option( 'bp_age_field', $default_age_field ); if ( $age_field == 0 ) { $age_field = $default_age_field; } if ( bp_is_active( 'xprofile' ) && xprofile_get_field_data( $age_field, $id ) ) { $birth = BP_XProfile_ProfileData::get_value_byid( $age_field, $id ); $field = new BP_XProfile_Field ( $age_field ); if ( $field->type == 'birthdate' ) { return strip_tags( $birth ); } if ( ! empty( $birth ) ) { $diff = time() - strtotime( $birth ); $age = floor( $diff / ( 365 * 60 * 60 * 24 ) ); } } else { $age = ''; } return $age; } function display_user_age($birthday_field_name = 'Birthday'){ return get_member_age_r_sq( bp_get_member_user_id(), $birthday_field_name ); }