Viewing 15 posts - 1 through 15 (of 23 total)
  • Author
    Posts
  • #906
    StevenJGood
    Participant

    I have seen that I am able to restrict users from editing pages by entering the ID when editing a specific user, but I need to restrict page editing access by user role.

    Is it possible to restrict editing of specific posts by user role?

    #907
    Vladimir
    Keymaster

    1) Select needed role.
    2) Input ‘pages’ to the ‘Quick Filter’ field. All user capabilities related to the ‘pages’ will be selected.
    3) Unselect them all.
    4) Update role.
    Users with this role will not have access to adding/editing/deleting any pages.

    #911
    StevenJGood
    Participant

    Sorry, I think I was unclear. I know that I am able to restrict access to adding/editing/deleting all pages. I am trying to restrict the ability to edit/delete specific pages by user role.

    Example: Editor role can add/edit/delete pages but cannot edit/delete “About” and “Join” pages.

    Is this possible?

    #958
    Vladimir
    Keymaster

    Sorry, that was my fault. I did not pay attention on the word ‘specific’ at your 1st message.
    Current version does not include the interface to restrict editing posts/pages by role. It is good feature request and I will add this functionality to Pro version with time.
    Now you may use this piece of code to prohibit your users with ‘editor’ role access to the list of pages:

    if (is_blog_admin() && current_user_can('editor')) {
        add_action('pre_get_posts', 'restrict_posts_list');
        function restrict_posts_list($query) {
    
                $suppressing_filters = $query->get('suppress_filters'); // Filter suppression on?
    
                if ($suppressing_filters) {
                    return query;
                }
    
    
                if ($query->query['post_type']=='page') {            
                    $posts_restriction_type = 2; // Prohibit
                    $posts_list = array(442, 484);   // comma separated list of pages IDs
                    if ($posts_restriction_type==1) {   // Allow
                        $query->set('post__in', $posts_list);
                    } else {    // Prohibit
                        $query->set('post__not_in', $posts_list);
                    }
                }
    
                return $query;
        }
        // restrict_posts_list()
    }
    

    Replace pages ID at $posts_list array and add this code to your active theme functions.php file.

    #1246
    JJSpringer
    Spectator

    This ability would be useful for me, as well. I need to have certain users be able to only edit certain pages.

    #1247
    Vladimir
    Keymaster

    @JJSpringer: Thanks for letting me know. This feature will be available until the end of this year.

    #1584
    oopgo
    Participant

    Is this feature available now? We are looking same type of functionality. If this is not available then can you please let us know where we need to add your code which you have provided in this thread.

    #1585
    Vladimir
    Keymaster

    It is possible to set posts/pages edit restrictions for selected users:
    https://www.role-editor.com/allow-user-edit-selected-posts/
    Plugin still does not support such restrictions for the roles.

    You may insert the provided code into your active theme functions.php file.

    #1697
    AntKat
    Spectator

    Hi Vladimir, I too am looking for the restrict pages by user role. +1 for this feature.

    #1698
    Vladimir
    Keymaster

    Hi,

    Thanks for letting me know. I will add it.

    #1709
    AntKat
    Spectator

    Vladimir,
    How might this work on a multisite with replicated content? We provide template websites where all sites have a set of pages (we use mirroring so that we can globally change these specific pages). We do not want anyone except super-admin to edit these pages but once created, individual sites can add more pages. So I can see that the code above would initially work across the network because the page IDs of the original blog template will be the same.

    However, wouldn’t this be a problem in the future if we ever wanted to add new mirrored pages across the network because the page IDs for all of the sites will not be the same if some sites add their own pages.

    Could the code be written to use slugs rather than IDs?

    #1711
    Vladimir
    Keymaster

    AntKat,
    This is a version of code modified to work with a list of pages slugs:

    
    add_action('pre_get_posts', 'restrict_posts_list');
    
    function restrict_posts_list($query) {
    
        if ( !(is_blog_admin() && current_user_can('editor')) ) {
            return $query;
        }
        $suppressing_filters = $query->get('suppress_filters'); // Filter suppression on?
    
        if ($suppressing_filters) {
            return query;
        }
    
        if ($query->query['post_type']=='page') {            
            $posts_restriction_type = 2; // Prohibit
            $posts_slugs = array(
                'jobs',
                'post-to-our-blog',
                'sample-page'
            );
            $posts_list = array();  // comma separated list of pages IDs
            foreach($posts_slugs as $post_slug) {
                $page = get_page_by_path($post_slug);
                if ($page) {
                    $posts_list[] = $page->ID;   
                }
            }
            if (empty($posts_list)) {
                return $query;
            }
            if ($posts_restriction_type==1) {   // Allow
                $query->set('post__in', $posts_list);
            } else {    // Prohibit
                $query->set('post__not_in', $posts_list);
            }
        }
    
        return $query;
    }
    // restrict_posts_list()
    
    #1713
    [email protected]
    Participant

    Vladimir,

    In a Multisiste environment, can I use this code to restrict editing pages by user role that was created by Role Editor Pro, NOT one of the WordPress built-in roles

    #1715
    [email protected]
    Participant

    This code currently blocks pages 3,4,5 fro all roles NOT just the “franchise” role how I allow the administrator and SUPER administrator to see/edit this page also?

    Thank you so much!

    if (is_blog_admin() && current_user_can(‘franchise’)) {
    add_action(‘pre_get_posts’, ‘restrict_posts_list’);
    function restrict_posts_list($query) {

    $suppressing_filters = $query->get(‘suppress_filters’); // Filter suppression on?

    if ($suppressing_filters) {
    return query;
    }

    if ($query->query[‘post_type’]==’page’) {
    $posts_restriction_type = 2; // Prohibit
    $posts_list = array(3,4,5); // comma separated list of pages IDs
    if ($posts_restriction_type==1) { // Allow
    $query->set(‘post__in’, $posts_list);
    } else { // Prohibit
    $query->set(‘post__not_in’, $posts_list);
    }
    }

    return $query;
    }
    // restrict_posts_list()
    }

    #1716
    Vladimir
    Keymaster

    Add to the begin of function:

    
    function restrict_post_list($query) {
    
    if (is_super_admin() || current_user_can('administrator')) {
        return $query;
    }
    ...
    

    or change the initial if condition to:

    
    if (is_blog_admin() && !(is_super_admin() || current_user_can('administrator')) && current_user_can('franchise')) {
    
Viewing 15 posts - 1 through 15 (of 23 total)
  • You must be logged in to reply to this topic.