Skip to:
Content

BuddyPress.org

Ticket #2603: pgibbs3.patch

File pgibbs3.patch, 3.4 KB (added by DJPaul, 14 years ago)
  • bp-xprofile/bp-xprofile-filters.php

     
    88add_filter( 'xprofile_get_field_data', 'wp_filter_kses', 1 );
    99add_filter( 'xprofile_field_name_before_save', 'wp_filter_kses', 1 );
    1010add_filter( 'xprofile_field_description_before_save', 'wp_filter_kses', 1 );
     11add_filter( 'xprofile_filter_format_field_data', 'wp_filter_kses', 1 );
    1112
    1213add_filter( 'bp_get_the_profile_field_edit_value', 'wp_filter_kses', 1 );
    1314add_filter( 'bp_get_the_profile_field_description', 'wp_filter_kses', 1 );
    1415
    1516add_filter( 'xprofile_field_name_before_save', 'force_balance_tags' );
    1617add_filter( 'xprofile_field_description_before_save', 'force_balance_tags' );
     18add_filter( 'xprofile_filter_format_field_data', 'force_balance_tags' );
    1719
    1820add_filter( 'bp_get_the_profile_field_value', 'wptexturize' );
    1921add_filter( 'bp_get_the_profile_field_value', 'convert_smilies', 2 );
     
    4143
    4244/* Custom BuddyPress filters */
    4345
     46/**
     47 * xprofile_filter_format_field_data()
     48 *
     49 * Sanitises xprofile field data.
     50 *
     51 * @package BuddyPress xProfile
     52 * @param string $value The new field value
     53 * @param int $id ID for bp_xprofile_data record. May be zero if this is a new record.
     54 * @param BP_XProfile_ProfileData $profiledata Current xProfile field data class.
     55 * @return string|array
     56 */
     57function xprofile_filter_format_field_data( $value, $id, $profiledata ) {
     58        if ( !$field = new BP_XProfile_Field( $profiledata->field_id ) )
     59                return $value;
     60
     61        switch ( $field->type ) {
     62                case 'textbox':
     63                case 'textarea':
     64                        $value = apply_filters( 'xprofile_filter_format_field_data', $value, $id );
     65                break;
     66
     67                case 'checkbox':
     68                case 'selectbox':
     69                case 'multiselectbox':
     70                case 'radio':
     71                        if ( !is_array( $value ) )
     72                                break;
     73
     74                        foreach ( $value as $v ) {
     75                                $v = apply_filters( 'xprofile_filter_format_field_data', $v, $id );
     76                        }
     77                break;
     78        }
     79
     80        return $value;
     81}
     82add_filter( 'xprofile_data_value_before_save', 'xprofile_filter_format_field_data', 10, 3 );
     83
    4484function xprofile_filter_format_field_value( $field_value, $field_type = '' ) {
    4585        if ( !isset($field_value) || empty( $field_value ) )
    4686                return false;
  • bp-xprofile/bp-xprofile-classes.php

     
    719719        function save() {
    720720                global $wpdb, $bp;
    721721
    722                 $this->user_id = apply_filters( 'xprofile_data_user_id_before_save', $this->user_id, $this->id );
    723                 $this->field_id = apply_filters( 'xprofile_data_field_id_before_save', $this->field_id, $this->id );
    724                 $this->value = apply_filters( 'xprofile_data_value_before_save', $this->value, $this->id );
    725                 $this->last_updated = apply_filters( 'xprofile_data_last_updated_before_save', date( 'Y-m-d H:i:s' ), $this->id );
     722                $this->user_id = apply_filters( 'xprofile_data_user_id_before_save', $this->user_id, $this->id, $this );
     723                $this->field_id = apply_filters( 'xprofile_data_field_id_before_save', $this->field_id, $this->id, $this );
     724                $this->value = apply_filters( 'xprofile_data_value_before_save', $this->value, $this->id, $this );
     725                $this->last_updated = apply_filters( 'xprofile_data_last_updated_before_save', date( 'Y-m-d H:i:s' ), $this->id, $this );
    726726
    727727                do_action( 'xprofile_data_before_save', $this );
    728728