wordpress Snippets 取消【用户】邮件地址必填

此代码在本站WordPress 5.5.1测试通过,参考地址:https://blog.naibabiji.com/skill/users-without-email-in-wordpress.html

安装Code Snippets插件,添加片段

/*此处移除后台修改信息时的空邮件地址错误*/
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');
}
/*去掉必填项*/
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) {
?>
<script type="text/javascript">
jQuery('#email').closest('tr').removeClass('form-required').find('.description').remove();
// Uncheck send new user email option by default
<?php if (isset($form_type) && $form_type === 'add-new-user') : ?>
jQuery('#send_user_notification').removeAttr('checked');
<?php endif; ?>
</script>
<?php
}