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.

Using The Membership Options Page Variables

Home Forums Community Forum Unofficial Extensions/Hacks Using The Membership Options Page Variables

This topic contains 2 replies, has 3 voices. Last updated by  Tim Haines 3 years, 4 months ago.

Topic Author Topic
Posted: Wednesday Nov 7th, 2012 at 11:09 pm #30987
Username: Bruce
Staff Member

A great way to customize your s2Member site is to use the Membership Options Page variables that s2Member passes when a user is redirected from protected content (find info on the variables in your Dashboard under s2Member® -> API / Scripting -> Membership Options Page / Variables). In this tutorial I will be using the WordPress Shortcode API to create a clutter-free Membership Options Page with this feature, though you could easily do the same without a Shortcode within your WordPress Page using a plugin to execute PHP, such as PHP Execution.

Creating the Shortcode

Not using Shortcodes? Skip this part

Creating a Shortcode with WordPress is fairly easily. You can check out the full API here, but for these purpose, we only need a few lines of code. You can start with the example at

function foobar_func( $atts ){
 return "foo and bar";
add_shortcode( 'foobar', 'foobar_func' );

Now we'll edit the code slightly to get a more suitable Shortcode name, and function call:

function s2hack_membership_options_vars( $atts ){
 return; # Nothing for now
add_shortcode( 'membership_options_vars', 's2hack_membership_options_vars' );

Now we have a WordPress Shortcode to test within a page. You can now put [membership_options_vars] within a WordPress Post/Page on your site to test with. Now, lets make the Shortcode do something.

Starting To Code

There is a lot of functionality within the Membership Options variables. You can find full documentation for the variables within your Dashboard under s2Member® -> API / Scripting -> Membership Options Page / Variables. In this example, we will add some text to the top of the Membership Options Page based on the type of content the user was redirected from, and the level required.

To do this, we first need to grab some PHP $_GET[] variables, and see if they exist in the current URL:

Next, we use these variables to decide what to display to the user. In this example, we will display Sorry, that {Content Type} is restricted. You need {s2Member Level/ccap} to access that.:

function s2hack_membership_options_vars( $atts ){
 if(isset($_GET['_s2member_seeking'])) # We need to display something
 	$s2_seeking = $_GET['_s2member_seeking']; # Content user was trying to access
 	$s2_level   = $_GET['_s2member_req'];     # What was needed to access said content]
 		$content = 'page';
 	elseif (!empty($s2_seeking['post']))
 		$content = 'post';
		$req = 'Level' . $s2_level['level'];
		$req = 'Our Membership';
	return &#039;<strong>Sorry, that ' . $content . 'is restricted. You need ' . $req . 'to access that.</strong>';
 	return; # We don't need to do anything, no variables passed.
add_shortcode( 'membership_options_vars', 's2hack_membership_options_vars' );

And that's it! You now have a cool new feature on your Membership Options Page, that you can customize easily. :) Use with [membership_options_vars]

If you have any issues, you can leave a comment below.

List Of Topic Replies

Viewing 2 replies - 1 through 2 (of 2 total)
Author Replies
Author Replies
Posted: Monday Jul 1st, 2013 at 3:35 am #52833

Okay, so even if that made any sense to me, whatsoever, I would still have no idea where I am supposed to put that code. Even if I knew where to put the code, then what? I just put [membership_options_vars] on my page? Somehow, I do not think so.

What do I post where? Exact language please. I am not stupid, but I do not know php.

Posted: Saturday Aug 17th, 2013 at 11:03 pm #56082
Tim Haines
Username: vericast

This doesn’t make sense to me either. Isn’t the coding YOUR job? Half joking…half venting. If we could code, we wouldn’t be buying your software. So how do we create (not “code” or “build”!) the Membership Options page? I’m really surprised you don’t have a simple toolbar for this in the page composition pane. I mean seriously

Viewing 2 replies - 1 through 2 (of 2 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.