0

For some reason my default password nag is playing up on a big multi-user site I've setup. Pretty sure it's got to do with the New User Approve and Gravity Forms User Rego combo that I'm using.

Anyway, problem is I need to hack the core WP code every time I upgrade. The wp-admin/includes/user.php file has the 'default password nag' function... so I just change this to the wording I want. But of course it doesn't stick and needs to be done every upgrade! Big hassle.

add_action('admin_notices', 'default_password_nag');
function default_password_nag() {
global $pagenow;
if ( 'profile.php' == $pagenow || ! get_user_option('default_password_nag') ) 
    return;

echo '<div class="error default-password-nag">';
echo '<p>';
echo '<strong>' . __('Notice:') . '</strong> ';
_e('You&rsquo;re using the auto-generated password for your account. Would you like to change it to something easier to remember?');
echo '</p><p>';
printf( '<a href="%s">' . __('Yes, take me to my profile page') . '</a> | ', get_edit_profile_url( get_current_user_id() ) . '#password' );
printf( '<a href="%s" id="default-password-nag-no">' . __('No thanks, do not remind me again') . '</a>', '?default_password_nag=0' );
echo '</p></div>';
}

Each time I change it to this, which works a treat:

add_action('admin_notices', 'default_password_nag');

function default_password_nag() {
global $pagenow;
if ( 'profile.php' == $pagenow || ! get_user_option('default_password_nag') ) 
    return;

echo '<div class="error default-password-nag">';
echo '<p>Visit your ';
printf( '<a href="%s">' . __('profile page') . '</a> to update your password any time. ', admin_url('profile.php') . '#password' );
echo '</p></div>';
   }

But I want a permanent fix. Any advice will be appreciated :)

2 Answers 2

0

The function is hooked to an action, so you should be able to remove it.

remove_action('admin_notices','default_password_nag');

You can then add back a function of your own choosing. Rename your function to something that won't conflict with the Core function name and...

add_action('admin_notices','my_password_nag');

You will need to create a plugin or mu-plugin to do it, but those are relatively easy to create.

3
  • Looks good, but are you saying I can't use this in functions.php? Mar 6, 2014 at 11:01
  • It should probably work in the theme's functions.php but if it isn't a theme you've written that will be overwritten when the theme updates.
    – s_ha_dum
    Mar 6, 2014 at 14:05
  • Thanks. Pretty much all my themes are ones that I've made myself ;-) Mar 7, 2014 at 2:44
0

Great. Using @s_ha_dum action in the right way (in functions.php). Full code is:

add_action('admin_notices', 'aa99_delete_pass_nag', 1);
function aa99_delete_pass_nag() {
remove_action('admin_notices','default_password_nag');
}

function aa99_add_password_nag() {
global $pagenow;
if ( 'profile.php' == $pagenow || ! get_user_option('default_password_nag') ) 
    return;

echo '<div class="error default-password-nag">';
echo '<p>Visit your ';
printf( '<a href="%s">' . __('profile page') . '</a> to update your password at any time. ', admin_url('profile.php') . '#password' );
echo '</p></div>';
}
add_action('admin_notices', 'aa99_add_password_nag');

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.