Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

Keep subscribers and customers out of the admin area

Users who can’t write posts are sent to the home page when they open the admin area. Their profile page and background requests still work.

  • Type PHP
  • Runs Everywhere (runs as WordPress loads)
  • Category Admin area
  • Tested with WordPress 7.1
PHP
<?php

add_action(
	'admin_init',
	static function () {
		if ( wp_doing_ajax() || current_user_can( 'edit_posts' ) || ! is_user_logged_in() ) {
			return;
		}
		global $pagenow;
		// Leave the profile screen and admin-post.php (form handlers) alone.
		if ( in_array( $pagenow, array( 'profile.php', 'admin-post.php' ), true ) ) {
			return;
		}
		wp_safe_redirect( home_url( '/' ) );
		exit;
	}
);

Good to know

WooCommerce does the same for customers already; this covers every other role without editing rights.

In these packs

  • More admin tweaks: Useful columns, a tidier admin bar, a welcome box for clients, and fewer menus for editors.
  • Users and profiles: Registration dates, last logins, social profile fields, longer sessions and stricter passwords.

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.