Restrict admin access to certain pages for certain users

As the title says, I’d like to restrict back-end access to certain pages for certain users.

While doing a site with 45-50 pages, I realised it would be a much better user experience if the Page menu only listed those pages which the user should be able to change/update.

I’ve tried the plugins below to no avail. Advanced access manager has the functionality but does not work/is buggy on 3.5.1.

http://wordpress.org/extend/plugins/advanced-access-manager
http://wordpress.org/extend/plugins/role-scoper
http://wordpress.org/extend/plugins/adminimize
http://wordpress.org/extend/plugins/s2member

Code snippet in functions.php?

2 s
2

This code seems to work well for me (in functions.php):

$user_id = get_current_user_id();
if ($user_id == 2) {
    add_filter( 'parse_query', 'exclude_pages_from_admin' );
}

function exclude_pages_from_admin($query) {
    global $pagenow,$post_type;
    if (is_admin() && $pagenow=='edit.php' && $post_type =='page') {
        $query->query_vars['post__not_in'] = array('123','234','345');
    }
}

Leave a Comment