Hello - just started using roots. Very cool. Am working on a plugin that has it’s own template_include
call based on a custom rewrite_url and and query variable to display content.
I want to be able to pass my content variables through to the resulting template for formatting. The method I have been employing works in other themes, but it breaks in roots (because of the Theme Wrapper, I would assume).
What’s the best way I can either fix my plugin to work or fix my roots to work ?
Here is what I mean:
<?php
function content_template( $template ) {
global $wp_query;
if (isset($wp_query->query_vars['contentid'])) {
$testvariable = 'this is a test variable';
$new_template = locate_template( array( 'template-custom.php' ) );
if ( '' != $new_template ) {
// if I use include here, other themes work fine and I can
// access the $testvariable
include(locate_template( array( 'template-custom.php' ) ) );
// however, with roots, I have to use:
return $new_template;
// which means the $testvariable is missing
} else {
// display a bioler plate if the user hasn't set a themed
// template file yet
include(dirname(__FILE__) . '/template.php');
}
exit;
}
return $template;
}
Appreciate your help. I could use a global $myclass; $myclass = new MyClass();
but I keep reading globals are bad. Then again, Wordpress uses them a lot.