Page redirect issues with Membership 2

According to this post, M2 should automatically redirect a user to the post he was looking for after he logs in.

In my case, the post is protected by a particular membership (not just default logged-in membership). So the user has to log in, AND join the right membership to see the page.

I have defined a special protection message for this membership, which I would expect the user to see after he logs in (since logging in alone is not sufficient to let him access the page).

However, after logging in, the user still sees the default content protection message, followed by a message saying "You are logged in as XXXX. Logout"

At this point, I would think the user should be offered to join the appropriate membership to see the page -- instead, he's kinda stuck. He's logged in, but still can't see the page he was after.

Can someone point me in the right direction? I don't know if I'm missing something, or if it's not working right.

My test page is here and it's protected by a membership called Administration/Technical (ID=4140). I've allowed support access to my site.

Thanks.

  • Milan

    Hello @kalico,

    I hope you are well today and thanks for asking us. :slight_smile:

    I can confirm issue that Membership 2 Pro is not displaying membership specific protection message. I've raised bug ticket for this issue, Hopefully developers will start their work on this.

    I've also noticed that we are not able to include shortcodes in protection message as whole message gets escaped at the time of rendering so wordpress skips shortcode execution. Having this said, for now we can include page link which displays list of memberships ? If its okay to you, you can include something like this in protection message( generic one, Membership > Settings > Protection Message )

    <a href="link_to_you_membership_page">Discover Our Different Memberships</a>

    At this point, I would think the user should be offered to join the appropriate membership to see the page -- instead, he's kinda stuck. He's logged in, but still can't see the page he was after.

    By default membership displays Register link just beneath login in form. When user clicks on it its renders registration form, and as soon as user register himself to your site, he gets redirected to your membership listing page.

    Alternatively you can use above trick of including page link which renders different membership list. If you are not sure which page is displaying list of memberships you can know that via Memberships > Settings > General > Membership 2 Pages

    I hope this helps you.

    Cheers,
    Milan

  • kalico

    Thank you, Milan. A thorough answer as always. :slight_smile:

    1) Thank you for reporting the bug. I look forward to it being resolved. If it's possible to find out a timeline, I would be very interested. We are trying to launch our site soon, and this is important functionality for our user experience.

    2) Your suggestion of a simple link in the protection message (instead of shortcode) is very helpful. I will try it out. On the other hand, I have come to understand that the "protected content message" is just that: a MESSAGE. It displays within the protected content PAGE via a shortcode. Now that I understand the context and how it's being used, the fact that this message is being escaped makes more sense, and I no longer see the need to use a shortcode in that context. I will endeavor to do my customizations on the PAGE instead of in the MESSAGE.

    3) You said:

    By default membership displays Register link just beneath login in form. When user clicks on it its renders registration form, and as soon as user register himself to your site, he gets redirected to your membership listing page.

    I don't think this is working, or perhaps I have set it up wrong. When I register a test account from that page, I am never redirected back to the original page.

    Also, as a followup to the #2 above, I tried using the [ms-membership-buy id="4140" label="Join"] shortcode on the protected content page, since that will always be seen regardless of which message is displayed. This works for our rather simple set up (would not work as smoothly from a UX standpoint if we had multiple memberships to select from). It nicely provides a path through registration for the user if he is not logged in...and a path through signing up for the membership if he is logged in.

    But, unfortunately, in both cases, we lose the connection with the original page, so the user is not redirected back to where he started.

    So this sounds like a possible bug...or maybe I'm just not understanding the functionality.

    Hope you can put me back on the right track. Thanks!

  • kalico

    Wait....I am wrong. But I still have a problem! (I have confused myself....)

    So the redirect from registration to the membership list (default workflow) IS working properly.

    What is not working, is a redirect back to the page the person came from. The problem seems to lie in the workflow for different types of users, and different types of protection.

    If we have a page protected by a membership that requires an invitation code, that's a different process than if the page just requires the user to be logged in. There is also the question of whether he is already a member (just not logged in) or if he has to create an account along the way. In the end, I want him to get back to where he started with some level of ease, rather than having to back-button his way through his history.

    What I am trying to achieve involves some logic like this:

    - non-logged in user lands on a protected page
    - sees a description stating that membership is required, and option to join OR login

    - if he logs in AND the page is available to all logged in users >> redirect to page he wanted to view

    - if he logs in AND the page is protected by a membershipt >> sees a "membership required" page with option to JOIN >> he joins the membership (via invitation code, in our case) >> redirect to page he wanted to view in the first place

    - if he registers AND the page requires a particular membership (which requires an invitation code) >> he is immediately logged in and redirected to the page he wanted to view, but it's still protected >> sees a "membership required" page with option to JOIN >> he joins the membership (via invitation code) >> redirect back to page he wanted to view

    Is this possible? If it's not blocked by a bug, what is the best way to get this to work?

    Or maybe you can tell me how M2 is supposed to work, if I'm imagining it all wrong for a situation like this.

    Thanks again!

  • Adam Czajczyk

    Hello Kalico!

    I'm really glad that the initial issue is solved now :slight_smile:

    According to your last post, let me please explain a bit how Membership 2 protection is supposed to work so we could then compare this against your needs and how it currently works on your site - just to make sure that we're on the same side and be able to troubleshoot that further.

    There are four types of memberships available: guest (logged out users), dripped (content released on time base), default (all logged in users) and standard (content available only to members of this membership). Let's skip "guest" and "dripped" as they doesn't seem to be relevant to this case.

    In case of both "default" and "standard" memberships the workflow is similar with one exception: all registered users of your WordPress are automatically "default" members, regardless whether they signed up for any "standard" membership or not.

    The first step is to protect content with memberships so you can assign both "default" and "standard" memberships to selected post/pages etc the same way. Then a "guest" (logged out visitor) will get access only to unprotected content, each logged in user that's not a member of any other membership will get access to unprotected content and content protected by "default" membership and the "standard" member will get access to unprotected, protected by "default" membership and protected by his "standard" membership content.

    As you can see, in this case an access sort of "overlaps".

    The "login/get access" workflow in case of users should be as described below. I'll refer to the page that contains protected content as The Page :slight_smile:

    For unprotected content:
    - any visitor (logged in or not) visits The Page and gets its content

    For "default" protected content:

    - logged out visitor visits The Page -> is redirected to "protected content" page/form -> logs in -> is redirected back to The Page -> is able to see its content

    - logged in user visits The Page -> is able to see its content

    For "standard" protected content:

    - logged out visitor visits The Page -> is rediercted to "protected content" page -> logs in -> I he is a member of that "standard" membership -> is redirected back to The Page -> is able to see its content

    but if he is NOT a member of that "standard" membership -> is redirected back to The page -> is not able to see its content and instead is presented with a message that the content is only available to members.

    The above scenario applies to both users that are not members of that particular "standard" membership and to the "default" members (thus WP users that can log in but are not members of any standard membership).

    Please note though, that I'm referring only to the "protected content page form" and not the default WP login/register form and Membership 2 pro widget login form - these do not follow that workflow and I think will not anytime soon.

    Let me also add registration/signup to that equation. If a logged out (guest) user visits The Page he/she is redirected to the "protected content" page with a login form and a register link. If he chooses to register is then pointed to Membership registration -> signup form and "drops out" of that workflow. I suppose that'd be issue number one (#1) that you're dealing with, is that right?

    Another exception is when user logs in (so gets redirected back to The Page) but is not a member of the membership that's protecting The Page. There's only a message with no option to sign up for membership. I thin that'd be issue number two (#2) that you're dealing with, am I correct?

    That said, could you please double-check and let me know if the current workflow on your site is the same (or close) to what I described and confirm if I'm right about issues #1 and #2?

    Best regards,
    Adam

  • kalico

    Adam,

    You are my hero! Awesome explanation there, really helped me understand and sort out what's going on. My responses below....

    If a logged out (guest) user visits The Page he/she is redirected to the "protected content" page with a login form and a register link. If he chooses to register is then pointed to Membership registration -> signup form and "drops out" of that workflow. I suppose that'd be issue number one (#1) that you're dealing with, is that right?

    Yes, that's right. Would really like that person to be directed back to the page he originally wanted -- or at least have a link to click to go there. Maybe using history, we could determine where he started? I realize that could be unstable....just not sure what options there might be.

    Another exception is when user logs in (so gets redirected back to The Page) but is not a member of the membership that's protecting The Page. There's only a message with no option to sign up for membership. I thin that'd be issue number two (#2) that you're dealing with, am I correct?

    I actually wasn't aware of this (haven't gotten past #1 to find out). But yes, this would be something I'd want to handle differently....What message is shown here? Is it one I can customize, and thereby include a shortcode to login/register?

    I will appreciate any advice or suggestions on how I can make this work. :slight_smile:

  • kalico

    After a bit more testing, I have a suggestion for how to give the admin a bit more control over the registration workflow when a user has to log in AND join the membership to see The Page (problem #2 above).

    I propose creating two new options (options, because "my way" might not be best for everyone):

    A) Option to show the "custom" protected content message for a specific membership ONLY to logged in users. So a guest user would see the standard protection message, and a logged in user would see the custom message.

    This would give us the opportunity to customize a special message for the user to see AFTER logging in, when he comes back and hits that same page, but it's still protected.

    As it stands now, the custom protection message overrides the default message at all times, regardless of the user's state. So we only have one chance to give the user a message, and it doesn't always make sense in the context of the user's state.

    B) Option to turn OFF the login form on the protected content page. Since the protection message is not parsing shortcodes, we can't display the signup button or a login form that we can customize. But being able to turn off the login/reg form would allow the admin to customize the protected content message with e.g., a link to the membership signup page -- without the confusion of a login/register form taking the user on a different path.

    This still doesn't get the user back to the right page after registration (problem #1 above), but at least it solves #2 and provides a lot more customization capabilities.

    The only solution I can see to #1 is to have an Ajax registration form that is filled out in a modal on top of The Page, and The Page autorefreshes to reflect the user's state. I thought I had come up with a hackish way to do this with Popup Pro, but I had to disable it because of a conflict. I will have to revisit that and see if it has any merit.

  • Adam Czajczyk

    Hello Kalico!

    I'm glad we sorted that out a bit and I really appreciate your kind words, thank you!

    As for issue #1.

    Currently, it seems that it's not possible "out of the box" to change that workflow. I have asked one of the developers involved with Membership 2 Pro for a little help here and I'm waiting for response. Your suggestion on this (Ajax form etc) does seem like a great solution but I'm afraid it wouldn't be that easy to implement in a form of "fix" or "patch" as it would most likely require quite significant changes in plugin's code. Still, that's a great idea.

    That said, I'm hoping that maybe the developer I mentioned will come up with a simpler solution here. I'll let you know.

    As for issue #2.

    You can define custom protection messages on "membership level" (Membership 2 -> Memberships -> "Edit" [for selected membership] -> Protection Messages), however that's just a text that you may display for a "shortcode protected" content and it cannot include other shortcodes.

    I'm thinking of another solution though. The main "Protected content" page is basically only the output of the "[ms-protection-message]" shortcode. For not logged in users it displays "Protected content" message along with a form and for logged in users it shows only protection message.

    You can however add other shortcodes to this page (edit the page content with WP editor to add shortcodes). For example:

    - let's assume that two members visit ThePage
    - ThePage is available only to "Pro" membership members and not to "Default" members
    - therefore the "Pro" member will see the content and the "Default" member will only see message
    - assuming that ID of "Pro" membership is "1" and "Default" s "2" you could add this shortcodes below [ms-protection-message]:

    [ms-protect-content id="2"]
    To be able to access this content, please sign up for this membership:
    [ms-membership-title id="1"]
    [ms-membership-details id="1"]
    [ms-membership-buy id="1" label="Buy now"]
    [/ms-protect-content]

    What now happens is:

    - if the "Pro" (id "1") membershp member visits the site, he/she is able to access content
    - if the "Default" (id "2") membership member visits the site, he/she is presented with protection message along whit something similar to this:

    To be able to access this content, please sign up for this membership:

    "Pro"
    This is out premium membership (<em>that's memberships description</em>)
    Buy now

    where "Buy now" is a direct link to membership signup/purchase.

    Also, the initial shortcode ([ms-protect-content id="X"]) can cover multiple memberships at once so you can use more than single id (separated by commas) to show "Buy now" link to all members of memberships that do not have access to that content.

    I think that'd (at least partially) solve the issue #2 :slight_smile:

    Best regards,
    Adam

  • kalico

    Ah, yes...I was thinking of something along that line for #2! Thanks for putting it together for me...I figured it would look something like that, just hadn't gotten the details figured out. I'll definitely start playing with that idea.

    RE: #1, I figured the ajax idea would not be simple thing. I still plan to revisit my Popup Pro concept, especially now that the earlier redirect bug has been fixed. If it works out, I will share it here. But I also have another idea.....which really involves a question.

    I would like to know how the workflow you described works with --or changes with -- the login widget. I haven't tested it yet, mainly because I don't like how it requires being in the sidebar, and the standard sidebar layout is not what we want for this project. But I've considered trying to make the rest of the page content wrap around the sidebar (below the login), or otherwise style the sidebar so it becomes smaller or less obtrusive after a person is logged in, so we don't have a big white space on the side. Or possibly to widgetize another area of the page....there are plugins that widgetize an entire page or create alternate widget layouts....I haven't gone down that rabbit hole yet, it's just a vague idea that maybe it would be worth the trouble if the workflow of the login widget was better suited to keeping the user on the page.

    If you can tell me about how it works, maybe we can come up with something there.

  • Adam Czajczyk

    Hello kalico!

    I'm glad I could help with issue #2!

    As for issue #1.

    I just got a word from one of the developers and it seems that's a "tough one". It'd be indeed quite complex, given the current Membership 2 Pro code, to introduce either ajax-based registration or at least a "back to entry page redirect". As much as I'd love to give you other answer, I'm afraid I can only suggest here post a feature request on our "Features & Feedback" forum. If more members will support the idea, there's a chance (please note though: no guarantee) that our developers will include it in one of future releases.

    Other than that, it would require some heavy custom coding which'd be beyond the scope of this support forum so you may want to ask on our "Jobs & Pros" job board (no WPMU DEV staff involved!) here:

    https://premium.wpmudev.org/wordpress-development/

    As for widget login. I've just checked this on my test site and this is how it goes when not logged in user visits The Page:

    - user is redirected to protected content page
    - user logs in via widget form
    - user is redirected back to The Page
    - if user is a member of protecting membership, the content is visible the user
    - if user is not a member of protecting membership, there's a protection message

    So basically, the workflow here seems to be pretty much the same. I remember that I mentioned before that in case of widget the workflow is different but it seems that's been corrected recently.
    The exception however would be if a "Redirect" add-on of Membership 2 is enabled as it should take priority then.

    Best regards,
    Adam

  • kalico

    Hi Adam,

    Thanks so much for all your assistance on this. I have a much better understanding and a reasonable path forward, in spite of the hiccup of issue #1.

    I still think I may have a workaround using Popup Pro with a CSS selector (on click), if I can get past the bug or conflict I'm currently dealing with. It was working in my first round of testing, then something went wonky and I had to disable it.

    Once again, thank you so much for your help. :slight_smile:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.