Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #4265
    chingaling
    Participant

    Hi

    I want to protect certain pages from being edited by anyone other than the Administrator.

    I found one approach here: http://www.wpbeginner.com/plugins/how-to-allow-editors-to-only-edit-certain-pages-in-wordpress/

    But I’d much prefer to use URE. Is there a feature or way I can do this with URE?
    The pages are mainly those which have vital shortcodes in them, hence why I do not want users to be able to edit/delete them – whilst still retaining access to edit other pages.

    #4267
    Vladimir
    Keymaster

    Hi,

    You can achieve this with Edit access restrictions add-on. You can prohibit with it the editing of a list of pages by ID for the editor role.

    #4269
    chingaling
    Participant

    Hi Vladimir

    Thank you for the link. I got as far as adding a new role, but I can’t seem to find how to access this panel:

    Also, looking at the way the plugin works, I’m not sure how I would do it because I’m using it on a Multisite where a user can sign up for a website (which would take its content from one of my subsites as a template) and upon signup they are given the EDITOR role. In the template which their website is based on, there are a few PAGES (ecommerce and account related) which need to be protected from anyone other than ADMIN/NETWORK ADMIN. Is this achievable please?

    #4272
    Vladimir
    Keymaster

    This screenshot belongs to other add-on: Content view restrictions, which works for front-end.

    I recommended to use another one. If you provide that those restricted pages will have the same IDs at any subsite of your network, you can setup the list of restricted pages, like “1, 3, 7” via custom filters ‘ure_edit_posts_access_id_list’ and ‘ure_edit_posts_access_restriction_type’ as a must use plugin – which will work for any subsite.

    
    add_filter('ure_edit_posts_access_id_list', 'ure_edit_posts_access_set_id_list');
    
    function ure_edit_posts_access_set_id_list($list) {
        $current_user = wp_get_current_user();
        $lib = URE_Lib_Pro::get_instance(); 
        if ($lib->user_can_role($current_user, 'editor')) {
            $list .= ',1,3,7';
        }
    
        return $list;
    }
    
    add_filter('ure_edit_posts_access_restriction_type', 'ure_edit_posts_access_set_restriction_type');
    
    function ure_edit_posts_access_set_restriction_type($restriction_type) {
        $current_user = wp_get_current_user();
        $lib = URE_Lib_Pro::get_instance(); 
        if ($lib->user_can_role($current_user, 'editor')) {
            $restriction_type = 2; // Block
        }
        
        return $restriction_type;
    }
    
    #4273
    chingaling
    Participant

    Thank you, I will try test that later today.

    One thing I can foresee being a potential issue, is that the pages aren’t guaranteed to be the same.
    For example the page ID for the Checkout page (with a permalink of checkout) for site 1 is likely to be different to the page ID for the Checkout page on site 2, 3 and 4.

    Is it possible to restrict those pages based on permalink?

    #4276
    Vladimir
    Keymaster

    It possible to extend a logic of the ‘set_id_list’ function using WP function url_to_postid(), in order to return a page ID related to current site.

    #4278
    chingaling
    Participant

    Hi Vladimir

    That sounds a bit beyond my technical understanding at the moment, is that something you can help with the code for please?

    #4279
    Vladimir
    Keymaster

    Give me more details. Does it one page for a subsite?
    Show a list of pages with ID and permalinks (without domain) and describe conditions, how will you decide what permalink for what site to select.

    #4280
    chingaling
    Participant

    Hi

    I hope this helps explain it better:

    So for example, in my multisite network I couldnt lock the pages by ID, because depending on when the pages are created, it may not be the ID for the page I want to lock, however I could make sure that certain permalinks are reserved for the multisite for the locked pages hence why I’d like to be able to define the (reserved) permalinks for which are to be locked.

    I hope that makes sense 🙂

    #4281
    Vladimir
    Keymaster

    This code does not depend from a page ID. It blocks edit access for pages with ‘shop’ and ‘busket’ slugs for any user with ‘edit_others_pages’ capability for any subsite.

    
    add_filter('ure_edit_posts_access_id_list', 'ure_edit_posts_access_set_id_list');
    
    function ure_edit_posts_access_set_id_list($list) {
        $current_user = wp_get_current_user();
        $lib = URE_Lib_Pro::get_instance(); 
        if (!current_user_can('edit_others_pages')) {
            return $list;
        }
        
        $slugs = array('shop', 'busket');
        $id_list = array();
        foreach($slugs as $slug) {
            $page = get_page_by_path($slug);
            if (!empty($page)) {
                $id_list[] = $page->ID;
            }
        }
        $id_list_str = implode(',', $id_list);
        $list .= $id_list_str;
    
        return $list;
    }
    
    add_filter('ure_edit_posts_access_restriction_type', 'ure_edit_posts_access_set_restriction_type');
    
    function ure_edit_posts_access_set_restriction_type($restriction_type) {
        $current_user = wp_get_current_user();
        $lib = URE_Lib_Pro::get_instance(); 
        if (current_user_can('edit_others_pages')) {
            $restriction_type = 2; // Block
        }
        
        return $restriction_type;
    }
    

    If you will wish to add some edit restriction for user with ‘edit_others_pages’ manually, you should take into account that this restricton should be the same type “Block” in order to not break this code and vice versa.

    #4284
    chingaling
    Participant

    Thank you Vladimir

    I added that code in as a Must Use plugin but the Editor can still seem to edit the shop (and basket – assuming its a typo) pages.

    To note, I did also try the first approach, with the ID numbers and that did not work either for me

    #4285
    Vladimir
    Keymaster

    Look how it works at my test site – demo video.

    Slightly enhanced code version. Update your copy:

    
    add_filter('ure_edit_posts_access_id_list', 'ure_edit_posts_access_set_id_list');
    
    function ure_edit_posts_access_set_id_list($list) {
        if (!current_user_can('edit_others_pages')) {
            return $list;
        }
        
        $slugs = array('shop', 'busket');   // input blocked pages slug here
        $id_list = array();
        foreach($slugs as $slug) {
            $page = get_page_by_path($slug);
            if (!empty($page)) {
                $id_list[] = $page->ID;
            }
        }
        if (count($id_list)>0) {
            $id_list_str = implode(',', $id_list);
            $list .= $id_list_str;
        }
    
        return $list;
    }
    
    add_filter('ure_edit_posts_access_restriction_type', 'ure_edit_posts_access_set_restriction_type');
    
    function ure_edit_posts_access_set_restriction_type($restriction_type) {
        if (current_user_can('edit_others_pages')) {
            $restriction_type = 2; // Block
        }
        
        return $restriction_type;
    }
    
    #4286
    chingaling
    Participant

    Thats fantastic – it works now! You’re amazing.

    I didnt have the Content Restrictions boxes ticked (was working off a backup)

    #4287
    chingaling
    Participant

    A bit off-topic but: it looks like you have a local development environment for a Multisite. I’ve been struggling to set up a Multisite local development environment on my pc; do you have any links to resources which guide through how to do it at all please?

    Thanks

    #4288
    Vladimir
    Keymaster

    I followed this article always.
    And selected “Subdirectories — a path-based network in which on-demand sites use paths” to not struggle configuring Apache with subdomains.

Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.