Make WordPress Core

Opened 10 years ago

Last modified 7 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
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 (2)

29379.diff (976 bytes) - added by mahype 9 years ago.
29379.patch (993 bytes) - added by shailu25 7 months ago.
Refreshed Patch.

Download all attachments as: .zip

Change History (6)

#1 @wonderboymusic
9 years ago

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

@mahype
9 years ago

#2 @mahype
9 years ago

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

Added actionhook like in example above.

#3 @desrosj
2 years 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.

@shailu25
7 months ago

Refreshed Patch.

#4 @shailu25
7 months ago

  • Keywords needs-refresh removed
Note: See TracTickets for help on using tickets.