1

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') );
  • 1
    See here for the proper way to use filters. – Jacob Peattie Dec 4 '19 at 13:13
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;
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.