Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: Plugin update first_name, last_name in wp_usermeta on activation


peterverkooijen
Participant

@peterverkooijen

This is the function that the regular wpmu registration process uses to add the user to wp_usermeta:

function update_usermeta( $user_id, $meta_key, $meta_value ) {
global $wpdb;
if ( !is_numeric( $user_id ) )
return false;
$meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);

/** @todo Might need fix because usermeta data is assumed to be already escaped */
if ( is_string($meta_value) )
$meta_value = stripslashes($meta_value);
$meta_value = maybe_serialize($meta_value);

if (empty($meta_value)) {
return delete_usermeta($user_id, $meta_key);
}

$cur = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $meta_key) );
if ( !$cur )
$wpdb->insert($wpdb->usermeta, compact('user_id', 'meta_key', 'meta_value') );
else if ( $cur->meta_value != $meta_value )
$wpdb->update($wpdb->usermeta, compact('meta_value'), compact('user_id', 'meta_key') );
else
return false;

wp_cache_delete($user_id, 'users');

return true;
}

Is this function also used by Buddypress or does Buddypress replace it with something else?

Where do meta_key and meta_value come from? Data from Buddypress xprofile field_1 is not included at this point…

What would happen if I just added $bp as global? Trying that now… EDIT: Does nothing.

I see xprofile_sync_wp_profile() uses this same function….

Skip to toolbar