Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/29/2021 10:20:39 AM (6 months ago)
Author:
imath
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-datebox.php

    r11905 r12931  
    480480                        <label for="date-format-elapsed">
    481481                            <input type="radio" name="field-settings[date_format]" id="date-format-elapsed" <?php checked( 'elapsed', $settings['date_format'] ); ?> value="elapsed" aria-describedby="date-format-elapsed-setting" />
    482                             <span class="date-format-label" id="date-format-elapsed-setting"><?php esc_html_e( 'Time elapsed', 'buddypress' ); ?></span> <?php _e( '<code>4 years ago</code>, <code>4 years from now</code>', 'buddypress' ); ?>
     482                            <span class="date-format-label" id="date-format-elapsed-setting"><?php esc_html_e( 'Time elapsed', 'buddypress' ); ?></span> <?php printf( '<code>%1$s</code>, <code>%2$s</code>', esc_html__( '4 years ago', 'buddypress' ), esc_html__( '4 years from now', 'buddypress' ) ); ?>
     483                        </label>
     484                    </div>
     485
     486                    <div class="bp-date-format-option">
     487                        <label for="date-format-age">
     488                            <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" />
     489                            <span class="date-format-label" id="date-format-age-setting"><?php esc_html_e( 'Age', 'buddypress' ); ?></span> <?php printf( '<code>%s</code>', esc_html__( '20 years old', 'buddypress' ) ); ?>
    483490                        </label>
    484491                    </div>
     
    602609            break;
    603610
     611            case 'age' :
     612                $formatted = bp_core_time_old( $field_value );
     613            break;
     614
    604615            case 'custom' :
    605616                $formatted = date_i18n( $settings['date_format_custom'], $field_value );
Note: See TracChangeset for help on using the changeset viewer.