Last active
November 6, 2020 15:19
-
-
Save thefuxia/3521964 to your computer and use it in GitHub Desktop.
T5 Force Log In
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 # -*- coding: utf-8 -*- | |
/** | |
* Plugin Name: T5 Force Log In | |
* Description: Grant access after log in only | |
* Plugin URI: http://toscho.de/?p=2207 | |
* Version: 2012.08.28 | |
* Author: Thomas Scholz | |
* Author URI: http://toscho.de | |
* License: MIT | |
* License URI: http://www.opensource.org/licenses/mit-license.php | |
*/ | |
add_action( 'template_redirect', function() { | |
is_user_logged_in() || auth_redirect(); | |
}); |
Where do I apply this code?
If you got a customized login page via front-end, you need to modify code as:
add_action( 'template_redirect', function() {
if ( !is_page( id_of_login_page ) )
is_user_logged_in() || auth_redirect();
});
or you will get a redirect error.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry for the late response. I was never notified of this comment.
It is secure for the HTML content. Images, on the other hand, are not routed through WordPress, so anyone can see them if they are able to get their URLs by guessing them or sniffing network traffic.