Skip to:
Content

BuddyPress.org

Ticket #6545: 6545.diff

File 6545.diff, 2.7 KB (added by boonebgorges, 11 years ago)
  • src/bp-xprofile/classes/class-bp-xprofile-field.php

    diff --git src/bp-xprofile/classes/class-bp-xprofile-field.php src/bp-xprofile/classes/class-bp-xprofile-field.php
    index e061c8a..4d08bca 100644
    class BP_XProfile_Field { 
    275275                 */
    276276                do_action_ref_array( 'xprofile_field_before_save', array( $this ) );
    277277
    278                 if ( $this->id != null ) {
     278                $is_new_field = is_null( $this->id );
     279
     280                if ( ! $is_new_field ) {
    279281                        $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, is_default_option = %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->is_default_option, $this->id );
    280282                } else {
    281283                        $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, is_default_option ) VALUES ( %d, %d, %s, %s, %s, %d, %s, %d, %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, $this->is_default_option );
    class BP_XProfile_Field { 
    287289                 */
    288290                if ( $wpdb->query( $sql ) !== null ) {
    289291
    290                         if ( ! empty( $this->id ) ) {
    291                                 $field_id = $this->id;
    292                         } else {
    293                                 $field_id = $wpdb->insert_id;
     292                        if ( $is_new_field ) {
     293                                $this->id = $wpdb->insert_id;
    294294                        }
    295295
    296296                        // Only do this if we are editing an existing field
    297                         if ( $this->id != null ) {
     297                        if ( ! $is_new_field ) {
    298298
    299299                                /**
    300300                                 * Remove any radio or dropdown options for this
    class BP_XProfile_Field { 
    311311                         */
    312312                        if ( $this->type_obj->supports_options ) {
    313313
    314                                 if ( !empty( $this->id ) ) {
    315                                         $parent_id = $this->id;
    316                                 } else {
    317                                         $parent_id = $wpdb->insert_id;
    318                                 }
     314                                $parent_id = $this->id;
    319315
    320316                                // Allow plugins to filter the field's child options (i.e. the items in a selectbox).
    321317                                $post_option  = ! empty( $_POST["{$this->type}_option"]           ) ? $_POST["{$this->type}_option"]           : '';
    class BP_XProfile_Field { 
    381377                        $this->type_obj            = bp_xprofile_create_field_type( $this->type );
    382378                        $this->type_obj->field_obj = $this;
    383379
    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 
    389380                        return $this->id;
    390381                } else {
    391382                        return false;