• Resolved jeffreygaudette

    (@jeffreygaudette)


    I have looked through API->Scripting but can’t seem to figure out how to tell a user what membership level they need in order to access a particular piece of content.

    For example, user is Level 1. They click an article that only Level 2 users can access I want to be able to tell the user: “sorry, you need Level 2 access”

    But, let’s say the article they wanted to download was Level 3 required. How do I get it to then say “sorry, you need level 3 access”.

    This way, the user knows which level they need to upgrade to to gain access.

    Thanks!

    https://wordpress.org/plugins/s2member/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Well, the restrictions redirect to the Membership Options Page, and a few variables are added to the querystring of the URL. WP Admin -> s2Member -> Membership Options Page Variables

    You can use those to customize the message.

    I hope that helps. 🙂

    Thread Starter jeffreygaudette

    (@jeffreygaudette)

    Hmm. Can you show me where Membership options is? It’s not in my menu: http://screencast.com/t/PL6JpnWl

    Thread Starter jeffreygaudette

    (@jeffreygaudette)

    Ok, I found it. It’s under API scripting for those that also need help.

    BUT

    How do I accomplish what I am trying to do here. How do I use the shortcode to target specifically just users needing access to level 2 or just those that need access to level 3.

    Here’s what I am using and it displays both messages

    ‘[s2If current_user_is(s2member_level1)]

    [s2MOP required_type=”level_2″]I’m sorry, but you need to be a Level 2 member to access this article. You can upgrade your membership easily by clicking here. If you want access to all the material, consider purchasing a Level 3 membership here.[/s2MOP]

    [s2MOP required_type=”level_3″]I’m sorry, but you need to be a Level 3 member to access this article. You can upgrade your membership to level 3 by clicking here.[/s2MOP]

    [/s2If]’

    As you can see, I don’t want to display the exact same message. I want to make it clear to the user which Level they need to upgrade to and their other options specific to their current membership level.

    I’ve tried:

    [s2MOP required_type=”level_3″]
    [s2MOP required_type_3=”level”]
    [s2MOP required_type_3=”level_3″]
    [s2MOP required_type=”level3″]

    Thanks!

    > Hmm. Can you show me where Membership options is? It’s not in my menu:

    I’m terribly sorry, I missing writing Scripting in that path I gave you… :/

    WP Admin -> s2Member -> Scripting -> Membership Options Page Variables

    > I’ve tried:

    None of those values are valid for the required_type attribute. See: http://www.s2member.com/kb/s2mop-shortcode/

    > How do I use the shortcode to target specifically just users needing access to level 2 or just those that need access to level 3.

    I’ll see how we can improve s2MOP to make that possible, but for now you’d use a conditional there, with the MOPage vars. Something like this (haven’t tested it, and you’ll require a PHP execution plugin):

    <?php
    if (!empty($_REQUEST['_s2member_vars']))
    	@list($restriction_type, $requirement_type, $requirement_value, $seeking_type, $seeking_value, $seeking_uri)
    		= explode('..', esc_html(stripslashes((string)$_REQUEST['_s2member_vars'])));
    
    if (current_user_is('s2member_level1') && !empty($requirement_type) && $requirement_type == 'level')
    	if ($requirement_value == '2')
    		{ ?>I'm sorry, but you need to be a Level 2 member to access this article. You can upgrade your membership easily by clicking here. If you want access to all the material, consider purchasing a Level 3 membership here.<?php }
    	elseif ($requirement_value == '3')
    		{ ?>I'm sorry, but you need to be a Level 3 member to access this article. You can upgrade your membership to level 3 by clicking here.<?php }
    ?>

    I hope that helps. 🙂

    Thread Starter jeffreygaudette

    (@jeffreygaudette)

    Awesome, that worked like a charm. Thank you VERY much!

    Excellent! Glad I could help. 🙂

    Hello Cristian & Jeffrey,

    I’m looking for pretty much the same thing you have provided here.

    But since I’m not a programmer, what else do I need in order to make this code work, that Cristian provided?

    I have the PHP execution plugin installed & activated & I copied and pasted the above code as-is to the top of the Member Options page.

    When I tried to access a level 2 protected page while logged-out, I was re-directed to the Member Options page but nothing from the new code was showing.

    What else do I need to make the proper text show based on the access level required for the ‘clicked on’ protected content AND for the “You can upgrade your membership to level 3 by clicking here” to be functional. In other words, when someone clicks on the phrase ‘clicking here’ they are taken to PayPal to purchase that level?

    Any help you can provide will be greatly appreciated.

    Thank you.

    – Steve

    The code Cristian provided is for upgrades, so it will only work if someone is logged in.

    In fact, that specific code will only work if the current user is logged in as a level 1 user.

    Thanks for the reply KTS915

    I’m missing something in the equation because I tried it as a level 1 logged in member and the protected content was for level 3.

    After copying the code above exactly as it is in the box and pasting it at the top of my Member Options page and updating, when I click on the level 3 content as a level 1 member I am taken to the Member Options page but nothing from that code is showing.

    When I copy and paste the following code, I get redirected as before only this time I get the text saying “You were trying to access a protected: post.” which is whats supposed to happen.

    That is why I’m thinking there is something else to the above code that I’m not getting.

    ‘ <?php
    if(!empty($_REQUEST[“_s2member_vars”]))
    @list($restriction_type, $requirement_type, $requirement_type_value, $seeking_type, $seeking_type_value, $seeking_uri)
    = explode(“..”, stripslashes((string)$_REQUEST[“_s2member_vars”]));

    if (!empty($seeking_type) /* One of: page|post|catg|ptag|file|ruri */ )
    echo ‘You were trying to access a protected: ‘ . esc_html($seeking_type) . ‘.’;
    ?>’

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Conditional to display what membership level needed to access content’ is closed to new replies.