Skip to:
Content

BuddyPress.org

Opened 6 years ago

Closed 4 years ago

#8083 closed enhancement (fixed)

Add Age option to BP Xprofile Databox

Reported by: venutius's profile Venutius Owned by: imath's profile imath
Milestone: 8.0.0 Priority: normal
Severity: normal Version:
Component: Extended Profile Keywords: has-patch 2nd-opinion
Cc: shanebp

Description

The BP datebox xProfile field has an elapsed time option but not an age option. I'd like to suggest we fill this missing hole as many BP's would probably prefer to display their age rather than their DoB. I think this could be an easy add, we just need to duplicate the elapsed time options and update them for age. I think the changes need to be made in a couple of places:

In class-bp-xprofile-field-type-datebox.php:

Line 478 insert:

<div class="bp-date-format-option">
    <label for="date-format-age">
	<input type="radio" name="field-settings[date_format]" id="date-format-age" <?php checked( 'age', $settings['date_format'] ); ?> value="age" aria-describedby="date-format-age-setting" />
	<span class="date-format-label" id="date-format-age-setting"><?php esc_html_e( 'Age', 'bp-xprofile-age-field' ); ?></span> <?php _e( '<code>4 years old</code>', 'bp-xprofile-age-field' ); ?>
    </label>
</div>

On line 600 insert:

case 'age' :
    add_filter( 'bp_core_time_since_ago_text', function($text){ return '%s old'; } );
    $formatted = bp_core_time_since( $field_value );
    remove_filter( 'bp_core_time_since_ago_text', function($text){ return '%s old'; } );
    break;

Attachments (2)

8083.patch (5.0 KB) - added by imath 4 years ago.
8083.2.patch (17.3 KB) - added by imath 4 years ago.

Download all attachments as: .zip

Change History (8)

@imath
4 years ago

#1 @imath
4 years ago

  • Keywords has-patch 2nd-opinion added
  • Milestone changed from Awaiting Review to 8.0.0

I like your idea @Venutius

8083.patch is what I suggest to make it happen!

#2 @shanebp
4 years ago

  • Cc shanebp added

Just my 2 cents... I recently wrote an 'Age' xprofile plugin for a client that allows for entering a date in Profile > Edit and automatically shows the age on Profile > Display. I store the date as a UNIX timestamp to facilitate integer range searches via custom searches or the BP Profile Search plugin.
You may want to consider providing an option to save as a UNIX timestamp.

Last edited 4 years ago by shanebp (previous) (diff)

#3 @imath
4 years ago

Thanks @shanebp for your comment. The BP datebox xProfile field type is already storing the date as a timestamp 👍

#4 @shanebp
4 years ago

My point was that doing range searches ( members between the age of 20 and 30 ) on a string value ( date ts ) in a key/value table is very slow. Doing it on an integer ( UNIX timestamp ) is fairly fast.
It's interesting that the edit function in the class already handles a unix timestamp, so at some point somebody understood the issue.

Last edited 4 years ago by shanebp (previous) (diff)

@imath
4 years ago

#5 @imath
4 years ago

In 8083.2.patch I'm moving the part of the bp_core_time_since() function that calculates the time difference between 2 dates into a new function bp_core_time_diff() that is also used by the bp_core_time_old() function. This way we can use bp_core_time_diff() to build other ways of displaying time difference.

@shanebp This patch is not about changing how the field type is saving the data into the DB. It was and remain a timestamp. It's about displaying this timestamp like 20 years old.

If you were doing range search thanks to the timestamps, you'll still be able to do so 👍

#6 @imath
4 years ago

  • Owner set to imath
  • Resolution set to fixed
  • Status changed from new to closed

In 12931:

Add an option to display a datebox Profile Field type value as an age

This xProfile field type now support a new date format allowing Community site admins to display the age of their members according to their birth date.

  • Moves the date difference calculation from bp_core_time_since() to a newly introduced function: bp_core_time_diff()
  • Introduce the function bp_core_time_old() to format a birth date as an age eg: "20 years old".

Props Venutius

Fixes #8083

Note: See TracTickets for help on using tickets.