[wp-hackers] Is there a way to get the callback function name out of a shortcode _programmatically_?

J.D. Grimes jdg at codesymphony.co
Mon Nov 11 20:30:19 UTC 2013


I don’t think you need to use is_callable(). add_shortcode() does that check before adding the shortcode to the $shortcode_tags global. Of course it couldn’t hurt.

-J.D.

On Nov 11, 2013, at 3:26 PM, Haluk Karamete <halukkaramete at gmail.com> wrote:

> Thank you guys...
> 
> Nikola, i'm just curious. I'm not sure as to why I should worry about the
> "is_callable" matter? Why would an existing shortcode tag work with a not
> callable function... see what I mean?
> 
> 
> On Mon, Nov 11, 2013 at 12:21 PM, Nikola Nikolov <nikolov.tmw at gmail.com>wrote:
> 
>> You can access the global $shortcode_tags variable. If you want to wrap it
>> in a function, it would look something like this:
>> 
>> function get_shortcode_callback_for( $shortcode ) {
>>    return isset( $GLOBALS['shortcode_tags'][ $shortcode ] ) ?
>> $GLOBALS['shortcode_tags'][ $shortcode ] : false;
>> }
>> 
>> This will return the callback for the shortcode tag that you passed, or
>> false if such shortcode hasn't been registered yet.
>> 
>> Note, that the returned callback can be any type of
>> callable<http://php.net/manual/en/language.types.callable.php>,
>> So - you should use is_callable( $callback )<
>> http://us3.php.net/is_callable> in
>> order to check if the parameter is actually callable.
>> 
>> 
>> On Mon, Nov 11, 2013 at 10:12 PM, Haluk Karamete <halukkaramete at gmail.com
>>> wrote:
>> 
>>> Is there a way to get the callback function name out of a shortcode
>>> _programmatically_?
>>> 
>>> for example
>>> 
>>> get_shortcode_callback_for('caption')
>>> 
>>> would return
>>> 
>>> "img_caption_shortcode"
>>> _______________________________________________
>>> wp-hackers mailing list
>>> wp-hackers at lists.automattic.com
>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>> 
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>> 
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list