[wp-hackers] Accessing a plugins function from theme

Christian Gundersson christian at buro2.se
Wed Jul 21 09:21:23 UTC 2010


Hi,

Thanks for the replies. I see now that I probably should have clarified a
bit more :)

I have done this but my function isn't getting called like it should. I get
a "call to undefined function" error when I access the theme file.

I have declared a function foo() in my plugins base file. I haven't attached
it to any filters or hooks of any kind. In my theme file I call the function
simply by 

if ( function_exists ( 'foo' ) )
foo();

Have I missed anything, or should that "just work"?

Thanks again!

//Christian



-----Ursprungligt meddelande-----
Från: wp-hackers-bounces at lists.automattic.com
[mailto:wp-hackers-bounces at lists.automattic.com] För Andrew Nacin
Skickat: den 21 juli 2010 11:02
Till: wp-hackers at lists.automattic.com
Ämne: Re: [wp-hackers] Accessing a plugins function from theme

On Jul 21, 2010, at 4:48 AM, Christian Gundersson wrote:

> Is there any way that I can access a function in a plugin from a theme?
>

On Wed, Jul 21, 2010 at 4:56 AM, Mike Schinkel <mikeschinkel at newclarity.net>
 wrote:

> Yes, any functions in your plugin go into PHP's global name space and will
> be accessible from your theme.
>

You may also wish to wrap that function in a function_exists() call to
ensure that the theme doesn't error out if the plugin is deactivated.

You may also be interested in this blog post on rethinking how functions
defined in plugins could be used in themes:
http://www.andrewnacin.com/2010/05/18/rethinking-template-tags-in-plugins/
_______________________________________________
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