I'm using different method to form a gallery in Wordpress, so I would like to hide an option to insert images and galleries into post for anyone but Administrator.
Can someone show me an example how it's done?
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityIf you actually wanted to remove it instead of just hiding it you could remove the 'admin-gallery' script that is used to insert the gallery settings form. And if you wanted it to be remove only for non-admins then something like this should work:
function disable_wp_gallery()
{
if( !current_user_can('manage_options') )
wp_deregister_script('admin-gallery');
}
add_action('admin_enqueue_scripts', 'disable_wp_gallery');
To remove elements in the media editor, you can unset them. I haven't tested it for the insert button, but you can try this. Put this function in the functions.php
file of your theme.
function remove_media_editor_fields($fields) {
unset($fields['submit']);
return $fields;
}
add_filter('attachment_fields_to_edit','remove_media_editor_fields');
Or with CSS, for both elements you cite :
function add_custom_admin_styles() {
if( !current_user_can('administrator') ){
echo '
<style type="text/css">
#media-items #savesend .button{display:none!important;}
#gallery-settings{display:none!important;}
</style>';
}
}
Well, I couldn't find how to unset
it, so I'm using my old method:
function auto_media() {
echo '<style type="text/css">
#media-items .savesend input.button, #gallery-settings * {display:none;}
</style>';
}
add_action('admin_head', 'auto_media');