Add filter for ease of extensions
This commit is contained in:
parent
75bfc8e4bb
commit
5f2b915f18
|
@ -353,11 +353,11 @@ function wc_modify_editable_roles( $roles ) {
|
|||
unset( $roles['administrator'] );
|
||||
}
|
||||
|
||||
if ( current_user_can( 'shop_manager' ) && isset( $roles['customer'] ) ) {
|
||||
return array(
|
||||
'customer' => $roles['customer'],
|
||||
);
|
||||
if ( current_user_can( 'shop_manager' ) ) {
|
||||
$shop_manager_editable_roles = apply_filters( 'woocommerce_shop_manager_editable_roles', array( 'customer' ) );
|
||||
return array_intersect_key( $roles, array_flip( $shop_manager_editable_roles ) );
|
||||
}
|
||||
|
||||
return $roles;
|
||||
}
|
||||
add_filter( 'editable_roles', 'wc_modify_editable_roles' );
|
||||
|
@ -389,7 +389,8 @@ function wc_modify_map_meta_cap( $caps, $cap, $user_id, $args ) {
|
|||
// Shop managers can only edit customer info.
|
||||
if ( current_user_can( 'shop_manager' ) ) {
|
||||
$userdata = get_userdata( $args[0] );
|
||||
if ( property_exists( $userdata, 'roles' ) && ! empty( $userdata->roles ) && ! in_array( 'customer', $userdata->roles ) ) {
|
||||
$shop_manager_editable_roles = apply_filters( 'woocommerce_shop_manager_editable_roles', array( 'customer' ) );
|
||||
if ( property_exists( $userdata, 'roles' ) && ! empty( $userdata->roles ) && ! array_intersect( $userdata->roles, $shop_manager_editable_roles ) ) {
|
||||
$caps[] = 'do_not_allow';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,12 +113,5 @@ class WC_Tests_User_Functions extends WC_Unit_Test_Case {
|
|||
$this->assertContains( 'do_not_allow', $caps );
|
||||
$caps = map_meta_cap( 'edit_user', $manager_id, $customer_id );
|
||||
$this->assertEquals( array( 'edit_users' ), $caps );
|
||||
|
||||
// Customers should not be able to edit or promote anyone.
|
||||
wp_set_current_user( $customer_id );
|
||||
$caps = map_meta_cap( 'edit_user', $customer_id, $admin_id );
|
||||
$this->assertContains( 'do_not_allow', $caps );
|
||||
$caps = map_meta_cap( 'edit_user', $customer_id, $editor_id );
|
||||
$this->assertContains( 'do_not_allow', $caps );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue