Where to put third party PHP library?

I’m developing a couple of open-source plugins and a theme (all part of a “suite”) that all use the same third party PHP library. I’m wondering what is the best way to include it in WordPress. Here are some thoughts:

  • put it in one of the plugins and require that plugin to be installed and activated
  • create a special “core” plugin that does nothing but including it
  • put it directly in wp-content

Any thoughts on that matter?

4 s
4

If each plugin/theme functions on its own, then you should probably drop the the library in every theme/plugin.

Then just check to see if it a class or function from the third-party library exists before requiring it.

<?php
if( class_exists( 'SomeClass' ) )
{
    // require/include here
}

or

<?php
if( function_exists( 'some_function' ) )
{
   // Require/include stuff here
}

Alternatively, you could wrap every function/class/variable/constant from the third party library in a check to see if it exists, like pluggable functions.

If all of the plugins and the theme are dependent on one another, then it doesn’t really make much sense to divide them up and you should probably rethink that.

Leave a Comment