WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What action or filter do I have to check or compare against $pagenow?

In the admin area, I need to let non admin and editor users only to access:

index.php (dashboard)
upload.php (attachments management)
media.php (attachments management)
media-new.php (attachments management)

Thanks in advance.

share|improve this question
up vote 2 down vote accepted

that depends on if you want to redirect users away the you should use init hook since no output or headers are sent before that hook. or if you want to display a nice "You Don't have the right permissions to access this page" message then you can use the wp_head action hook:

//display meassage
function my_restrict_access_meassage(){
    global $pagenow;
    if ($pagenow == 'upload.php' && !current_user_can( 'upload_files' )){
        echo '<div class="wrap"><br />
            <div id="message" class="error">You Dont have the right permissions to access this page</div>
//or redirect
function my_restrict_redirect(){
    global $pagenow;
    if (!is_admin())
        return '';
    if ($pagenow == 'upload.php' && !current_user_can( 'upload_files' )){
        wp_redirect( home_url() );
share|improve this answer

I propose Members plugin. It allows you to create new user groups and define their access to each and almost every page in wp-admin. You can find it here: http://wordpress.org/extend/plugins/members/

share|improve this answer

Your Answer


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.