Events Made Easy › Forums › Bug fixed or feature request implemented › #_IS_USER_HAS_ROLE{xxx}
- This topic has 11 replies, 2 voices, and was last updated 4 years, 7 months ago by Anonymous.
-
AuthorPosts
-
Wed 27 May 2020 at 13:28 #61253AnonymousInactive
Hi Franky,
I’m trying to use #_IS_USER_HAS_ROLE{xxx} in the booking form to restrict events to people with specific roles but it doesn’t seem to be working.
Below is the code I’m using – in my mind it should check that the person logged in is a subscriber, which they are, and show the booking form but the booking form doesn’t show. It also doesn’t show ‘You are unable to book a place on this event’ when I try looking at it as a different role (Administrator).
[eme_if tag='#_IS_USER_HAS_ROLE{subscriber}' value='1'] <table class='eme-rsvp-form'> <tr><th scope='row'>First Name*:</th><td>#REQ_FIRSTNAME</td></tr>#_SEATS <tr><th scope='row'>Last Name*:</th><td>#_LASTNAME</td></tr> <tr><th scope='row'>E-Mail*:</th><td>#_EMAIL</td></tr> </table> #_SUBMIT [/eme_if] [eme_if tag='#_IS_USER_HAS_ROLE{subscriber}' value='0'] You are unable to book a place on this event. [/eme_if]
I’d like to be able to effectively lock events for specific user roles, I assume once I get this working I’ll be able to add more than one role in {xxx}?
Not sure where I’ve gone wrong.
Hope you can help.
Thanks,
David.Wed 27 May 2020 at 16:12 #61255FrankyKeymasterHi,
first: it is not #_IS_USER_HAS_ROLE{xx}, that’s a typo in the doc. It is just #_USER_HAS_ROLE{xx}. I corrected that.
Second: the next version will support multiple caps/roles in the {xx} (separated by ‘,’).Wed 27 May 2020 at 16:22 #61256AnonymousInactiveThanks Franky, that makes sense.
I’m still having a problem though, with the code:
[eme_if tag='#_USER_HAS_ROLE{subscriber}' value='1'] <table class='eme-rsvp-form'> <tr><th scope='row'>First Name*:</th><td>#REQ_FIRSTNAME</td></tr>#_SEATS <tr><th scope='row'>Last Name*:</th><td>#_LASTNAME</td></tr> <tr><th scope='row'>E-Mail*:</th><td>#_EMAIL</td></tr> </table> #_SUBMIT [/eme_if] [eme_if tag='#_USER_HAS_ROLE{subscriber}' value='0'] You are unable to book a place on this event. [/eme_if]
When logged in as Administrator or Subscriber is still shows ‘You are unable to book a place on this event.’ Am i right in thinking this should show the form if the account logged in is has the WordPress role subscriber?
I’ve tried #_USER_HAS_ROLE{subscriber} and #_USER_HAS_ROLE{Subscriber} but the capital at the start doesn’t seem to make a difference.
Wed 27 May 2020 at 16:25 #61257FrankyKeymasterThat should be correct, I’ll check that too (maybe a code bug, I don’t think many people use this yet π )
Wed 27 May 2020 at 16:39 #61259AnonymousInactiveCool, cheers Franky.
Wed 27 May 2020 at 18:25 #61261FrankyKeymasterOk, it’s a bug π
Fast fix: in eme_events.php there are 2 calls to get_current_user(), and those should be changed to wp_get_current_user() .
I fixed those in the released version too, this is the change:
https://plugins.trac.wordpress.org/changeset/2313269/Thu 28 May 2020 at 10:21 #61263AnonymousInactiveThat change worked a treat Franky.
Looking forward to the next release so I can utilise multiple caps/roles in the {xxx} (separated by β,β). Then I’m going to see if I can get custom fields to work with #_USER_HAS_ROLE, see if I can setup a multi select list of roles, so I can easily pick which roles should be able to book onto an event.
Thanks,
David.Mon 1 Jun 2020 at 12:07 #61274AnonymousInactiveHi Franky,
I’ve updated the plugin and seen that it’s no longer using #_USER_HAS_ROLE but is instead using #_ADDBOOKINGFORM_IF_USER_HAS_ROLE.
I’ve tried changing the # as shown below but am getting 500 Internal Server Error when trying to load the event, not sure what I’ve done wrong.
[eme_if tag='#_ADDBOOKINGFORM_IF_USER_HAS_ROLE{subscriber,administrator}' value='1'] <table class='eme-rsvp-form'> <tr><th scope='row'>First Name*:</th><td>#REQ_FIRSTNAME</td></tr>#_SEATS <tr><th scope='row'>Last Name*:</th><td>#_LASTNAME</td></tr> <tr><th scope='row'>E-Mail*:</th><td>#_EMAIL</td></tr> </table> #_SUBMIT [/eme_if] [eme_if tag='#_ADDBOOKINGFORM_IF_USER_HAS_ROLE{subscriber,administrator}' value='0'] You are unable to book a place on this event. [/eme_if]
If I don’t have the table with First Name, etc… in the if statement I see this:
Ach, some problems here:
Please correct the RSVP form format to use #_EMAIL.
Please correct the RSVP form format to use #_LASTNAME.
Please correct the RSVP form format to use #_SUBMIT.
Press the back-button in your browser to return to the previous screen and correct your errorsHope you can help?
Mon 1 Jun 2020 at 13:23 #61275FrankyKeymasterWhat do you mean with “Iβve updated the plugin and seen that itβs no longer using #_USER_HAS_ROLE but is instead using #_ADDBOOKINGFORM_IF_USER_HAS_ROLE.” ?
Those are 2 different things. One returns a value (0/1) based on the role the user has, the other returns a booking form (not meant to be used in an eme_if condition).Mon 1 Jun 2020 at 15:15 #61276AnonymousInactiveSorry Franky, I may have got mixed up.
I tried the following code after the update but the comma separated values didn’t work as expected, both user accounts with the roles administrator and subscriber showed “You are unable to book a place on this event.”
[eme_if tag='#_USER_HAS_ROLE{administrator,subscriber}' value='1'] <table class='eme-rsvp-form'> <tr><th scope='row'>First Name*:</th><td>#REQ_FIRSTNAME</td></tr>#_SEATS <tr><th scope='row'>Last Name*:</th><td>#_LASTNAME</td></tr> <tr><th scope='row'>E-Mail*:</th><td>#_EMAIL</td></tr> </table> #_SUBMIT [/eme_if] [eme_if tag='#_USER_HAS_ROLE{administrator,subscriber}' value='0'] You are unable to book a place on this event. [/eme_if]
I was expecting the comma separated values functionality you mentioned to work for #_USER_HAS_ROLE but it doesn’t seem to (unless I’m doing something wrong?), so when I looked at the change log it showed:
β’The placeholders #_ADDBOOKINGFORM_IF_USER_HAS_CAP, #_ADDBOOKINGFORM_IF_USER_HAS_ROLE, #_ADDBOOKINGFORM_IF_USER_IN_GROUP and #_ADDBOOKINGFORM_IF_USER_IS_MEMBER_OF now allow multiple arguments (separated by β,β) so you can e.g. show the form to only users that are in one of the mentioned EME groups, with certain rols, or if member of one of the mentioned memberships
I tried to do the same with those place holders and failed miserably! Do you think you’ll introduce comma separated values for #_USER_HAS_ROLE or will I need to try again with #_ADDBOOKINGFORM_IF_USER_HAS_ROLE?
Thanks,
David.Mon 1 Jun 2020 at 17:46 #61277FrankyKeymasterNo, the changelog is correct. I didn’t do it for the conditional tags (just forgot about it …). This fixes it:
https://plugins.trac.wordpress.org/changeset/2315954/Wed 3 Jun 2020 at 10:35 #61290AnonymousInactiveTremendous, the new release works perfectly.
Thanks Franky. -
AuthorPosts
- The forum ‘Bug fixed or feature request implemented’ is closed to new topics and replies.