私は自分のサイトの権限を管理するためにMembersプラグインを使います。標準的なテンプレートの場合、それはとてもうまくいきます - ユーザがページを見る許可を持っていないとき、彼らは以下のメッセージを受け取ります:
申し訳ありませんが、このコンテンツを閲覧する権限がありません。
カスタムテンプレートでこのメッセージがまだ表示されるようにするにはどうすればよいですか。どのタグを含める必要がありますか?
編集。テンプレートのソース:
<?php
/*
Template Name: Stats
*/
?>
<?php
get_header();
?>
<div id="main">
<div id="contentwrapper">
<div class="topPost">
<h2 class="topTitle"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
<div class="topContent">
<p>Listeners are counted every minute. The green line is the <b>maximum</b> during any given time period. The red area is the <b>average</b> number of listeners during the same time period.</p>
<h3>Listeners over the last hour</h3>
<img class="alignnone" title="Listeners over the last hour" src="<?php echo get_graph(60,60); ?>" alt="" width="481" height="149" />
<hr/>
<h3>Listeners over the last day</h3>
<img class="alignnone" title="Listeners over the last day" src="<?php echo get_graph(3600,24); ?>" alt="" width="481" height="149" />
<hr/>
<h3>Listeners over the last week</h3>
<img class="alignnone" title="Listeners over the last week" src="<?php echo get_graph(86400,7); ?>" alt="" width="481" height="149" />
</div>
<div class="cleared"></div>
<div class="cleared"></div>
</div> <!-- Closes topPost -->
</div> <!-- Closes contentwrapper-->
<?php get_sidebar(); ?>
<div class="cleared"></div>
</div><!-- Closes Main -->
<?php get_footer(); ?>
注:このテンプレートの目的は、シェルスクリプトのフロントエンドとして機能することです。データベース上のコンテンツは無関係なので、ループはありません。 (ただし、ダミーループを含めることは役に立ちませんでした。)
あなたが引用したメッセージはmembers_content_permissions_protect()
関数によって生成されています。デフォルトではthe_content()
とthe_excerpt()
関数のフィルタとして使われます。あなたのカスタムテンプレートはこれらを使用しないので - functionが実行されるケースはありません。
テンプレートでこのようなことを試してください。
$content = 'Content to protect';
echo members_content_permissions_protect( $content );
もう一つのアイデア:
$protected = members_content_permissions_protect( false );
if( false !== $protected ) {
echo $protected;
}
else {
//template stuff goes here
}
ユーザレベルシステムを使用することができます、あなたはここで役割レベルと能力に関するより多くの情報を見つけることができます:
http://codex.wordpress.org/Roles_and_Capabilities
古い「ロール」がどのようにユーザーレベルシステムにマップされるかについては、こちらを参照してください。
http://codex.wordpress.org/Roles_and_Capabilities#User_Levels
与えられたロールのユーザがページを閲覧できるかどうか、あるいは以下を使用しない限り、テンプレートでさらに定義することができます。
global $current_user;
get_currentuserinfo();
if ($current_user->user_level < 8) {
// stuff that is only visible to users lower than level 8
}
また覚えておいてください:
if ( is_user_logged_in() ) { ... }
http://codex.wordpress.org/Function_Reference/is_user_logged_in
これらを使用することで、誰が何を見ることができ、誰がどのレベルのアクセス権でそれを見ることができるかを制御できるようになります。