Recent contributions

I was delighted to receive some pull requests over on GitHub recently.

While it admittedly took a little time for me to review and respond, all three requests were welcome and I’d like to thank @mikejanzen and @mikevalstar for taking the time to put those contributions together, which are now merged into the develop branch and all things being equal will be released as part of version 3.2.

These contributions all build on the RSVP system:

  • Limiting event attendees is now possible (thanks @mikevalstar)
  • Confirmed attendees can now be email en masse (thanks again to @mikevalstar)
  • A list of confirmed attendees can optionally be listed on the single event page (thanks to @mikejanzen for this one)

Extending [event_embed] with custom parameters

The [event_embed] shortcode already understands a host of different parameters, but even so it can be useful at times to extend it with new parameters to cover special cases. In this short tutorial we look at the process for doing just that, based on a request by @tballiance to be able to include events that have been hidden from event listings.

Background

Events can be hidden from event listings? Yes they can! In the event editor, the event options meta box provides a couple of options:

Screenshot of the event options meta box

The result of this is that they will disappear from the main events listings. Consequently, they are also absent from straightforward usages[1] of the [event_embed] shortcode.

The proposal

While we might sometimes want to force the inclusion of these hidden events, we probably don’t always want to do this. The best way forward, then, is to add a new shortcode parameter to make this optional.

Here’s what I’m envisioning – a new hidden parameter that can be used as follows:

[event_embed hidden="include"]

The solution

There are essentially two parts to the solution:

  • We need to hook into Event Rocket in order to listen out for and set things up when the new hidden parameter is set
  • We also need to hook into The Events Calendar to modify the actual query

Luckily, both plugins ship with hooks a plenty:

  • The eventrocket_embed_event_args filter hook will allow us to interface with the [event_embed] shortcode
  • The tribe_events_pre_get_posts action hook provides a convenient way to change the actual query

The code

Here is some basic code achieving this goal. It can be added to a theme’s functions.php file, as is often done, though a custom plugin or mu-plugin file may be a tidier way to go 🙂

What are we doing here? In the extend_event_embed_hidden_events() function we check to see if hidden=”include” is set. If it is, extend_event_embed_include_hidden() rolls into action[2].

Under the hood, The Events Calendar excludes the hidden events by setting a post__not_in query var – our second function tests to see if it has been populated and then wipes it if so.

Now, the thoughtful hacker may wonder: what if post__not_in was already set, independently of anything to do with hiding upcoming events? This is indeed a risk in a few (probably uncommon) special cases but it is certainly possible to introduce more logic to handle this sort of scenario (though it goes beyond the scope of this post to cover that).

Footnotes
  1. A “straightforward usage” in this case means you are not specifying start or end dates and have not specified specific event IDs/slugs
  2. Note also how we instantly unhook it – this is needed to avoid interfering in subsequent event queries
  3. Originally this was going to be a 2-part tut where we continued to look at improved handling of the post__not_in parameter, however in the end I think this is something best left to the individual developer so they can tailor things to meet the actual scenario in front of them

Enable RSVPs

Sometimes you may want users of your website to be able to RSVP and indicate if they plan on attending an event.

Event Rocket adds a simple RSVP system to The Events Calendar to facilitate just this and it can be enabled on a per event basis, by finding the new RSVP section within the event editor:

Screenshot of RSVP settings in the event editor

Right now you can choose to let anybody RSVP or you can restrict things to logged in users only (recommended). When users view the event, they will then see an extra form:

Screenshot of RSVP formIt’s a very simple system, but one which will hopefully meet a number of use cases.

Create a list of venues

Listing all of your venues within a post or page is easy – simply use the [venue_embed] shortcode.

It’s assumed that you are only interested in venues that are actually going to be hosting some upcoming (or current) events. That said, if you want to list all venues – regardless of whether they have upcoming events or not – you can:

[organizer_embed with_events="no"]

Custom templates and date formatting

In this recipe we’re going to look at setting up a custom template for the [event_embed] shortcode and doing something interesting to the dates within that template. The scenario is roughly based on this forum thread, which can be summarized as follows:

  • Let’s say we have numerous long running (multi day) events such as one that runs from 10 December – 20 December
  • If today is 15 December, we want the start date to show as the 15th rather than the 10th

There are a few ways of approaching this, but we’re going to use a custom template for this recipe. Start by locating the default template used by the [event_embed] shortcode – you should find it in:

plugins/event-rocket/templates/embedded-events.php

Simply copy the contents of this file to:

themes/YOUR_THEME/tribe-events/embedded-custom-dates.php

To actually trigger the use of this custom template we need to tell the shortcode to use it. This can be done via the template attribute:

[event_embed template="embedded-custom-dates"]

The part of the template we are interested in changing is this line:

<div class="schedule"> <?php echo tribe_events_event_schedule_details() ?> </div>

It is actually possible to use a filter to modify the output of that function, but we’re going to keep things simple and do our work right in the template … naturally, if you prefer, you could break out the logic into a function and make it reusable.

This is our replacement code for the above section:

<div class="schedule">
	<?php
	// Date format to use throughout
	$format = get_option( 'date_format' );

	// We need to compare the start date with today's date
	$start = tribe_get_start_date( null, false, 'Ymd' );
	$now   = date_i18n( 'Ymd' );

	// If it started some days ago, make the start date appear as if it were today
	if ( $now > $start ) $start_date = date_i18n( $format );

	// Otherwise, if the event isn't starting until some future point, use it's
	// actual start date
	else $start_date = tribe_get_start_date( null, false, $format );

	// Let's put it together and print our modified event dates
	echo $start_date . ' – ' . tribe_get_end_date( null, false, $format );
	?>
</div>

Now, if an event started a number of days ago, the start date will appear as if it had only started today.

Create a list of organizers

Listing all of your organizers within a post or page is easy – simply use the [organizer_embed] shortcode.

It’s assumed that you are only interested in organizers that actually have some upcoming events to their name, however if you want to list all organizers – regardless of whether they have upcoming events or not – you can:

[organizer_embed with_events="no"]