Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#34167 closed enhancement (fixed)

Shortcode_atts pass $shortcode

Reported by: mattheu's profile mattheu Owned by: helen's profile helen
Milestone: 4.4 Priority: normal
Severity: normal Version: 4.4
Component: General Keywords: has-patch
Focuses: Cc:


It would be useful to pass the Shortcode name as the 4th param to the filter shortcode_atts_{$shortcode}

Use case - I am wanting to add a filter for a number of shortcodes - so I loop through the and add the filter. However this means that I don't know the exact shortcode context in the callback.

Workaround - I am currently working around this by using a closure and use to import the $shortcode variable into the closure. However this is not PHP 5.2 compatable.

Attachments (2)

34167.diff (724 bytes) - added by mattheu 9 years ago.
34167.2.diff (887 bytes) - added by mattheu 9 years ago.

Download all attachments as: .zip

Change History (9)

9 years ago

#1 @jdgrimes
9 years ago

  • Keywords has-patch added

Just FYI, another option in a case like this is to use the current_filter() function to determine the value of the dynamic portion of the hook. Your patch would be even better, of course. :-)

#2 @helen
9 years ago

  • Milestone changed from Awaiting Review to 4.4

Just for reference, since I wondered this as I read the ticket: in #15155 it appears that @nacin suggested not having the generic `shortcode_atts` filter.

#3 @mattheu
9 years ago

Oh good call on using current_filter to achieve this. I'd be happy enough with this solution.

#4 @helen
9 years ago

Two things about the patch:

  • Needs a changelog entry for the added argument.
  • Since we're touching the lines, add curly braces.

Adding context seems like a smart thing to do, though workarounds may exist.

9 years ago

#5 @mattheu
9 years ago

Updated patch to address comments by @helen

#6 @helen
9 years ago

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

In 34868:

Shortcodes: Pass the name as context for shortcode_atts_{$shortcode}.

props mattheu.
fixes #34167.

#7 @nacin
9 years ago

Good change.

Note: See TracTickets for help on using tickets.