Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#41853 closed feature request (worksforme)

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

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

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
7 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 7 years ago by birgire (previous) (diff)

#2 @TigrouMeow
7 years ago

  • Resolution set to worksforme
  • Status changed from new to closed

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
7 years ago

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