Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#41853 closed feature request (worksforme)

Filter to handle/override the list of IDs in the Gallery Shortcode

Reported by: TigrouMeow Owned by:
Priority: normal Milestone:
Component: Gallery Version: 4.8.1
Severity: normal Keywords:
Cc: Focuses: ui

Description

It would be nice to handle the IDs of the media which are used in the Gallery Shortcode from other plugins, depending on the attributes of the shortcode for instance.

A simple filter like:

$attr['ids'] = apply_filters( 'gallery_images', !empty( $attr['ids'] ) ? $attr['ids'] : null, $attr );

Would be perfect! And it could be right before:

if ( ! empty( $attr['ids'] ) ) {
  // 'ids' is explicitly ordered, unless you specify otherwise.
  if ( empty( $attr['orderby'] ) ) {
                $attr['orderby'] = 'post__in';
  }
  $attr['include'] = $attr['ids'];
}

It is a simple change that wouldn't break anything. And it would allow plugins/themes to handle images in Gallery without having to create complicated Gallery systems. What about it?

Thanks :)

Change History (3)

#1 @birgire
9 years ago

Thanks for your suggestion, but what about the shortcode_atts_gallery filter available since version 3.6?

Example:

add_filter('shortcode_atts_gallery', function( $out, $pairs, $atts ) {
    // ... 
    return $out;
}, 10, 3 );

where

* @param array  $out       The output array of shortcode attributes.
* @param array  $pairs     The supported attributes and their defaults.
* @param array  $atts      The user defined shortcode attributes.
Last edited 9 years ago by birgire (previous) (diff)

#2 @TigrouMeow
9 years ago

  • Resolutionworksforme
  • Status newclosed

Indeed, that works perfectly for me, in my case :) I'll mark this as resolved. Thanks a lot for your help, I didn't knew about this filter :)

#3 @SergeyBiryukov
9 years ago

  • Milestone Awaiting Review
Note: See TracTickets for help on using tickets.