1

I want to remove '@' from a user_meta when users register or update their profile.

Here is my code

add_action('edit_user_profile_update', 'update_extra_profile_fields');
add_action('personal_options_update', 'update_extra_profile_fields');
add_action( 'user_register', 'update_extra_profile_fields');

function update_extra_profile_fields($user_id) {
    if (isset($_POST['telegram_id'])) {
        $telegram_id = $_POST['telegram_id'];
        $telegram_id = str_replace('@', '', $telegram_id);
        update_user_meta($user_id, 'telegram_id', $telegram_id);
    }
}

So here update_user_meta is not working. It doesn't update the user meta when users register or update their profile from wordpress dashboard but when they update their profile from the frontend page that I've created for my website, it works!

In order to see what the problem is, I changed this line update_user_meta($user_id, 'telegram_id', $telegram_id); to this: $_POST['telegram_id'] = $telegram_id; and now it's working (But it's not a good solution). It seems that my function is run before another wordpress function which re updates the user_meta. How should I solve this problem?

  • did you find a solution to this? – Marc Dec 4 '17 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.