Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Last active February 8, 2022 00:11
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cliffordp/39e68939132bd0f483e0111972165455 to your computer and use it in GitHub Desktop.
Save cliffordp/39e68939132bd0f483e0111972165455 to your computer and use it in GitHub Desktop.
Override The Events Calendar's V2 Views from a custom plugin location
<?php
/**
* Add your own plugin as a template override location for The Events Calendar, Event Tickets, and related plugins. Only
* for TEC's V2 Views and ET's addons/overrides of TEC's V2 Views. Still need the old snippet for overriding ET's files.
*
* Each custom array's `path` is whatever you want it to be (i.e. customizable) up until the 'v2' part of each
* template's override path. We chose to keep it as `tribe/events` and `tribe/tickets` for simplicity.
* So if the TEC location for a view is:
* /wp-content/plugins/the-events-calendar/src/views/v2/list/event/featured-image.php
* Then this plugin's override location would be:
* /wp-content/plugins/MY-PLUGIN/tribe/events/list/event/featured-image.php
* And the theme's override location would be:
* /wp-content/themes/YOUR-CHILD-THEME/tribe/events/v2/list/event/featured-image.php
* FYI: Parent/Child Themes will override this custom plugin's override. Use your own custom code with the
* `tribe_template_theme_path_list` filter instead of this snippet to trump theme overrides if you must, but that is not
* typical best practice, although it may be necessary in order to override a theme that comes with V2 Views overrides
* (e.g. Avada) that you want to override.
*
* @link https://gist.github.com/cliffordp/39e68939132bd0f483e0111972165455 This snippet is only for V2 Views.
* @link https://gist.github.com/b76421f2490a8b8995493f203e11b331 Similar functionality for pre-TEC v5.x (not V2 views) or for ET.
* @link https://theeventscalendar.com/knowledgebase/k/custom-additional-template-locations/ Official article with all the details.
*
* @see \Tribe__Template::get_template_path_list()
*
* @param array $folders Array of data for loading locations.
*
* @return array
*/
function tribe_v2_additional_plugin_template_locations( $folders ) {
// Example: /app/public/wp-content/plugins/my-plugin/tribe/
$my_base_path = trailingslashit( plugin_dir_path( __FILE__ ) . 'tribe' );
/*
* Custom loading location for overriding The Events Calendar's templates from within this plugin.
*/
$folders['my_plugin_tec'] = [
'id' => 'my_plugin_tec',
'priority' => 5, // TEC is 20, ET is 17, so do something earlier, like 5
'path' => $my_base_path . 'events', // Example: /app/public/wp-content/plugins/my-plugin/tribe/events
];
/*
* Custom loading location for overriding Event Tickets' addons/overrides for TEC's v2 views.
* Still need to use the old/non-v2 snippet to override ET's other template files.
*/
$folders['my_plugin_et'] = [
'id' => 'my_plugin_et',
'priority' => 5, // TEC is 20, ET is 17, so do something earlier, like 5
'path' => $my_base_path . 'tickets', // Example: /app/public/wp-content/plugins/my-plugin/tribe/tickets
];
return $folders;
}
add_filter( 'tribe_template_path_list', 'tribe_v2_additional_plugin_template_locations' );
@djouonang
Copy link

djouonang commented Dec 15, 2021

Hi clifforp. I really need your help. i have followed your tutorial above and it works fine except for the events calendar pro override. This is my code:

function load_template_plugin($folders, string $template ) {

/*
 * Custom loading location for overriding The Events Calendar's templates from within the deltec plugin
 */
$folders['theevent_calendar_addon'] = [
  'id'       => 'theevent_calendar_addon',
  'priority' => 1, // The Event Calendar is 20, Event Tickets is 17
  'path'     =>  EVENTCALENDAR_DIR . 'tribe/events/v2', 
];

$folders['theevent_calendar_addon_pro'] = [
'id' => 'theevent_calendar_addon_pro',
'priority' => 5, // The Event Calendar is 20, Event Tickets is 17
'path' => EVENTCALENDAR_DIR . 'tribe/events-pro/v2',
];

return $folders;

}

add_filter( 'tribe_template_theme_path_list', 'load_template_plugin', 10, 2 );

when i copy the folder to the theme the events pro works. but i dont seem to see what i am doing wrong with my plugin

@cliffordp
Copy link
Author

@djouonang - as previously stated, you need to contact https://support.theeventscalendar.com/ for additional requests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment