I'm looking for a way to save all email addresses to user meta as lowercase, ideally without validating and asking the user to change it but instead just saving it as lowercase. I've got as far as the following but can't get it to work:

add_action( 'update_user_meta', 'meta_email_tolowercase', 10, 4 );
function meta_email_tolowercase( $meta_id, $object_id, $meta_key, $_meta_value ) {

    if( strpos( $_meta_value, '@' ) !== false && ! ctype_lower( $_meta_value ) ):

        $result = update_user_meta( get_current_user_id(), $meta_key, strtolower( $_meta_value ) );

  • As far as I am aware, there is no such action hook update_user_meta. Where/how is this being applied? If you're doing this on a profile update or something, just apply strtolower() directly to the specific meta field you are targeting.
    – butlerblog
    Dec 12, 2019 at 13:43

1 Answer 1


you can use this filter to do that

add_filter("sanitize_email", function ($sanitized_email, $email, $message) {

    $sanitized_email = strtolower($sanitized_email);

    return $sanitized_email;

}, 10, 3);

but I am not sure if using "strtolower" is a good idea, does another readers know if it's better to use "mb_strtolower" to handle multibyte characters ?

  • Awesome, thanks, @Kaperto. That's worked like a charm. Dec 12, 2019 at 14:59

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.