How can I import a class privately into a plugin?

Use namespaces, but check the PHP version on the server side and deactivate the plugin with a useful error message if the requirements aren’t met.

If you look at the official statistics, you can see how many installations are still running on outdated WordPress versions. But almost all new plugins require the latest WordPress version, and nobody complains about that. I think there is a large number of abandoned or poorly managed installations out there. They will probably never use your plugin anyway.

That leaves you with a rather small number of installations that are up to date but still on PHP 5.2. They can upgrade. All web hosts offer this nowadays, they couldn’t run Symfony or most other popular scripts otherwise.

The other option is to move the library to a separate plugin and to require that library to be installed first. Then hook into library_loaded to start your specialized plugin’s code.

Leave a Comment