Created
April 19, 2024 02:08
-
-
Save tranchausky/b8f576509df395931db50d0a0ea59121 to your computer and use it in GitHub Desktop.
wp need login not sub page free
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 | |
//every page need login | |
//not page of /free | |
//http://myweb.com/free | |
//http://myweb.com/free/page1 | |
//http://myweb.com/free/page2.... | |
function _nok_force_user_login() { | |
global $wp; | |
$pagename = isset($wp->query_vars['pagename'])? $wp->query_vars['pagename']:""; | |
$isBreak = false; | |
if(!empty($pagename)){ | |
if(substr($pagename, 0, 4) == "free"){ | |
$isBreak = true; | |
} | |
} | |
if ( !is_page('login') && !is_user_logged_in() && !$isBreak){ | |
auth_redirect(); | |
} | |
} | |
add_action( 'template_redirect', '_nok_force_user_login' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment