Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 钩住一个过滤器_Php_Wordpress_Filter_Woocommerce_Hook - Fatal编程技术网

Php 钩住一个过滤器

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' ) )

由于最近的WooCommerce更新,具有“shopmanager”角色的用户不再能够编辑具有“订户”角色的用户

我发现以下职能部门对此负责:

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;