Support

Home Forums WP User Integration create s2member ccap upon registration (not using autocreate)

create s2member ccap upon registration (not using autocreate)

Posted: December 2, 2017 at 1:09 am

Viewing 9 reply threads


HIL Tennis

December 2, 2017 at 1:09 am

I posted a question about this about a month ago, but I realize that I did not specify that the user must be logged in before registering for an event. I think the solution provided by Tony can be used if the “auto-create” user option is enabled only. So for all my events the user need to be logged in before they can register. Ideally I would like to add different CCAP for different events also, but can manage with just one if that’s easier.


HIL Tennis

December 2, 2017 at 1:58 am

update: can you “map” EE category to CCAP? It would make it more “sensible” for non-tech users. So whenever an event has a category assigned it will create this CCAP for the user registered for an event


HIL Tennis

December 3, 2017 at 2:42 pm

Found this post that describes exactly what I would like to achieve, but it’s from 2012 and there is no “solution” to this thread (not from what I can see). Is there another easier method of doing this or is the Pro API for remote operations a preferred route (modify_user (updates existing Users/Members) and “”s2member_ccaps” =>”


HIL Tennis

December 3, 2017 at 2:48 pm

Found this post that describes exactly what I would like to achieve

sorry here’s the link: https://eventespresso.com/topic/bridging-s2member-and-event-espresso/


Tony

  • Support Staff

December 4, 2017 at 7:01 am

I don’t think you need the Pro API for remote operations for this, you can do it locally on the site.

There is another hook fired in the WP user integration add-on when a user account is updated and not just when created:

do_action( 'AHEE__EED_WP_Users_SPCO__process_wpuser_for_attendee__user_user_updated', $user, $attendee, $registration );

(Only runs for the primary registrant)

So then, as you have the WP_User object you can use the examples here:

https://s2member.com/kb-article/rolescapabilities-via-php/

update: can you “map” EE category to CCAP? It would make it more “sensible” for non-tech users. So whenever an event has a category assigned it will create this CCAP for the user registered for an event

Yes, you can with the above.

You have the registration object in $registration, you can pull the event from that:

$event = $registration->event();

Then pull the terms for that event:

$category = $event->first_event_category();
    
if ( $category instanceof EE_Term ) {
    $category_slug = $category->slug();
}

That obviously only pulls the ‘first’ category set on the event but you can pull them all using $event->get_all_event_categories(); and loop over the returned array to add a ccap for each if needed.

Is that what you are looking for?


HIL Tennis

December 4, 2017 at 2:43 pm

Is that what you are looking for?

Spot on Tony! That’s exactly what I’m looking for!
In the example you are referring to it is mentioned that one can set up a cron job that will run the script at intervals. Is it possible to trigger the script from the registration itself instead? So that the ccap is updated directly after the primary registrant has paid or registered for the event?


Tony

  • Support Staff

December 4, 2017 at 2:52 pm

You don’t need a cron job, hook your code into the action I mentioned above and that code will run each time a logged in user registers.

Have you used hooks (actions/filters) before?

The code examples I’m referring to is how to add caps/ccaps to the user, the cron jobs are for something else.

So looking here:

https://s2member.com/kb-article/rolescapabilities-via-php#toc-207845e1

Shows how you can add the caps with the WP User object.


HIL Tennis

December 5, 2017 at 1:56 am

Have you used hooks (actions/filters) before?

My knowledge is limited to adding code snippets to my child-themes functions.php. Also I have added a site-specific plugin to add a remaining tickets column to the ticket selector in Event Espresso 4.
So yes I do need some more help getting started, but I think with a little help I can manage. Can you please describe step-by-step what I will have to do to get this done? Truly appreciate your help Tony!


Tony

  • Support Staff

December 5, 2017 at 4:05 am

Whilst I’m happy to help point you in the right direction, it’s important to note that we don’t support customizations so you may need the help of a developer.

Take a look at this function:

https://gist.github.com/Pebblo/47ee6301aa5767066074b4a450309bb7

That uses the hook I mentioned before, pulls all of the categories assigned to an event and adds them as capabilities to the current users account using the format ‘access_s2member_ccap_{category_slug}’ which I think is what you are looking for.


HIL Tennis

December 5, 2017 at 4:35 am

Fantastic Tony, you are the best! Your example works as advertised and you totally saved my day. Next time I’m in Scouserland too watch a game with my favourite football team I’ll buy you a beer 🙂

Viewing 9 reply threads

The support post ‘create s2member ccap upon registration (not using autocreate)’ 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.

Event Espresso