Security Guide Intermediate 4 min

Hardening WordPress, Part 4: Plugin Updates, User Roles and Sessions

Most hacked sites run an outdated plugin or have an admin account nobody uses any more. Keep plugins patched automatically, give every account only the access it needs, and make logins expire sooner for staff.

Hardening WordPress · Part 4 of 4
TutorialIntermediate15 minTested on WordPress 7.1Updated November 17, 2026

The first three parts of this series locked down wp-config.php, added security headers and protected the login. This part looks at what happens around those defences: the plugins you run, the accounts that exist and how long they stay logged in. These are the boring parts of security, and the ones attackers count on being neglected.

Before you start

  • An administrator accountTo review users and plugins
  • Backups that run on their ownDaily, and stored off the server, before turning on automatic updates
  • A way to add PHP snippetsChild theme, must-use plugin or a snippets plugin

Keep plugins patched

When a security hole is found in a popular plugin, a fix usually ships within days, and bots start scanning for unpatched sites soon after. Sites that wait for someone to log in and click Update are the ones that get caught.

Part 1 kept WordPress’s own security releases automatic. Do the same for plugins:

functions.phpPHP
// Update every plugin automatically.
add_filter( 'auto_update_plugin', '__return_true' );

// Or only some plugins, by folder name. Use this instead of the line above.
// add_filter( 'auto_update_plugin', function ( $update, $item ) {
// 	$slugs = [ 'woocommerce', 'nahnu-login-shield' ];
// 	return in_array( $item->slug ?? '', $slugs, true ) ? true : $update;
// }, 10, 2 );
Tested on WordPress 7.1 · PHP 8.3Checked November 17, 2026
Backups first

An update can occasionally break something. With daily backups you can roll back in minutes. If a plugin handles payments or another critical feature and you’d rather test its updates first, use the version of the snippet that lists only the plugins you choose.

Delete what you don’t use. A deactivated plugin still sits on your server, and its files can still be reached directly. If you haven’t used it in months, delete it. The same goes for old themes: keep your active theme, its parent if it has one, and one default theme as a fallback.

WordPress emails you after every automatic update. If that becomes noise, our post on WordPress emails shows how to keep only the failure messages.

Give every account only the access it needs

Open Users and filter by Administrator. Every account there can install plugins, add users and change anything on the site. Ask of each one: does this person still need to be an administrator?

  • Former staff, agencies and freelancers should be deleted or downgraded. When you delete a user, WordPress lets you give their posts to someone else.
  • People who write need Author or Editor, not Administrator.
  • Shared logins should become one account per person, so you know who did what and can remove one person without changing everyone’s password.

To spot accounts nobody uses any more, add a last-login column to the Users screen:

Snippet

Show Last Login Date in the Users Table

Record when each user last logged in and show it as a sortable column on the Users screen, in your site's timezone.

PHPIntermediate
View

It records logins from the moment you add it, so give it a few weeks before acting on the dates.

Stop new sign-ups getting more power than they should. If the “New User Default Role” setting is ever changed to Editor or Administrator, whether by mistake or by an attacker, every new registration gets that role. Fix it in code:

Snippet

Set the Role for New Users in Code

Lock the "New User Default Role" setting so new sign-ups always get the role you choose, even if someone changes the setting.

PHPBeginner
View

Keep customers and subscribers out of wp-admin

Customers and subscribers have no reason to see the dashboard. Send them to My Account, or the homepage if you don’t run a shop, while still allowing the background requests that front-end forms rely on:

Snippet

Keep Customers and Subscribers Out of wp-admin

Redirect users who can't edit content away from wp-admin to My Account or the homepage, without breaking AJAX.

PHPBeginner
View

And hide the admin toolbar for them on the front end, so it doesn’t link back to wp-admin:

Snippet

Remove the Admin Bar for Non-Admin Users

Hide the WordPress admin toolbar on the front end for any user who isn't an administrator, keeping the public-facing site clean for logged-in subscribers, customers, and members.

PHPBeginner
View
You should now see

Log in as a test subscriber and visit /wp-admin/. You land on My Account or the homepage, and there’s no toolbar at the top of the site.

Make staff logins expire sooner

WordPress keeps people logged in for 2 days, or 14 days with “Remember me”. A laptop left open in a café stays logged in to your site for two weeks. For anyone who can edit content, shorter is safer:

Snippet

Shorten Login Sessions for Staff

Log out editors and administrators after 8 hours, or 2 days with "Remember me", instead of WordPress's 2 and 14 days.

PHPBeginner
View

Staff are logged out after 8 hours, or 2 days with “Remember me”. Customers keep the normal lengths. If a session expires while someone is working in wp-admin, WordPress shows a login pop-up, so they don’t lose their work.

Someone left? End their sessions now

Open their profile and click Log Out Everywhere Else, or delete the account. Changing their password also ends their sessions.

Accounts and updates checklist

0 / 8

Summary

Keep plugins updated automatically with backups behind them, and delete what you don’t use. Review your administrators, give everyone else the lowest role that works, and fix the default role for new sign-ups in code. Keep customers out of wp-admin, and log staff out after a working day.

Check your understanding

1Why delete a deactivated plugin instead of leaving it?
2A former freelancer still has an administrator account. What’s the safest fix?

Was this helpful?

Written by Nahnu Plugins

We build and maintain WordPress plugins. Every guide is tested on a fresh WordPress site before it goes out, and checked again when WordPress updates.

More guides

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only