Update [gallery] shortcode

- Roll in changes added from WordPress 3.5

- More minimal code output
This commit is contained in:
Ben Word
2012-12-26 11:22:28 -06:00
parent e3f7365ec6
commit 8000e5c611

View File

@@ -273,11 +273,18 @@ add_filter('img_caption_shortcode', 'roots_caption', 10, 3);
* @link http://twitter.github.com/bootstrap/components.html#thumbnails * @link http://twitter.github.com/bootstrap/components.html#thumbnails
*/ */
function roots_gallery($attr) { function roots_gallery($attr) {
global $post, $wp_locale; $post = get_post();
static $instance = 0; static $instance = 0;
$instance++; $instance++;
if (!empty($attr['ids'])) {
if (empty($attr['orderby'])) {
$attr['orderby'] = 'post__in';
}
$attr['include'] = $attr['ids'];
}
$output = apply_filters('post_gallery', '', $attr); $output = apply_filters('post_gallery', '', $attr);
if ($output != '') { if ($output != '') {
@@ -295,8 +302,9 @@ function roots_gallery($attr) {
'order' => 'ASC', 'order' => 'ASC',
'orderby' => 'menu_order ID', 'orderby' => 'menu_order ID',
'id' => $post->ID, 'id' => $post->ID,
'icontag' => 'li', 'itemtag' => '',
'captiontag' => 'p', 'icontag' => '',
'captiontag' => '',
'columns' => 3, 'columns' => 3,
'size' => 'thumbnail', 'size' => 'thumbnail',
'include' => '', 'include' => '',
@@ -310,15 +318,13 @@ function roots_gallery($attr) {
} }
if (!empty($include)) { if (!empty($include)) {
$include = preg_replace( '/[^0-9,]+/', '', $include ); $_attachments = get_posts(array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
$_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
$attachments = array(); $attachments = array();
foreach ($_attachments as $key => $val) { foreach ($_attachments as $key => $val) {
$attachments[$val->ID] = $_attachments[$key]; $attachments[$val->ID] = $_attachments[$key];
} }
} elseif (!empty($exclude)) { } elseif (!empty($exclude)) {
$exclude = preg_replace('/[^0-9,]+/', '', $exclude);
$attachments = get_children(array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby)); $attachments = get_children(array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
} else { } else {
$attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby)); $attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
@@ -330,48 +336,26 @@ function roots_gallery($attr) {
if (is_feed()) { if (is_feed()) {
$output = "\n"; $output = "\n";
foreach ($attachments as $att_id => $attachment) foreach ($attachments as $att_id => $attachment) {
$output .= wp_get_attachment_link($att_id, $size, true) . "\n"; $output .= wp_get_attachment_link($att_id, $size, true) . "\n";
}
return $output; return $output;
} }
$captiontag = tag_escape($captiontag); $output = '<ul class="thumbnails gallery">';
$columns = intval($columns);
$itemwidth = $columns > 0 ? floor(100/$columns) : 100;
$float = is_rtl() ? 'right' : 'left';
$selector = "gallery-{$instance}";
$gallery_style = $gallery_div = '';
if (apply_filters('use_default_gallery_style', true)) {
$gallery_style = '';
}
$size_class = sanitize_html_class($size);
$gallery_div = "<ul id='$selector' class='thumbnails gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>";
$output = apply_filters('gallery_style', $gallery_style . "\n\t\t" . $gallery_div);
$i = 0; $i = 0;
foreach ($attachments as $id => $attachment) { foreach ($attachments as $id => $attachment) {
$link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false); $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);
$output .= " $output .= '<li>' . $link;
<{$icontag} class=\"gallery-item\"> if (trim($attachment->post_excerpt)) {
$link $output .= '<div class="caption hidden">' . wptexturize($attachment->post_excerpt) . '</div>';
";
if ($captiontag && trim($attachment->post_excerpt)) {
$output .= "
<{$captiontag} class=\"gallery-caption hidden\">
" . wptexturize($attachment->post_excerpt) . "
</{$captiontag}>";
}
$output .= "</{$icontag}>";
if ($columns > 0 && ++$i % $columns == 0) {
$output .= '';
} }
$output .= '</li>';
} }
$output .= "</ul>\n"; $output .= '</ul>';
return $output; return $output;
} }