This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Tahoearthauscinema\Theater\Calendar; | |
// Change days header. | |
function change_days_header( $html ) { | |
global $wp_locale; | |
$start_of_week = get_option( 'start_of_week' ); | |
$html_dom = new \DOMDocument(); | |
$html_dom->loadHtml( $html ); | |
$theads = $html_dom->getElementsByTagName( 'thead' ); | |
foreach( $theads as $thead ) { | |
$row = $thead->getElementsByTagName( 'tr' )[ 0 ]; | |
while ( $row->hasChildNodes() ) { | |
$row->removeChild( $row->firstChild ); | |
} | |
for( $i=0; $i < 7; $i++) { | |
$day_timestamp = strtotime( sprintf( 'next Sunday + %d days', $start_of_week + $i ) ); | |
$day = $html_dom->createElement( | |
'th', | |
date_i18n( 'l', $day_timestamp ) | |
); | |
$row->appendChild( $day ); | |
} | |
} | |
$html = $html_dom->saveHtml(); | |
return $html; | |
} | |
add_filter( 'wpt_calendar_html', __NAMESPACE__.'\change_days_header' ); | |
// Remove day links. | |
function remove_day_links( $day_link, $day, $day_url, $day_label, $events ) { | |
ob_start(); | |
?><div class="day_label"><?php echo $day_label; ?></div><?php | |
return ob_get_clean(); | |
} | |
add_filter( 'wpt_calendar_html_day_link', __NAMESPACE__.'\remove_day_links', 10, 5 ); | |
// Add movie titles. | |
function add_movie_titles( $day_link, $day, $day_url, $day_label, $events ) { | |
if ( empty( $events ) ) { | |
return $day_link; | |
} | |
ob_start(); | |
?><div class="day_events"><?php | |
foreach( $events as $event ) { | |
?><div class="day_event"><?php | |
echo $event->starttime_html(); | |
echo $event->title( array( 'html' => true ) ); | |
?><div class="more_info"><a href="<?php echo $event->permalink(); ?>">More info</a></div><?php | |
echo $event->tickets_html(); | |
?></div><?php | |
} | |
return $day_link.ob_get_clean(); | |
} | |
add_filter( 'wpt_calendar_html_day_link', __NAMESPACE__.'\add_movie_titles', 11, 5 ); | |
/** | |
* Output a celandar with support for past events. | |
* | |
* @since 4.0 | |
* @return string | |
*/ | |
function get_calendar_html( ) { | |
global $wp_theatre; | |
$args = array( | |
'start' => '-10 years', | |
); | |
return $wp_theatre->calendar->html( $args ); | |
} | |
add_shortcode( 'Tahoearthauscinema_Calendar', __NAMESPACE__.'\get_calendar_html' ); | |
function set_active_month( $html, $month ) { | |
$current_month = \wp_date( 'Y-m' ); | |
if ( $month == $current_month ) { | |
$html = str_replace( '"wpt_month"', '"wpt_month active"', $html ); | |
} else { | |
$html = str_replace( '"wpt_month active"', '"wpt_month"', $html ); | |
} | |
return $html; | |
} | |
add_filter( 'wpt_calendar_html_month', __NAMESPACE__.'\set_active_month', 10, 2 ); | |
/** | |
* Shows past events in the calendar. | |
* | |
* Changes the HTML of a day in the calendar, because by default the calendar only shows upcoming events. | |
* | |
* @since 4.0 | |
* @return string | |
*/ | |
function show_past_movies( $html, $day, $events ) { | |
if ( !empty( $events ) ) { | |
return $html; | |
} | |
// Bail if current day is not in the active month. | |
if ( strpos( $html, '"trailing"' ) !== false ) { | |
return $html; | |
} | |
if ( date( 'Ymd', strtotime( $day ) ) < \wp_date( 'Ymd' ) ) { | |
$past_events = get_past_events_per_day(); | |
if ( !empty( $past_events[ $day ] ) ) { | |
ob_start(); | |
?><td><?php | |
echo remove_day_links( '', '', '', substr( $day, 8, 2), false ); | |
echo add_movie_titles( '', '', '', '', $past_events[ $day ] ); | |
?></td><?php | |
$html = ob_get_clean(); | |
} | |
} | |
return $html; | |
} | |
add_filter( 'wpt_calendar_html_day', __NAMESPACE__.'\show_past_movies', 10, 3 ); | |
/** | |
* Gets all past events, grouped by day. | |
* | |
* @since 4.0 | |
* @return array | |
*/ | |
function get_past_events_per_day() { | |
$past_events_per_day = wp_cache_get( 'past_events_per_day' ); | |
if ( false === $past_events_per_day ) { | |
global $wp_theatre; | |
$args = array( | |
'groupby' => 'day', | |
'end' => 'now', | |
); | |
$past_events = $wp_theatre->events->get( $args ) ; | |
$past_events_per_day = array(); | |
foreach ( $past_events as $past_event ) { | |
$day = \wp_date( 'Y-m-d', $past_event->datetime() ); | |
if ( empty( $past_events_per_day[ $day ] ) ) { | |
$past_events_per_day[ $day ] = array(); | |
} | |
$past_events_per_day[ $day ][] = $past_event; | |
} | |
wp_cache_set( 'past_events_per_day', $past_events_per_day ); | |
} | |
return $past_events_per_day; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Tahoearthauscinema\Theater\Excerpt; | |
/* | |
* Only show custom excerpts, no auto generated excerpt. | |
* | |
* since 3.0 | |
* @param string $excerpt The current excerpt. | |
* @param WPT_Production $production The production. | |
* @return string The updated excerpt. | |
*/ | |
function block_auto_excerpts($excerpt, $production) { | |
if ( empty( $production->post()->post_excerpt ) ) { | |
$excerpt = ''; | |
} | |
return $excerpt; | |
} | |
add_filter('wpt_production_excerpt', __NAMESPACE__.'\block_auto_excerpts', 10, 2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Tahoe City Art House and Cinema - Theater customizations | |
Version: 6.0 | |
Description: Custom functionality for use with the Theater for WordPress plugin | |
Author: Jeroen Schmit | |
Author URI: https://slimndap.com | |
Plugin URI: https://gist.github.com/slimndap/c08d85216621420137f5d551c35cf701 | |
*/ | |
namespace Tahoearthauscinema\Theater; | |
include_once( 'calendar.php' ); | |
include_once( 'excerpt.php' ); | |
include_once( 'venue.php' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Tahoearthauscinema\Theater\Venue; | |
/** | |
* Adds venue and city filters to the default options for event listings. | |
* | |
* @param array $defaults The current defaults. | |
* @return array The defaults with venue and city added. | |
*/ | |
function add_venue_filter_to_events($defaults) { | |
$defaults['venue'] = false; | |
return $defaults; | |
} | |
add_filter( 'wpt/frontend/shortcode/events/defaults', __NAMESPACE__.'\add_venue_filter_to_events', 10 ); | |
add_filter( 'wpt/events/get/defaults', __NAMESPACE__.'\add_venue_filter_to_events', 10 ); | |
/** | |
* Adds venue and city meta_queries to event query args. | |
* | |
* @param array $args The current event query args. | |
* @param array $filters The filters for this listing. | |
* @return array The new event query args. | |
*/ | |
function add_venue_filter_events_query($args, $filters) { | |
if ( $filters['venue'] ) { | |
$args['meta_query'][] = array( | |
'key' => 'venue', | |
'value' => $filters[ 'venue' ], | |
); | |
} | |
return $args; | |
} | |
add_filter( 'wpt/events/get/args', __NAMESPACE__.'\add_venue_filter_events_query', 10, 2 ); | |
function add_venue_shortcode_atts( $out, $pairs, $atts, $shortcode ) { | |
if ( empty( $atts[ 'venue' ] ) ) { | |
return $out; | |
} | |
global $wp_theatre; | |
$events_args = array( | |
'venue' => $atts[ 'venue' ], | |
); | |
$events = $wp_theatre->events->get( $events_args ); | |
$post__in = array(); | |
if ( empty( $events ) ) { | |
$post__in = array( -1 ); | |
} else { | |
foreach( $events as $event ) { | |
if ( $production = $event->get_production() ) { | |
$post__in[] = $event->get_production()->ID; | |
} | |
} | |
} | |
$out[ 'post__in' ] = implode( ',', $post__in ); | |
return $out; | |
} | |
add_filter( 'shortcode_atts_wpt_productions', __NAMESPACE__.'\add_venue_shortcode_atts', 10, 4 ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment