Skip to content

Instantly share code, notes, and snippets.

@slimndap
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slimndap/4d4345eed7183fac8adf to your computer and use it in GitHub Desktop.
Save slimndap/4d4345eed7183fac8adf to your computer and use it in GitHub Desktop.
Adds a link to the venue to the location HTML output. See http://theater.slimndap.com/link-the-event-location-to-the-venue-website/ for the full article.
<?php
/**
* Adds a new 'Venue URL' field to the event editor.
*
* @param array $fields The current fields of the event editor.
* @return array The new fields of the event editor.
*/
function wpt_event_editor_add_venue_url_field($fields) {
$new_fields = array();
foreach($fields as $field) {
$new_fields[] = $field;
if ('venue' == $field['id']) {
$new_fields[] = array(
'id' => 'venue_url',
'title' => 'Venue URL',
'edit' => array(
'placeholder' => 'http://',
),
);
}
}
return $new_fields;
}
add_filter( 'wpt/event_editor/fields', 'wpt_event_editor_add_venue_url_field');
/**
* Adds a link to the venue HTML if the venue URL is set.
*
* @param string $html The current venue HTML.
* @param WPT_Event $event The event.
* @return string The new venue HTML.
*/
function wpt_event_add_venue_url($html, $event) {
$venue_url = $event->custom('venue_url');
if (!empty($venue_url)) {
$html = '<a href="'.esc_attr($venue_url).'" target="_blank" style="display: block;">'.$html.'</a>';
}
return $html;
}
add_filter( 'wpt_event_location_html', 'wpt_event_add_venue_url', 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment