Разрешить доступ к странице только администраторам


Мне нужно знать, как создать шаблон страницы в WordPress, к которому могут получить доступ только администраторы. Как я могу применить его к следующему шаблону?

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

Я бы предпочел сделать это без плагинов.

Author: stealthyninja, 2012-11-17

1 answers

<?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();
?>
 3
Author: Johannes Pille, 2012-11-17 21:00:59