-
-
Save cliffordp/39e68939132bd0f483e0111972165455 to your computer and use it in GitHub Desktop.
<?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' ); |
Hello and thanks for that snippet, it works great !
However, I'm trying to customize the single event template and its meta template files. The file I wanted to edit is details.php which is on modules folder ( /src/views/modules/meta/details.php ),
Do you know if there is a way to do that because your snippet seems to only target files which are in v2 folder ?
Thank you !
Glad to help, but you'll have to contact https://support.theeventscalendar.com/ for additional requests.
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
@djouonang - as previously stated, you need to contact https://support.theeventscalendar.com/ for additional requests
Glad to help! 😺