2

I'm creating a setting to set a logo. It works but there is a problem.
I only need one image to be set so the gallery item should be disabled / hidden. Of course this should only effect this page, of even better this setting.

<?php
// above this I do a simple settings api
?>
<input id="set_logo" type="text" size="100" name="set_logo" value="<?php echo esc_attr( $value ); ?>" />
<?php
do_action( 'media_buttons', 'set_logo' );

I've looked in multiple places in code but I can't find any clues how to do this.

EDIT
I've solved it in a different way that is not related to this. The solution is now implemented in my first plugin: http://wordpress.org/extend/plugins/default-featured-image/
shameless plug.

2 Answers 2

2

You can disable tabs using a filter hook. Replace wpse_76095_isOurMediaUpload() with however you determine that you're running the media popup.

add_filter('media_upload_tabs', 'wpse_76095_filterMediaUploadTabs');

/**
* filter out unwanted media upload tabs
* @param array $tabs
* @return array
*/
function wpse_76095_filterMediaUploadTabs($tabs) {
    if (wpse_76095_isOurMediaUpload()) {
        unset(
            $tabs['type_url'],  // no linking from external sites (no local image)
            $tabs['gallery'],   // no galleries
            $tabs['nextgen']    // no NextGEN galleries
        );
    }

    return $tabs;
}
1
  • 2
    This only works for WP pre-3.5. Check the answer by Brasofilo.
    – W van Dam
    Jan 12, 2015 at 15:16
2

I didn't reproduced the particulars of the Q. But the following works to disable the Create Gallery link from the new media interface:

add_action( 'admin_footer-post-new.php', 'disable_media_gallery_wpse_76095' );
add_action( 'admin_footer-post.php', 'disable_media_gallery_wpse_76095' );
function disable_media_gallery_wpse_76095() 
{
    ?>
    <script type="text/javascript">
    jQuery(document).ready( function($) {
        $(document.body).one( 'click', '.insert-media', function( event ) {
            $(".media-menu").find("a:contains('Gallery')").remove();
        });
    });
    </script>
    <?php
}

ps: I just discovered the one in jQuery, nice one ;)

remove gallery from new media uploader

4
  • Ahh thanes for the response. But I already found a solution, and implemented it in my plugin: wordpress.org/extend/plugins/default-featured-image
    – janw
    Jan 6, 2013 at 21:43
  • Well, the Question was hanging all alone in Unanswered list... Would be nice then that you added an Answer with your solution.
    – brasofilo
    Jan 6, 2013 at 21:44
  • Yes I understand but the way I solved it is so different (in code) It doesn't fit. And I kinda forgot this question :|
    – janw
    Jan 7, 2013 at 10:15
  • The 'unset( $strings['createGalleryTitle'] );' solution does not work properly on WP 3.6- but this did. Cheers.
    – Christine Cooper
    Aug 11, 2013 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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