I’m working on a plugin that creates a custom post type and I would like to display a custom template without modifying the theme.
Here’s the simplified code I’m working with:
add_filter('template_include', 'my_custom_template');
function my_custom_template($incFile) {
global $wp;
global $wp_query;
if ($wp->query_vars['post_type'] == 'custom-post-type') {
$incFile = MY_PLUGIN_TEMPLATES . '/template.php';
}
return $incFile;
}
The problem I’m running into is that when allow_url_include is turned off in a server’s php.ini file, this throws a fun little error:
Warning: include() [function.include]: http:// wrapper is disabled in the server configuration by allow_url_include=0 in http://pathtowp-includestemplate-loader.php on line 43
So I guess the question is, is there a way to send a template through the template_include filter without triggering this allow_url_include error?
Thanks!
Wouldn’t ya know – 10 minutes or less since I asked my question and I’ve discovered the answer.
I was attempting to define MY_PLUGIN_TEMPLATES using using plugins_dir_url(), now it looks like this and is working:
Thanks to mfields for the suggestion of dirname instead of WP_PLUGIN_DIR.