If a user is trying to access restricted content, they get forwarded to the page you choose in the options, with some variables in the query string.
Under the API / Scripting -> Membership Options Page Variables, it shows the custom links based on redirection. Documentation is great describing the variables in the links. Here's how I put it to use:
- Code: Select all
<?php
// What level they need to be. I'm not using this for now as I only have one premium level
// $level_required = $_GET['s2member_level_req'];
$url_attempt = $_GET['s2member_seeking']; // What page/post they were trying to access
if($url_attempt){ // If it was a redirect
$url_attempt = str_replace(" ", "", $url_attempt); //Ensure no spaces (shouldn't be issue)
$id_attempt = explode("-", $url_attempt); // Seperate post/page and ID
// This would tell if you if post, page, or other (I'm not using this for now)
// echo 'page/post ', $id_attempt[0];
if(is_numeric(end($id_attempt))){ // if page/post is a number - ID ?>
<p> Sorry "<?php echo get_the_title(end($id_attempt)); ?>" is for members only. Check out our awesome deals below to get access to the templates, along with tools, plugins, and other goodies!</p>
<br />
<?php
// Of course you might want to be more specific depending on what they were trying to access
}
} ?>
Hope it's of some assistance to someone.
Cheers!
PS Loving the amazing extensibility of the plugin and how incredibly thorough it is. Very well done!