If you’re running a WordPress site with multiple users, this is a snippet to consider.
Once you turn over login information to a guest writer or a Church volunteer who’s helping update your Church’s website, you have no control over what password they’re using.
Hopefully, they’re not using one of the top 20 passwords!
Drop this in your functions.php or a functionality plugin:
[cc lang=”php”]if ( is_admin() )
add_action( ‘init’, ‘disable_password_fields’, 10 );
function disable_password_fields() {
if ( ! current_user_can( ‘administrator’ ) )
$show_password_fields = add_filter( ‘show_password_fields’, ‘__return_false’ );
}[/cc]
If you you’re running a multi-site install or superadmin replace:
[cc lang=”php”]if ( is_admin() )
add_action( ‘init’, ‘disable_password_fields’, 10 );[/cc]
with:
[cc lang=”php”]add_action( ‘admin_init’, ‘disable_password_fields’, 10 );[/cc]
And that’s it!
Not only can you control who has what passwords, but you can force users to use a new password. This is especially useful if you’ve setup a generic login for the Church office, etc …
🙂
Sunny khan says
Hi Sir,
can you please give me coding for disabling password field for non admins users can you please create the plugin for me i dont know how to do that thanks in advance !