Change $url
according to your requirements. In the current state the $url
links to a stylesheet custom-style.css
located in your current active theme's subdirectory admin
. I tested this code and it is working fine. Enjoy :-)
/**
* 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');