Php 钩住一个过滤器
由于最近的WooCommerce更新,具有“shopmanager”角色的用户不再能够编辑具有“订户”角色的用户 我发现以下职能部门对此负责:Php 钩住一个过滤器,php,wordpress,filter,woocommerce,hook,Php,Wordpress,Filter,Woocommerce,Hook,由于最近的WooCommerce更新,具有“shopmanager”角色的用户不再能够编辑具有“订户”角色的用户 我发现以下职能部门对此负责: function wc_modify_editable_roles( $roles ) { if ( is_multisite() && is_super_admin() ) { return $roles; } if ( ! wc_current_user_has_role( 'administrator' ) )
function wc_modify_editable_roles( $roles ) {
if ( is_multisite() && is_super_admin() ) {
return $roles;
}
if ( ! wc_current_user_has_role( 'administrator' ) ) {
unset( $roles['administrator'] );
if ( wc_current_user_has_role( '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' );
我需要在apply_filters('woocommerce_shop_manager_editable_roles',数组('customer')中向数组添加subscriber
代码>但这就是我被卡住的地方
如何连接到该筛选器以添加额外角色?
这就是我到目前为止得到的(根本不起作用,但这是一个开始:)
分类
您需要返回新角色数组,如下所示:
add_filter( 'woocommerce_shop_manager_editable_roles', 'addanotherrole' );
function addanotherrole($roles) {
// add the additional role to the woocommerce allowed roles (customer)
$roles[] = 'subscriber';
// return roles array
return $roles;
我希望这有帮助
add_filter( 'woocommerce_shop_manager_editable_roles', 'addanotherrole' );
function addanotherrole($roles) {
// add the additional role to the woocommerce allowed roles (customer)
$roles[] = 'subscriber';
// return roles array
return $roles;