Short answer: I guess the problem of your code is the missing die();
as last line of doThemeRedirect
method.
After that, your code can be simplified a lot, using the template_include
filter hook instead of the template_redirect
action hook.
Simplify means reduce the chances of bugs, or at least, let recognization of them simpler.
public function __construct() {
add_filter( 'template_include', array( $this, 'uniThemeRedirect') );
}
public function uniThemeRedirect( $template ){
if( get_query_var('post_type') == 'videos' || (is_single() && get_post_type() == 'videos') ) {
// the 'single-videos.php' will be included for both
// single and archive view of CPT 'videos'
// to stop including for single view, remove
// (is_single() && get_post_type() == 'videos') ) from if condition
// to stop including for archive view, remove
// get_query_var('post_type') == 'videos' from if condition
$templateFilename="single-videos.php";
$locate = locate_template( $templateFilename );
if( $locate ) return $locate;
if( file_exists( user_trailingslashit(UNISLIDER_TEMPLATES) . $templateFilename ) )
return user_trailingslashit(UNISLIDER_TEMPLATES) . $templateFilename );
}
// die 'not working';
return $template;
}
So you don’t need the doThemeRedirect
method at all.
This code is simpler than your, but more powerful (it supports child themes where the yours doesn’t) and a bit more good-practised: there is no one global variable in it.