Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #61253
    Anonymous
    Inactive

    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.

    #61255
    Franky
    Keymaster

    Hi,

    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 ‘,’).

    #61256
    Anonymous
    Inactive

    Thanks 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.

    #61257
    Franky
    Keymaster

    That should be correct, I’ll check that too (maybe a code bug, I don’t think many people use this yet πŸ™‚ )

    #61259
    Anonymous
    Inactive

    Cool, cheers Franky.

    #61261
    Franky
    Keymaster

    Ok, 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/

    #61263
    Anonymous
    Inactive

    That 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.

    #61274
    Anonymous
    Inactive

    Hi 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 errors

    Hope you can help?

    #61275
    Franky
    Keymaster

    What 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).

    #61276
    Anonymous
    Inactive

    Sorry 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.

    #61277
    Franky
    Keymaster

    No, 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/

    #61290
    Anonymous
    Inactive

    Tremendous, the new release works perfectly.
    Thanks Franky.

Viewing 12 posts - 1 through 12 (of 12 total)
  • The forum ‘Bug fixed or feature request implemented’ is closed to new topics and replies.
Scroll to Top