plugins - Override WP Class Private Function

I'm new to community, I think you experts can help me in this.I have plugin installed and i want to its overwrite

I'm new to community, I think you experts can help me in this. I have plugin installed and i want to its overwrite one function which is in class

    <?php 

 class wf_fedex_woocommerce_shipping_admin{

private function wf_user_permission($auto_generate=null){

$current_minute=(integer)date('i');
        if(!empty($auto_generate) && ($auto_generate==md5($current_minute) || $auto_generate==md5($current_minute+1) ))
        {
            return true;
        }
        $current_user = wp_get_current_user();
        $user_ok = false;
        $wf_roles = apply_filters( 'wf_user_permission_roles', array('administrator', 'shop_manager') );

        if ($current_user instanceof WP_User) {
            $role_ok = array_intersect($wf_roles, $current_user->roles);
            if( !empty( $role_ok ) ){
                $user_ok = true;
            }
        }
        return $user_ok;
}
}
?>

I want to rewrite if so WP will use my custom instead of plugin I need a single change in new function ( I mean i just need pass 'subscriber' in array )

$wf_roles = apply_filters( 'wf_user_permission_roles', array('administrator', 'shop_manager', 'subscriber') );

I'm new to community, I think you experts can help me in this. I have plugin installed and i want to its overwrite one function which is in class

    <?php 

 class wf_fedex_woocommerce_shipping_admin{

private function wf_user_permission($auto_generate=null){

$current_minute=(integer)date('i');
        if(!empty($auto_generate) && ($auto_generate==md5($current_minute) || $auto_generate==md5($current_minute+1) ))
        {
            return true;
        }
        $current_user = wp_get_current_user();
        $user_ok = false;
        $wf_roles = apply_filters( 'wf_user_permission_roles', array('administrator', 'shop_manager') );

        if ($current_user instanceof WP_User) {
            $role_ok = array_intersect($wf_roles, $current_user->roles);
            if( !empty( $role_ok ) ){
                $user_ok = true;
            }
        }
        return $user_ok;
}
}
?>

I want to rewrite if so WP will use my custom instead of plugin I need a single change in new function ( I mean i just need pass 'subscriber' in array )

$wf_roles = apply_filters( 'wf_user_permission_roles', array('administrator', 'shop_manager', 'subscriber') );
Share Improve this question edited Dec 4, 2019 at 13:07 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Dec 4, 2019 at 13:06 Naveen GuleriaNaveen Guleria 232 bronze badges 1
  • 1 See here for the proper way to use filters. – Jacob Peattie Commented Dec 4, 2019 at 13:13
Add a comment  | 

1 Answer 1

Reset to default 2

As @jacob suggest, you can add subscriber role into that array using add_filter . add below code in active theme's functions.php file.

add_filter( 'wf_user_permission_roles', 'wf_user_permission_roles_callback' ) ;
function wf_user_permission_roles_callback( $roles ) {
    $roles[] = 'subscriber';
    return $roles;
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744940781a4602307.html

相关推荐

  • plugins - Override WP Class Private Function

    I'm new to community, I think you experts can help me in this.I have plugin installed and i want to its overwrite

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信