Created
January 27, 2012 08:13
-
-
Save dragunoff/1687747 to your computer and use it in GitHub Desktop.
[WP] Block site from non-logged in users
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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