2

I'm looking for a way to uncheck the box by default when we create a new user on WordPress.

Right now it is checked when we access wp-admin/user-new.php like you can see on the screenshot below:

enter image description here

This is the code that generated the setting (see file wp-admin/user-new.php in WordPress core):

<tr>
    <th scope="row"><?php _e( 'Send User Notification' ); ?></th>
    <td>
        <input type="checkbox" name="send_user_notification" id="send_user_notification" value="1" <?php checked( $new_user_send_notification ); ?> />
        <label for="send_user_notification"><?php _e( 'Send the new user an email about their account.' ); ?></label>
    </td>
</tr>
2
  • Hey, did my solution work for you? Could you solve the issue?
    – Sven
    Commented May 22, 2020 at 7:26
  • 1
    sorry for the late reply. it works. thanks :)
    – Samuel
    Commented May 23, 2020 at 16:10

1 Answer 1

3

There does not seem to be an easy overwrite without replicating the whole user interface. So the quickest solution might be to un-check the checkbox via JavaScript:

add_action('admin_footer', 'uncheck_send_user_notification');
function uncheck_send_user_notification() {
    $currentScreen = get_current_screen();
    if ('user' === $currentScreen->id) {
        echo '<script type="text/javascript">document.getElementById("send_user_notification").checked = false;</script>';
    }
}

The script is only injected on the user-new.php page (see $currentScreen->id), then selects the checkbox (see document.getElementById) and sets checked to false.

Update: Instead of checking for the current screen in the function there is the admin_footer-{$hook_suffix} action that only runs on specific admin pages:

add_action('admin_footer-user-new.php', 'uncheck_send_user_notification');
function uncheck_send_user_notification() {
    echo '<script type="text/javascript">document.getElementById("send_user_notification").checked = false;</script>';
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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