Opened 9 years ago
Closed 6 years ago
#33979 closed enhancement (maybelater)
Add filter for 'post_gallery_item'
Reported by: | lostmotionassembly | Owned by: | antpb |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.4 |
Component: | Gallery | Keywords: | has-patch |
Focuses: | Cc: |
Description
This would allow developers to customise the individual gallery items, without having to duplicate the entire gallery_shortcode() function to do so. This would make it quicker, easier to understand, and reduce the likelihood of the gallery shortcode functionality 'drifting' away from core. A sample use case would be wanting to add additional classes to the gallery item based on attachment meta (such as additional orientation options like 'square' or 'panorama').
Attachments (4)
Change History (21)
#3
@
7 years ago
- Milestone changed from Awaiting Review to 4.9.3
I've refreshed the patch for 4.9.3. This could be very useful going forward.
#4
@
7 years ago
- Milestone changed from 4.9.3 to 5.0
New hooks are generally added in major releases, moving to 5.0.
This ticket was mentioned in Slack in #core-media by antpb. View the logs.
7 years ago
#8
in reply to:
↑ 6
@
7 years ago
Replying to tristangemus:
Similar? https://core.trac.wordpress.org/attachment/ticket/38228/patch_38228.3.diff
This is similar but a different context. That ticket aims to filter the entire generated output of the shortcode whereas this one is being used for just a single image within the gallery. Love both of these tickets, but we should definitely keep them separate :)
I would also like to see the ability to modify more than just classes using this filter. Adding data attributes to the tag, or changing the image size for the current image would be great. That could allow more creative gallery layouts, such as the tiled gallery in Jetpack. https://jetpackme.files.wordpress.com/2013/11/example-gallery-tiled.jpg
This ticket was mentioned in Slack in #core-media by antpb. View the logs.
7 years ago
#10
@
7 years ago
- Owner set to antpb
- Status changed from new to assigned
It was mentioned by @mikeschroder in the Media Component meeting today that we should look into how this may impact Gutenberg. My gut tells me that this wont enhance the Gutenberg experience since the filter is set somewhere in the shortcode functions but maybe we can look into this through the Gutenberg lens.
This ticket was mentioned in Slack in #core by jon_bossenger. View the logs.
6 years ago
This ticket was mentioned in Slack in #core by pbiron. View the logs.
6 years ago
@
6 years ago
pass an array, rather than a string, to filter. and sanitize the return value of the filter.
#14
@
6 years ago
we discussed the possibility of including this in 4.9.8 during today's bug scrub. It was decided not to do so, because it was felt the latest patch (at that time) was missing a few things.
33979.4.diff addresses those things:
- filter should accept an array (instead of string) for
$classes
; this is for consistency with similar existing filters, e.g., post_class; - filter return value cast to array() (just in case);
sanitize_html_class()
applied to each element in the filter return value array;
Notice that 33979.4.diff
begins by passing an empty array to the filter, and then adds gallery-item
in as the final step before the item's opening tag is added to the output. I'd be OK doing it the way the previous patch did (i.e., passing array( 'gallery-item' )
to the filter, but it seems safer to me to do it the way I did.
This ticket was mentioned in Slack in #core-media by joemcgill. View the logs.
6 years ago
#17
@
6 years ago
- Milestone 5.1 deleted
- Resolution set to maybelater
- Status changed from assigned to closed
This one needs to be re-evaluated. A lot has changed in the last 6 months, and the path forward is the gallery block (and blocks in general), not the gallery shortcode (and shortcodes in general).
Not against adding a filter for the gallery shortcode, but there are a lot more factors to consider now that the block editor has been released. If someone wants to dig back into this, it can be reopened and explored further.
Added filter for gallery item classes.