[buddypress-trac] [BuddyPress Trac] #5916: Action xprofile_field_after_save has no way of knowing field_id for newly created field

buddypress-trac noreply at wordpress.org
Tue Sep 30 11:47:49 UTC 2014


#5916: Action xprofile_field_after_save has no way of knowing field_id for newly
created field
-------------------------+------------------
 Reporter:  tometzky     |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  2.2
Component:  XProfile     |     Version:  2.1
 Severity:  minor        |  Resolution:
 Keywords:  2nd-opinion  |
-------------------------+------------------
Changes (by tometzky):

 * cc: tometzky+wordpress@… (added)


Comment:

 I've managed to code a workaround in my plugin. If there's no `$field->id`
 then I check for `parent_id` column in a database. If its `NOT NULL` then
 there was an option and I use `parent_id` instead of `$wpdb->insert_id`.

 {{{
 $field_id = $field->id;
 if ( !isset($field_id) ) {
   $field_id = $wpdb->insert_id;
   // There could be another insert after field - a record with type set to
 'option'
   // we need to use its 'parent_id' instead
   $sql = $wpdb->prepare(
     "SELECT parent_id from {$bp->profile->table_name_fields} WHERE id =
 %d",
     $wpdb->insert_id
   );
   $parent_id = $wpdb->get_var($sql);
   if ( isset($parent_id) ) {
     $field_id = $parent_id;
   }
 }
 }}}

 So maybe there's no need for API change.

--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/5916#comment:2>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list