Are you using Jetpack on your website? I do, and if you are not, you should!
It is a plugin by Automattic which boosts your website with many WordPress.com features, like markdown support, contact forms, subscriptions (to the blog), related posts, and many others.
I want to show you a single module in this article, the Contact form module. It adds the ability for who has access to the Dashboard to add contact forms to posts, and recently to products in WooCommerce.
When enabling this module, you will see a button like this on products, before the content editors:
This is cool, you can use the contact form to create a Product enquiry form, or something else, but you might not want the button to be available for everyone. The problem occurs when using plugins who give access to manage products like WooCommerce Product Vendors.
Product Vendors allows vendor admins to log in the Dashboard to manage products. They will see, by default, the contact form button as well. How to disable it?
With a snippet, obvious no?
Add this code at the end of the file functions.php in wp-content/themes/your-child-theme-name/:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'init', 'remove_jpcf_nonadmin' ); | |
function remove_jpcf_nonadmin() { | |
if ( ! current_user_can( 'manage_woocommerce' ) ) { | |
remove_action( 'media_buttons', 'grunion_media_button', 999 ); | |
} | |
} |
Notice on line 3 I use the capability manage_woocommerce
to allow only administrators and shop managers to see the button. If you want it to be available only to administrators, change it to manage_options
.
Leave a Reply