Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#25313 closed defect (bug) (fixed)

Video and audio shortcode callback functions wrapped in a filter, but executed too early to be hooked onto

Reported by: ericlewis's profile ericlewis Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 3.7 Priority: normal
Severity: normal Version: 3.6
Component: Media Keywords: has-patch commit
Focuses: Cc:

Description

In the add_shortcode calls for the video and audio shortcodes, both seem to offer developers the option to register their own callback for this shortcode by wrapping the default callback in a wrapper. However, media.php is loaded before even mu-plugins, so there is no way save hacking core to add a filter here.

Attachments (7)

25313.patch (2.8 KB) - added by SergeyBiryukov 11 years ago.
25313.2.patch (2.8 KB) - added by SergeyBiryukov 11 years ago.
25313.3.patch (1.6 KB) - added by SergeyBiryukov 11 years ago.
25313.4.patch (1.5 KB) - added by ericlewis 11 years ago.
25313.5.patch (1.5 KB) - added by SergeyBiryukov 11 years ago.
25313.6.patch (2.0 KB) - added by ericlewis 11 years ago.
25313.7.patch (2.6 KB) - added by SergeyBiryukov 11 years ago.

Download all attachments as: .zip

Change History (24)

#1 @ericlewis
11 years ago

  • Summary changed from Video and audio shortcode callback functions wrapped in a filter, but too early to be hooked onto to Video and audio shortcode callback functions wrapped in a filter, but executed too early to be hooked onto

#2 @SergeyBiryukov
11 years ago

Confirmed, the filters are currently unusable:
wp_audio_shortcode_handler: tags/3.6.1/wp-includes/media.php#L949
wp_video_shortcode_handler: tags/3.6.1/wp-includes/media.php#L1093

#3 @SergeyBiryukov
11 years ago

25313.patch is an attempt to add all the default shortcodes on init with the highest priority, like we do for create_initial_post_types().

#4 @nacin
11 years ago

I'm OK with 25313.patch, though:

  • It needs a better name. add_shortcodes() sounds like a multiple-shortcode version of add_shortcode(), not a core registration. wp_add_initial_shortcodes() perhaps.
  • As always, I am curious what this might break...

#5 @nacin
11 years ago

To be honest, though, I'd rather just remove these filters and force everything to go through wp_audio_shortcode() and wp_video_shortcode(). Then, have an early filter in both of those functions that allow short-circuiting.

This pattern for existing shortcodes came up *huge* when we changed how the caption shortcode worked, when we put the caption inside the shortcode content. Huge forwards compatibility win.

#6 @SergeyBiryukov
11 years ago

25313.2.patch uses wp_add_initial_shortcodes().

#8 @SergeyBiryukov
11 years ago

  • Milestone changed from Awaiting Review to 3.7

@ericlewis
11 years ago

#9 @ericlewis
11 years ago

Piggybacking on Sergey's work, attachment:25313.4.patch:

  • changes the new filter's name to wp_(audio|video)_shortcode_override, as the filter isn't a handler
  • passes $instances into the filter, as this can be handy in the overriding function to give separate media instances independent names.

#10 @SergeyBiryukov
11 years ago

  • Keywords has-patch added

25313.5.patch changes the default value to an empty string, for consistency with the post_gallery filter.

#11 @ericlewis
11 years ago

#25312 was marked as a duplicate.

#12 @SergeyBiryukov
11 years ago

  • Keywords commit added

#13 @nacin
11 years ago

We should properly document these. Also, while post_gallery is a good model to follow, I'm not sure I love '' !==. We use false more often, though ideally we actually use null wherever possible. Or so goes my idealistic thinking, anyway.

Is there a compelling reason to use ''? I'd think any string returned should be obeyed. Returning nothing is valid in some contexts, I'd suggest.

@ericlewis
11 years ago

#14 @ericlewis
11 years ago

attachment:25313.6.patch adds hook documentation, and changes the pre-filtered value to null.

#15 @SergeyBiryukov
11 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 25484:

Replace non-functional 'wp_audio_shortcode_handler' and 'wp_video_shortcode_handler' filters with 'wp_audio_shortcode_override' and 'wp_video_shortcode_override'.

props ericlewis, SergeyBiryukov.
fixes #25313.

#16 @SergeyBiryukov
11 years ago

25313.7.patch makes the arguments more consistent with the ones of img_caption_shortcode and post_gallery filters, per the IRC discussion.

#17 @SergeyBiryukov
11 years ago

In 25485:

Make the arguments of 'wp_audio_shortcode_override' and 'wp_video_shortcode_override' more consistent with the ones of 'img_caption_shortcode' and 'post_gallery' filters.

see #25313.

Note: See TracTickets for help on using tickets.