Dashifen.com

Disabling the WordPress Admin Area

While working on a different project, I had the occasion to require the disabling of the WordPress administrative area and the login capabilities of all users of the site.  After some googling around, it seemed that while “maintenance mode” style plugins were readily available, there wasn’t one that simply turned off the ability to login and make changes to your site while concurrently still allowing others to browse and enjoy your content.

So, without further ado, my solution.  Just add this to your functions.php file:

function dashifen_disable_login_and_admin() {
   if(
      strpos($_SERVER["SCRIPT_NAME"], "wp-login") !== false ||
      strpos($_SERVER["SCRIPT_NAME"], "wp-admin") !== false
   ) exit("Administration disabled.");
}

add_action("init", "dashifen_disable_login_and_admin");

Obviously, you can change the name of the function to suit your needs; just be sure to change it both in the definition and in the add_action() call.  It could also be spruced up a bit.  Even a simple redirection to a specific page on your site that perhaps gives reasons why you’re disabling the administration of your site would be better than a fairly bland message, but it serves the purposes I needed it for until a better solution is presented.

I’ll now go back into my cave and post again in a few months.

Comments are closed.

Tweeting:

  • Question: what's a good basic introduction book on Paganism these days? Are we still all starting with Cunningham? #pagan101 9 hours ago

The Fuller Dash:

Social Stuff