Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I use the media uploader in a own meta-box for a custom post type called "premium". The Thickbox opens after a click of the button in the meta-box and files can be uploaded.

Now I want to remove the tabs "From URL" and "Library" only when used the uploader in the edit/new-page for the CPT or if possible with the call of the click-event.

I have no idea how to resolve.

P.S.: I use this js for calling the thickbox and tried to remove a tab via jQuery:

jQuery(document).ready(function() {
    jQuery('#pc_extContent_button').click(function() {
    formfield = jQuery('#pc_extContent').attr('name');
    tbframe_interval = setInterval(function() {
        jQuery('#tab-type_url').hide();
    }, 2000);
    tb_show('', 'media-upload.php?type=file&TB_iframe=true')
    return false;
});
share|improve this question

2 Answers 2

up vote 5 down vote accepted

You can use the media_upload_tabs filter check for your post type and unset any tab you don't want ex:

function remove_media_library_tab($tabs) {
    if (isset($_REQUEST['post_id'])) {
        $post_type = get_post_type($_REQUEST['post_id']);
        if ('premium' == $post_type)
            unset($tabs['library']);
            unset($tabs['type_url']);
    }
    return $tabs;
}
add_filter('media_upload_tabs', 'remove_media_library_tab');
share|improve this answer
    
Thanks for the starting point. But it doesn't work, if you call the thickbox, via a js like mentioned in my question. So I ended up with the solution I quote in the following answer. –  Guru 2.0 Mar 26 '12 at 17:59

First it is necessar to change the JavaScript for including the post_id in the request:

jQuery(document).ready(function() {
    jQuery('#pc_extContent_button').click(function() {
        var pID = jQuery('#post_ID').val();
        formfield = jQuery('#pc_extContent').attr('name');
        tb_show('premiumTB', 'media-upload.php?post_id='+ pID +'&type=image&TB_iframe=true');
        return false;
    });
    window.send_to_editor = function(html) {
        imgurl = jQuery('img', html).attr('href');
        jQuery('#pc_extContent').val(imgurl);
        tb_remove();
    }
});

Then the solution of Bainternet can be used in the functions.php (or similar)

function remove_media_library_tab($tabs) {
  if (isset($_REQUEST['post_id'])) {
    $post_type = get_post_type($_REQUEST['post_id']);
    if ('premium' == $post_type) {
      unset($tabs['library']);
      unset($tabs['type_url']);
    }
  }
  return $tabs;
}
add_filter('media_upload_tabs', 'remove_media_library_tab');

So all works fine together and the tabs are removed.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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