Change WordPress user roles and capabilities › Forums › How to or FAQ › Search Pages not working for custom roles
- This topic has 8 replies, 2 voices, and was last updated 4 years, 4 months ago by
edering.
-
AuthorPosts
-
21/10/2020 at 23:51 #7111
edering
ParticipantHi. I can’t figure out why Users with any of my Roles that go to Pages see the “Search Pages” function, but when they do a search, it takes them to the Dashboard. Any ideas?
22/10/2020 at 03:41 #7112Vladimir
KeymasterHi,
Do you use “Admin menu access” add-on with “Block not selected” option? If Yes, read carefully the “Technical details” part of the documentation article.
22/10/2020 at 10:03 #7113edering
ParticipantNo, I am using Admin Menu Access with Block Selected.
22/10/2020 at 16:52 #7116Vladimir
KeymasterI assume a conflict with some plugin. If it’s possible to look at this on your site send admin credentials and testing role name to support [at-sign] role-editor.com
22/10/2020 at 16:56 #7117edering
ParticipantThanks, I just sent the email
22/10/2020 at 17:44 #7119Vladimir
KeymasterThanks you.
The source of the issue is that admin menu item ‘All Posts’ (edit.php) is prohibited (selected) for the role, but allowed are ‘All Pages’ (edit.php?post_type=page).
When user try to search some page, URL becomes edit.php?post_type=page&s=something…
which is not apparently allowed and edit.php is in the list of prohibited URLs. Thus URE fulfills the redirection. The same is similar for other custom post types, URL for which starts from edit.php too.Quick workaround is allow for a role ‘All Posts’ menu and submenu items. I tested this for IU administrator role and left as it is for your review.
Let me know if this workaround is suitable for you. If it is not, I may offer you a piece of code which will hide ‘All Posts’ menu items from admin menu directly after adding to the active theme functions.php file.
22/10/2020 at 18:00 #7120edering
ParticipantThanks. Yes, we don’t use “Posts” so we were hiding it so the Users would not get confused and to keep the WordPress menu clean. How can I hide “Posts” from the menu but keep the function for searching Pages?
23/10/2020 at 07:30 #7126Vladimir
KeymasterTry to add code below to the end of your active theme functions.php file:
// block Posts menu for all users except administrator function remove_posts_menu() { global $menu, $submenu; $user = wp_get_current_user(); if ( in_array( 'administrator', $user->roles ) ) { return; } //remove 'All posts' submenu item if ( isset( $submenu['edit.php'][5] ) ) { unset($submenu['edit.php'][5]); } // remove Posts top level menu if ( isset( $menu[5] ) ) { unset($menu[5]); } // redirect in case of try edit.php URL access $result = stripos($_SERVER['REQUEST_URI'], 'edit.php'); if ($result===false) { return; } $result = stripos($_SERVER['REQUEST_URI'], 'post_type='); if ($result!==false) { // allow access to custom post types return; } wp_redirect(get_option('siteurl') . '/wp-admin/index.php'); } add_action('admin_head', 'remove_posts_menu', 100);
23/10/2020 at 13:22 #7128edering
ParticipantThanks, that worked!
-
AuthorPosts
- You must be logged in to reply to this topic.