I have a PHP class that I want to use in several plugins, rather than add the class to each plugin I want to add the class as a plugin and access it that way. This is more OOP and reduces duplication.

What is the best way to go about this?

Safety issues can be ignored, I can write checks to make sure a plugin is available before trying to use it.

The class I am trying to add is an Excel document creator in XML format. It would normally be used as follows.


$excel=new ExcelWriter("myXls.xls");

1 Answer 1


You can check if the class is already include / exists, and if it not exists include it.

In your plugin, depending on how you can be sure that the install has plugin activated, you'll maybe need to include your class inw every plugin.

    $excel = new Excel_Writer('myxls.xls');

Be carefull with files paths.

If you really want to include your file only in one plugin, the main plugin (with the required file) must be load first.

Then the other plugin will be able to find and work with the class.

You can add some code to desactivate "sub" plugins if the main is not available with is_plugin_active

Hope it gives you some hints to help you !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.