Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to restrict access to my wordpress site to allow registered users only. I have tried the following plugins:

  • Require-login
  • Authenticator
  • WP-lock

All of them have the same problem: After seeing the login page, you can easily retype the URL in the browser address bar to bypass the login screen and access the home page directly, without needing to login. Only the home page can be accessed in this way. Clicking on any menus, will take you back to the login screen.

I suspect there is a problem with my site, not the plugins.

I have the following active plugins:

  • Advanced Custom Fields
  • Akismet
  • Analytics360
  • Custom Post Templates
  • Custom Post Type UI
  • Disqus Comment System
  • Duplicator
  • Easy Tweet Embed
  • Email This Page
  • Google Analytics
  • Gravity Forms
  • HotSpots
  • List category posts
  • Mini twitter feed
  • Peter's Login Redirect
  • Select Q&A - WordPress Questions and Answers Plugin
  • Raw HTML
  • Relevanssi
  • Revision Control
  • Swiftype Search
  • ThreeWP Activity Monitor
  • Usernoise Pro
  • W3 Total Cache
  • WP-Lock
  • WPML Multilingual CMS

Any help would be much appreciated, thanks.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

It seems to me that all you should need is this:

function force_login_wpse_89581() {
  if (!is_user_logged_in()) wp_safe_redirect(wp_login_url());
}
add_action('template_redirect','force_login_wpse_89581');

That should force users to the login page except for users who have already logged in.

I don't know what bells and whistles those plugins provide that my solution does not. Maybe you need something more complex.

share|improve this answer
    
This code does what you require, if I understand you. 1) Visitors who are not logged in are sent to the login page. 2) Visitors who are logged in can visit the site as normal. –  s_ha_dum Mar 6 '13 at 3:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.