1

I've searched all day for this and couldn't find a plugin that allow me to restrict the access to specific pages in the wp-admin backed by user role.

Example: I have several users on my website and I want them to only see the pages that they are allowed to edit. I've done this manually by code and it's working (see code below), but I wanted a plugin that allowed me to the same thing.

Why? Because I have a support team that manages the site and they can't code. Every time I need to add a page or allow someone else on some page I need to manually go there and edit that file.

The closest I came to a solution was the Pages by User Role plugin, on CodeCanyon, but it doesn't work on the backend. Something similar that works on the backend would be great.

if(current_user_can('custom-editor')){
    function allowed_pages_custom_e($query) {
        global $pagenow,$post_type;
        if (is_admin() && $pagenow=='edit.php' && $post_type =='page') {
            $query->query_vars['post__in'] = array('11678');
        }
    }
    add_filter( 'parse_query', 'allowed_pages_custom_e' );
}
  • Ultimate member might be a better choice to go with – Aniket Sahrawat Oct 16 '16 at 1:46
  • I'd prefer if it wouldn't be a plugin. – bfagundes Oct 21 '16 at 13:15
  • My answer was UM because you have mentioned that you couldn't find a plugin that allow to restrict pages by User Role. Check the answer section, i have written some code for you. – Aniket Sahrawat Oct 26 '16 at 9:51
1
if( is_admin() ) {
    add_filter( 'init', 'custom_restrict_pages_from_admin' );
}

function custom_restrict_pages_from_admin() {
    global $pagenow;

    $arr = array(
        'update-core.php',
        'edit.php'
    );

    if( custom_check_user_roles() && in_array( $arr , $pagenow ) ) {
        //echo some custom messages or call the functions 
    } else {
        echo 'This page has restricted access to specific roles';
        wp_die();
    }
}

function custom_check_user_roles() {
    //restrict pages by user role 

    if( current_user_can( 'administrator' ) || current_user_can( 'editor' ) ) 
         return true;
    else { 
        echo 'Not allowed!'; 
        wp_die();
    }
}
0

Use Advanced Access Manager ( https://wordpress.org/plugins/advanced-access-manager/ ) Plugin to restrict users in backend according to their roles....

I thing this will be a better solution for your issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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