Skip to content

Instantly share code, notes, and snippets.

@bentasm1
Forked from digitalchild/functions.php
Last active February 16, 2016 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bentasm1/10e34e45656c9df4ebcf to your computer and use it in GitHub Desktop.
Save bentasm1/10e34e45656c9df4ebcf to your computer and use it in GitHub Desktop.
Give vendors permissions to edit media
<?php
// The following functions will allow a vendor to edit and delete their media alt text and descriptions.
// HOWEVER this requires post editing permissions so would also allow them to edit ALL posts and comments on
// your site if they know how to do it.
// WC Vendors will not support this code and is provided for educational purposes only.
// THIS IS DANGEROUS TO DO -- USE AT YOUR OWN RISK -- YOU HAVE BEEN WARNED!
// Update vendor role to support media handling
function update_vendor_role( ){
remove_role( 'vendor' );
add_role( 'vendor', __('Vendor', 'wcvendors-pro') ,
array(
'assign_product_terms' => true,
'edit_products' => true,
'edit_posts' => true,
'delete_posts' => true,
'edit_product' => true,
'edit_published_products' => false,
'manage_product' => true,
'publish_products' => false,
'read' => true,
'upload_files' => true,
'view_woocommerce_reports' => true,
)
);
} // update_vendor_role()
// Remove admin menu options to suit new updated role
function remove_admin_menus( ){
if ( WCV_Vendors::is_vendor( get_current_user_id() ) ) {
remove_menu_page( 'edit.php' );
remove_menu_page( 'edit-comments.php' );
}
} // remove_admin_menus()
// Remove admin menu options to suit new updated role
function remove_admin_bar_menus( ){
if ( WCV_Vendors::is_vendor( get_current_user_id() ) ) {
global $wp_admin_bar;
$wp_admin_bar->remove_node( 'new-post' );
}
} // remove_admin_menus()
add_action( 'admin_init', 'update_vendor_role' );
add_action( 'admin_menu', 'remove_admin_menus' );
add_action( 'admin_bar_menu', 'remove_admin_bar_menus', 999 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment