user_contactmethods
过滤器挂钩将两个参数传递给注册的函数。第二个参数是WP_User
对象,可以在其帮助下检查已编辑用户的角色和上限。
add_filter( \'user_contactmethods\', \'se330743_user_contact_methods\', 20, 2 );
function se330743_user_contact_methods( $user_contact, $user )
{
// --- fields for admins ---
if ( !in_array(\'administrator\', (array)$user->roles) )
return $user_contact;
// --- fields for users with cap \'create_users\' ---
// if ( !user_can($user, \'create_users\') )
// --- fields for admin---
// if ( !in_array(\'administrator\', (array)$user->roles) || !user_can($user, \'create_users\') )
$user_contact[\'company\'] = \'Company\';
return $user_contact;
}