Skip to content

Instantly share code, notes, and snippets.

@dragunoff
Created January 27, 2012 08:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dragunoff/1687747 to your computer and use it in GitHub Desktop.
Save dragunoff/1687747 to your computer and use it in GitHub Desktop.
[WP] Block site from non-logged in users
<?php
/**
* Plugin name: Simple Password lockdown
* Plugin URI: https://gist.github.com/1687747
* Description: Block site from non-logged in users
*/
add_action('get_header', 'wpq_member_only_site');
function wpq_member_only_site() {
// logged in users or visits to a specified page are allowed
if ( !is_user_logged_in() && !is_page( 'user-registration' ) ) {
// vars
$redirect_after_login = 'http://' . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
$login_url = wp_login_url( $redirect_after_login );
// redirect visitors
wp_redirect( $login_url, 302 );
exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment