Template_Bootstrap
Class Template_Bootstrap
Source
File: src/Tribe/Views/V2/Template_Bootstrap.php
class Template_Bootstrap {
/**
* Disables the Views V1 implementation of a Template Hijack
*
* @todo use a better method to remove Views V1 from been initialized
*
* @since 4.9.2
*
* @return void
*/
public function disable_v1() {
remove_action( 'plugins_loaded', [ 'Tribe__Events__Templates', 'init' ] );
}
/**
* Determines with backwards compatibility in mind, which template user has selected
* on the Events > Settings page as their base Default template
*
* @since 4.9.2
*
* @return string Either 'event' or 'page' based templates
*/
public function get_template_setting() {
$template = 'event';
$default_value = 'default';
$setting = tribe_get_option( 'tribeEventsTemplate', $default_value );
if ( $default_value === $setting ) {
$template = 'page';
}
return $template;
}
/**
* Based on the base template setting we fetch the respective object
* to handle the inclusion of the main file.
*
* @since 4.9.2
*
* @return object
*/
public function get_template_object() {
$setting = $this->get_template_setting();
return $setting === 'page'
? tribe( Template\Page::class )
: tribe( Template\Event::class );
}
/**
* Gets the View HTML
*
* @todo Stop handling kitchen sink template here.
*
* @since 4.9.2
*
* @return string
*/
public function get_view_html() {
$query = tribe_get_global_query_object();
if ( isset( $query->query_vars['tribe_events_views_kitchen_sink'] ) ) {
$context = [
'query' => $query,
];
/**
* @todo Replace with actual code for view and move this to correct kitchen sink
*/
$template = Arr::get( $context['query']->query_vars, 'tribe_events_views_kitchen_sink', 'page' );
if ( ! in_array( $template, tribe( Kitchen_Sink::class )->get_available_pages() ) ) {
$template = 'page';
}
$html = tribe( Kitchen_Sink::class )->template( $template, $context, false );
} else {
$context = tribe_context();
$view_slug = $context->get( 'view' );
$html = View::make( $view_slug, $context )->get_html();
}
return $html;
}
/**
* Determines when we should bootstrap the template for The Events Calendar
*
* @since 4.9.2
*
* @param WP_Query $query Which WP_Query object we are going to load on
*
* @return boolean
*/
public function should_load( $query = null ) {
if ( ! $query instanceof WP_Query ) {
$query = tribe_get_global_query_object();
}
if ( ! $query instanceof WP_Query ) {
return false;
}
/**
* Bail if we are not dealing with our Post Type
*
* @todo needs support for Venues and Template
*/
if ( ! in_array( TEC::POSTTYPE, (array) $query->get( 'post_type' ) ) ) {
return false;
}
return true;
}
/**
* Filters the `template_include` filter to return the Views router template if required..
*
* @since 4.9.2
*
* @param string $template The template located by WordPress.
*
* @return string Path to the File that initalizes the template
*/
public function filter_template_include( $template ) {
// Determine if we should load bootstrap or bail.
if ( ! $this->should_load() ) {
return $template;
}
return $this->get_template_object()->get_path();
}
}
Changelog
| Version | Description |
|---|---|
| 4.9.2 | Introduced. |
Methods
- __construct — Template_Bootstrap constructor.
- add_body_classes — Add body classes.
- context_view_as_single_event — Sets the current view context to `single-event` for the legacy view system.
- disable_v1 — Disables the Views V1 implementation of a Template Hijack
- filter_add_body_classes — Set the correct body classes for our plugin.
- filter_template_file — Filter the template file in case we're in single event and we need to use the theme overrides.
- filter_template_include — Filters the `template_include` filter to return the Views router template if required.
- get_template_object — Based on the admin template setting we fetch the respective object to handle the inclusion of the main file.
- get_template_setting — Determines, with backwards compatibility in mind, which template user has selected on the Events > Settings page as their base Default template.
- get_view_html — Gets the View HTML
- is_single_event — Determines whether we are in a Single event page or not, base only on global context.
- on_template_redirect — Redirects the user to the default mobile view if required.
- should_add_body_class_to_queue — Contains the logic for if this object's classes should be added to the queue.
- should_load — Determines when we should bootstrap the template for The Events Calendar