1

In my project (wordpress 3.7.1) contributor users can upload media file, but I want to force them to insert only gallery in post, not single images. Using Capability Manager Enhanced plugin I gave cotributor the ability to upload images, but I don't know how to remove the button "Insert to post" on "Insert Media" menu.

I found the filter media_view_strings and I was able to remove "Insert from URL" like this:

add_filter( 'media_view_strings', 'my_media_view_strings');
function my_media_view_strings($strings) {
  if (!current_user_can('edit_theme_options') ){
    unset($strings["insertFromUrlTitle"]);
  }
  return $strings;
}

I was trying to unset insertMediaTitle too, but this just rename "Insert Media" into "Media Library".

I was looking to understand how the new media gallery works in order to remove unwanted menu, but it's too complex for me to hook into backbone structure.

Is there a simple way to solve my problem?

Thanks to all.

Vannus

1

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! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.