Change WordPress user roles and capabilities › Forums › Restrict or Permit access inside WordPress – how to › Question Implementing: Restrict the list of parent pages
Tagged: menu
- This topic has 5 replies, 2 voices, and was last updated 9 years, 12 months ago by
feeco.
-
AuthorPosts
-
03/11/2015 at 22:02 #1786
feeco
ParticipantHi, 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!
04/11/2015 at 02:17 #1787Vladimir
KeymasterHi,
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=editPage ID is 876 for the link above.
04/11/2015 at 02:18 #1788Vladimir
KeymasterYes, replace ‘mynewrole’ with your own role name, for which you wish to setup the restriction.
04/11/2015 at 15:41 #1789feeco
Participantso does this code actually remove the items from the main menu users see? If not can you please point me in the right direction?
04/11/2015 at 16:24 #1790Vladimir
KeymasterThis 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.
04/11/2015 at 16:25 #1791feeco
Participantok, thank you.
-
AuthorPosts
- You must be logged in to reply to this topic.