Skip to:
Content

BuddyPress.org

Changeset 10203


Ignore:
Timestamp:
10/07/2015 03:34:32 PM (9 years ago)
Author:
boonebgorges
Message:

Pass field ID to xprofile field type filter methods.

display_filter() and pre_validate_filter() are more useful if they receive
the field ID. So we pass it, when available.

See #5625.

Location:
trunk/src/bp-xprofile
Files:
4 edited

Legend:

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

    r10200 r10203  
    2727add_filter( 'bp_get_the_profile_field_value',           'convert_smilies', 9 );
    2828add_filter( 'bp_get_the_profile_field_value',           'xprofile_filter_format_field_value',         1, 2 );
    29 add_filter( 'bp_get_the_profile_field_value',           'xprofile_filter_format_field_value_by_type', 8, 2 );
    30 add_filter( 'bp_get_the_profile_field_value',           'xprofile_filter_link_profile_data',          9, 2 );
     29add_filter( 'bp_get_the_profile_field_value',           'xprofile_filter_format_field_value_by_type', 8, 3 );
     30add_filter( 'bp_get_the_profile_field_value',           'xprofile_filter_link_profile_data',          9, 3 );
    3131
    3232add_filter( 'bp_get_the_profile_field_edit_value',      'force_balance_tags' );
     
    216216
    217217/**
    218  * Apply display_filter() filters as defined by the BP_XProfile_Field_Type classes, when fetched inside
    219  * a bp_has_profile() loop.
     218 * Apply display_filter() filters as defined by BP_XProfile_Field_Type classes, when inside a bp_has_profile() loop.
    220219 *
    221220 * @since 2.1.0
     221 * @since 2.4.0 Added `$field_id` parameter.
    222222 *
    223223 * @param mixed  $field_value Field value.
    224224 * @param string $field_type  Field type.
     225 * @param int    $field_id    Optional. ID of the field.
    225226 *
    226227 * @return mixed
    227228 */
    228 function xprofile_filter_format_field_value_by_type( $field_value, $field_type = '' ) {
     229function xprofile_filter_format_field_value_by_type( $field_value, $field_type = '', $field_id = '' ) {
    229230    foreach ( bp_xprofile_get_field_types() as $type => $class ) {
    230231        if ( $type !== $field_type ) {
     
    233234
    234235        if ( method_exists( $class, 'display_filter' ) ) {
    235             $field_value = call_user_func( array( $class, 'display_filter' ), $field_value );
     236            $field_value = call_user_func( array( $class, 'display_filter' ), $field_value, $field_id );
    236237        }
    237238    }
     
    253254function xprofile_filter_format_field_value_by_field_id( $field_value, $field_id ) {
    254255    $field = xprofile_get_field( $field_id );
    255     return xprofile_filter_format_field_value_by_type( $field_value, $field->type );
     256    return xprofile_filter_format_field_value_by_type( $field_value, $field->type, $field_id );
    256257}
    257258
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-datebox.php

    r10179 r10203  
    302302     *
    303303     * @since 2.1.0
    304      *
    305      * @param string $field_value The date value, as saved in the database.
    306      *                            Typically, this is a MySQL-formatted date
    307      *                            string (Y-m-d H:i:s).
     304     * @since 2.4.0 Added the `$field_id` parameter.
     305     *
     306     * @param string $field_value The date value, as saved in the database. Typically, this is a MySQL-formatted
     307     *                            date string (Y-m-d H:i:s).
     308     * @param int    $field_id    Optional. ID of the field.
    308309     *
    309310     * @return string Date formatted by bp_format_time().
    310311     */
    311     public static function display_filter( $field_value ) {
     312    public static function display_filter( $field_value, $field_id = '' ) {
    312313
    313314        // If Unix timestamp.
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-url.php

    r10179 r10203  
    125125     *
    126126     * @since 2.1.0
     127     * @since 2.4.0 Added the `$field_id` parameter.
    127128     *
    128129     * @param string $submitted_value Raw value submitted by the user.
     130     * @param int    $field_id        Optional. ID of the field.
    129131     *
    130132     * @return string
    131133     */
    132     public static function pre_validate_filter( $submitted_value = '' ) {
     134    public static function pre_validate_filter( $submitted_value = '', $field_id = '' ) {
    133135
    134136        // Allow empty URL values.
     
    153155     *
    154156     * @since 2.1.0
     157     * @since 2.4.0 Added the `$field_id` parameter.
    155158     *
    156159     * @param string $field_value The URL value, as saved in the database.
     160     * @param int    $field_id    Optional. ID of the field.
    157161     *
    158162     * @return string URL converted to a link.
    159163     */
    160     public static function display_filter( $field_value ) {
     164    public static function display_filter( $field_value, $field_id = '' ) {
    161165        $link      = strip_tags( $field_value );
    162166        $no_scheme = preg_replace( '#^https?://#', '', rtrim( $link, '/' ) );
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type.php

    r10163 r10203  
    408408     *
    409409     * @since 2.1.0
     410     * @since 2.4.0 Added the `$field_id` parameter.
    410411     *
    411412     * @param mixed $field_value Submitted field value.
     413     * @param int   $field_id    Optional. ID of the field.
    412414     *
    413415     * @return mixed
    414416     */
    415     public static function pre_validate_filter( $field_value ) {
     417    public static function pre_validate_filter( $field_value, $field_id = '' ) {
    416418        return $field_value;
    417419    }
     
    425427     *
    426428     * @since 2.1.0
     429     * @since 2.4.0 Added `$field_id` parameter.
    427430     *
    428431     * @param mixed $field_value Field value.
     432     * @param int   $field_id    ID of the field.
    429433     *
    430434     * @return mixed
    431435     */
    432     public static function display_filter( $field_value ) {
     436    public static function display_filter( $field_value, $field_id = '' ) {
    433437        return $field_value;
    434438    }
Note: See TracChangeset for help on using the changeset viewer.