Make WordPress Core

Ticket #33979: 33979.4.diff

File 33979.4.diff, 1.7 KB (added by pbiron, 6 years ago)

pass an array, rather than a string, to filter. and sanitize the return value of the filter.

  • src/wp-includes/media.php

    From cedd0cb7a72104f4f7117508199a3c9950fcb1e3 Mon Sep 17 00:00:00 2001
    From: Paul Biron <paul@sparrowhawkcomputing.com>
    Date: Mon, 16 Jul 2018 16:05:00 -0600
    Subject: [PATCH] revised patch: 1) filter should accept an array (instead of
     string) for $classes; 2) filter return value cast to array() (just in case);
     3) sanitize_html_class() array_map'd to filter return value; 4)
     'gallery-item' added if not already present.
    
    ---
     src/wp-includes/media.php | 16 +++++++++++++++-
     1 file changed, 15 insertions(+), 1 deletion(-)
    
    diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php
    index c93c3db..19c8d1a 100644
    a b function gallery_shortcode( $attr ) { 
    18631863                if ( isset( $image_meta['height'], $image_meta['width'] ) ) {
    18641864                        $orientation = ( $image_meta['height'] > $image_meta['width'] ) ? 'portrait' : 'landscape';
    18651865                }
    1866                 $output .= "<{$itemtag} class='gallery-item'>";
     1866
     1867                /**
     1868                 * Filter the gallery item classes.
     1869                 *
     1870                 * @since 5.0
     1871                 *
     1872                 * @param array $classes    Classes applied to gallery item.
     1873                 * @param object $attachment Attachment object.
     1874                 */
     1875                $gallery_item_classes = (array) apply_filters( 'gallery_item_classes', array(), $attachment );
     1876                $gallery_item_classes = array_filter( array_map( 'sanitize_html_class', $gallery_item_classes ) );
     1877                $gallery_item_classes = array_merge( array( 'gallery-item' ), $gallery_item_classes );
     1878                $gallery_item_classes = implode( ' ', $gallery_item_classes );
     1879
     1880                $output .= "<{$itemtag} class='{$gallery_item_classes}'>";
    18671881                $output .= "
    18681882                        <{$icontag} class='gallery-icon {$orientation}'>
    18691883                                $image_output