plugin template tag function

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

plugin template tag function

Matt Read
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);
                }
        }
}


--
Matthew Read
http://www.mattread.com/
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: plugin template tag function

Robert Deaton
On 2/10/06, Matt Read <[hidden email]> 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

_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: plugin template tag function

Andy Skelton
On 2/10/06, Robert Deaton <[hidden email]> wrote:
> 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.

+1 for elegance
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: plugin template tag function

Mark Jaquith
On Feb 10, 2006, at 7:41 AM, Andy Skelton wrote:

> On 2/10/06, Robert Deaton <[hidden email]> wrote:
>> 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.
>
> +1 for elegance

Be sure to tell them to check and make sure they're not stepping on  
an existing hook, (http://wphooks.flatearth.org/) but otherwise, I  
like it a lot!

--
Mark Jaquith
http://txfx.net/


_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers