Created
June 12, 2015 15:25
-
-
Save pelmered/b73b40dd024d299ccf81 to your computer and use it in GitHub Desktop.
Allow template to override plugin templates
This file contains hidden or 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
function include_template( $template, $args = array() ) | |
{ | |
//Allow plugins to manipulate the tempalte data before sending it to the template | |
$data = apply_filters('prefix_template_data', $args, $template); | |
//Look in theme folder first, then plugin folder | |
if(locate_template($template) === '') | |
{ | |
include PREFIX_PLUGIN_PATH . 'templates/' . $template; | |
} | |
else | |
{ | |
include locate_template($template); | |
} | |
} | |
//Usage | |
$args = array( | |
'my' => 'template_data', | |
'foo' => 'bar' | |
) | |
$template_name = 'plugin-template-filename.php'; | |
include_template( $template, $args ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment