admin管理员组文章数量:1410705
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 ) );
endif;
}
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 ) );
endif;
}
Share
Improve this question
asked Dec 12, 2019 at 13:31
Kevin NugentKevin Nugent
5631 gold badge8 silver badges20 bronze badges
1
|
1 Answer
Reset to default 0you 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 ?
https://www.php/manual/en/ref.mbstring.php
本文标签: hooksSave User Meta Email Address in Lowercase
版权声明:本文标题:hooks - Save User Meta Email Address in Lowercase 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744910031a2631857.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
update_user_meta
. Where/how is this being applied? If you're doing this on a profile update or something, just applystrtolower()
directly to the specific meta field you are targeting. – butlerblog Commented Dec 12, 2019 at 13:43