Programatically choosing Login Welcome and Membership Options pages.
- This topic has 10 replies, 2 voices, and was last updated 8 years ago by Cristián Lávaque.
-
AuthorPosts
-
2015-12-07 at 14:08 #500Scott PParticipant
Cristián, many thanks for creating this excellent resource which I’ve just discovered and all the help that you have provided to the many people with questions about s2members. You have been an invaluable resource over the years to the s2member community and me in particular.
Now to my question to anyone on this forum, I would like to programmatically select different Login Welcome and Membership Options pages based on conditionals and thus bypass the s2member admin UI for this. I have been looking for sample code to accomplish this. I suspect the code must reside as a MU plugin. Any references or suggestions on how to accomplish this?
BTW, I am running the Pro plugin.
Many thanks,
Scott2015-12-07 at 15:52 #503Cristián LávaqueKeymasterThank you Scott! It means a lot to me that you say that. 🙂
programmatically select different Login Welcome and Membership Options pages based on conditionals
I recently helped Cassel with a hack to do just that: http://s2member.net/forum/redirect-if-user-does-not-have-the-correct-ccap-371#post-386
You can customize it to your own restriction requirements and landing pages, and even add several instead of just one.
I’m thinking about writing an add-on plugin to achieve this from the s2Member admin instead of a hack.
I hope that helps!
2015-12-09 at 16:21 #506Scott PParticipantHello Cristián,
Many thanks for your code sample. I see you base it on CCAP which is cool and this has given me ideas for another s2m project.For the current site I have a lot of custom capabilities for the different courses but I’m actually using WPML to convert the English only site to multi-lingual and need to direct members in one language, say French or Spanish, to the login welcome page in their language rather than the English page. Likewise for the members option page there will be only one page for each language. In both cases I would like to direct language-specific users to their respective pages using conditionals such as:
if ( ICL_LANGUAGE_CODE=='en' ) { // direct to English Login Welcome page url } if ( ICL_LANGUAGE_CODE=='fr' ) { // direct to French Login Welcome page url }
Cheers,
Scott2015-12-10 at 23:58 #510Cristián LávaqueKeymasterI see. Well, you could ask the WPML guys what the code to detect the language would be, then do the redirection. You can see the redirection line in my hack for an example. 🙂
2015-12-11 at 12:46 #511Scott PParticipantHello Cristián,
That one is easy. I can just query ICL_LANGUAGE_CODE for the single letter language code. So, for example, if I want to test if the user is in the French site I would just test if (ICL_LANGUAGE_CODE == ‘fr’). My challenge is in understanding how s2member fires the triggers that redirects the user to the members option page and how I can step in and and replace the default url if the user is in, for example, the French context. Ditto for the login welcome page. So my focus is on the s2member side and not WPML. I can see this being generally useful to anyone who needs to redirect based on any conditional that interests them.
Your code example tests for a specific CCAP and then redirects if found. How would I change that to redirect if a specific condition is met? I guess I am trying to better understand the variable _s2member_vars.
if (!empty($_REQUEST['_s2member_vars']) && strpos($_REQUEST['_s2member_vars'], 'ccap..ccap..element') !== false) { header('Location: http://mysite.org/french-member-options-page//?lang=fr'); exit; }
Many thanks,
Scott2015-12-12 at 02:28 #512Cristián LávaqueKeymasterJust having
!empty($_REQUEST['_s2member_vars'])
in the conditional will spot if the user was sent to the Membership Options Page.You don’t need to check for a ccap as I did in that particular case, you can just redirect the visitor to the Membership Options Page for that particular language.
For example (untested):
if (!empty($_REQUEST['_s2member_vars'])) { header('Location: http://mysite.org/'.strtolower(ICL_LANGUAGE_NAME_EN).'-member-options-page/?lang='.ICL_LANGUAGE_CODE); exit; }
I hope that helps. 🙂
2015-12-12 at 10:33 #515Scott PParticipantCristián,
That helps immensely! Many thanks! I will test it.
if ( !empty($_REQUEST['_s2member_vars'] && ( ICL_LANGUAGE_CODE=='fr' ) ) ) { header('Location: http://mysite.org/'.strtolower(ICL_LANGUAGE_NAME_EN).'-member-options-page/?lang='.ICL_LANGUAGE_CODE); exit; }
In my OP I also was interested in the Login Welcome page redirection. What signals that?
Cheers,
Scott2015-12-12 at 10:48 #516Scott PParticipantCristián,
This goes into the MU plugin, of course but do I need to place it in a function and add it as an action to anything?
Cheers,
Scott2015-12-12 at 22:23 #517Cristián LávaqueKeymasterNo, no hook needed. Just open the PHP block as the very first thing in the file, add that code, and that’s it. Save the file with a PHP extension and upload it to /wp-content/mu-plugins/.
2015-12-15 at 17:12 #523Scott PParticipantThanks, Cristián. That solves the membership options side of my question. When a member logs in they are taken to the English login welcome page. How does one override that based on conditionals?
Cheers,
Scott2015-12-17 at 00:28 #525Cristián LávaqueKeymasterCheck the $_SERVER array to see if the page requested is the Login Welcome one (look for its slug in the ‘REQUEST_URI’). http://php.net/reserved.variables.server
-
AuthorPosts
- You must be logged in to reply to this topic.