<?php

/*
Plugin Name: Better Gallery
Description: Replaces <tt>[gallery]</tt> shortcode.
Author: Sam
Version: 0.1
*/

add_filter('post_gallery', 'my_post_gallery', 10, 2);

function my_post_gallery( $output, $args ) {
	
	if ( isset( $args['orderby'] ) ) {
		$args['orderby'] = sanitize_sql_orderby( $args['orderby'] );
	}
	
	$attr = array_merge( array(
		'order'      => 'ASC',
		'orderby'    => 'menu_order ID',
		'id'         => get_the_ID(),
		'itemtag'    => false, // can't use this, we only use LI
		'icontag'    => false,
		'captiontag' => false,
		'columns'    => 0,
		'size'       => 'thumbnail',
		// new
		'captions'	=> false,
		'permalink'	=> false,
		'type'	=> 'image',
		'icon'	=> false,
		)
		, $args
	);
	
	var_dump($args, $attr);
	
	$attachments = get_children( array(
		'post_parent' => get_the_ID(),
		'post_type' => 'attachment',
		'post_mime_type' => $attr['type'],
	));
	if ( empty($attachments) )
		return '';
		
	$output .= '<!-- ' . __FILE__ . ' -->' . '<ul class="gallery">'; // classes
	foreach ( $attachments as $id => $attachment ) {
		$output .= "\n\t<li>"
			. wp_get_attachment_link( $id, $attr['size'], (bool) $attr['permalink'], (bool) $attr['icon'] )
			. '</li>';
	}
	$output .= '</ul>';
	
	return $output;
}

?>