0

I am really desperate, looking for a solution for days now.

I need to achieve: restricted access for logged in users only not logged in users need to be redirected to a custom login page

I am on a multisite setup

the closest solution yet, is the following piece of code but it only protects 1 page, in this scenario it is the home page (e-mover.ch/distributor) because the multisite is using subfolders, so the main url is e-mover.ch/distributor. So if someone is going to this url, he will see the custom login page (haendler-login) but he could ignore it and just hit one of the menu items and will get access. I need the entire website restricted to logged in users and I want them to use the custom login page, which is "haendler-login".

I have tried some plugins but I always got redirect loop errors when using custom login plugins in combination with restricted access plugins. This is why I am looking for a "non-plugin" solution.

Any help is welcome.

This is the closest I could get:

if ( !is_user_logged_in()  ) {
$url_uri = $_SERVER['REQUEST_URI'];

//redirect shop page.
if ( $url_uri == '/distributor/' ) {
    wp_redirect( home_url( '/haendler-login' ) );
}
}

Cheers Mark

4

If you're willing to try another plugin, I suggest using Force Login. It's a simple lightweight plugin that will require all visitors to login.

Once the plugin is installed and activated, add the following code to your functions.php file to change your site's login URL to point to your custom login page:

function my_login_page( $login_url, $redirect ) {
    return site_url( '/haendler-login/?redirect_to=' . $redirect );
}
add_filter( 'login_url', 'my_login_page', 10, 2 );
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.