[wp-hackers] plugin template tag function

Robert Deaton false.hopes at gmail.com
Fri Feb 10 12:16:59 GMT 2006


On 2/10/06, Matt Read <lists at mattread.com> wrote:
> I think it would be nice if there was a function for calling plugin functions
> from templates; it would check if the function exists etc.
>
> Here's one I came up with:
>
>
> function plugin_template_tag($function, $args = '') {
>         if (is_array($function)) {
>                 if (is_object($function[0])) {
>                         call_user_func_array($function, $args);
>                 }
>                 elseif (class_exists($function[0])) {
>                         call_user_func_array($function, $args);
>                 }
>         }
>         else {
>                 if (function_exists($function)) {
>                         call_user_func_array($function, $args);
>                 }
>         }
> }

Personally, I like the idea that was discussed a few months back,
where plugins tell users to put a do_action('plugin_template_hook');
or somesuch in the theme, so that it degrades nicely as well. Its a
bit shorter and achieves the same purpose.

--
--Robert Deaton
http://somethingunpredictable.com


More information about the wp-hackers mailing list