使用WordPress搭建的网站是支持用户注册做商城网站的,注册的时候默认要求用户填写一个邮箱,并且是必须填写的,而某些网站情况特殊,可能并不需要强制填写邮件,所以我们可以通过下面的代码把强制填写邮件功能改为必填项目。具体方法如下:
最近在给客户外贸建站的时候,都习惯了使用Code Snippets这个插件来管理自定义代码,所以本教程同样使用这种方法。
2、新建一个Code,复制下面的代码然后保存。
// 移除空邮件地址的提示
add_action('user_profile_update_errors', 'my_user_profile_update_errors', 10, 3 );
function my_user_profile_update_errors($errors, $update, $user) {
$errors->remove('empty_email');
}
// 这将删除电子邮件输入所需的javascript验证
// 还将删除标签中的(必填)提示
// https://blog.naibabiji.com/skill/users-without-email-in-wordpress.html
add_action('user_new_form', 'my_user_new_form', 10, 1);
add_action('show_user_profile', 'my_user_new_form', 10, 1);
add_action('edit_user_profile', 'my_user_new_form', 10, 1);
function my_user_new_form($form_type) {
?>
jQuery('#email').closest('tr').removeClass('form-required').find('.description').remove();
// Uncheck send new user email option by default
jQuery('#send_user_notification').removeAttr('checked');
}
3、保存后,用户前台注册或者后台添加用户的时候,邮件就不是必填项目了。
给本文打分 post