Posted: October 3, 2015 at 8:44 am
|
Hi all, I have a client that needs a different venue against each date for any given event. I was going to create my own table that would simple contain the ID of the venue and the ID of the datetime (since all dates and venues are pulled from a 3rd party system and automatically inserted I dont need to worry about an interface). However, they also want the correct venue details to appear in the email – how can I do this? Can I create my own shortcode for the emails? Cheers 🙂 |
Are you using EE3 or EE4? |
|
|
EE4! |
Hi Zoe, Yes it’s possible to add your own custom message shortcodes. While we don’t currently have step by step developer documentation that shows how to register new message shortcodes, the Event Espresso 4 ticketing add-on registers its own message shortcodes via the plugin API. I can recommend stepping through the code in the ticketing add-on to learn how to make your own messages shortcodes in a little plugin. |
|
|
I dont think we’re using the ticketing plugin for any of our clients (I can’t find it anywhere and its not in my downloads) – is it possible to get a copy of the relevant code? |
It turns out that Event Espresso 4 core also uses the same API to register new shortcodes. You’ll find examples in EE_Caf_Messages.class.php. |
|
|
Thanks Josh, we create our own shortcodes quite often, does any registered shortcode work in the emails? Thanks! |
Hi Zoe, Only shortcodes that are specifically registered for messages can be used in messages. |
|
|
Hi Josh, I’ll be honest I’m struggling a little here. I already have my shortcode I just can’t figure out how to register it for the messages without editing ee core files. I’ve found the EE_Register_Shortcode class but don’t know how to hook in to or replicate this outside of the ee core files. Help!! |
Hi Zoe E, There’s basically 2 steps to registering a new shortcode with the EE Messages system. Firstly you register the shortcode and where it can be used, here is an example of how you would do that: function register_new_tony_shortcodes( $shortcodes, EE_Shortcodes $lib ) { if ( $lib instanceof EE_Datetime_Shortcodes ) { $shortcodes['[TONYS_SHORTCODE]'] = _('This is Tonys Custom Shortcode!'); } return $shortcodes; } add_filter( 'FHEE__EE_Shortcodes__shortcodes', 'register_new_tony_shortcodes', 10, 2 ); That function hooks into the EE Message shortcodes and adds ‘[TONYS_SHORTCODE]’ to the EE_Datetime_Shortcodes. Then you need to tell EE what to do with the shortcode when it finds it within the message. We do that by adding shortcode a parser. Here is an example of how you add a parser: function register_new_tony_shortcodes_parser( $parsed, $shortcode, $data, $extra_data, EE_Shortcodes $lib ) { if ( $lib instanceof EE_Datetime_Shortcodes && $data instanceof EE_Datetime ) { if ( $shortcode == '[TONYS_SHORTCODE]' ) { return $data->ID(); } } return $parsed; } add_filter( 'FHEE__EE_Shortcodes__parser_after', 'register_new_tony_shortcodes_parser', 10, 5 ); We are hooking into the shortcodes after EE has done it’s thing and parsing our shortcode. $parsed is the currently parse content and must be returned (or you’ll have nothing to send) So we check if we are currently within the EE_Datetime_shortcodes library:
If so we want to find our specific shortcode:
In this case I’m just returning the ID of the current datetime:
But you will be using that to pull venue info from your custom table and returning that information instead. Here’s a gist containing both those functions as its easier to read: https://gist.github.com/Pebblo/e87cc8e30c4848dcdfe2 Does that help? |
|
Also just to clarify for future readers, the EE Messages shortcodes are not standard WordPress shortcodes. They are specific shortcodes registered within the messages system and can only be parsed within that system, so WordPress shortcodes will not work within the message system and EE Message shortcodes will not work outside of the message system. |
|
|
Hi all, Thanks for the code above, very very useful. I’ve created my shortcode but am struggling with testing it – I’ve just placed an order but no email confirmation has arrived. Also when I view the receipt on the website (the one thats linked to on the order confirmation screen) I get these errors – are the two things related? Could my shortcode be causing this? Also is there a way to test the short code without placing a full order. It’d be nice to be able to test it more quickly to iron out any bugs before testing it full in the email. Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘register_new_get_custom_venue_dates’ not found or invalid function name in /home/devhrtrainingco/public_html/wp-includes/plugin.php on line 213 Warning: array_key_exists() expects parameter 2 to be array, null given in /home/devhrtrainingco/public_html/wp-content/plugins/event-espresso-core-reg/core/helpers/EEH_Parse_Shortcodes.helper.php on line 236 Thanks! |
Yes it is likely your custom functions causing this.
Currently the messages are only parsed when sending the message, so the only way to test it is by sending the message.
Double check the naming of your functions and that they match up with the callback within the filter
Double check you are returning the shortcodes array within the functions used to register the shortcode and the parsed content within the parser. EE is expecting an array of shortcodes and is being passed nothing (null) |
|
|
Hi Tony, thanks for your help on this. I’ve spotted why the first error is occuring but not sure about the second one, the shortcode is being registered exactly as your example above (just with the names changed) so I pressume its coming from this function:
but I’m not sure what I need to do to ensure it returns my data as an array? Thank you 🙂 |
To double check if it is that function, comment out the code and just use:
Then check that the shortcode parses to the ID of the datetime. Can you post up both functions please, however I would recommend using something like http://pastebin.com/ and a Gist as the forum alters the formatting slightly. The code this is failing is when EE tries to pull in all of the shortcodes for a message type and check if the shortcode exists, so I think its where you are registering your shortcode, rather than when you are trying to parse it. |
|
|
Thanks Tony, I’ll give that a go now. Here are both my functions 🙂 http://pastebin.com/x2pfeJS7 |
|
Interesting – I just reinserted my shortcode in to the receipt email and I got this message:
|
That’s because your using a shortcode you have registered within EE_Datetime_Shortcodes within the main content, EE_Datetime_SHortcodes are not valid within the main content section. You need to use that shortcode within the Datetime_list section – http://take.ms/QOJHm I’ve just pasted both your functions into my functions.php file, swapped out the return for just a string – http://take.ms/K5nzX. Then tested that within the messages and it worked fine. Obviosuly I can’t set your other code as the query won’t work but was your eventually just returning a string it should work. Have you tried returning a var_dump() of $thevenues? You can do that using output buffering or even using var_export, have a read here: http://stackoverflow.com/questions/139474/how-can-i-capture-the-result-of-var-dump-to-a-string Then see if $thevenues actually has values. |
|
|
Awesome, I have it working now 🙂 One last sort of related q – my mini basket buttons link to my live site (I moved my site to a dev URL) – where are these set? I’ve replaced all the URLs in my database. Cheers 😀 |
Can I ask what the problem was? Which links are these? Can you link me to the page? Did you replace the URLs manually? I remember from your other thread you mentioned replacing the URLs though phpMyAdmin. |
|
|
I exported the database and did a find and replace in a text editor so I know theres none left in there 🙂 |
Can you link me to the page so I can view this please? |
|
|
|
Have you flushed your Permalinks? Go to Dashboard -> Settings -> Parmalinks Make no changes and save the settings. If that doesn’t work go to Event Espresso -> General Settings -> Critical pages. Then save the settings there and retest. |
|
|
Hi Tony, have just done both of those and those URLs are still wrong. I dont understadn where they are coming from as a find in our theme/mu-plugins returns nothing as does a find on the entire database. |
It uses the WP core function get_permalink() to build those links. The view cart link is built using the reg_page_url() function within EE core, which is just: public function reg_page_url() { if ( ! $this->reg_page_url ) { $this->reg_page_url = get_permalink( $this->reg_page_id ) . '#checkout'; } return $this->reg_page_url; } So it seems get_permalink() is returning your old URL, so WordPress (not EE) still thinks its on the old url. If you look within Dashboard -> Settings -> General. Are your WordPress URL and Site URL values setup using the dev domain? It could also be a plugin/the theme filtering get_permalink to use your old URL. |
|
The support post ‘Venue against each date’ 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.