独立したテンプレート(single-post_type_1.phpとsingle-post_type_2.php)にリダイレクトしてそれらの表示を処理したい2つのカスタム投稿タイプ(post_type_1とpost_type_2)があります。ディスプレイテンプレートをテーマフォルダーに配置したくないのは、それぞれのプラグインフォルダーに自己完結させたいためです。
他のユーザーに影響を与えることなく、それぞれにtemplate_redirectフックを登録させるにはどうすればよいですか?または、別のテクニックを使用する必要がありますか?
現在、私はプラグイン1でこれを行っています。
add_action( 'template_redirect', 'template_redirect_1' );
function template_redirect_1() {
global $wp_query;
global $wp;
if ( $wp_query->query_vars['post_type'] === 'post_type_1' ) {
if ( have_posts() )
{
include( PATH_TO_PLUGIN_1 . '/views/single-post_type_1.php' );
die();
}
else
{
$wp_query->is_404 = true;
}
}
}
そして、これはプラグイン2です。
add_action( 'template_redirect', 'template_redirect_2' );
function template_redirect_2() {
global $wp_query;
global $wp;
if ( $wp_query->query_vars['post_type'] === 'post_type_2' ) {
if ( have_posts() )
{
include( PATH_TO_PLUGIN_2 . '/views/single-post_type_2.php' );
die();
}
else
{
$wp_query->is_404 = true;
}
}
}
プラグイン2のtemplate_redirectフックを登録すると、プラグイン1は機能しなくなります。
何か不足していますか?
これを行う最良の方法は何ですか?