Event details

  • Thu 31 March 2016
  • All day
  • Canterbury Heritage Museum, Stour Street, Canterbury, CT1 2NR
Loading Map....

This is the most important line in our function. To avoid any runtime errors, we’ll just return the original replacement value if the $EM_Event isn’t an object. The preg_match method runs a regex matching operation to make sure we’re dealing with a conditional placeholder with the name of has_style_x , where x is the id number of that style. The last function is just a precaution to avoid unexpected PHP warnings in case the styles weren’t loaded correctly, but we could probably even do without it (as a plugin dev it’s now a habit for me).

This regex also stores the found number in the $matches array, which we use in the next line to check if this event has this style id in its styles array. If it does, we remove the start and end placeholder tags with a preg_replace statement and return the contents, otherwise we just return a blank string.

You can use this function within any formats that accept Event placeholders from within your settings page, shortcode, template tags or directly accessing the event objects. In our next tutorial, we’re going to create a custom event information page which will show a list of styles and display the upcoming events under each style, as well as our single style pages.