I solved in this way
add_filter( 'media_view_strings', 'my_media_view_strings');
function my_media_view_strings($strings) {
if (!current_user_can('edit_theme_options') ){
$strings["insertMediaTitle"] = ""; //Don't unset!
unset($strings["insertFromUrlTitle"]);
}
return $strings;
}
//Media button click open "Create Gallery"
add_action( 'wp_enqueue_media', 'openGallery' );
function openGallery(){
if (!current_user_can('edit_theme_options') )
add_action( 'admin_print_footer_scripts','openGallery_script', 999);
}
function openGallery_script(){
?>
<script type="text/javascript">
jQuery(function(){
jQuery(".insert-media").click(function (event){
var options = {
frame: 'post',
state: 'gallery',
title: wp.media.view.l10n.createGalleryTitle,
multiple: true
};
wp.media.editor.open(null,options);
});
});
</script>';
<?php
}
Now when a contributor click on “Add Media” button, it shows “Create Gallery” interface.
Problem solved! 🙂