views:

42

answers:

2

Hi

so I'm using Wordpress, which loads the theme and possibly many plugins which can have functions with the same names as the ones in the theme.

How can I avoid function name conflicts between the theme and plugins, without having to rename them to something like "theme_function()"?

+1  A: 

Rename them. It's easy. The theme functions are in theme folder's functions.php file. You must rename them to avoid conflict.

Other way is to use namespaces but that would take more effort, IMO, then just rename a handful of functions.

shamittomar
+4  A: 

You can't really. You need to rename your functions in a way they don't collide with any other function. Prefixing functions with your theme's name sounds pretty clean and optimal.

Possible other workarounds that come to mind are

  • Using a static class Theme and adding any functions to that (Theme::function();)- not much different from adding a theme_ prefix to normal function names, though

  • Once PHP 5.3 is widely spread in a few years, you can use namespaces - it's too early at the moment, though, if you want to build redistributable themes or plugins.

Pekka
+1 for namespaces
Treffynnon
thanks I guess I'll go with the prefixes then :)
Alex