Skip to:
Content

BuddyPress.org

Changeset 9983


Ignore:
Timestamp:
07/02/2015 12:13:10 PM (9 years ago)
Author:
boonebgorges
Message:

Set the id property of a new BP_XProfile_Field object during the save() method.

Props Offereins.
Fixes #6545.

Location:
trunk
Files:
2 edited

Legend:

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

    r9879 r9983  
    288288        if ( $wpdb->query( $sql ) !== null ) {
    289289
    290             if ( !empty( $this->id ) ) {
     290            if ( ! empty( $this->id ) ) {
    291291                $field_id = $this->id;
    292292            } else {
     
    382382            $this->type_obj->field_obj = $this;
    383383
    384             return $field_id;
     384            // If this is a new field, set the `id` property of the current object.
     385            if ( empty( $this->id ) ) {
     386                $this->id = $field_id;
     387            }
     388
     389            return $this->id;
    385390        } else {
    386391            return false;
  • trunk/tests/phpunit/testcases/xprofile/class-bp-xprofile-field.php

    r9878 r9983  
    109109        );
    110110    }
     111
     112    /**
     113     * @ticket BP6545
     114     */
     115    public function test_newly_created_field_should_have_field_id_property_set() {
     116        $field = new BP_XProfile_Field();
     117        $field->group_id = 1;
     118        $field->name = 'Foo';
     119
     120        $new_field_id = $field->save();
     121
     122        $this->assertSame( $new_field_id, $field->id );
     123    }
    111124}
Note: See TracChangeset for help on using the changeset viewer.