Posted: September 18, 2013 at 6:32 am
|
I’m using this snippet (https://gist.github.com/Apina/5576163) so that when a user registers for an event, he is also registered as a wordpress user (subscriber role). But I would like to modify it so that, if an user registers for event A is recorded as a subscriber, but if an user registers for event B is recorded as contributor. I have tried to edit the snippet with an if statement where I put the id of the events A and B, but there are no successful Could you give me some advice to change the snippet? Regards |
Personally I would add a parameter to the function which you can set when calling. Say for example $contributor_role. Set it to false by default. Then the role is set from line 23 on, if($contributor_role = true) { $user->set_role( 'contributor' ); } else { $user->set_role( 'subscriber' ); } Then when calling the function, check the event ID if it matches Event B’s ID, call the function with $contributor_role = true set, else call the function normally. *This is fully untested/unsupported, just a nudge in the direction I would look into |
|
|
Hi Tony, Thanks in advance |
|
Well, you will know the Event B id already I assume. The function that you are using has an array called $attendee_data. Look at that. The event id is in there $attendee_data[‘event_id’]; So you can use that to compare it to Event B. |
In the screen shot provided, the function will no longer work as it sets the user’s role before actually creating the user. On the original gist, the code needs to go after $user = new WP_User( $user_id ); Also I can’t see if you have added a default attribute to the function. Having said that, Deans suggestion make this easier for you. Using the original Gist replace lines 23, 24, 25 with: // Set the role $user = new WP_User( $user_id ); if($attendee_data['event_id'] == *EVENTIDHERE*) { $user->set_role( 'contributor' ); } else { $user->set_role( 'subscriber' ); } Change the *EVENTIDHERE* to Event B’s event_id such as: if($attendee_data['event_id'] == 2) That should do what you need. Here is a the full function with the event_id amendment. |
|
|
Woooow!!! Thank you very much Dean! Thank you very much Tony! IT WORKS!!! |
The support post ‘Wp User Snippet’ 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.