Home › Forums › Community Forum › Registration questions
This topic contains 17 replies, has 3 voices. Last updated by Raam Dev 4 years, 8 months ago.
Topic Author | Topic |
---|---|
Posted: Saturday Apr 7th, 2012 at 12:34 pm #10279 | |
|
|
Just to set my capabilities first, I’m pretty comfortable with WordPress functionality, html, and css; I have some programming background, so I can look through php and often alter existing code to do what I want, but I don’t know it well enough to write my own from scratch, so any answer to my question that involves adding some php code will hopefully be pretty thorough in its explanation of how to use it! Here’s my issue: I have a site which will have two levels of restricted content available to qualified users. Both of these will be free. The most basic level will be existing customers of the product, and we’re just going to use the standard level 0 designation for them. The “higher” level wil be for Certified Trainers… in order to qualify for this level, I have the registration form with a Yes/No radio button for “Certified Trainer?”, and a field for them to enter their Certification number. I’d like to be able to code the registration so that it checks a list of valid Certification numbers, and assuming it finds a match, automatically designates that user as a Level 1 member. Is that possible? Any hints on how best to accomplish it? Thanks! |
List Of Topic Replies
Author | Replies |
---|---|
Author | Replies |
Posted: Sunday Apr 8th, 2012 at 4:47 am #10311 | |
|
|
Hi John. Yes, you could create a customization like that. You can use the hooks available after registration, or you could use the registration notification to load a script that’ll check that profile field and adjust the role accordingly. You may find these helpful: [hilite path]Dashboard -› s2Member® -› API / Notifications -› Registration Notifications[/hilite] |
|
Posted: Sunday Apr 8th, 2012 at 2:44 pm #10323 | |
|
|
Hi, thanks for responding so quickly. I’m still unsure of how to proceed, even on a basic level. I had already seen the doc page for S2Get custom fields, and I’ve been able to use that to, for instance, show on the Welcome page the name of the currently logged in member, the “true” or “false” for their answer to the “certified trainer?” radio button, and their Certification Number after they log in. However, I don’t know the syntax to set up the conditional for which the “translation” would be something like “if currently-logged-in-user is a certified trainer then show this content”. Or, even less, “if the registrant’s entry in the certification number field is 560369, check this list to see if that’s a valid number, and if it is, set their member level to 1”. The links you sent me have lots of information which I suspect would be highly useful if I had a more basic understanding of how to apply it, but I really need some initial help at a more basic level before I can make sense of it. Thanks in advance! |
|
Posted: Sunday Apr 8th, 2012 at 4:48 pm #10331 | |
|
|
Here’s an example: [hilite pre_code]set_role('s2member_level1'); } ?> [/hilite] You’ll need to customize it some, but it should give you an idea. |
|
Posted: Sunday Apr 8th, 2012 at 5:46 pm #10333 | |
|
|
Excellent, thanks, I’m getting the idea. I appreciate your patience with a beginner! Here’s how I read the code: The first line sets up an array for valid certification numbers, with possible values of 1, 2, 3, or 4. All of which is basically what I need, except I’m not sure where to put the code… does it go in one of the php pages available in the Appearance -> Editor section, or elsewhere? Thanks again! |
|
Posted: Sunday Apr 8th, 2012 at 10:07 pm #10345 | |
|
|
You can put it in the Login Welcome page, the HTML tab. Use a PHP execution plugin so PHP works in the page, e.g. http://wordpress.org/extend/plugins/php-execution-plugin/ You can use the Offers on Login feature to add a variable to the first login [hilite path]Dashboard -› s2Member® -› General Options -› One-Time Offers (Upon Login)[/hilite], like
Then add that to the conditional, like [hilite code]isset($_GET['first'])[/hilite]. [hilite pre_code]set_role('s2member_level1'); } ?> [/hilite] If that’s getting too advanced for you, I recommend you get help from a freelancer from a site like eLance.com, oDesk.com o jobs.wordpress.net. I hope that helps. |
|
Posted: Tuesday Apr 10th, 2012 at 2:18 pm #10484 | |
|
|
Hi, Thanks again… it’s not getting too complicated for me, but it’s not working. I used your exact code, and everything is executing without errors, but it doesn’t seem to be successfully setting the variable “first”. I made a new Login Welcome page, so that I can tell that the One-Time Offer is working (i.e., it sends the user to the new page only on first login, after that it sends them to the old page). The url is showing up correctly when it does that, with the variable “first” in the browser url field. However, it’s not changing the user’s level to 1. To test that the variable was being set correctly, I added this code to the page:
which invariably returns “Variable is NOT set”. I also have:
Which returns “Epic fail”, but also does show the cert_number variable correctly (I’ve tried all the numbers in the array, 1, 2, 3, and 4 at different times), which shows that the conditionals would be met in the if statement, if isset was finding the variable ‘first’. Does that make sense? Any suggestions? Thanks! |
|
Posted: Tuesday Apr 10th, 2012 at 3:23 pm #10500 | |
|
|
You have more than one condition in that if [hilite pre_code]if (isset($_GET['first']) && !empty($cfields['cert_number']) && in_array($cfields['cert_number'], $valid_certs)) { echo "First"; [/hilite] They all have to be true for the echo to happen. |
|
Posted: Tuesday Apr 10th, 2012 at 4:37 pm #10517 | |
|
|
But the last two conditions are demonstrably true: the cert_number field is not empty, and cert_number is one of the numbers in the array. That means the only one that’s apparently not true is the first condition, so the ‘first’ variable is not set, right? |
|
Posted: Tuesday Apr 10th, 2012 at 4:44 pm #10518 | |
|
|
Wait, back to the drawing board… I removed the second two conditions, and now “First” is echoed. That means the issue is somewhere else. I’ll beat it up for awhile longer and hopefully solve it, if not I’ll be back for another round… Thanks for your help! |
|
Posted: Tuesday Apr 10th, 2012 at 9:20 pm #10531 | |
|
|
Hmmm… interesting. I have it working now, and what I had to do was change
to
I’m not really sure why that works better, it seems that the original example is the right syntax. But who am I to argue? |
|
Posted: Wednesday Apr 11th, 2012 at 1:05 pm #10566 | |
![]() |
|
Thank you for the update, John! |
|
Posted: Wednesday Apr 11th, 2012 at 1:22 pm #10573 | |
|
|
You’re welcome! As it turns out, the code worked better if I used ‘get_user_field (“cert_number”)’ instead of get_s2member_custom_fields and then looked for the “cert_number” field. I do have one slight glitch, however, which is that the code establishes the role correctly, but not on first load of the page. I tested this with this code:
When the page first loads, the text “I’m sorry, this area of the site is for NAPPI Certified Trainers only. Thanks!” is what appears, even if the user does have a Certification number; however, if I reload the page, the correct text, “Hello Trainer… etc.” shows up instead, leading me to believe that the role-setting code doesn’t execute immediately, before the code below it is read. It’s not the end of the world if that’s not possible; since the user level IS properly set, I can just work around the issue. But it would be more elegant to force the role-setting code to execute immediately; is that possible? Thanks! |
|
Posted: Wednesday Apr 11th, 2012 at 4:12 pm #10604 | |
![]() |
|
I believe that is happening because a WordPress user object has already loaded with the page. When you run new WP_User(), you’re creating a second user object and making the changes to that. The user object that s2Member uses in your s2If checks isn’t refreshed until you reload the page. I recommend looking into how you can reference the existing objects and make your changes through them instead of instantiating a new one. I’m not entirely sure how to do this, but the WordPress.org Support Forums should have the answer. |
|
Posted: Tuesday Apr 24th, 2012 at 2:47 pm #11725 | |
|
|
First let me say I’m really appreciative of S2member’s tech support! And… I have another follow-up on this issue: This is the code I’m now using, which replaces the array with a routine for reading the Certification Numbers from an external text file:
You’ll note I also replaced
with
and that changes the user’s role immediately upon loading the page, instead of only after reloading. This all works great! Except for one thing: it no longer sends a notification by email when a new member registers. Any idea why this is happening, or what I can do about it? Thanks! |
|
Posted: Tuesday Apr 24th, 2012 at 4:04 pm #11749 | |
![]() |
|
Thank you again for the update, John! :) When you say “it no longer sends a notification by email when a new member registers”, are you referring to the email that gets sent to the user upon new WordPress user registration or something else? Your code above looks like it interacts with an existing user and simply updates their role. You might want to install the Email Log plugin mentioned in this article to see if the WordPress is sending the email, but it’s not being received: Knowledge Base » Troubleshooting Email Delivery Problems
Awarded user ‘John Prusinski’ the Advanced badge.
|
|
Posted: Tuesday Apr 24th, 2012 at 4:38 pm #11756 | |
|
|
Ah, thanks for that… I checked, and the admin notification was not being sent. Then I remembered that I recently changed my s2hacks.php… I took that out, and it works fine now. |
|
Posted: Wednesday Apr 25th, 2012 at 1:34 pm #11851 | |
![]() |
|
Excellent! Thank you for the update. |
This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.