Skip to content

Instantly share code, notes, and snippets.

@utkrishta
Last active June 15, 2020 23:37
Show Gist options
  • Save utkrishta/d5b7d5a5cc90f59d8e078d4a509016af to your computer and use it in GitHub Desktop.
Save utkrishta/d5b7d5a5cc90f59d8e078d4a509016af to your computer and use it in GitHub Desktop.
Add CLASS to admin body if user is not an Administrator
<?php
//Add class to admin body if user is not an Administrator
if( ! current_user_can('administrator') ) {
add_filter( 'admin_body_class', 'rw_admin_only_body_class' );
function rw_admin_only_body_class( $classes )
{
$classes = 'admin-readonly';
return $classes;
}
}
/*
* This function can be particularly useful when you don't other users except Administrator to make changes to given fields
* ie make those fields "read-only" or "hidden" for other users
*/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment