Make WordPress Core

Opened 10 years ago

Last modified 21 months ago

#29379 new enhancement

Add a hook to filter gallery classes

Reported by: grosbouff's profile grosbouff Owned by:
Milestone: Future Release Priority: low
Severity: normal Version: 3.9.2
Component: Gallery Keywords: has-patch needs-refresh
Focuses: Cc:

Description

Hi, it would be really great to be allowed to filter the gallery classes.

Here's what I suggest :

instead of :

	$size_class = sanitize_html_class( $atts['size'] );
	$gallery_div = "<div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>";

rather use

        $classes_str = null;
        $classes = array(
            'gallery',
            'galleryid-'.$id,
            'gallery-columns-'.$columns,
            'gallery-size-'.sanitize_html_class( $atts['size'] )
        );
        
        $classes = apply_filters('gallery_classes',$classes,$attr);

        if (!empty($classes)){
            $classes = array_filter($classes);
            $classes_str = " class='".implode(' ',$classes)."'";
        }
        

	$size_class = sanitize_html_class( $atts['size'] );
	$gallery_div = "<div id='$selector' $classes_str>";

Attachments (1)

29379.diff (976 bytes) - added by mahype 8 years ago.

Download all attachments as: .zip

Change History (4)

#1 @wonderboymusic
9 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release

@mahype
8 years ago

#2 @mahype
8 years ago

  • Keywords has-patch needs-docs added; needs-patch removed

Added actionhook like in example above.

#3 @desrosj
21 months ago

  • Keywords needs-refresh added; needs-docs removed
  • Milestone set to Future Release
  • Priority changed from normal to low

29379.diff needs to be refreshed against the current code base.

While gallery blocks are the preferred way to implement galleries now and they do not use gallery_shortcode() directly, I think this is a reasonable change to make. Adding a classes attribute to $attr may also make sense to accompany this.

Note: See TracTickets for help on using tickets.