Updating WordPress user meta data after login
If you require to update some user meta data after the user logged in to your WordPress site you can use one of the below codes.
Method 1 (recommended)
add_action('super_before_login_user_action', '_super_update_user_meta_data_after_login', 1);
function _super_update_user_meta_data_after_login($x){
extract(shortcode_atts(array('data'=>array(), 'user_id'=>0), $x));
// We want to update some user meta data from a hidden field named `push_id`
$fieldName = 'push_id';
$metaKey = 'custom_user_meta_data_key';
// In case the field is empty, we don't do anything since the user might have logged in via other means
if(empty($data[$fieldName])) return;
$data = wp_unslash($data);
$metaValue = trim(sanitize_text_field($data[$fieldName]['value']));
// Now update user meta
update_user_meta($user_id, $metaKey, $metaValue);
}Method 2
PreviousCustom API Phone Number Validation for Your WordPress FormNextAutomatically redirecting to next step after displaying text or a progress bar
Last updated