Redirect if user does not have the correct ccap
Tagged: ccaps, membership option
- This topic has 8 replies, 2 voices, and was last updated 9 years ago by Cristián Lávaque.
-
AuthorPosts
-
2015-11-11 at 08:18 #371Carole AsselinParticipant
As far as i know (and i might be wrong too), if a page is restricted by a ccap, if the user does not have that ccap, he gets redirected to the Membership option page, by default.
Is there a way to redirect to a specific page where the user could purchase the access to this particular page (or set of pages)?
Here is the scenario:
I have Course A that includes dripping content where many pages are restricted.
I also have a nice, elaborate sale page for that Course.Right now, if someone tries to access one of the restricted pages, he gets redirected to the Membership option page, where i have also other courses listed, so the user will not see the sale page that relates to the particular page/course he wanted to access since he will also see info on Course B and Course C, etc.
Is there a way to currently redirect unauthorized visitors to a specific page instead of the default Membership option page?
If it is not possible, maybe a suggestion to add a link to that specific page under the “Require Custom Capabilities?” in the s2Member box?If it is not possible yet, maybe i can add that suggestion in the Github forum?
2015-11-11 at 14:03 #375Cristián LávaqueKeymasterWell, you could customize the behavior in different ways…
You can change the Membership Options Page’s content with conditionals, using the MOP Vars. WP Admin -> s2Member -> Scripting -> Membership Options Page Variables
Or, you could try a must-use plugin that checks if the required access is the ccap you’re talking about, and redirect the person to another page instead. Or do the redirection in the page with a conditional and a JavaScript redirection.
Maybe somthing like this: In /wp-content/mu-plugins/s2mop-redir.php
<?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_value) && $seeking_value == 'yourccaphere' ) { header('Location: http://www.yoursite.com/yourccapsalespage'); exit; }
Not tested, but I hope it helps. 🙂
2015-11-11 at 14:12 #377Carole AsselinParticipantThat might work. I`ll try and report back.
But if it is not a native function of s2M, i think it would be a great feature to add, directly in the dashboard. Don’t you think?
2015-11-11 at 14:53 #378Carole AsselinParticipantI am not good enough in php syntax but as it, it is not working. Shouldn’t there be a closing tag or something at the end?
2015-11-11 at 16:40 #380Cristián LávaqueKeymasterNo, the PHP closing tag is not required there.
Hmm… What is the ccap you’re using for that? Can I have a link to a page protected with it to see what the MOP vars are when redirected?
Thanks!
2015-11-11 at 17:58 #381Carole AsselinParticipantHere is the code i am using
<?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_value) && $seeking_value == 'element' ) { header('Location: http://scrapbookcampus.com/creative-scrap/creative-scrap-register/'); exit; }
Here is one page that you need the ‘element’ ccap to access:
http://scrapbookcampus.com/element-creation-index/folded-edge/and the sale page is obviously this one:
http://scrapbookcampus.com/creative-scrap/creative-scrap-register/2015-11-12 at 22:31 #386Cristián LávaqueKeymasterThanks!
Okay, I wrote a new simpler one, and tested it to confirm it works.
http://s2member.net/?_s2member_vars=ccap..ccap..element..page..4286
<?php if (!empty($_REQUEST['_s2member_vars']) && strpos($_REQUEST['_s2member_vars'], 'ccap..ccap..element') !== false) { header('Location: http://scrapbookcampus.com/creative-scrap/creative-scrap-register/'); exit; }
🙂
2015-11-13 at 04:53 #387Carole AsselinParticipantGreat! It works exactly as i was hoping. Now, if it can be integrated as a native feature, everyone will be able to use it easily. 🙂
2015-11-13 at 20:01 #395Cristián LávaqueKeymasterGreat! 😀
-
AuthorPosts
- You must be logged in to reply to this topic.