最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp admin - Uncheck the box "Send User Notification" by default on new-user.php

programmeradmin2浏览0评论

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:

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>

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:

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>
Share Improve this question edited May 2, 2020 at 16:02 Sven 3,6841 gold badge35 silver badges48 bronze badges asked May 2, 2020 at 15:18 SamuelSamuel 3541 gold badge11 silver badges32 bronze badges 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
Add a comment  | 

1 Answer 1

Reset to default 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)

  1. 暂无评论