Created
October 7, 2016 15:19
-
-
Save stompweb/627c03e819746c433f11f5048efd0173 to your computer and use it in GitHub Desktop.
Shop Roles
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
<?php | |
/** | |
* Add custom member role, created with the same capability as customer. | |
*/ | |
function courtauld_add_member_role() { | |
if ( true == get_option( 'member_role_added_7_oct' ) ) { | |
return; | |
} | |
global $wp_roles; | |
$customer = $wp_roles->get_role( 'customer' ); | |
$wp_roles->add_role( 'member', 'Member', $customer->capabilities ); | |
add_option( 'member_role_added_7_oct', true, '', 'no' ); | |
} | |
add_action( 'admin_init', 'courtauld_add_member_role' ); | |
/** | |
* Add custom shop manager admin role, can edit theme optins (menus, widgets etc) | |
*/ | |
function courtauld_add_shop_manager_admin_role() { | |
if ( true == get_option( 'shop_manager_admin_added_7_oct' ) ) { | |
return; | |
} | |
global $wp_roles; | |
if ( ! isset( $wp_roles ) ) { | |
$wp_roles = new WP_Roles(); | |
} | |
// Get the default WooCommerce shop manager role | |
$shop_manager = $wp_roles->get_role( 'shop_manager' ); | |
// Add the Shop Manager Admin role | |
$wp_roles->add_role( 'shop_manager_admin', 'Shop Manager Admin', $shop_manager->capabilities ); | |
// Get the Shop Manager Admin role | |
$shop_manager_admin = get_role( 'shop_manager_admin' ); | |
// Add edit_theme_options to Shop Manager Admin role | |
$shop_manager_admin->add_cap( 'edit_theme_options' ); | |
add_option( 'shop_manager_admin_added_7_oct', true, '', 'no' ); | |
} | |
add_action( 'admin_init', 'courtauld_add_shop_manager_admin_role' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment