Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/25/2014 01:36:44 PM (11 years ago)
Author:
boonebgorges
Message:

Introduce BP_XProfile_Field_Type::display_filter(), and implement in BP_XProfile_Field_Type_Datebox.

The new display_filter() method makes it easy for field types to customize the
appearance of its values. In the case of Datebox fields, this means formatting
the MySQL- or UNIX-formatted date in the format of bp_format_time().

Fixes #5630

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/bp-xprofile-classes.php

    r8535 r8547  
    16961696     */
    16971697    public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {}
     1698
     1699    /**
     1700     * Format Date values for display.
     1701     *
     1702     * @since BuddyPress (2.1.0)
     1703     *
     1704     * @param string $field_value The date value, as saved in the database.
     1705     *        Typically, this is a MySQL-formatted date string (Y-m-d H:i:s).
     1706     * @return string Date formatted by bp_format_time().
     1707     */
     1708    public static function display_filter( $field_value ) {
     1709        // If Unix timestamp
     1710        if ( is_numeric( $field_value ) ) {
     1711            $field_value = bp_format_time( $field_value, true, false );
     1712
     1713        // If MySQL timestamp
     1714        } else {
     1715            $field_value = bp_format_time( strtotime( $field_value ), true, false );
     1716        }
     1717
     1718        return $field_value;
     1719    }
    16981720}
    16991721
     
    28522874    }
    28532875
     2876    /**
     2877     * Allow field types to modify the appearance of their values.
     2878     *
     2879     * By default, this is a pass-through method that does nothing. Only
     2880     * override in your own field type if you need to provide custom
     2881     * filtering for output values.
     2882     *
     2883     * @since BuddyPress (2.1.0)
     2884     *
     2885     * @param mixed $field_value Field value.
     2886     * @return mixed
     2887     */
     2888    public static function display_filter( $field_value ) {
     2889        return $field_value;
     2890    }
    28542891
    28552892    /**
Note: See TracChangeset for help on using the changeset viewer.