Skip to:
Content

BuddyPress.org

Changeset 9986


Ignore:
Timestamp:
07/02/2015 01:25:25 PM (9 years ago)
Author:
boonebgorges
Message:

Better setting of id property in BP_XProfile_Field::save().

This ensures that the property is set before the after_save hook is fired.

Props Offereins.
Fixes #6545.

File:
1 edited

Legend:

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

    r9983 r9986  
    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 {
     
    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                /**
     
    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).
     
    381377            $this->type_obj            = bp_xprofile_create_field_type( $this->type );
    382378            $this->type_obj->field_obj = $this;
    383 
    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             }
    388379
    389380            return $this->id;
Note: See TracChangeset for help on using the changeset viewer.