Last active
December 12, 2015 12:39
-
-
Save mattonomics/4773955 to your computer and use it in GitHub Desktop.
This will make sure that only logged in users can view ANY content on the site. Drop it at the tip top of your functions.php file.
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 | |
// fancy PHP 5.3+ style | |
add_action( 'template_redirect', function() { | |
if ( ! is_user_logged_in() ) { | |
wp_redirect( wp_login_url() ); | |
exit; | |
} | |
} ); | |
// and <PHP 5.3 style | |
if ( ! is_user_logged_in() && 'wp-login.php' !== $pagenow ) { | |
wp_redirect( wp_login_url() ); | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
props to @nacin and @nathanrice for the edits