Support

Home Forums Event Espresso Premium Custom shortcodes in messages

Custom shortcodes in messages

Posted: June 10, 2016 at 4:19 pm

Viewing 8 reply threads


phillipsdriving

June 10, 2016 at 4:19 pm

Is there a way for me to add in my own shortcodes to the the messages? I have a purchase code that is not related to the registration code.


Tony

  • Support Staff

June 13, 2016 at 3:32 am

Hi there,

Yes it is possible to add your own shortcodes to the messages system, I have previously posted details of doing so here:

https://eventespresso.com/topic/venue-against-each-date/#post-177488

Or you can view the code here:

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


phillipsdriving

June 13, 2016 at 9:04 am

I’ve added the two snippets of code to my functions file and they still don’t work. Where do I need to put this code? Currently I had it in the child theme functions file. I moved it to the parent, and then my site loaded a blank page when using the example code. What am I doing wrong?


phillipsdriving

June 13, 2016 at 9:08 am

Ok I got it to show up (missing semicolon on my end). Since it’s showing up in the DateTime list, what is the name for the Attendees List section? I thought it would be EE_Attendee_Shortcodes, but it wasn’t.


phillipsdriving

June 13, 2016 at 9:32 am

Can you also run do_shortcode() within your shortcodes to trigger one of your shortcodes?


phillipsdriving

June 13, 2016 at 9:45 am

I got the shortcode to register correct, but nothing is being returned. It’s only showing the bracket shortcode. [DRIVERSED_SHORTCODE]


Tony

  • Support Staff

June 14, 2016 at 1:18 am

Can you either create a Gist or post your code to something like http://pastebin.com/ and post the URL here so I can view the code please?

If its returning the string it sounds like there is no parser for the shortcode.


phillipsdriving

June 15, 2016 at 11:07 am

http://pastebin.com/7iiDhRms

I got it to parse correctly if I just kept it to the EE_Datetime_Shortcodes instance, but as soon as I changed those to EE_Event_List_Shortcodes, it wasn’t parsing correctly. Any suggestions?


Tony

  • Support Staff

June 16, 2016 at 5:02 am

Your parse function is different from your hook:

register_new_tony_shortcodes_parser and register_new_driversed_shortcodes_parser

The reason the shortcode won’t work with that setup is $data will never be an instance of EE_Event_List (there is no EE_Event_List class) remove the instanceof check:

&& $data instanceof EE_Event_List

And fix the hook function name, then that shortcode will parse within the event list shortcodes.

Can you also run do_shortcode() within your shortcodes to trigger one of your shortcodes?

No you can’t, do_shortcode() runs on standard shortcodes and EE message shortcodes are not apart of the WP Shortcodes.

Any EE data you need can but pulled in using the $data variable, it will be different depending on the shortcode your are parsing but for EE_Eent_list_shortcodes data will be passed a EE_Messages_Addressee object.

You’ll need to go through and find the data available from the EE_Messages_Addressee class and call whatever it is you need from there.

You can use Kint and use d($data); within your shortcode, then preview the message to see the output. You’ll find multiple different objects available from within $data.

For example on your shortcode you can use:


$primary_reg = $data instanceof EE_Messages_Addressee ? $data->primary_reg_obj : NULL;

if ($primary_reg instanceof EE_Registration) {

	$primary_attendee = $primary_reg->attendee();

	$first_name = $attendee->fname();

}

To display the first name of the primary registrant.

Can I ask why you are using the event list shortcodes? Where do you want the output to be and what details do you want to use?

Viewing 8 reply threads

The support post ‘Custom shortcodes in messages’ 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