Change WordPress user roles and capabilities Forums Restrict or Permit access inside WordPress – how to Question Implementing: Restrict the list of parent pages

Tagged: 

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1786
    feeco
    Participant

    Hi, I have the paid version of the plugin and am trying to implement the code for “Restrict the list of parent pages” found on this page: https://www.role-editor.com/restrict-the-list-of-parent-pages/ – this will remove the items from the main menu correct?

    I’m having problems finding the IDs to replace the 10,2 found on the first line. Also do I enter in the role name by current_user_can?

    add_filter('page_attributes_dropdown_pages_args', 'restrict_parent_pages_for_role', 10, 2);
     
    function restrict_parent_pages_for_role($args, $post) {
     
        if (current_user_can('mynewrole')) {   
            // list of pages to exclude from the parent pages dropdown menu. Do not use with 'include' together.
            $args['exclude'] = array(47); 
        }
     
        return $args;
    }

    Thank you!

    #1787
    Vladimir
    Keymaster

    Hi,

    This code removes items from the “Parent” menu at the “Page attributes” meta box of the page editor.

    Do not touch ’10, 2′ values. 10 – is a priority of execution, 2 – is a quant of parameters in use.

    Page ID at the code sample is 47. If you need to remove a list of pages, add IDs as a comma separated list:

    
    $args['exclude'] = array(47, 52, 67);
    

    You may find page ID at the pages list – look post parameter value at the ‘Edit’ link under needed page. For example:

    
    wp-admin/post.php?post=876&action=edit
    

    Page ID is 876 for the link above.

    #1788
    Vladimir
    Keymaster

    Yes, replace ‘mynewrole’ with your own role name, for which you wish to setup the restriction.

    #1789
    feeco
    Participant

    so does this code actually remove the items from the main menu users see? If not can you please point me in the right direction?

    #1790
    Vladimir
    Keymaster

    This code removes items from the list of parent pages at the ‘Page Attributes’ meta box placed to the right at the page editor screen. It does not related to any ‘main menu’.

    If you name ‘main menu’ the menu to the left at the WordPress wp-admin, then use ‘Admin menu’ access add-on to block/hide that menu items from users:
    https://www.role-editor.com/block-admin-menu-items
    You don’t need any additional code for that.

    If you write about some other menu, please clarify what menu do you mean.

    #1791
    feeco
    Participant

    ok, thank you.

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