I use the Members plugin to manage permissions on my site. For standard templates, it works great - when the user doesn't have permission to see a page, they get the following message:

Sorry, but you do not have permission to view this content.

How can I make sure I still get this message in my custom templates? Which tag do I need to include?

EDIT. Template source:

Template Name: Stats


<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" />
      <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" />
      <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 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(); ?>

Note: The purpose of this template is to act as a front end for a shell script. Any content on the database is irrelevant, so there's no loop. (Though including a dummy loop didn't seem to help.)

  • 1
    Please add the template tags you use in your custom template to your question.
    – hakre
    Sep 16, 2010 at 21:28
  • I've added the whole source for your enjoyment.
    – Tom Wright
    Sep 17, 2010 at 11:14

2 Answers 2


Message you quoted is being generated by members_content_permissions_protect() function. By default it is used as a filter on the_content() and the_excerpt() functions. Since your custom template doesn't use these - there is no case for function to run.

Try something like this in template:

$content = 'Content to protect';
echo members_content_permissions_protect( $content );

Another idea:

$protected = members_content_permissions_protect( false );

if( false !== $protected ) {

    echo $protected;
else {

    //template stuff goes here
  • 1
    That's basically why I asked which template tags are in use (or not). I already suspected something like that.
    – hakre
    Sep 17, 2010 at 12:47
  • This gives me the right message, but doesn't hide the contents of the template. Is there a conditional form? Or will I have to convert my template to a PHP string?
    – Tom Wright
    Sep 17, 2010 at 23:33
  • You will have to convert template to a PHP string, at least for my example. I suggest you ask plugin's developer for recommended usage to protect non-loop content.
    – Rarst
    Sep 18, 2010 at 7:41
  • Got another idea for a snippet, see my answer. But suggestion to check with developer still stands.
    – Rarst
    Sep 18, 2010 at 8:03

You can use the userlevels system, youc an find more information on roles levels and capabilities here:


See here for how the old 'roles' map onto the user levels system:


You can further define in your templates wether a user of a given role can view a page or not using the following:

global $current_user;


if ($current_user->user_level < 8) {
    // stuff that is only visible to users lower than level 8

Also bear in mind:

if ( is_user_logged_in() ) { ... }


Using these you should be able to control who can see what, and at what level of access they need to see it

  • Numerical User Levels tend to out-date. I don't think it's a god advise to use them. Next to that, if the proper template tags are used, you can safe all the hassle to code some logic on your own.
    – hakre
    Sep 17, 2010 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.