WordPress.org

Ready to get started?Download WordPress

Forums

Plugins using php libraries, where to put the libraries (2 posts)

  1. Crisium
    Member
    Posted 1 year ago #

    Hi wordpressUsers,

    I create lots of plugins and have a common library they all use. I would like all my plugins to have access to this library, but where do I put it?

    I read some posts on the internet to put it in the themes directory,.. but that just opens a new can of worms; Permissions, how to get a non programmer to install it and so on....

    Right now I have added my library as a plugin and forcing it to be the first to load. This works, but it too has it's problems. If another plugin fights for the first place then every load will be a battle for first plugin to load.

    How and where do I install my common library in wordpress?

    any suggestions?

    Peter

  2. Platonic
    Member
    Posted 4 months ago #

    I don't think there is a good solution for that problem. From what you write, I assume that you want WordPress to load the plugin, so that you do not need to require it. But what speaks against require?

    I use something along these lines in such cases, assuming that I use myplugin located at myplugin/myplugin.php in WordPress' plugins directory:

    // Just to save me some typing.
    define( __NAMESPACE__ . '\\MYPLUGIN', '/myplugin/myplugin.php' );
    
    require ( file_exists( WPMU_PLUGIN_DIR . MYPLUGIN ) ) ? WPMU_PLUGIN_DIR . MYPLUGIN : WP_PLUGIN_DIR . MYPLUGIN;

    To me, this has the additional benefit that the plugin only needs to be installed, it doesn't need to be activated.

    Am I missing something?

Topic Closed

This topic has been closed to new replies.

About this Topic