0

I wonder if there is any way to make email an optional field while registering using default form. So that those who don't know mail may leave it blank.

I got code from stackexchange but that doesn't seems to work.I added code to functions.php under theme folder.

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();

    <?php if (isset($form_type) && $form_type === 'add-new-user') : ?>
        jQuery ('#send_user_notification') .removeAttr('checked');
    <?php endif; ?>
    </script>
    <?php
}

UPDATE

I mend to have optional mail registration on default registration page of wordpress (http://example.org/wp-login.php?action=register) not in dashboard.

Sorry for clarity in question .Won't repeat it again( am a newbie )

Any help is much appreciated. Thanks

Reference

8
  • This code works well on my setup. Are you on a wordpress multisite ? – Gregory Nov 15 '20 at 10:22
  • 1
    Do you have a particular error if you activate wp debug ? Do you have a cache plugin ? – Gregory Nov 15 '20 at 10:26
  • @Gregory No brother , I am not on multisite – David Becckam Nov 15 '20 at 10:51
  • Look my second comment. – Gregory Nov 15 '20 at 14:15
  • I'd guess that other code in WordPress assumes that the user will have an email address though. Do you really need to support users without one - are they that common? – Rup Nov 16 '20 at 9:52

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.