I am currently writing a custom theme for my rugby team. As part of the theme, there is a ‘player’s area’.

The code to setup the restriction on certain pages works like this:

functions.php

$guest_player_perms = array(
... a lot more permissions ...
   'view_players_area' => true
);
add_role(
   'guest_player',
   'Guest Player',
   $guest_player_perms
);

top of archive-player-page.php (and a bunch of other templates)

<?php if ( ! current_user_can ('view_players_area') ) 
           { include_once ( 'noaccess-player.php' ); exit; } ?>

Now my problem is that every once in a while, the above code snippet fails to work. The if statement executes regardless of the fact that I KNOW I am logged in and the administrator user also has that permission. I get irate and start changing stuff, then it works again.

Anybody have any clue what is going on? It is driving me crazy…

Read more here: Problem with members area using current_user_can and a custom capability


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , , ,

Wordpress related questions and answers: