Support

Home Forums Event Espresso Premium URGENT: Getting primary registrant email from within custom shortcode

URGENT: Getting primary registrant email from within custom shortcode

Posted: April 17, 2018 at 10:27 am

Viewing 10 reply threads


deon@dieselbrook.co.za

April 17, 2018 at 10:27 am

I’ve created some custom shortcodes to be used within the mailing messages of EE4. This works fine, but I am trying to get the primary registrant email (or any of the data for that matter) from within EE_MESSAGES_ADDERESSEE (which I can see has a $primary_registrant_email property)

How do I go about retrieving this info? I’ve tried several approaches. EE_MESSAGES_ADDRESSEE has no get method in order to retrieve data, but all of its properties are public.

my code for the shortcode in question is (for the moment) :

if ( !empty( $event ) ) {
$aee = $data instanceof EE_Messages_Addressee ? $data : NULL;
$aee = $extra_data instanceof EE_Messages_Addressee ? $extra_data : $aee;
$event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration ? $aee->reg_obj->event() : NULL;
$message = 'Result : <br/>'. $aee->primary_registrant_email;
wp_mail('test@test.com', 'Debug' , $message); //purely for debugging
return $message;
}

Could I just get this data from the database itself? But I’d still need an ID or something from the registration. Stuck, please help.


Tony

  • Support Staff

April 17, 2018 at 2:40 pm

Hi there,

This works fine, but I am trying to get the primary registrant email (or any of the data for that matter) from within EE_MESSAGES_ADDERESSEE (which I can see has a $primary_registrant_email property)

Can I ask where you see that?

As far as I can tell the EE_Messages_Addressee object does not have a primary_registrant_email property, the only place I see that is the shortcode [PRIMARY_REGISTRANT_EMAIL] which calls the email method on an EE_Attendee object.

EE_Messages_Addressee has both the primary registration and primary attende objects available as properties, so you would do something like:

$primary_reg = $eea->primary_reg_obj;
$primary_attendee = $eea->primary_att_obj;

You’ll need to double check they return the expected objects before using them:

if( $primary_reg instanceof EE_Registration ) {
    //Is a valid EE_Registration object, do something with it here.
}

and

if ( $prmary_attendee instanceof EE_Attendee ) {
    //$primary_attendee is a valid EE_Attendee object, as it's the primary 
    //attendee object you can pull the email from it.
    $primary_att_email = $primary_attendee->email();
}

Note that urgent or not, we do not provide support for custom code. Whilst I’m more than happy to help point you in the right direction with the above it’s important to note that custom code is outside the scope of our support.


deon@dieselbrook.co.za

April 18, 2018 at 12:39 am

Thanks for the feedback. I took a look at the classes in the source code for EE_MESSAGES_ADDRESSEE, EE_EVENT, EE_ATTENDEE, etc. and saw that they had public properties for each of these. I will give this a go, should be fine now, but will post an update.


deon@dieselbrook.co.za

April 25, 2018 at 9:06 am

So it seems like the system doesn’t find any object except the event object (I used your code from https://gist.github.com/Pebblo/e87cc8e30c4848dcdfe2). The $aee object keep on returning null (as per $aee = $data instanceof EE_Messages_Addressee ? $data : NULL;). At first I thought this was because I was sending a test message directly from the message template and that there would thus be no object to associate. But I also tried doing an actual registration on the site, and it still returned null.

Can I get the attendee details from just the event object, or can perhaps I use the other shortcodes within my custom shortcode?

What I am trying to create (and why I don’t just use the existing shortcode as is) is I’ve built a page that has a quiz relating to the event with an access list (of registrants)(Everything is working fine up until this point). I now want to send the users that registered a link to the quiz page with an encrypted version of their email as a url parameter. I can handle the encryption/decryption, but I just need to get the registrant email for this.


Tony

  • Support Staff

April 25, 2018 at 2:55 pm

Can I get the attendee details from just the event object,

No, the event object is just all of the event details, it’s not linked to registrations, attendees etc.

or can perhaps I use the other shortcodes within my custom shortcode?

You mean other EE message shortcodes? No but if you don’t have access to the data already, then neither will the shortcode at that point.

I now want to send the users that registered a link to the quiz page with an encrypted version of their email as a url parameter. I can handle the encryption/decryption, but I just need to get the registrant email for this.

What context are you sending the message from?

Which message template etc?

Can you post all of your code to either a gist or pastebin so I can take a look over it?

$data or $extra_data should usually be an instance of EE_Messages_Addressee but its possible that’s not always the case but I’ll need to know where your code is running to narrow it down.


deon@dieselbrook.co.za

April 26, 2018 at 12:30 am

https://pastebin.com/9wMG5BWR for the pastebin, I’ve commented out some code in order to debug, this is only the code for the shortcode.


Tony

  • Support Staff

April 26, 2018 at 1:25 am

What context are you sending the message from?

Which message template etc?


deon@dieselbrook.co.za

April 26, 2018 at 2:32 am

Oh yeah, sorry. Shortcode is inside the [EVENT_LIST] context.


Tony

  • Support Staff

April 26, 2018 at 2:46 am

Which message template etc?

I need to know where you are using the shortcode, I can see from the code is an event based shortcode but in which message template are you using it and which ‘context’, see:

https://eventespresso.com/wiki/messages-system-working-with-message-contexts/


deon@dieselbrook.co.za

April 26, 2018 at 3:25 am

Email Registration Approved Template (Registrant Recipient) . Thanks for clarifying, wasn’t really sure what you meant.


Tony

  • Support Staff

April 26, 2018 at 4:03 am

Ok, you need something like this:

https://gist.github.com/Pebblo/dc950fde4e8bfd5a70c6d6fc5e2ac9c7

$extra_data is now formatted differently from when I first created that gist so it’ll need updating, the reason that’s not causing issues for other users is $data should now always be an instanceof EE_event for event based shortcodes, meaning the code that uses extra_data in that example is not used. Your trying to pull registration/attendee based info from the event shortcodes so it needs the data from extra_data (technically this is the ‘correct’ way to do this as event shortcodes should be solely on the event itself, this is not, but that’s up to you).

The way I would have done this is to add the shortcode to either the EE_Primary_Registration_Details_Shortcodes or EE_Recipient_Details_Shortcodes, both of which have the EE_Registration object passed to them which can be used to pull the primary registrant (or just check if the current registration is the primary) and the event, but that’s something for you to dig into if you wish.

Also be careful with your conditionals, in the code you linked to:

$event = $extra_data instanceof EE_Event ? $data : null;

Check if $extra_data is an EE_Event, then if it is, assign $data (which has nothing to do with what we just checked for) to $event? You want to be checking what $data is, not $extra_data.

Similar problem here:

$aee = $extra_data instanceof EE_Messages_Addressee ? $data : NULL;

If $extra_data is an EE_Messages_Address object, set $data (which is likely an EE_Event) to $eea?

But anyway, the Gist I linked to above will return the primary_att_email, a quick example:

Shortcode: http://take.ms/UugKN
Parsed: http://take.ms/xoWJN

Viewing 10 reply threads

The support post ‘URGENT: Getting primary registrant email from within custom shortcode’ 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