Removing items from the admin bar menu
-
Hi community. This is my first post, and I am new to the word press eco system. I am on my second project using WP. The first was a simple shop/website. The second is a little more challenging.
My background is IT/Software (PL/SQl, Shell, early VB, a little Pl/M which is a precursor to C and such like). I have also supported various web based systems over the years, running on apache/IIS Jboss/Weblogic/Websphere and so on. However, I have never worked with HTML or PHP. It is time to learn.What I am trying to achieve is the following.
On a multisite install of marketpress 2.9.5.3. I want my users to be able to upload a product, but no other admin style privileges.. So in order to do this I have tried a few things so far.I am using: marketpress 2.9.5.3. “WP_hide_admin_bar”, “User Account Manager” and “User Role Editor” plugins.
First attempt:
I have created a new role based on the Admin and used an editor and removed most of privileges. This got quite close, to what I wanted to achieve – I had the Admin bar available to my user base, and the only item on there was the “+NEW” menu. I managed to de-select the privileges to the extent that the only “+NEW” items they could add were pages and products. This was progress and close to what I wanted.
I started to suspect that a product is simply a type of “post” and therefore restricting the users rights/privileges will always allow the user to add a page or a product. I do not want them adding pages. The reason I started to suspect this is because the new “product” resolves to –/wp-admin/post-new.php?post_type=product
and a page resolves to:
/wp-admin/post-new.php?post_type=page.So it looks like a product and a page are types of post. As soon as I enable an ability to edit pages I get both, and I cannot seem to set a permission for a “product only”. Presumably because a product is part of Marketpress and not part of WP.
I then tried changing the user role *back* to a subscriber thus removing the admin bar altogether and creating a URL link to the /wp-admin/post-new.php?post_type=product on a separate page (restricted to only registered users).
However, I get insufficient privileges kind of error. Ok, I thought, we are getting somewhere…what about allowing the subscriber permission to edit a post but also activate the hide admin bar plug in. Breifly I thought I had what I wanted, but no the admin bar comes back once the permission is set to edit a post in the “user role editor”.
—————————————————Next I reassigned my user back to a role based on the admin role, thus re-enabling the admin bar for them..
I used the IE developer interface [F12] and object picker to identify the ID of the objects i want to remove.
I then edited functions.php and used this kind of approach: OK – so a bit hit and miss in desperation to try and get the menu to have nothing other than the +New>>Product.
function remove_admin_bar_links() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu(‘wp-logo’);
$wp_admin_bar->remove_menu(‘wp-admin-bar-new-content-default’);
$wp_admin_bar->remove_node(‘wp-admin-bar-new-content-default’);
$wp_admin_bar->remove_menu(‘wp-admin-bar-new-post’);
$wp_admin_bar->remove_node(‘wp-admin-bar-new-post’);
}
add_action( ‘wp_before_admin_bar_render’, ‘remove_admin_bar_links’ );I see that using “remove_menu” does remove top level items from the menu, for example the first remove line takes out the WP logo. But what I couldnt do was remove the actual menu items from the menu. I.e. I could remove the entire “+new” menu, but not remove the item “post” from the “+New” menu on the admin bar.
I tried coding a few thingss – “remove_menu” and “remove_menu_item” and “remove_node”. None of these achieved what I wanted.
I then tried a different approach and edited class-wp-admin-bar.php like below – this resulted in my user loosing a lot of the left side bar and the entire admin_bar 🙂
add_action( ‘admin_bar_menu’, ‘remove_page’, 999 );
function remove_page( $wp_admin_bar ) {
$wp_admin_bar->remove_node( ‘page’ );In short – I want my users to be able to add a product and nothing else.
Sorry if this is as clear as mud, it is all quite new to me. (No link to the site available yet-sorry).
Any ideas ?
Thanks
Mark
-
P.s. – I am in an R&D phase, and don’t want to spend much on plugins until such time as I have proved the concept.
I have just installed WpMUDev’s custom admin bar, and tried that. Pretty much the same results. New post and new product seem to go hand in hand.
Well, progress of some sort, but still not completely resolved.
Just to be clear – two separate things here – the wp_admin_bar at the top of the screen and the wp_toolbar at the left of the screen.
I have managed to remove the entire ADD NEW from the admin bar and have a simple link to the New products page. This is not ideal at all really, but I have been unable to find anyway to restrict the permissions so that the user can create a product, but no new pages.
As a temporary workaround – I now need to remove the “Pages” from the left hand side wp-toolbar. This is present when a user views their profile, or when they click to create a new product and it takes them to the /wp-admin/post-new.php?post_type=product page.
This is where the left hand side wp-toolbar is visible.Any ideas. I tried adding similar code to that listed above and again, all that happens is I lose the entire wp_admin_bar.
Resolved. I simply used a plugin to edit the admin menus.
The topic ‘Removing items from the admin bar menu’ is closed to new replies.