Tagged: id

Event Espresso 4 – Helpful Functions

event-espresso-logo-600x213-black1-600x198

I’ve recently been working on a project using Event Espresso 4 and I’ve had to customize it quite extensively. I wrote a few functions that I think might be handy for others so I thought I would share them:

Get Event ID From Registration Code

I wrote this one to help me get the event information when a user clicks on a ‘cancel registration’ link. The reg code is more secure way to pass as a GET variable in a link than the user/event/registration id.

The Function

Usage Example

Get Event Date

This one is handy if you have the event id and you are just looking for the date of the event.

The Function

Usage Example

Get the Status of the Registration From Registration Code

This one can be used to see the status of a particular registration. I wrote it to provide confirmation that a registration had been cancelled in a custom built ‘cancellation journey’.

The Function

This function returns a status code:

“RAP” (registration status of approved. This is the default behavior.)
“RCN” (registration status of cancelled.)
“RDC” (registration status of declined.)
“RIC” (registration status of incomplete.)
“RNA” (registration status of not approved.)
“RPP” (registration status of pending payment.)

Usage Example

Get the Status of the Event From Registration ID

Same as above just using the Registration ID.

The Function

This function returns a status code:

“RAP” (registration status of approved. This is the default behavior.)
“RCN” (registration status of cancelled.)
“RDC” (registration status of declined.)
“RIC” (registration status of incomplete.)
“RNA” (registration status of not approved.)
“RPP” (registration status of pending payment.)

Usage Example

Get Registrant Details From Registration ID

This function gives you the all the registration details of a Registrant if you have the registration ID.

The Function

This function returns an object with ‘first_name’, ‘last_name’ and ’email’ as the parameters.

Usage Example

 

More

Dynamically Naming Elements in Nested Loops

Wanted to share a technique I use quite a lot at the moment for dynamically naming elements in a loop or, more specifically for this method, in multiple nested loops.

Consider the following code which is pretty standard for most jquery modals at present.

To render these modals in a loop you might be familiar with the following code which I have seen a million times.  This set up makes sure that each link points to a corresponding container div with a matching unique id. Fine and dandy:

The problem with this method occurs when you are using this type of markup as a function or if you have some sort of dynamic setup where the above code may be outputted on the same page more than once. This would break the code as the link would just point to the first container div with that name.

I’ve seen setups with some very strange methods to get round this.

The Solution

Here is a simple solution that utilises php’s  uniqid function. This ensures you will NEVER get two id’s matching no mater how many nested loops you have going.

Implement it like so:

If you want to store the id’s of these for use at a later point, like I’ve done recently, you can do this:

Then you have access to the id’s later like so:

I’ve used this not just with modals, but when generating unique ids for other jQuery functions, when using with Advanced Custom Fields ‘Flexible Field’ addon to make sure all generated sections of content have a nice unique ids to point to.

More