-
-
Save Pebblo/cf18ff686cca964193cbd8026c2c3379 to your computer and use it in GitHub Desktop.
This snippet loads custom templates defined in the $custom_templates array from a /templates/ directory in your plugin. Use this to override templates within EE that don't automatically search for custom templates.
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 | |
// This function allows you to load custom templates into Event Espresso for template that do not normally allow for it. | |
// If EE uses locate_template to load the template you can load it from your theme's root directory, if not use this. | |
function tw_ee_load_custom_templates( $template_path ) { | |
// Set the custom templates you want to override here. | |
$custom_templates = array( | |
'question_groups_main_meta_box.template.php', | |
); | |
// You could do this dynamically and pull all of the `*.template.php` files from the templates directory using glob. | |
// $custom_templates = glob($custom_templates_path . '*.template.php'); | |
// That will return an array of full paths to the files sound, so you then need to loop over for filenames. | |
//Grab the template name being pulled. | |
$template_name = basename( $template_path ); | |
// Set the custom template path for this plugin. | |
$custom_templates_path = plugin_dir_path(__FILE__) . 'templates/'; | |
// Check if we have a custom template for the current one. | |
if( in_array($template_name, $custom_templates) ) { | |
if( is_readable($custom_templates_path . $template_name) ) { | |
return $custom_templates_path . $template_name; | |
} | |
} | |
return $template_path; | |
} | |
add_filter('FHEE__EEH_Template__display_template__template_path', 'tw_ee_load_custom_templates'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment