I think the solution is here…
https://www.ads-software.com/support/topic/what-is-the-php-function-to-save-fields-in-um_user/#post-10965068
…but it’s still not 100% clear to me and it’s not working so far.
@wptechnology, I reply to your topic in mine as yours is closed.
You suggest…
global $ultimatemember;
$user_id = um_user('ID');
um_fetch_user($user_id);
$toupdate[] = array('name_of_field' => 'its_value');
UM()->user()->update_profile($toupdate);
update_user_meta($user_id, 'name_of_field','its_value');
In my context, 3 checkboxes to update when the profile is created, I think it would become this (in functions.php)…
add_action('um_after_save_registration_details', 'ui_registration_enable_notifications', 10, 2);
function ui_registration_enable_notifications( $user_id, $submitted ) {
um_fetch_user($user_id);
$toUpdate[] = array('profile_notif_new_post' => array (0 => 'enable'),
'profile_notif_new_comment' => array (0 => 'enable'),
'profile_notif_new_mention' => array (0 => 'enable'));
UM()->user()->update_profile($toUpdate);
update_user_meta($user_id, 'profile_notif_new_post', array (0 => 'enable'));
update_user_meta($user_id, 'profile_notif_new_comment', array (0 => 'enable'));
update_user_meta($user_id, 'profile_notif_new_mention', array (0 => 'enable'));
}
But I have several questions:
1/ Is global $ultimatemember;
still needed in my case?
2/ What’s the differences in between the UM()->user()->update_profile()
and the update_user_meta()
updates? What are they respectively updating?
3/ For $toUpdate[]
, can we group 3 fields to update in 1 array like I did?
4/ I think checkbox values are set by an array like this array (0 => 'value')
, correct?
5/ For the update_user_meta() update, we need to use 3 lines of code, we can’t group the update for the 3 fields, correct?
6/ How do we update checkboxes in meta? Also by an array like array (0 => 'value')
, same?
I ask you those questions as something must be wrong. I have no error but it’s not working, the checkboxes are not ticked in the user’s profile.
Thanks!
-
This reply was modified 5 years, 4 months ago by
ftpwp.