改变$url
根据您的要求。在当前状态下$url
指向样式表的链接custom-style.css
位于当前活动主题的子目录中admin
. 我测试了这段代码,它运行得很好。享受:-)
/**
* This function registers and enqueues styles on front-end if
* logged-in user has a role \'author\'.
*/
function customStylesheetForAuthorsOnly() {
/* Unique slug for the specific resource. */
$handle = \'unique-css-stylesheet-handle\';
/* URL of the stylesheet (resource). */
$url = get_template_directory_uri() . \'/admin/custom-style.css\';
/* Array containing the handles of all the dependencies. */
$dependencies = array();
wp_register_style($handle, $url, $dependencies);
global $current_user;
get_currentuserinfo();
/* Check if current user has \'author\' in his roles */
if(in_array(\'author\', $current_user->roles) === true) {
wp_enqueue_style($handle);
}
}
add_action(\'admin_enqueue_scripts\', \'customStylesheetForAuthorsOnly\');