Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need to know how to make a page template in WordPress that can only be accessed by admins. How could I apply it to the following template?

<?php /*
Template Name: Agency Area
*/
?>
<?php get_header(); ?>

<div id="body">
    <div class="agency_area_menu">
        <?php wp_nav_menu(); ?>
    </div>
</div>

<?php get_footer(); ?>

I'd prefer to do it without plugins.

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted
<?php
/*
Template Name: Agency Area
*/
get_header();

echo '<div id="body">';

    global $current_user;

    if( in_array( 'administrator', $current_user->roles ) ) {
        echo '<div class="agency_area_menu">';
            wp_nav_menu();
        echo '</div>';
    } else {
        // echo '<p>You do not have the rights required to view this page. Sorry.</p>';
        /* or with internationalization
           (uncomment either, adjust text domain if applicable) */
        echo '<p>' .
            __(
                'You do not have the rights required to view this page. Sorry.',
                'theme-text-domain'
            ) .
            '</p>';
    }

echo '</div>';

get_footer();
?>
share|improve this answer
    
thank you for your answer but i need a log in form to appear once he opens the page if he logged in successfully the page would appear if not 'else' and thanks again –  Faisal Abu Jabal Nov 17 '12 at 21:11
    
Adjust the content of the conditional accordingly... –  Johannes Pille Nov 17 '12 at 21:17
    
it worked i added wp_login_form after the else function –  Faisal Abu Jabal Nov 17 '12 at 21:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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