Hooks
Class Hooks
Source
File: src/Tribe/Views/V2/Hooks.php
class Hooks extends \tad_DI52_ServiceProvider {
/**
* Binds and sets up implementations.
*
* @since 4.9.2
*/
public function register() {
$this->container->tag( [
Event_Query_Controller::class,
], 'query_controllers' );
$this->add_actions();
$this->add_filters();
}
/**
* Adds the actions required by each Views v2 component.
*
* @since 4.9.2
*/
protected function add_actions() {
add_action( 'rest_api_init', [ $this, 'register_rest_endpoints' ] );
add_action( 'tribe_common_loaded', [ $this, 'on_tribe_common_loaded' ], 1 );
add_action( 'loop_start', [ $this, 'on_loop_start' ], PHP_INT_MAX );
add_action( 'wp_head', [ $this, 'on_wp_head' ], PHP_INT_MAX );
add_action( 'tribe_events_pre_rewrite', [ $this, 'on_tribe_events_pre_rewrite' ] );
}
/**
* Adds the filters required by each Views v2 component.
*
* @since 4.9.2
*/
protected function add_filters() {
// Let's make sure to suppress query filters from the main query.
add_filter( 'tribe_suppress_query_filters', '__return_true' );
add_filter( 'template_include', [ $this, 'filter_template_include' ], 50 );
add_filter( 'posts_pre_query', [ $this, 'filter_posts_pre_query' ], 20, 2 );
add_filter( 'body_class', [ $this, 'filter_body_class' ] );
add_filter( 'query_vars', [ $this, 'filter_query_vars' ], 15 );
}
/**
* Fires when common is loaded.
*
* @since 4.9.2
*/
public function on_tribe_common_loaded() {
$this->container->make( Template_Bootstrap::class )->disable_v1();
}
/**
* Fires when the loop starts.
*
* @since 4.9.2
*
* @param \WP_Query $query
*/
public function on_loop_start( \WP_Query $query ) {
$this->container->make( Template\Page::class )->maybe_hijack_page_template( $query );
}
/**
* Fires when WordPress head is printed.
*
* @since 4.9.2
*/
public function on_wp_head() {
$this->container->make( Template\Page::class )->maybe_hijack_main_query();
}
/**
* Fires when Tribe rewrite rules are processed.
*
* @since 4.9.2
*
* @param \Tribe__Events__Rewrite $rewrite An instance of the Tribe rewrite abstraction.
*/
public function on_tribe_events_pre_rewrite( Rewrite $rewrite ) {
$this->container->make( Kitchen_Sink::class )->generate_rules( $rewrite );
}
/**
* Filters the template included file.
*
* @since 4.9.2
*
* @param string $template The template included file, as found by WordPress.
*
* @return string The template file to include, depending on the query and settings.
*/
public function filter_template_include( $template ) {
return $this->container->make( Template_Bootstrap::class )
->filter_template_include( $template );
}
/**
* Registers the REST endpoints that will be used to return the Views HTML.
*
* @since 4.9.2
*/
public function register_rest_endpoints() {
register_rest_route( Service_Provider::NAME_SPACE, '/html', [
'methods' => \WP_REST_Server::READABLE,
/**
* @todo Make sure we do proper handling of cache longer then 12h.
*/
'permission_callback' => static function ( \WP_REST_Request $request ) {
return wp_verify_nonce( $request->get_param( '_wpnonce' ), 'wp_rest' );
},
'callback' => static function ( \WP_REST_Request $request ) {
View::make_for_rest( $request )->send_html();
},
'args' => [
'url' => [
'required' => true,
'validate_callback' => static function ( $url ) {
return is_string( $url );
},
'sanitize_callback' => static function ( $url ) {
return filter_var( $url, FILTER_SANITIZE_URL );
}
],
],
] );
}
/**
* Filters the posts before the query runs but after its SQL and arguments are finalized to
* inject posts in it, if needed.
*
* @since 4.9.2
*
* @param null|array $posts The posts to filter, a `null` value by default or an array if set by other methods.
* @param \WP_Query|null $query The query object to (maybe) control and whose posts will be populated.
*/
public function filter_posts_pre_query( $posts = null, \WP_Query $query = null ) {
foreach ( $this->container->tagged( 'query_controllers' ) as $controller ) {
/** @var Abstract_Query_Controller $controller */
$controller->inject_posts( $posts, $query );
}
}
/**
* Filters the publicly available query variables to add the ones supported by Views v2.
*
* To keep back-compatibility with v1 we're registering the same query vars making this method
* a copy of the original `Tribe__Events__Main::eventQueryVars` one.
*
* @since 4.9.2
*
* @param array $query_vars The list of publicly available query variables.
*
* @return array The filtered list of publicly available query variables.
*/
public function filter_query_vars( array $query_vars = [] ) {
$query_vars[] = 'eventDisplay';
$query_vars[] = 'eventDate';
$query_vars[] = 'eventSequence';
$query_vars[] = 'ical';
$query_vars[] = 'start_date';
$query_vars[] = 'end_date';
$query_vars[] = 'featured';
$query_vars[] = TEC::TAXONOMY;
$query_vars[] = 'tribe_remove_date_filters';
return $this->container->make( Kitchen_Sink::class )->filter_register_query_vars( $query_vars );
}
/**
* Filters the body classes to add theme compatibility ones.
*
* @since 4.9.3
*
* @param array $classes Classes that are been passed to the body.
*
* @return array $classes
*/
public function filter_body_class( $classes ) {
return $this->container->make( Theme_Compatibility::class )->filter_add_body_classes( $classes );
}
}
Changelog
| Version | Description |
|---|---|
| 4.9.2 | Introduced. |
Methods
- action_add_promo_banner — Include the promo banner after the after component.
- action_disable_assets_v1 — Fires to deregister v1 assets correctly.
- action_disable_shortcode_assets_v1 — Fires to deregister v1 assets correctly for shortcodes.
- action_include_filters_excerpt — Includes includes edge cases for filtering when we need to manually overwrite theme's read more link when excerpt is cut programmatically.
- action_initialize_legacy_views — Initializes the legacy Views for Single and Embed.
- action_save_wplang — Flush rewrite rules after the site language setting changes.
- action_set_title_events — This retrieves the posts to be used on the rendered page, and stores them for use in title generation.
- add_body_classes — Add body classes.
- add_period_repository — Adds the period repository to the map of available repositories.
- body_class_should_add_to_queue — Contains hooks to the logic for if this object's classes should be added to the queue.
- body_classes_should_add — Logic for if body classes should be added.
- customizer_inline_stylesheets — Add views stylesheets to customizer styles array to check.
- enqueue_customizer_in_block_editor — Enqueue Customizer styles for the single event block editor screen.
- filter_admin_post_thumbnail_html — Filters the `admin_post_thumbnail_html` to add image aspect ratio recommendation.
- filter_body_class — Filters the body classes to add theme compatibility ones.
- filter_body_classes — Filters the body classes to add theme compatibility ones.
- filter_date_escaping — Ensures that date formats are escaped properly.
- filter_document_title_parts — Filters the `wp_get_document_title` template tag.
- filter_events_properties — Updates and modifies the properties added to the event post object by the `tribe_get_event` function to hide some sensitive information, if required.
- filter_excerpt_length — Filters the `excerpt_length`.
- filter_excerpt_more — Filters the `excerpt_more`.
- filter_general_settings_tab_live_update — Modifies the Live update tooltip properly.
- filter_get_stylesheet_option — Filter the stylesheet option to do some switching for V2
- filter_live_filters_option_value — Filter the liveFiltersUpdate option to do some switching for V2.
- filter_map_canonical_query_args — Include the The Events calendar mapping for query args, into to canonical url.
- filter_posts_pre_query — Filters the posts before the query runs but after its SQL and arguments are finalized to inject posts in it, if needed.
- filter_query_vars — Filters the publicly available query variables to add the ones supported by Views v2.
- filter_redirect_canonical — Filters the `redirect_canonical` to prevent any redirects on embed URLs.
- filter_register_template_updates — Registers The Events Calendar with the views/overrides update checker.
- filter_rewrite_i18n_slugs_raw — Filters rewrite rules to modify and update them for Views V2.
- filter_single_event_details_event_website_label — Filter the website link label and change it for Single Event Classic Editor.
- filter_single_event_details_organizer_website_label — Filter the website link label and change it for Single Event Classic Editor.
- filter_single_event_details_venue_website_label — Filter the website link label and change it for Single Event Classic Editor.
- filter_system_information — Add the views v2 status in a more prominent way in the Troubleshooting page system info panel.
- filter_tec_events_noindex — Allow specific views to hook in and add their own calculated events.
- filter_tec_events_query_default_view
- 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 included file.
- filter_url_date_conflicts — Ensure we use the correct date on shortcodes.
- filter_view_month_today_button_label — Filters the Today button label to change the text to something appropriate for Week View.
- filter_view_month_today_button_title — Filters the Today button title and aria-label to change the text to something appropriate for Month View.
- filter_wp_title — Filters the `wp_title` template tag.
- filter_wp_title_plural_events_label — Filter the plural events label for Featured V2 Views.
- inject_ical_event_ids — Overrides the default iCalendar export link logic to inject a list of event post IDs fitting the Views V2 criteria.
- is_v1_or_blocks — Sugar function for the above that determines if the labels should be filtered.
- live_filters_maybe_convert — Converts old (boolean) values to the new string values.
- manage_sensitive_info — Fires to manage sensitive information on password protected posts.
- on_loop_start — Fires when the loop starts.
- on_template_redirect — Fires on the `template_redirect` action to allow the template bootstrap to conditionally redirect, if required.
- on_tribe_common_loaded — Fires when common is loaded.
- on_tribe_events_pre_rewrite — Fires when Tribe rewrite rules are processed.
- on_wp_head — Fires when WordPress head is printed.
- parse_query — Suppress v1 query filters on a per-query basis, if required.
- pre_get_document_title — Filters the `pre_get_document_title` to prevent conflicts when other plugins modify this initial value on our pages.
- print_inline_styles_in_footer — Changes the action the Customizer should use to try and print inline styles to print the inline styles in the footer.
- print_single_json_ld — Print Single Event JSON-LD.
- register — Binds and sets up implementations.
- register_rest_endpoints — Registers the REST endpoints that will be used to return the Views HTML.
- unregister — Unregisters all the filters and action handled by the class.