Skip to:
Content

BuddyPress.org

Changeset 12697


Ignore:
Timestamp:
07/31/2020 02:26:24 PM (6 months ago)
Author:
boonebgorges
Message:

Remove 'whitelist' language from xProfile component.

This is part of a set of changes to make our codebase clearer and
more inclusive to all contributors.

See #8339.

Location:
trunk
Files:
3 edited

Legend:

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

    r12694 r12697  
    455455    // For certain fields, only certain parameters are acceptable, so add them to the list of allowed values.
    456456    if ( $field_type_obj->supports_options ) {
    457         $field_type_obj->set_whitelist_values( wp_list_pluck( $field->get_children(), 'name' ) );
     457        $field_type_obj->set_allowed_values( wp_list_pluck( $field->get_children(), 'name' ) );
    458458    }
    459459
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type.php

    r12694 r12697  
    3232     * @var array Field type allowed values.
    3333     */
    34     protected $validation_whitelist = array();
     34    protected $validation_allowed_values = array();
    3535
    3636    /**
     
    154154
    155155    /**
    156      * Add a value to this type's whitelist that profile data will be asserted against.
     156     * Add a value to this type's list of allowed values that profile data will be asserted against.
     157     *
     158     * @since 2.0.0
     159     * @deprecated 7.0.0 Use set_allowed_values() instead.
     160     *
     161     * @param string|array $values Whitelisted values.
     162     * @return BP_XProfile_Field_Type
     163     */
     164    public function set_whitelist_values( $values ) {
     165        _deprecated_function( __METHOD__, '7.0.0', 'BP_XProfile_Field_Type::set_allowed_values()' );
     166        $this->set_allowed_values( $values );
     167    }
     168
     169    /**
     170     * Add a value to this type's list of allowed values that profile data will be asserted against.
    157171     *
    158172     * You can call this method multiple times to set multiple formats. When validation is performed,
    159173     * it's successful as long as the new value matches any one of the registered formats.
    160174     *
    161      * @since 2.0.0
    162      *
    163      * @param string|array $values Whitelisted values.
     175     * @since 7.0.0
     176     *
     177     * @param string|array $values Allowed values.
    164178     * @return BP_XProfile_Field_Type
    165179     */
    166     public function set_whitelist_values( $values ) {
     180    public function set_allowed_values( $values ) {
    167181        foreach ( (array) $values as $value ) {
    168182
    169183            /**
    170              * Filters values for field type's whitelist that profile data will be asserted against.
     184             * Filters values for field type's list of allowed values that profile data will be asserted against.
    171185             *
    172186             * @since 2.0.0
     187             * @deprecated 7.0.0 Use 'bp_xprofile_field_type_set_allowed_values' instead.
    173188             *
    174189             * @param string                 $value  Field value.
     
    176191             * @param BP_XProfile_Field_Type $this   Current instance of the BP_XProfile_Field_Type class.
    177192             */
    178             $this->validation_whitelist[] = apply_filters( 'bp_xprofile_field_type_set_whitelist_values', $value, $values, $this );
     193            $this->validation_allowed_values[] = apply_filters_deprecated( 'bp_xprofile_field_type_set_whitelist_values', array( $value, $values, $this ), '7.0.0', 'bp_xprofile_field_type_set_allowed_values' );
     194
     195            /**
     196             * Filters values for field type's list of allowed values that profile data will be asserted against.
     197             *
     198             * @since 7.0.0
     199             *
     200             * @param string                 $value  Field value.
     201             * @param array                  $values Original array of values.
     202             * @param BP_XProfile_Field_Type $this   Current instance of the BP_XProfile_Field_Type class.
     203             */
     204            $this->validation_allowed_values[] = apply_filters( 'bp_xprofile_field_type_set_allowed_values', $value, $values, $this );
    179205        }
    180206
     
    215241        }
    216242
    217         // If there's a whitelist set, make sure that each value is a whitelisted value.
    218         if ( ( true === $validated ) && ! empty( $values ) && ! empty( $this->validation_whitelist ) ) {
     243        // If there's a list of allowed values, make sure that each value is on that list.
     244        if ( ( true === $validated ) && ! empty( $values ) && ! empty( $this->validation_allowed_values ) ) {
    219245            foreach ( (array) $values as $value ) {
    220                 if ( ! in_array( $value, $this->validation_whitelist, true ) ) {
     246                if ( ! in_array( $value, $this->validation_allowed_values, true ) ) {
    221247                    $validated = false;
    222248                    break;
  • trunk/tests/phpunit/testcases/xprofile/class-bp-xprofile-field-type.php

    r11849 r12697  
    2525    }
    2626
    27     public function test_textbox_validate_whitelisted_string() {
     27    public function test_textbox_validate_allowed_string() {
    2828        $field = bp_xprofile_create_field_type( 'textbox' );
    2929
    3030        $this->assertTrue( $field->is_valid( 'a string' ) );
    31         $this->assertFalse( $field->set_whitelist_values( 'pizza' )->is_valid( 'pasta' ) );
     31        $this->assertFalse( $field->set_allowed_values( 'pizza' )->is_valid( 'pasta' ) );
    3232        $this->assertTrue( $field->is_valid( 'pizza' ) );
    3333    }
    3434
    35     public function test_multiselectbox_validate_whitelisted_array() {
     35    public function test_multiselectbox_validate_allowed_array() {
    3636        $field = bp_xprofile_create_field_type( 'multiselectbox' );
    37         $field->set_whitelist_values( array( 'cheese', 'pepporoni' ) );
     37        $field->set_allowed_values( array( 'cheese', 'pepporoni' ) );
    3838
    3939        $this->assertTrue( $field->is_valid( array( 'cheese', 'pepporoni' ) ) );
     
    4545    public function test_multiselectbox_validate_null_value() {
    4646        $field = bp_xprofile_create_field_type( 'multiselectbox' );
    47         $field->set_whitelist_values( array( 'cheese', 'pepporoni' ) );
     47        $field->set_allowed_values( array( 'cheese', 'pepporoni' ) );
    4848
    4949        $this->assertFalse( $field->is_valid( array( '' ) ) );
     
    9999    }
    100100
    101     public function test_number_validate_whitelisted_array() {
     101    public function test_number_validate_allowed_array() {
    102102        $field = bp_xprofile_create_field_type( 'number' );
    103         $field->set_whitelist_values( array( 123, 456 ) );
     103        $field->set_allowed_values( array( 123, 456 ) );
    104104
    105105        $this->assertTrue( $field->is_valid( array( 123 ) ) );
     
    109109    }
    110110
    111     public function test_radiobutton_validate_whitelisted_array() {
     111    public function test_radiobutton_validate_allowed_array() {
    112112        $field = bp_xprofile_create_field_type( 'radio' );
    113         $field->set_whitelist_values( array( 'cheese', 'pepporoni' ) );
     113        $field->set_allowed_values( array( 'cheese', 'pepporoni' ) );
    114114
    115115        $this->assertTrue( $field->is_valid( array( 'cheese', 'pepporoni' ) ) );
     
    120120    }
    121121
    122     public function test_radiobutton_do_not_validate_empty_items_in_whitelist() {
     122    public function test_radiobutton_do_not_validate_empty_items_in_allowed_list() {
    123123        $field = bp_xprofile_create_field_type( 'radio' );
    124         $field->set_whitelist_values( array( '' ) );
     124        $field->set_allowed_values( array( '' ) );
    125125
    126126        $this->assertFalse( $field->is_valid( array( '' ) ) );
    127127    }
    128128
    129     public function test_checkbox_validate_whitelisted_array() {
     129    public function test_checkbox_validate_allowed_array() {
    130130        $field = bp_xprofile_create_field_type( 'checkbox' );
    131         $field->set_whitelist_values( array( 'cheese', 'pepporoni' ) );
     131        $field->set_allowed_values( array( 'cheese', 'pepporoni' ) );
    132132
    133133        $this->assertTrue( $field->is_valid( array( 'cheese', 'pepporoni' ) ) );
     
    140140    public function test_checkbox_validate_null_value() {
    141141        $field = bp_xprofile_create_field_type( 'checkbox' );
    142         $field->set_whitelist_values( array( 'cheese', 'pepporoni' ) );
     142        $field->set_allowed_values( array( 'cheese', 'pepporoni' ) );
    143143
    144144        $this->assertFalse( $field->is_valid( array( '' ) ) );
Note: See TracChangeset for help on using the changeset viewer.