Created
February 8, 2016 00:50
-
-
Save digitalchild/d1c30d6725ad3343d7c6 to your computer and use it in GitHub Desktop.
Give vendors permissions to edit media
This file contains hidden or 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
<?php | |
// The following functions will allow a vendor to edit and delete their media | |
// HOWEVER this requires post permissions so would also allow them to access posts and comments | |
// This code will then hide the posts and comments from the wp-admin menus | |
// WC Vendors will not support this code and is provided for educational purposes only. | |
// 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