• Just cracked a tough nut and figured I’d share it with the WordPress community…

    I install WP for users who are not WordPress savvy and get confused by the multiple default “Upload/Insert” options. Plus I don’t want them uploading their MP3 or video collections to their blogs and maxxing out their storage. Obviously they still want to upload pictures, but unfortunately the solutions I’ve found here in the forum are “all or nothing” — either show all the Media Uploads or remove them altogether.

    Previously I would go in and edit the admin files to either delete the button links I didn’t want, or overwrite the button images with 1×1 blank gifs. But that was when I was young and foolish, fiddling with the core code because I could. Now that I’m older and wiser, I wanted a solution that would survive WordPress version updates.

    Which brings me to what I developed. Just insert the code below into your theme’s functions.php file….

    function zg_post_buttons()
    	{
    	global $post_ID, $temp_ID;
    
    	$uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID);
    
    	$generic_title = 'Upload/Insert';
    
    	$media_upload_iframe_src = "media-upload.php?post_id=$uploading_iframe_ID";
    	$media_title = 'Add Media';
    	$media_button = '<a href="' . $media_upload_iframe_src . '&TB_iframe=true" id="add_media" class="thickbox" title="' . $media_title . '" onclick="return false;"><img src="images/media-button-other.gif" alt="' . $media_title . '" /></a>';
    
    	$video_upload_iframe_src = apply_filters('video_upload_iframe_src', "$media_upload_iframe_src&type=video");
    	$video_title = 'Add Video';
    	$video_button = '<a href="' . $video_upload_iframe_src . '&TB_iframe=true" id="add_video" class="thickbox" title="' . $video_title . '" onclick="return false;"><img src="images/media-button-video.gif" alt="' . $video_title . '" /></a>';
    
    	$audio_upload_iframe_src = apply_filters('audio_upload_iframe_src', "$media_upload_iframe_src&type=audio");
    	$audio_title = 'Add Audio';
    	$audio_button = '<a href="' . $audio_upload_iframe_src . '&TB_iframe=true" id="add_audio" class="thickbox" title="' . $audio_title . '" onclick="return false;"><img src="images/media-button-music.gif" alt="' . $audio_title . '" /></a>';
    
    	$image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src&type=image");
    	$image_title = 'Add an Image';
    	$image_button = '<a href="' . $image_upload_iframe_src . '&TB_iframe=true" id="add_image" class="thickbox" title="' . $image_title . '" onclick="return false;"><img src="images/media-button-image.gif" alt="' . $image_title . '" /></a>';
    
    	return $image_title . ':' . $image_button;
    	}
    
    add_action('media_buttons_context','zg_post_buttons');

    This replaces the output from “media_buttons_context” (all the “Upload/Insert” buttons) with just what comes after the “return” (in this case, just the image upload). I left in the values for the other 3 buttons so it can be easily customized if you want images AND videos (or audio, or other media).

    I think this is 75% on the way to being a plugin, but I’m happy just putting the code into the theme’s functions file. If someone else wants to take it the rest of the way and make a plugin, more power to ya! (I would imagine a plugin would have checkbox options for which button(s) to include, as well as what text would precede the buttons.)

    In the meantime, I hope this helps some folks looking for the solution I was.

Viewing 3 replies - 1 through 3 (of 3 total)
  • I am trying to put two custom fields for uploading audio as well as thumbnail but the files are not getting upload on the specified location.
    And I don’t want to use any plug-in. This is a type of custom coding.

    Thanks In Advance

    nice code!

    i’m trying to stylize the upload panel too, but i can’t find a way to do it “pluginically”…! there aren’t hooks to do that (at least I don’t have found them…)

    This is great! Thanks for sharing!

    I took things one half-step further by making the link land on the Media Library tab by default:

    $image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src&type=image&tab=library");

    Just added &tab=library onto the end. I reuse a lot of the same pictures for my site, so more often than not I need to look in the library and not upload.

    Most people probably don’t need to do that, but if you do, then there you go. ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom “Upload/Insert” Media Toolbar for Posts & Pages’ is closed to new replies.