From 8000e5c6114a7591cab28e8a0d27697da65a5120 Mon Sep 17 00:00:00 2001 From: Ben Word Date: Wed, 26 Dec 2012 11:22:28 -0600 Subject: [PATCH] Update [gallery] shortcode - Roll in changes added from WordPress 3.5 - More minimal code output --- lib/cleanup.php | 56 ++++++++++++++++++------------------------------- 1 file changed, 20 insertions(+), 36 deletions(-) diff --git a/lib/cleanup.php b/lib/cleanup.php index ac5666c..c194a07 100644 --- a/lib/cleanup.php +++ b/lib/cleanup.php @@ -273,11 +273,18 @@ add_filter('img_caption_shortcode', 'roots_caption', 10, 3); * @link http://twitter.github.com/bootstrap/components.html#thumbnails */ function roots_gallery($attr) { - global $post, $wp_locale; + $post = get_post(); static $instance = 0; $instance++; + if (!empty($attr['ids'])) { + if (empty($attr['orderby'])) { + $attr['orderby'] = 'post__in'; + } + $attr['include'] = $attr['ids']; + } + $output = apply_filters('post_gallery', '', $attr); if ($output != '') { @@ -295,8 +302,9 @@ function roots_gallery($attr) { 'order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post->ID, - 'icontag' => 'li', - 'captiontag' => 'p', + 'itemtag' => '', + 'icontag' => '', + 'captiontag' => '', 'columns' => 3, 'size' => 'thumbnail', 'include' => '', @@ -310,15 +318,13 @@ function roots_gallery($attr) { } 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(); foreach ($_attachments as $key => $val) { $attachments[$val->ID] = $_attachments[$key]; } } 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)); } else { $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()) { $output = "\n"; - foreach ($attachments as $att_id => $attachment) + foreach ($attachments as $att_id => $attachment) { $output .= wp_get_attachment_link($att_id, $size, true) . "\n"; + } return $output; } - $captiontag = tag_escape($captiontag); - $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 = "'; return $output; }