WordPress.org

Make WordPress Core

Ticket #26623: media(2).php.patch

File media(2).php.patch, 2.5 KB (added by bcworkz, 6 years ago)
  • src/wp-includes/media.php

     
    735735                'size'       => 'thumbnail',
    736736                'include'    => '',
    737737                'exclude'    => '',
    738                 'link'       => ''
     738                'link'       => '',
     739                'class'          => ''
    739740        ), $attr, 'gallery'));
    740741
    741742        $id = intval($id);
     
    804805                        /* see gallery_shortcode() in wp-includes/media.php */
    805806                </style>";
    806807        $size_class = sanitize_html_class( $size );
    807         $gallery_div = "<div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>";
    808         $output = apply_filters( 'gallery_style', $gallery_style . "\n\t\t" . $gallery_div );
    809808
     809        //allow plugins or themes to alter the gallery class
     810        $gallery_class = apply_filters( 'gallery_class', "gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class} {$class}", $selector, $attr );
     811
     812        //allow plugins or themes to alter the gallery container's opening markup. E.g. include extra attributes or even use a different tag
     813        $gallery_start = apply_filters( 'gallery_container_start', "<div id='$selector' class='$gallery_class'>", $selector, $gallery_class, $attr );
     814
     815        //allow plugins or themes to alter the default gallery inline styles
     816        $gallery_style = apply_filters( 'gallery_style', $gallery_style, $selector, $attr );
     817
     818        //allow plugins or themes to alter the gallery column separator markup
     819        $gallery_separator = apply_filters( 'gallery_column_separator', '<br style="clear: both" />', $selector, $attr );
     820
     821        //allow plugins or themes to alter the gallery container's closing markup
     822        $gallery_end = apply_filters( 'gallery_container_end', "
     823                        <br style='clear: both;' />
     824                </div>\n", $selector, $attr );
     825
     826        $output =  $gallery_style . "\n\t\t" . $gallery_start;
     827
    810828        $i = 0;
    811829        foreach ( $attachments as $id => $attachment ) {
    812830                if ( ! empty( $link ) && 'file' === $link )
     
    816834                else
    817835                        $image_output = wp_get_attachment_link( $id, $size, true, false );
    818836
     837                $image_output = apply_filters('gallery_image_output', $image_output, $id, $size );
    819838                $image_meta  = wp_get_attachment_metadata( $id );
    820839
    821840                $orientation = '';
     
    835854                }
    836855                $output .= "</{$itemtag}>";
    837856                if ( $columns > 0 && ++$i % $columns == 0 )
    838                         $output .= '<br style="clear: both" />';
     857                        $output .= $gallery_separator;
    839858        }
    840859
    841         $output .= "
    842                         <br style='clear: both;' />
    843                 </div>\n";
     860        $output .= $gallery_end;
    844861
    845862        return $output;
    846863}