• Resolved hyp0xia

    (@hyp0xia)


    Just looking for the easiest way to accomplish this. Currently, if a user is not logged in and they try to access a protected page, they get a 404 error. I was hoping I could add a login form here instead so that they know this is protected content and their member login is required.

    Many many thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • I am doing this; it’s very easy. You want the free plugin Groups 404 Redirect – https://www.ads-software.com/plugins/groups-404-redirect/

    So you then create a page with a login form, along with whatever notification text you want to include (such as “content restricted – please login to view”)

    Then simply set the Groups 404 Redirect to redirect to that page with the first option on its settings page.

    Thread Starter hyp0xia

    (@hyp0xia)

    This fit the bill perfectly. Many thanks Abigail!

    The trickier part is to get the page to redirect back to the protected page after login. I haven’t managed to figure out how to do that, unfortunately.

    Instead, what happens is — the user goes to

    mysite.com/restricted-page

    the user is referred to the page with the login and notice “this content is restricted, please log in”) – i.e., mysite.com/login-notice-page

    After log in, the user is still on the same page where they logged in. (The restriction notice and login box is gone, because that is set to display only to people who aren’t logged in — but the other content on the page is still there) So they have to navigate back again to the restricted-page

    Thread Starter hyp0xia

    (@hyp0xia)

    So funny you mention that because that is the first issue which I noticed with this technique. I was actually going to post here about it but didn’t want to spawn a separate topic.

    So I used a mix between the Groups shortcodes and WordPress conditional tags to create a “smart” login system.

    I’ve created a page called “signup” which displays a user login form, and this is the page that Groups 404 redirects to if a user is not logged in.

    Because Groups just reloads that same page after a successful login, we need to basically change how that page looks depending on whether they are logged in or not. So my redirect login template file goes a little like this:

    [groups_member group="Members"]
    <notice here telling users that they have been successfully logged in along with some links to quickly access member only content>
    [/groups_member]
    if (is_user_logged_in()) {
          echo do_shortcode( '
    [groups_non_member group="Members"]
    <notice here telling users that they have successfully logged in to their account, however their account does not have sufficient privileges to view members only content>
    [/groups_non_member] );
        };

    Now the thing about the [groups_non_member group=”Members”] shortcode is that is basically only displays that notice to people who are not part of the Members group. This unfortunately includes users that are not even logged in. So to combat this, I wrapped it in the wordpress is_user_logged_in conditional tag which now will only show that notice to a user who is logged in, but not part of the Members group. Exactly how it’s supposed to work.

    Now we want to display the login form however we do not want the login form to display on this same page once the user successfully logs in. So wrap the login form in the same is_user_logged_in conditional, but with an exclamation in front:

    if (!is_user_logged_in()) {
    
    <login form stuff here>
    
    }

    And basically how it works is this:

    – User visits members page, but it not logged in -> redirect to custom sign-in page
    – Sign-in page shows login form
    – User with member privs signs in and page turns into a “login success” page along with some quick links to members content
    – user without member privs signs in and page turns into a “login success” page along with a notice stating that they do not have member access along with some additional information
    – Login form is hidden on each login success

    Hope this helps!!

    Thanks so much — that’s very helpful in a situation with multiple levels of group privileges — but I am looking for a way to take a group member back to whatever page they were trying to reach before they were redirected to the custom sign in page.

    So here is what typically happens.

    There is a useful, informative page on the web site, Page A.

    The group member receives the link to Page A in an email communication — for example, a private email sent to all group member announcing the creation of Page A.

    Group member uses the Page A link to go to the site but is not logged in, so is redirected to Page B, which is the custom log in page. I will call this B-1.

    Gruup member logs in. Now Page B looks different as it is displaying the appropriate text for members, and some useful links — but it is still Page B. Since appearance has changed with login, I will call this B-2.

    I want a way to redirect the user back to page A after a successful login — rather than having to re-enter the URL to Page A or to find it via navigation tools. So ideally I want the user to come to page A, be redirected to B1, and then be redirected back to page A after login rather than ending up on B2.

    Thread Starter hyp0xia

    (@hyp0xia)

    I wish I could do this too.. You’re right, when you are sending out links to specific content, the user is going to get lost after they log in. Unless you put a notice telling them to follow the link again after the signin is successful (bandaid solution, I know)

    I think maybe you should create a new thread about this topic and hopefully the developer can chime in. If you do, can you post the link to it here? I’ll follow it.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to add login form on protected pages?’ is closed to new replies.