Advertisement
rdusnr

Untitled

Jul 26th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. /**
  2. * Calculate member age based on date of birth
  3. *
  4. * @param int $id User id to get the age for
  5. *
  6. * @return string
  7. */
  8. function get_member_age_r_sq( $id , $birthday_field_name) {
  9. $default_age_field = get_profile_id_by_name( $birthday_field_name );
  10. $age_field = sq_option( 'bp_age_field', $default_age_field );
  11. if ( $age_field == 0 ) {
  12. $age_field = $default_age_field;
  13. }
  14.  
  15. if ( bp_is_active( 'xprofile' ) && xprofile_get_field_data( $age_field, $id ) ) {
  16. $birth = BP_XProfile_ProfileData::get_value_byid( $age_field, $id );
  17.  
  18. $field = new BP_XProfile_Field ( $age_field );
  19.  
  20. if ( $field->type == 'birthdate' ) {
  21. return strip_tags( $birth );
  22. }
  23. if ( ! empty( $birth ) ) {
  24. $diff = time() - strtotime( $birth );
  25. $age = floor( $diff / ( 365 * 60 * 60 * 24 ) );
  26. }
  27. } else {
  28. $age = '';
  29. }
  30.  
  31. return $age;
  32. }
  33.  
  34. function display_user_age($birthday_field_name = 'Birthday'){
  35. return get_member_age_r_sq( bp_get_member_user_id(), $birthday_field_name );
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement