Hi @skeldogg
If you would like to protect entire page and redirect users to wp-login.php page, you can use this code snippet and insert it at the end of your theme’s functions.php file:
add_action( 'template_redirect', function() {
// Redirect users from specific page
// when user doesn't have particular role
$user = wp_get_current_user();
if ( is_page('contact') && ( ! is_user_logged_in() || ( ! empty($user) && in_array( 'author', (array) $user->roles ) ) ) ) {
$redirect = 'https://your-domain.com/wp-login.php'; // Change this to the correct URL
wp_redirect( $redirect );
exit;
}
} );
Hopefully, that helps.
Hi @caseproof
Sorry, I didn’t explain myself very well (although your solution is handy for future reference).
I would like to use Private Site Mode with a custom login page instead of the default WordPress wp-login. I added a function to redirect users to /login, but it caused a redirect loop with your plugin. Is there a way to override the URL that Private Site Mode uses?
Thanks in advance!
Could you please leave your code with redirection add this code:
add_filter('members_is_private_page', function($is_private) {
global $post;
if($post->post_title === "Login") {
return false;
}
return $is_private;
});
It should make the Login page public and stop redirection loop.
Hopefully, that helps.