Restrict user access to specific templates
wordpress snippet
This is a slight modification of a great little snippet by Elliott Richmond I just changed “include” to “get_template_part”. Create a new template file and drop in this snippet and you can restrict user access to this template. Don’t forget to change the template name at the top. You will of course also need to create a template file called error.php or the other option is to use something like “wp_die(‘You don’t have access.’)” instead of loading a template.
snippet : PHPcopy
<?php
/* Template Name: Restricted to Authors only */
if ( !current_user_can('author')) {
get_template_part('error');
exit(0);
}
?>
this months featured snippets
- http://www.squareonemd.co.uk Elliott the web design guy
- http://wpsnipp.com Kevin Chard
- http://www.cliffpaulick.com Cliff Paulick
- http://wpsnipp.com Kevin Chard






