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
1 Answer
Reset to default 3There 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>';
}