[wp-trac] [WordPress Trac] #52055: Enhancing media gallery on the front-end is almost impossible. Improvement suggestion.

WordPress Trac noreply at wordpress.org
Sun Dec 13 08:52:01 UTC 2020


#52055: Enhancing media gallery on the front-end is almost impossible. Improvement
suggestion.
-------------------------+-----------------------------
 Reporter:  webbistro    |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Media        |    Version:  5.6
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 Hi there! I am an author of the Enhanced Media Library plugin, and I
 constantly encounter the same problem with enhancing media
 galleries/playlists.

 The problem: I need to add a parameter to the gallery (shortcode). That
 parameter changes the **query**, and returns another set of attachment IDs
 (content of the gallery). I do not need to change the **look** (HTML) of
 the gallery, I just need to process gallery parameters and change its
 content which is supposed to be displayed by a theme or a plugin **after**
 my plugin changed the `ids` set.

 So, I hook to the `shortcode_atts`.

 But! In the `gallery_shortcode` function we have called the `post_gallery`
 filter, which allows totally redefine the gallery's output (HTML) and
 which is used by plugins and themes for this purpose.

 If it was used, then the function returns its result and **all code bellow
 is never executed**.

 So, the `shortcode_atts` function is never called in case that some
 theme/plugin changes **just** gallery HTML. We do not have any hook prior
 to the `post_gallery` to make changes to the gallery's content.

 So, we have an option of whether to change the content **OR** the look of
 the gallery, which is, actually, weird.

 Of course, I can use the `post_gallery` and change both the content
 **and** the look. But in this case, a theme or a plugin cannot change the
 look of my content after that.

 I believe, that we have to separate modifying the gallery content query
 and the gallery output.

 The simplest solution (I see) is to move

 {{{#!php
 <?php
 $output = apply_filters( 'post_gallery', '', $attr, $instance );

 if ( ! empty( $output ) ) {
     return $output;
 }
 }}}

 after the call of `shortcode_atts`.

 But I also would like to separate the code of the `gallery_shortcode` into
 two parts:
 (1) querying for the content with its hooks
 (2) displaying HTML with its hooks.

 Any thoughts on this?

 Best,
 -Nadia

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/52055>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list