Posted: December 12, 2014 at 2:28 am
|
Hey guys, I’ve been pulling my hair out trying to figure out how to manipulate and override the way Event Espresso works and displays information. The documentation pages might help people already knowing what to do, but I don’t, so they haven’t been much help. I finally think I’ve managed to understand a couple of things, so to help other newbies like myself to override default Event Espresso functionality, I figured I’d try to write this post explaining how. I’ve probably misunderstood at least a couple of things, so if anyone have corrections or pointers, please feel free to add your comments in the replies. I also have some questions and suggestions for improvements to the Event Espresso core (unless they also are misunderstandings, of course), so perhaps someone with more insight than me can provide some further help with these questions. This walk-through is based on overriding the «Thank you»-page you land on after registering for an event. ==== PART 1: By filters and actions ==== Under «Existing», you see two filters. You might not know what a filter is, I sure didn’t. But reading this helped alot: So, we’ll start out by taking a look at the file we want to alter, located in [event espresso plugin folder]/shortcodes/espresso_thank_you/templates/thank-you-page-overview.template.php. This is the file outputting the thank you-page. As you’ll se, the file contains several actions and one filter. To change the Congratulations text, we need to hook into the filter. The filter is named FHEE__thank_you_page_overview_template__order_conf_desc, and as you can see in the file, what it does is simply output the congratulations text. To hook into the filter, open your theme’s functions.php file (or better, make a site specific plugin, as explained here: https://eventespresso.com/wiki/create-site-specific-plugin-wordpress-site/ . That way you won’t risk loosing your changes if your theme gets updated.) In the functions.php in your theme or in the main site specific plugin file, add the following code:
function custom_congratulations_message() { What this little piece of code does is hook into the filter named FHEE__thank_you_page_overview_template__order_conf_desc, and replace it with the function named custom_congratulations_message. Then, in the function named custom_congratulations_message, the desired output is generated. To display your own text, change the text in the custom_congratulations_message function. You can also add other functionality here if you want to. Some filters have variables passed to them, for example to loop through arrays or format content. If that’s the case, you’ll need to process the array and return the content in the same format the original filter does. A similar way of controlling the content is also available for content presented from do_action (instead of apply_filter). That’ll have to wait until another time, I’m not sure how to do it myself yet. (But this seems like an okay place to start: http://frumph.net/2010/06/14/understanding-do_action-and-add_action/ ) So, to alter content in the various parts of Event Espresso, here’s a shorthand list of what you need to do: ==== PART 2: Direct template replacement ==== If so, the easiest way would be to create my own thank-you-page-registration-details.template.php, and put it in a place Event Espresso could find it. However, I can’t seem to get it loaded by Event Espresso, no matter where the template file is placed. I’ve tried these locations: I have, however, also made an attempt at finding out why it doesn’t work, and I think I’ve found a possible solution. But first, the problem: The template file is loaded like this in shortcodes/espresso_thank_you/EES_Espresso_Thank_You.shortcode.php:
The locate_template function is then loaded. This is located in core/helpers/EEH_Template.helper.php. The locate_template function basically loops through a bunch of template folders looking for our file – or at least it’s supposed to. When echoing the contents of the arrays it’s working with, it seems as most of the custom locations are lost somewhere in the process. At one point in locate_template it loops through the array of possible template locations, creating the final array that will eventually be checked (around line 215 in EEH_Template.helper.php). The template path to be checked is constructed like this: This causes problems. Because the locate_template is loaded with the THANK_YOU_TEMPLATES_PATH appended, the $full_template_paths array gets several entries with double absolute paths, e.g. in my case like this: So, it’s understandable that it can’t find my custom template file, seeing as the path and file doesn’t exist on my system. I figure there are two ways of fixing this. I have only tried and tested method 2, and as far as I can see, it works. Here is what I did: Open EEH_Template.helper.php. Find the locate_template function (around line 156). Around line 209, there is a foreach that starts like this: After that last quoted line of code, add this: The next line of code in the file should be something like this: Add this right after it: Then, a little further on in the function, you’ll see a foreach that starts like this: BEFORE that foreach, add the following: Then you should be good to go! Now, all template files added in uploads/espresso/templates/ with the same file name as the original template file, will get loaded in stead of the original template file. If you remove (or rename) your override template file, the original file is loaded again. All the default checks are still being run, so other parts of the system using locate_template still works as normal. So, if you want to alter the Thank you page, you’ll have to copy the /shortcodes/espresso_thank_you/templates/thank-you-page-overview.template.php file to uploads/espresso/templates/, and edit it there. Parts of the page is made with other php files in the same folder, so feel free to copy them over as well as needed. Here’s what the code added to EEH_Template.helper.php above does: A big warning and heads up, though: The downside to this, of course, is that it requires altering a core file. So, that’s why I’m guessing I might be off – perhaps there’s an even easier way to do this? Perhaps adding your own custom php files in the template directory should work already? (Even though it won’t work on my setup, at least. Any help on figuring out why is much appriciated.) If there is no way around altering the core to achieve this, I hope the Event Espresso staff will consider altering EEH_Template.helper.php as described (or similar) so this way of customizing Event Espresso can be possible in the future. It would make a great system even better and more flexible. Also, adding a more understandable and easy documentation would also be nice. Anyway, thank you for your attention, and as stated at the beginning, I’m expecting to be wrong about all or parts of this, so please feel free to both correct and enlighten me. All the best, |
|
Thanks for that. It seems like we’re working on the same things. Another approach to dealing with some of the templates might be to create a custom page template for the Thank You page and then remove the events espresso shortcode from the Thank You page that they create on your site. For your first approach, hooking into filters, there is also the gettext filter hook. It is very easy to use to change short strings of text that is run through the __() translation function, but it seems that on sites that are not using internationalization it can lead to performance problems (I don’t know how significant that is.) Simon |
|
I’ve been looking at this for too long, but it seems to me that all that has to change is line 477 of Simon |
|
Ah, great, thanks 🙂 An advantage of altering the locate_template itself is that the edit would also make other templates available for editing, not only the EES_Espresso_Thank_You.shortcode.php. So, when the adaption disappears in core updates, you’ll only have to re-edit the locate_template file, not every template you’ve overwritten. Eivind |
|
Also, your description of using gettext in another forum thread is useful when working on this subject, so I thought I’d post the link to it: |
Hi there,
Possibly, but you’ll find that you’ll end up having to do a lot more maintenance over time because when future versions contain changes in those templates, your templates may not be compatible with future versions. In short, hooks typically do not change, but entire templates do change when new features are added. Hooks allow you to make specific changes to specific parts of a template, whereas overriding an entire template to make a few changes to the Thank You page can lead to a lot of trouble after an update. We’ve seen a lot of support issues caused from someone copying over entire templates in order to make a few changes to a template, then later when they go to update the plugin, their template ends up breaking things. |
|
|
Thanks. I’d like to edit my comment above about creating a custom page template and removing the [ESPRESSO_THANK_YOU] shortcode from the thank you page. Don’t do it!!! See the Critical Pages tab of Event Espresso >> General Settings in the WordPress dashboard. Those shortcodes and page settings are required for Event Espresso to function properly. |
The support post ‘A basic walkthrough on how to customize Event Espresso templates’ 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.