Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save KaineLabs/60fee42f4c1babef2930b6f06eaeea96 to your computer and use it in GitHub Desktop.
Save KaineLabs/60fee42f4c1babef2930b6f06eaeea96 to your computer and use it in GitHub Desktop.
Redirect Non Logged In Users To Login Page
<?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