[wp-hackers] Facebook API and WordPress Plugin Development - Insight / Best Practice

John Blackbourn johnbillion+wp at gmail.com
Thu Nov 15 05:34:54 UTC 2012


On 15 November 2012 04:32, Mike Schinkel <mike at newclarity.net> wrote:
> On Nov 14, 2012, at 10:42 PM, John Blackbourn <johnbillion+wp at gmail.com> wrote:
>> Surely all this can be avoided by simply using namespaces in PHP. If I
>> bundle API X in my plugin and namespace it, then another plugin can
>> include the same or a different version of API X and there will be no
>> conflict.
>
> I don't see how PHP namespaces address the problem I posed. What am I missing?
>
> Here's how I see it. If I'm using a published and tested version of Mark Jaquith's transient library in my plugin and you are use a later published and tested version of Mark Jaquith's transient library. Both of those version are still going to have used the same namespace:
>
> namespace markjaquith/wp_tlc_transients;
>
> So if we both want to use a non-forked version of the library that Mark published we still have the same problem, right?

No, you would namespace it according to your plugin, not according to
the library. So for example:

namespace myplugin;

class wp_tlc_transients { ... }

And another plugin might use:

namespace foo_plugin;

class wp_tlc_transients { ... }

People use classes for namespacing their functions in the same way.

> Also, PHP namespaces require PHP 5.3 and since WordPress supports 5.2.4 using namespaces it is not even an option to solve the problem of using shared libraries in a WordPress plugin or theme.

Correct of course, and this is unfortunate, but it doesn't rule out
plugins having PHP requirements higher than WordPress'. Even
Automattic publishes plugins which require PHP 5.3.

> Finally, what I proposed is two functions probably less than 40 lines of code each. Is that really so much to avoid if using it would potentially solve a real problem?

Your proposal is simple and is quite similar to WordPress'
enqueuing/dependencies API for scripts and stylesheets. I was simply
offering a solution that can work outside of WordPress too.

John


More information about the wp-hackers mailing list