[buddypress-trac] [BuddyPress Trac] #6545: Provide new XProfile field object with WPDB's insert_id

buddypress-trac noreply at wordpress.org
Thu Jul 2 11:34:23 UTC 2015


#6545: Provide new XProfile field object with WPDB's insert_id
----------------------------------+-----------------------------
 Reporter:  Offereins             |      Owner:
     Type:  defect (bug)          |     Status:  new
 Priority:  normal                |  Milestone:  Awaiting Review
Component:  Component - XProfile  |    Version:
 Severity:  normal                |   Keywords:
----------------------------------+-----------------------------
 For my plugin for #5192 I stumbled upon this missing logic during the
 creation of a new XProfile field. While this is
 [https://buddypress.trac.wordpress.org/browser/branches/2.3/src/bp-
 xprofile/classes/class-bp-xprofile-group.php#L149 done correctly for
 XProfile field groups], using `wpdb->insert_id`, the logic in
 `BP_XProfile_Field::save()` does not do so. It does not update the field
 object with the newly created field's id. This is unfortunate when you'd
 like to use the field's object in later hooks.

 I suggest this easy fix by replacing:

 {{{
 if ( ! empty( $this->id ) ) {
   $field_id = $this->id;
 } else {
   $field_id = $wpdb->insert_id;
 }

 // Other code. No other use of $field_id here.

 return $field_id;
 }}}

 with

 {{{
 if ( empty( $this->id ) ) {
   $this->id = $wpdb->insert_id;
 }

 // Other code. No other use of $field_id here.

 return $this->id;
 }}}

 in [https://buddypress.trac.wordpress.org/browser/branches/2.3/src/bp-
 xprofile/classes/class-bp-xprofile-field.php#L290 class-bp-xprofile-
 field.php].

 PS. Excuse me for not providing a correct patch file at the moment.

--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/6545>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list