Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,7 @@ If your theme supports widgets, the events calendar can also be added as a widge
## UK dates ##

If the [CMB UK date field plugin](https://github.com/castlegateit/cgit-wp-cmb-ukdate) plugin is installed and you are using the Custom Meta Boxes plugin, the start and end dates will use that field type. If not, they will use the standard Unix date field.

## License

Released under the [MIT License](https://opensource.org/licenses/MIT). See [LICENSE](LICENSE) for details.
14 changes: 13 additions & 1 deletion admin-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class cgit_wp_events {
'cgit_wp_events_post_type_support_author' => '',
'cgit_wp_events_post_type_support_thumbnail' => '',
'cgit_wp_events_post_type_support_comments' => '',
'cgit_wp_events_post_type_support_page-attributes' => ''
'cgit_wp_events_post_type_support_page-attributes' => '',
'cgit_wp_events_post_type_support_calendar-direct-url-to-event' => '1'
);
}

Expand Down Expand Up @@ -158,6 +159,17 @@ function cgit_wp_events_render_settings_page() {
</label>
</td>
</tr>

<tr>
<td>
<label>
<input type="checkbox" name="cgit_wp_events_post_type_support_calendar-direct-url-to-event" value="1"<?php echo get_option('cgit_wp_events_post_type_support_calendar-direct-url-to-event') ? ' checked="checked"' : ''; ?> />
Direct URL to event on event calendar
<br />
<small>When enabled, the event calendar will display a direct link to an event when it is the only one on the day.</small>
</label>
</td>
</tr>

</table>

Expand Down
29 changes: 27 additions & 2 deletions calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ private function days()
// Output variable
$out = '';

// Check if the calendar should display a direct link to an event
$display_direct_link_to_event = $this->displayDirectLinkToEvent();

// Loop through and output calendar days
$i = 1;
foreach ($this->getDays($this->year, $this->month) as $day) {
Expand All @@ -249,7 +252,7 @@ private function days()
$out.= "<td class=\"" . $day['class'] . "\"><a";

if ($day['events']) {
if (count($day['events']) == 1) {
if ($display_direct_link_to_event && count($day['events']) == 1) {
$link = reset($day['events']);
$link = $link['permalink'];
} else {
Expand Down Expand Up @@ -482,7 +485,8 @@ public function getAjax()
'year' => $this->year,
'month' => $this->month,
'days' => $this->getDays(),
'current' => $current->format($this->options['current_month'])
'current' => $current->format($this->options['current_month']),
'display_direct_link_to_event' => $this->displayDirectLinkToEvent(),
);
}

Expand Down Expand Up @@ -514,4 +518,25 @@ private function c($index)
}

// -------------------------------------------------------------------------

/**
* Checks if the calendar should display a direct link to an event if it's the only one on the day.
*
* @author Castlgate IT <info@castlegateit.co.uk>
* @author Lamé Moatshe
*
* @return bool
*/
private function displayDirectLinkToEvent()
{
$display_direct_link = get_option('cgit_wp_events_post_type_support_calendar-direct-url-to-event');

if($display_direct_link) {
return true;
}else {
return false;
}
}

// -------------------------------------------------------------------------
}
2 changes: 1 addition & 1 deletion cgit-wp-acf-events.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Plugin URI: https://github.com/castlegateit/cgit-wp-acf-events/
Description: A simple and easy to use events interface with complete developer
control.
Version: 1.7.3
Version: 1.7.4
Author: Castlegate IT
Author URI: http://www.castlegateit.co.uk/
*/
Expand Down
9 changes: 8 additions & 1 deletion js/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ jQuery(document).ready(function($) {
function cgitEventsDrawCalendar(response) {
var calendar = $('.cgit-events-calendar');

// Checks if the calendar should display a direct link to an event if it's the only one on a specific day
var display_direct_link_to_event = response.display_direct_link_to_event;

// Trigger data loading event.
calendar.trigger('cgit-wp-acf-events:data:loading');

Expand All @@ -35,7 +38,11 @@ jQuery(document).ready(function($) {
//$(this).children('a').attr('href', response.days[index].link);
if (response.days[index].events.length == 1) {
// If the day has events, give it a link
$(this).children('a').attr('href', response.days[index].events[0].permalink);
if(display_direct_link_to_event) {
$(this).children('a').attr('href', response.days[index].events[0].permalink);
}else {
$(this).children('a').attr('href', response.days[index].link);
}
} else if (response.days[index].events.length > 1) {
$(this).children('a').attr('href', response.days[index].link);
} else {
Expand Down