Opened 9 years ago
Closed 8 years ago
#32790 closed enhancement (fixed)
Filter for do_shortcode_tag()
Reported by: | danielbachhuber | Owned by: | flixos90 |
---|---|---|---|
Milestone: | 4.7 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Shortcodes | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
As a WordPress developer with a collection of shortcodes, I want to include some standard JavaScript every time a shortcode in my collection is run.
In this pull request, I had to create a standard callback for all shortcodes in order to run wp_enqueue_script()
. If I could filter the return value for do_shortcode_tag()
, I could still enqueue my scripts, as well as modify the output of the shortcode.
Attachments (2)
Change History (9)
#1
@
9 years ago
- Keywords needs-patch removed
- Milestone changed from Future Release to Awaiting Review
#3
@
8 years ago
- Keywords has-patch needs-unit-tests added
32790.diff introduces the do_shortcode_tag
filter to allow filtering the shortcode output. This also allows us, in combination with 38506, to cache expensive shortcodes.
I also removed a bit of repetitive code before to only handle what's different between the two if-clauses (namely whether $content
is passed to the shortcode callback or not).
#4
@
8 years ago
- Milestone changed from Awaiting Review to 4.7
- Owner set to flixos90
- Status changed from new to assigned
32790.diff looks good. Just add some unit tests, and we're good to go! :-)
#5
@
8 years ago
- Keywords has-unit-tests added; needs-unit-tests removed
32790.2.diff adds unit tests for the filter.
I had similar requirements.
Having already implemented all my shortcodes using the same handler
it was easy for me to add the new filter functions for 1. and 2.
I don't know how to do 3. yet. :-)
See http://www.oik-plugins.com/oik_api/bw_shortcode_event/
You may also want to look at #32445:3
where Nacin proposes rewriting the shortcode API to use hooks under the hood.
Perhaps if do_shortcode_tag() or do_shortcode() were pluggable then we'd be able to do all sorts of interesting things.
Maybe the function to invoke in the preg_replace_callback(,do_shortcode_tag, ) calls could be determined using a filter.
Let's hope this requirement gets considered in the shortcode roadmap.