Opened 6 years ago
Closed 4 years ago
#8083 closed enhancement (fixed)
Add Age option to BP Xprofile Databox
Reported by: | Venutius | Owned by: | 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)
Change History (8)
#1
@
4 years ago
- Keywords has-patch 2nd-opinion added
- Milestone changed from Awaiting Review to 8.0.0
#2
@
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.
#3
@
4 years ago
Thanks @shanebp for your comment. The BP datebox xProfile field type is already storing the date as a timestamp 👍
#4
@
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.
#5
@
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 👍
I like your idea @Venutius
8083.patch is what I suggest to make it happen!