diff --git a/inc/bootstrap-wp-gallery.php b/inc/bootstrap-wp-gallery.php index 6ccc70c..1a471a2 100644 --- a/inc/bootstrap-wp-gallery.php +++ b/inc/bootstrap-wp-gallery.php @@ -1,105 +1,129 @@ 'ASC', 'orderby' => 'menu_order ID', 'id' => $post->ID, - 'itemtag' => '', - 'icontag' => '', - 'captiontag' => '', + 'itemtag' => 'div', + 'icontag' => 'div', + 'captiontag' => 'div', 'columns' => 3, 'size' => 'thumbnail', - 'include' => '', - 'exclude' => '', - 'link' => '' - ], $attr)); - $id = intval($id); - $columns = (12 % $columns == 0) ? $columns : 3; - $grid = sprintf('col-sm-%1$s col-lg-%1$s', 12 / $columns); - if ($order === 'RAND') { - $orderby = 'none'; - } - if (!empty($include)) { - $_attachments = get_posts(['include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby]); - $attachments = []; - foreach ($_attachments as $key => $val) { - $attachments[$val->ID] = $_attachments[$key]; + 'exclude' => '' + ), $attr ) ); + + // Initialize + $id = intval( $id ); + $attachments = array(); + if ( $order == 'RAND' ) $orderby = 'none'; + + + if ( ! empty( $include ) ) { + + // Include attribute is present + $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 ) ); + + // Setup attachments array + foreach ( $_attachments as $key => $val ) { + $attachments[ $val->ID ] = $_attachments[ $key ]; } - } elseif (!empty($exclude)) { - $attachments = get_children(['post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby]); + + } else if ( ! empty( $exclude ) ) { + + // Exclude attribute is present + $exclude = preg_replace( '/[^0-9,]+/', '', $exclude ); + + // Setup attachments array + $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(['post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby]); + // Setup attachments array + $attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) ); } - if (empty($attachments)) { - return ''; - } - if (is_feed()) { + + if ( empty( $attachments ) ) return ''; + + // Filter gallery differently for feeds + if ( is_feed() ) { $output = "\n"; - foreach ($attachments as $att_id => $attachment) { - $output .= wp_get_attachment_link($att_id, $size, true) . "\n"; - } + foreach ( $attachments as $att_id => $attachment ) $output .= wp_get_attachment_link( $att_id, $size, true ) . "\n"; return $output; } - $unique = (get_query_var('page')) ? $instance . '-p' . get_query_var('page') : $instance; - $output = '' : ''; - $output .= ''; - return $output; -} -add_shortcode('gallery', 'shortcode_gallery'); -/** - * Add class="thumbnail img-thumbnail" to attachment items - */ -function attachment_link_class($html) { - $html = str_replace(' 0 ? floor( 12 / $columns ) : 100; + $float = is_rtl() ? 'right' : 'left'; + $selector = "gallery-{$instance}"; + + // Filter gallery CSS + $output = apply_filters( 'gallery_style', " + + \n"; + + return $output; + } -add_filter('wp_get_attachment_link', 'attachment_link_class', 10, 1); + +// Apply filter to default gallery shortcode +add_filter( 'post_gallery', 'bootstrap_wp_gallery', 10, 2 );