I would need to simplify the “upload new image” interface for our Authors : basically, hide a few fields that will only confuse my wordpress “authors” (like the “Description” and “Alt” text inputs). Administrators and Editors need to see these, though.
How can i implement that hiding/showing inputs according to the user’s priviledges?
You will need to hook into attachment_fields_to_edit
and unset them for a role.
You can use current_user_can('author')
http://codex.wordpress.org/Function_Reference/current_user_can
Example to remove image alt field
function remove_caption($form_fields) {
if (current_user_can('author')){
$form_fields['image_alt']['input'] = 'hidden';
return $form_fields;
}}
add_filter('attachment_fields_to_edit','remove_caption', 15, 2);
My initial post used unset
but I tried it and it did not work, from the example in this post: How can I remove fields in the attachment editor? , not sure why, instead the example above works using hidden
.