Skip to content

Commit 4c01def

Browse files
committed
Add a nag message if the user is still using an auto-generated password. See WordPress#9710 props DD32.
git-svn-id: https://develop.svn.wordpress.org/trunk@11162 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 263b761 commit 4c01def

5 files changed

Lines changed: 28 additions & 1 deletion

File tree

wp-admin/includes/upgrade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ function wp_install($blog_title, $user_name, $user_email, $public, $deprecated='
6060
if ( !$user_id ) {
6161
$random_password = wp_generate_password();
6262
$user_id = wp_create_user($user_name, $random_password, $user_email);
63+
update_usermeta($user_id, 'default_password_nag', true);
6364
} else {
6465
$random_password = __('User already exists. Password inherited.');
6566
}

wp-admin/includes/user.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,4 +791,24 @@ function is_search() {
791791
}
792792
endif;
793793

794+
add_action('admin_init', 'default_password_nag_handler');
795+
function default_password_nag_handler() {
796+
if ( 'hide' == get_user_setting('default_password_nag') || isset($_GET['default_password_nag']) && '0' == $_GET['default_password_nag'] ) {
797+
global $user_ID;
798+
delete_user_setting('default_password_nag');
799+
update_usermeta($user_ID, 'default_password_nag', false);
800+
}
801+
}
802+
add_action('admin_notices', 'default_password_nag');
803+
function default_password_nag() {
804+
global $user_ID;
805+
if ( ! get_usermeta($user_ID, 'default_password_nag') )
806+
return;
807+
808+
echo '<div class="error default-password-nag"><p>';
809+
printf(__("Howdy, you're still using the auto-generated password for your account. We recommend that you change it to something you'll remember easier. Would you like to do this now?<br />
810+
<a href='%s'>Yes, Take me to my profile page</a> | <a href='%s' id='default-password-nag-no'>No Thanks, Do not remind me again.</a>"), admin_url('profile.php') . '#password', '?default_password_nag=0');
811+
echo '</p></div>';
812+
}
813+
794814
?>

wp-admin/js/common.dev.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ jQuery(document).ready( function($) {
232232
return '';
233233
});
234234
});
235+
$('#default-password-nag-no').click( function() {
236+
setUserSetting('default_password_nag', 'hide');
237+
$('div.default-password-nag').hide();
238+
return false;
239+
});
235240
});
236241

237242
(function(){

wp-admin/user-edit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ function use_ssl_preference($user) {
353353
$show_password_fields = apply_filters('show_password_fields', true);
354354
if ( $show_password_fields ) :
355355
?>
356-
<tr>
356+
<tr id="password">
357357
<th><label for="pass1"><?php _e('New Password'); ?></label></th>
358358
<td><input type="password" name="pass1" id="pass1" size="16" value="" autocomplete="off" /> <?php _e("If you would like to change the password type a new one. Otherwise leave this blank."); ?><br />
359359
<input type="password" name="pass2" id="pass2" size="16" value="" autocomplete="off" /> <?php _e("Type your new password again."); ?><br />

wp-login.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ function reset_password($key) {
179179
// Generate something random for a password...
180180
$new_pass = wp_generate_password();
181181
wp_set_password($new_pass, $user->ID);
182+
update_usermeta($user->ID, 'default_password_nag', true); //Set up the Password change nag.
182183
$message = sprintf(__('Username: %s'), $user->user_login) . "\r\n";
183184
$message .= sprintf(__('Password: %s'), $new_pass) . "\r\n";
184185
$message .= site_url('wp-login.php', 'login') . "\r\n";

0 commit comments

Comments
 (0)