latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

MOP Vars shortcodes. Y/N?

Home Forums Community Forum MOP Vars shortcodes. Y/N?

This topic contains 4 replies, has 1 voice. Last updated by  Glyn Davidson 3 years ago.

Topic Author Topic
Posted: Tuesday Dec 31st, 2013 at 4:30 am #62288

According to this topic (Apr 27th, 2012), MOP Vars aren’t accessible with shortcodes. Is this still the case?

List Of Topic Replies

Viewing 4 replies - 1 through 4 (of 4 total)
Author Replies
Author Replies
Posted: Tuesday Dec 31st, 2013 at 5:18 am #62291

Made my own:

function mop_var_shortcode($atts) {
	$_g = stripslashes_deep ($_GET);
	if (isset ($_g["_s2member_seeking"]["ruri"])){
		$seeking_uri = esc_html (base64_decode ($_g["_s2member_seeking"]["ruri"]));
		if (strpos($seeking_uri, $atts['page']) >0) 
  			 echo 'You were trying to access the ' . $atts['page'] . ' page!';    
	}		
}
add_shortcode('s2Show_mop_var_uri', 'mop_var_shortcode');
[s2Show_mop_var_uri page="page_name" /]
Posted: Tuesday Dec 31st, 2013 at 5:51 am #62293

Here’s what I wanted to achieve:

I have buddypress installed and URI restricted to level 1 users. However, I want level 0 users to be able to access a similar, non buddypress page.

When a level 0 tries to access the buddypress page, they get redirected to the membership options page.

What I was hoping to do was query the URI and if they had tried to access the buddypress page, then redirect them from the MOP to the non buddypress equivalent.

This works by putting this shortcode in the MOP.

[s2Redirect if_page_is="a_buddypress_page" redirect_to="the_none_buddypress_page" /]
function mop_uri_redirect_shortcode($atts) {
    $_g = stripslashes_deep ($_GET);
	if (isset ($_g["_s2member_seeking"]["ruri"])){
		$seeking_uri = esc_html (base64_decode ($_g["_s2member_seeking"]["ruri"]));
		if (strpos($seeking_uri, $atts['if_page_is']) >0) 
			echo '<script type="text/javascript">window.location = "' . $atts['redirect_to'] . '"</script>';
	}		
}
add_shortcode('s2Redirect', 'mop_uri_redirect_shortcode');

This works but it’s a really dirty hack because it means the Membership Options Page has to load before it redirects.

Posted: Tuesday Dec 31st, 2013 at 6:44 am #62295

Here’s my final (and much better) solution:

The shortcode:

[s2If was_previous_page(page_name_goes_here) ]
	Provide some useful information here
[/s2If]

To get this to work requires some hacks to s2Member php files:

I added this to /plugins/s2Member/includes/functions/api-functions.inc.php
Right after “exit(“Do not access this file directly.”);” on line 18:

if(realpath(__FILE__) === realpath($_SERVER["SCRIPT_FILENAME"]))
	exit("Do not access this file directly.");

/** Glyn's hack to test against the denied page uri. Only works on the membership options page */
if(!function_exists("was_previous_page"))
	{
		function was_previous_page($page = FALSE)
			{
				$_g = stripslashes_deep ($_GET);
				if (isset ($_g["_s2member_seeking"]["ruri"])){
					$seeking_uri = esc_html (base64_decode ($_g["_s2member_seeking"]["ruri"]));
					if (strpos($seeking_uri, $page) >0) return true;
				}		
				return false;
			}
	}

And modified line 63 in /plugins/s2Member/includes/classes/sc-if-conds-in.inc.php:

$blog_farm_safe = apply_filters ("ws_plugin__s2member_sc_if_conditionals_blog_farm_safe", array ("was_previous_page", "is_user_logged_in", ...rest of the line needs to go here
Posted: Tuesday Dec 31st, 2013 at 7:10 am #62296

And a working example:

[s2If current_user_is(s2member_level0)]
    [_s2If was_previous_page(page_for_paying_members_only) ]
        <p class="notice">
            I'm sorry but that page is restricted to paying members only. As a free subscriber, you can use <a href="#">this page</a> instead.
        </p>
    [/_s2If]
    [_s2If !was_previous_page(page_for_paying_members_only) ]
        <p class="notice">
            You must be a paying member to view that page.
        </p>
        <ul>
            <li><a href="#">Upgrade to level 1</a></li>
            <li><a href="#">Membership Benefits</a></li>
            <li><a href="#">How to Join</a></li>
        </ul>
    [/_s2If]
[/s2If]
Viewing 4 replies - 1 through 4 (of 4 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.