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
1 Answer
Reset to default 2As @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
评论列表(0条)