A CSS rule would be the simple action.
You can just create a single global admin area foot script set of instructions and disable a whole series of elements by user capability and simply add instructions as needed, and affect all areas of the admin area.
functions.php or create a plugin that would give flexibility to be used on any WP site without dependence on specific theme.
add_action('admin_print_footer_scripts', function() {
## block fields from non admins
// set default empty vars
$non_admin_css_blocks= $non_admin_js_blocks="";
// user condition check
if( !current_user_can('manage_options') ) {
$non_admin_blocks="
#post_tag .jaxtag,
.other-field,
.another-field {display: none !important;}
";
// javascript instructions
$non_admin_js_blocks="
$("#post-body #title,#edit-slug-box button.edit-slug").attr("disabled","disabled");
";
}
$css="
<style>
".$non_admin_blocks.'
</style>
';
$js="
<script>
jQuery(function($) {
".$non_admin_js_blocks.'
});
</script>
';
echo $css . $js;
});
Note
You can always scan the files in wp-admin to find all the hooks that will deliver any alteration desired. Just search for do_action
or apply_filters
and read the commented tip to determine firing time and behavior. If a hook has a variable, that will be used in the callback argument. If there are multiple vars you will need to define the count. EG
priority 10,args count 2
add_action('do_something_different', function($alt,$target) {
}10,2);