Support

Home Forums Event Espresso Premium Get Signed Up Events for Current User

Get Signed Up Events for Current User

Posted: April 28, 2020 at 8:01 am

Viewing 1 reply thread


kubus

April 28, 2020 at 8:01 am

Dear EE-support team,

we are currently implementing a custom plugin to be able to do further actions / custom functions with the data provided by our EE instalment. If a user opens an event, we want to check with his user_id to see if he’s already signed up on that event. If he is, then we will change the “enrol / sign up” button to a “cancel enrolment / sign off” button with further functionality (user will be able to cancel his enrolment). But there are also other functions planned that would need a list of the user’s enrolled events and then “do something else with that”. 😉

The problem that we seem to have (please feel free to correct me as we are no php professionals like you are) is, that when we use filters and hooks (like the filter for changing the button’s name), we’re not able to parse more data to other custom functions in our custom plugin.
What we’ve done so far is using [ESPRESSO_MY_EVENTS] and the add_filter(‘FHEE__EES_Espresso_My_Events__actions’, ‘tw_reg_to_my_events’, 10, 2) to show a list of the associated events for the current user. However this list is really extensive. We would only need some kind of ‘list’ or array with the event names that the current user is enrolled to – just like you do in EE with $registration->event_name() at your filter ‘FHEE__EES_Espresso_My_Events__actions‘ (but we cannot access $registration->event_name() from our custom plugin).

Maybe we’re just missing something as will still learn Event Espresso and custom code for wordpress, but does EE provide some way to get that data described? In advance, thank you very much for any help, hint or trick! 🙂


Tony

  • Support Staff

April 28, 2020 at 9:11 am

Hi there,

If a user opens an event, we want to check with his user_id to see if he’s already signed up on that event.

Depending on your setup, you may not be able to just use the user_id for the current user. For example, if you don’t sync up the registration form with the current wp user, then not all of the registrations will be linked to the current users EE contact and the above wont work.

If you allow group registrations, the additional group registrations not using the primary registrants EE contact, would not be linked to the current user.

In short there is a fair bit to getting the above done.

The problem that we seem to have (please feel free to correct me as we are no php professionals like you are) is, that when we use filters and hooks (like the filter for changing the button’s name), we’re not able to parse more data to other custom functions in our custom plugin.

I’m not really sure what you are asking here.

If you are asking if you can call other functions within a callback function on a hook within EE, then yes you can.

Do you have an example?

What we’ve done so far is using [ESPRESSO_MY_EVENTS] and the add_filter(‘FHEE__EES_Espresso_My_Events__actions’, ‘tw_reg_to_my_events’, 10, 2) to show a list of the associated events for the current user.

We (EE staff) normally prefix functions with our initials, so tw_reg_to_my_events would be a callback to a function I created, but I don’t recognise that function name and there isn’t enough information to know what the code is doing above.

FHEE__EES_Espresso_My_Events__actions is a hook within the My Events output but that doesn’t seem related to the first question in your post, unless I’m misunderstanding?

However this list is really extensive. We would only need some kind of ‘list’ or array with the event names that the current user is enrolled to – just like you do in EE with $registration->event_name() at your filter ‘FHEE__EES_Espresso_My_Events__actions‘ (but we cannot access $registration->event_name() from our custom plugin).

Why can you not access $registration from within your custom plugin?
Are you using the above hook or another?

It depends on what has been passed to the hook you are using if you have an object available, if not you would need to manually pull the details in yourself using our model system.

Maybe we’re just missing something as will still learn Event Espresso and custom code for wordpress, but does EE provide some way to get that data described? In advance, thank you very much for any help, hint or trick!

It sounds like you could do with reading over the documentation on our model system, available here:

https://github.com/eventespresso/event-espresso-core/tree/master/docs/G–Model-System

You can pull any info from within EE using those models.

—-

Whilst we don’t have an example of what you requested in your initial question, I do have a snippet that adds another action to the My Events output that allows the user to cancel their registration, would that help?

Note the snippet is unsupported and should be considered untested, so confirm it does everything you need before pushing it live:

https://gist.github.com/Pebblo/9534d318347082e63fc01f5c9c413361

Viewing 1 reply thread

The support post ‘Get Signed Up Events for Current User’ 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