Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
01/09/2015 05:48:38 AM (9 years ago)
Author:
r-a-y
Message:

XProfile: Make sure xprofile_get_field_id_from_name() returns a field ID for a field name.

Previously, when using xprofile_get_field_id_from_name(), it was possible
to get the option ID instead of the desired field ID because a field name
and an option value (for a checkbox or radio field) can potentially be the
the same in the wp_bp_xprofile_fields DB table.

This commit ensures that field name look ups will return a field ID instead
of an option ID. Commit also includes a unit test.

Props dontdream.

Fixes #6082.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/xprofile/class-bp-xprofile-field.php

    r8958 r9324  
    2727        $this->assertEquals( '0', $f2->can_delete );
    2828    }
     29
     30    /**
     31     * @group xprofile_get_field_id_from_name
     32     */
     33    public function test_get_id_from_name_field_name_option_value_conflict() {
     34        $group = $this->factory->xprofile_group->create();
     35
     36        // force some checkbox options for our profile field
     37        $_POST['checkbox_option'] = array(
     38            1 => 'BuddyPress',
     39            2 => 'WordPress'
     40        );
     41
     42        // checkbox field
     43        $f1 = $this->factory->xprofile_field->create( array(
     44            'field_group_id' => $group,
     45            'type' => 'checkbox',
     46            'name' => 'Interests'
     47        ) );
     48
     49        // textbox field with the same name as our checkbox value
     50        $f2 = $this->factory->xprofile_field->create( array(
     51            'field_group_id' => $group,
     52            'type' => 'textbox',
     53            'name' => 'BuddyPress'
     54        ) );
     55
     56        $this->assertEquals( $f2, xprofile_get_field_id_from_name( 'BuddyPress' ) );
     57
     58        // cleanup!
     59        unset( $_POST['checkbox_option'] );
     60    }
    2961}
Note: See TracChangeset for help on using the changeset viewer.