Creating an Events Manager Add-On : A Complete Walkthrough
Warning: This series of tutorials was designed to help developers and designers learn how to make common modifications and understand some of the possibilities in Events Manager. We assume here that you already know your way around Wordpress and some basic knowledge of PHP.
Aside from being the most flexible events plugin for styling without modifying code, Events Manager is made with developers in mind, meaning that any aspect of the plugin can be hooked into and modified to suit your needs!
We have put together a collection of tutorials that create one comprehensive add-on (or plugin) for Events Manager. In this series we will show you how to make a fully fledged plugin that adds further functionality in various aspects of EM.
We hope that you'll find this useful when you need to make changes to EM without hacking the plugin directly. Or if you're browsing for flexible event registration plugins on wordpress, maybe this will help!
In this sample project, we are going to add a new plugin called "Styles", which will allow users to assign certain styles to an Event via a drop-down menu. This functionality effectively gives you the same as event categories, but serves as a great way to show how easy it is to connect to all aspects of this plugin.
Important: Since the release of version 5, you are able to quickly achieve a very similar effect by registering a custom taxonomy, as covered in our taxonomies tutorial. 'Styles' makes more sense as a taxonomy, but this tutorial serves the purpose to show the different possible implementation methods.
In this tutorial, you will learn how to do the following:
- Decide where to correctly add your code in an upgrade-safe way
- Create a new custom admin page in events manager for users to manage styles
- Attach custom style information to the event upon instantiation so it can be accessed easily
- Add a meta box in the edit events page for users to select the event style
- Perform necessary actions to save event styles when an event is added or updated
- Make styles searchable via shortcode, and function search attributes
- Insert a style search drop-down menu into the events search form
- Add a custom placeholder for listing the event styles
- Add a custom condition placeholder for showing event information if it has a specific style
- Create a new style pages that lists all events categorized by style (much like the new categories pages)
- Create a new permalink rule so that our new style pages have pretty SEO permalinks.
This may sound like a lot, but surprisingly, this can be done comfortably in about 300 lines of code! However, due to the length of the explanation, and the modularity of these functions, we'll be splitting this tutorial up into various steps, as each step can be reused in various ways to tweak and modify Events Manager to your liking.
Step 1 - Adding your code to the right files
We need to decide where to make these changes. In this case, we're just going to create an em-styles.php file within our mu-plugins folder and insert the code there. Here's some more information on how to add php code to wordpress.
Step 2 - Create a new custom admin page in Events Manager
Users will need to be able to manage styles, so we have to create a styles admin page that allows users to add, edit and delete their styles.
For this example add-on, we will be storing our styles as a serialized array inside a wp_options table row with option_name my_em_styles. The array keys represent the style ID and the value is the name of that style. You could create your own table should you need to, in this case the wp_options table will do.
Step 3 - Add a meta box in the edit events page for users to select the event style
When managing events, we will need somewhere on the event registration form to choose from the list of styles. The event forms have various hooks for both the admin area and front-end that allow us to insert extra event form elements. This provides a seamless integration with the rest of the plugin. We are going to make a new meta box and input area for the event submission forms