Posted: July 30, 2018 at 6:10 am
|
Hello, I read one of the support forum questions and I wanted to limit the member users to buy the member-only ticket. Now – But still I am able to select the member ticket when I log in again which shouldn’t allow. |
Hi there, First the basics. Have you confirmed that the custom functions plugin you say you added the code to has been activated on the site? Go to Dashboard -> Plugins and confirm that the custom function plugin is activated there (not just installed). With the WP User integration add-on active, if you have done this:
Then it means the capability is not being removed from the user account, EE just checks if the If can you confirm and check the account in question, does it still have the above cap? |
|
|
Hello, – Yes the plugin is activated. but how do I check if its executed? Regards |
|
Hello , I checked the user account and still it does have the cap. how do I know that the plugin has been executed? |
How far through the registration did you go? All the way to the end and triggered the emails? Paid or free tickets?
You could add some code to write to a log file within the function, if the log file has whatever you set in that function, the code ran. |
|
|
I completed the registration until the end in both case 4 and 5. received emails and receipt as well. These are paid tickets. What code that be? I used the exact code snippet for removing the capability you mentioned in https://gist.github.com/joshfeck/51c2ef122616b48cc4846b1f44384859 thx |
Hi Rashmin, What you’re seeing is actually expected because in the above steps, you added the capability to the user role.
Instead of editing the subscriber role, you actually need to edit the individual user account to add the cap. The source of the WP_User::remove_cap() helps show why: So when you add the cap to the role, then WP will remove the cap from the user, then add the cap back because it merges in all caps from the user role. If you have a lot of user accounts that need the custom cap added, the second part of that gist includes a sample plugin you can use to programmatically add the custom cap to the user accounts: |
|
|
Hello, Great. its working now. Thanks for the explanation. 1) But I still have another query, with this remove cap, will work for 1 event.For every new event we organise, I need to add this (has_unique_invitation_code) to the user base again, am I right? Thanks for your help |
It will work better to have a unique cap for each event where you’re restricting the tickets in this manner, and update your custom code accordingly.
I think you’re on the right track, but please remember you’re not dealing with user roles. Rather, it’s user accounts and adding/removing capabilities from those accounts. |
|
Correct.
With the current code, when they register onto eithr event the cap is remove, so you’d need a function to check for both caps. However, what I would do, is use a function to pull the capability from the ticket linked to the registration, check if the user had that cap and remove it. Replace Josh’s first example with this: https://gist.github.com/Pebblo/25cab2c24fe28b0c65285b15f0e25104 Then for every event you want to use a unique capability, you can add the event name, or ID to the cap, for example – So you’d add that cap to your user, add the capability to the specific ticket for that event and the function will remove whatever cap is set on the ticket. So your users may have Make sense? |
|
|
Yes. got it. |
|
Hello , I thought I wouldn’t have to use Tony’s code in the above message as we are having only 1 upcoming event. But for 1 event we have different ticket types wherein depending on the member user, need to display all the member tickets of only 1 ticket type. I deactivated the existing plugin, deleted/removed the old folder & file using the FTP account and reloaded the plugin with same name with the changed code. But the capability is not being removed and I have a feeling that the plugin is not executed. |
Hi Rashmin, The code example needed a few fixes. Here’s an updated example: https://gist.github.com/joshfeck/ad9d682bf56880eeb7d489ed9c16c93f |
|
|
Hello Josh, The code with removing single event capability worked well. But the latest code you gave yesterday still doesn’t remove the capability from the user after registration. Rashmin. |
What are the capabilities you have set on the ticket/user? The above snippet will only look for capabilities that begin with |
|
|
Hello Tony, Yes I have set the capability has_unique_invitation_code followed by event_student or event_family depending on the ticket. Depending on the kind of membership taken, I have added respective capability to the user. Regards |
As mentioned:
The code will only remove a capability from a user if the capability contains the text
What code are you referring to? The code I posted should remove the capability from the user as long as the capability contains the text |
|
|
I guess I wasn’t clear. Thanks |
Ah, ok, I follow now. I’ve just gone through and tested both mine and Josh’s example with the dynamic cap removal and both work (mine had a typo which has now been fixed). I set up 3 tickets similar to yours – http://take.ms/18yeA Then register onto 2 of them individually, when I return to the ticket selector it has removed the caps – http://take.ms/OdTpC If you enable WP_DEBUG using this code in your wp-config.php file: https://eventespresso.com/wiki/troubleshooting-checklist/#wpdebug Do you see any error sin /wp-content/debug.log? |
|
|
Hello Tony, Or can I set it up in a different way to avoid this? Thanks |
I’ve added another example to my gist that pulls in all of the registrations, then loops over them all and pulls the ticket and the cap set for that ticket, then removes them from user. Try this one: https://gist.github.com/Pebblo/25cab2c24fe28b0c65285b15f0e25104#file-example-multiple-caps-php Note additional queries are needed to pull in all of these additional details, nothing major, just something to be aware of. |
|
|
Thanks a lot Tony. Regards |
You’re most welcome 🙂 I’m glad that worked for you. If have a minute we would really appricate if you could share your experience with Event Espresso or provide a review on WP.org. |
|
The support post ‘limiting the member user to buy discounted tickets (has_unique_invitation_code)’ is closed to new replies.
Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.