Skip to content

Instantly share code, notes, and snippets.

@atsea
Created September 27, 2016 16:48
Show Gist options
  • Save atsea/4f1e24b3ea4c25f93fbb558a5171cf07 to your computer and use it in GitHub Desktop.
Save atsea/4f1e24b3ea4c25f93fbb558a5171cf07 to your computer and use it in GitHub Desktop.
WordPress: check user role and add inline css
/**
* http://wordpress.stackexchange.com/questions/131814/if-current-user-is-admin-or-editor
* set wpadminbar to position fixed to work with UD Theme 8/29/15 CL
*/
$user = wp_get_current_user();
$allowed_roles = array('editor', 'administrator', 'author');
if( array_intersect($allowed_roles, $user->roles ) )
$custom_css =
"@media screen and (max-width:600px) {#wpadminbar {position: fixed !important;}}".'/n';
"@media only screen and (max-width:48em) {#wpadminbar {position:fixed !important;}}".'/n';
wp_add_inline_style( $this->sb_bar .'-admin-styles', $custom_css );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment