Skip to:
Content

BuddyPress.org

Changeset 8535


Ignore:
Timestamp:
06/16/2014 07:30:37 PM (12 years ago)
Author:
boonebgorges
Message:

Record 'option_order' when passed through xprofile_insert_field()

Previously, this value was not recorded in the main part of BP_XProfile_Field.
Instead, the requisite option_order checking only happened when a parent field
was being saved via the UI.

Fixes #5472

Location:
trunk
Files:
2 edited

Legend:

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

    r8524 r8535  
    636636                $this->order_by    = apply_filters( 'xprofile_field_order_by_before_save',    $this->order_by,    $this->id );
    637637                $this->field_order = apply_filters( 'xprofile_field_field_order_before_save', $this->field_order, $this->id );
     638                $this->option_order = apply_filters( 'xprofile_field_option_order_before_save', $this->option_order, $this->id );
    638639                $this->can_delete  = apply_filters( 'xprofile_field_can_delete_before_save',  $this->can_delete,  $this->id );
    639640                $this->type_obj    = bp_xprofile_create_field_type( $this->type );
     
    642643
    643644                if ( $this->id != null ) {
    644                         $sql = $wpdb->prepare( "UPDATE {$bp->profile->table_name_fields} SET group_id = %d, parent_id = 0, type = %s, name = %s, description = %s, is_required = %d, order_by = %s, field_order = %d, can_delete = %d WHERE id = %d", $this->group_id, $this->type, $this->name, $this->description, $this->is_required, $this->order_by, $this->field_order, $this->can_delete, $this->id );
     645                        $sql = $wpdb->prepare( "UPDATE {$bp->profile->table_name_fields} SET group_id = %d, parent_id = 0, type = %s, name = %s, description = %s, is_required = %d, order_by = %s, field_order = %d, option_order = %d, can_delete = %d WHERE id = %d", $this->group_id, $this->type, $this->name, $this->description, $this->is_required, $this->order_by, $this->field_order, $this->option_order, $this->can_delete, $this->id );
    645646                } else {
    646                         $sql = $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, order_by, field_order, can_delete ) VALUES (%d, %d, %s, %s, %s, %d, %s, %d, %d )", $this->group_id, $this->parent_id, $this->type, $this->name, $this->description, $this->is_required, $this->order_by, $this->field_order, $this->can_delete );
     647                        $sql = $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, order_by, field_order, option_order, can_delete ) VALUES (%d, %d, %s, %s, %s, %d, %s, %d, %d, %d )", $this->group_id, $this->parent_id, $this->type, $this->name, $this->description, $this->is_required, $this->order_by, $this->field_order, $this->option_order, $this->can_delete );
    647648                }
    648649
  • trunk/tests/phpunit/testcases/xprofile/functions.php

    r8518 r8535  
    591591                $this->assertNotEmpty( $f );
    592592        }
     593
     594        /**
     595         * @group xprofile_insert_field
     596         */
     597        public function test_xprofile_insert_field_type_option_option_order() {
     598                $g = $this->factory->xprofile_group->create();
     599                $parent = $this->factory->xprofile_field->create( array(
     600                        'field_group_id' => $g,
     601                        'type' => 'selectbox',
     602                        'name' => 'Parent',
     603                ) );
     604
     605                $f = xprofile_insert_field( array(
     606                        'field_group_id' => $g,
     607                        'parent_id' => $parent,
     608                        'type' => 'option',
     609                        'name' => 'Option 1',
     610                        'option_order' => 5,
     611                ) );
     612
     613                $field = new BP_XProfile_Field( $f );
     614
     615                $this->assertEquals( 5, $field->option_order );
     616        }
    593617}
Note: See TracChangeset for help on using the changeset viewer.