Last active
July 21, 2018 00:45
-
-
Save KaineLabs/60fee42f4c1babef2930b6f06eaeea96 to your computer and use it in GitHub Desktop.
Redirect Non Logged In Users To Login Page
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 | |
/** | |
* Redirect Non Logged In Users To Login Page. | |
*/ | |
function youzer_redirect_nonloggedin_users_to_login_page() { | |
if ( is_user_logged_in() ) { | |
return; | |
} | |
if ( 'off' == get_option( 'yz_activate_membership_system' ) ) { | |
return true; | |
} | |
// Get Login Page Url | |
$login_page = logy_page_url( 'login' ); | |
if ( ( is_home() || is_front_page() ) && ! is_user_logged_in() ) { | |
wp_safe_redirect( $login_page ); | |
exit; | |
} | |
} | |
add_action( 'template_redirect', 'youzer_redirect_nonloggedin_users_to_login_page' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment