Easier Plugin Development by Moving Plugin Directory

If you’re a experienced programmer you’re testing your programs not only with the latest version of WordPress but also with some older versions since there are many dated installations. So you have several versions installed on your development server and want to test your newly created code with every single version.

You could copy your plugin files to all installed version’s plugin directory manually every time you change the code… but you’re a programmer, so this is no option, is it?
If your dev server works under a *nix system you probably have tried to use symbolic links but it didn’t work. This is not a bug of WordPress but of PHP. So this does not work either.

Fortunately WordPress defines two constants which can help you to simplify things nonetheless: WP_PLUGIN_DIR and WP_PLUGIN_URL. These constants point to the plugin directory of the respective WordPress installation. They are defined since WordPress 2.6 and supporting older versions is most likely unnecessary
To make your plugins accessible to all your installed WordPress versions you simply move them to a central directory and define the constants accordingly:

define( 'WP_PLUGIN_DIR', '/var/www/plugins' ); // or with XAMPP C:/xampp/htdocs/plugins
define( 'WP_PLUGIN_URL', 'http://localhost/plugins' );

In this example the plugins reside in the directory ‘plugins’ in the root directory of the webserver. If you now define the above constants in every WordPress installation you have easy access to them to test your code with every version.

(Thanks to John Blackbourn on the wp-hackers list for having the idea.)

Hint for Multisite-Users

Also usable for WordPress Multisite

define( 'WPMU_PLUGIN_DIR', '/var/www/multisite-plugins' );
define( 'WPMU_PLUGIN_URL', 'http://localhost/multisite-plugins' );


9 responses to “Easier Plugin Development by Moving Plugin Directory”

  1. […] Bei WPEngineer wird beschrieben, wie man für die Plugin-Entwicklung das Plugin-Verzeichnis aus dem WordPress-Verzeichnis auslagern kann. Dadurch kann man sein Plugin in mehreren WordPress-Installationen testen, ohne es mehrfach vorhalten zu müssen. […]

  2. Dominik Avatar

    And if you want, you can do the same with WPMU_PLUGIN_DIR and WPMU_PLUGIN_URL.

  3. Mike Schinkel Avatar

    Nice! I didn’t know about those.

  4. Frank Avatar

    @Dominik: yes, use this also; now i have add an small hint; thanks

  5. Jens Törnell Avatar

    Can this be done with themes as well? What define is there for themes folder?

  6. Frank Avatar

    @Jens: not the same clearly constant, but you can use the constant for wp-content and move this to an other place.
    see: https://wpengineer.com/2382/wordpress-constants-overview/#paths

  7. Andreas Nurbo Avatar

    Jens: If you don’t use __FILE__ (which you shouldn’t) You can easily just symlink the folders. Thats how I do it.
    If WordPress used once and only in wp-config __FILE__ you would be able to symlink WP as well.

  8. Tushar Avatar

    Is there any way to modify the default plugin directory to our CDN server .. Like if i have domain abc.com and want to use a CDN – cdn.abc.com then how can i shift my all plugins files to cdn?

  9. Frank Avatar

    @Tushar: yes, you can also change this: see my post about this; sorry only in german language; but the code is readable for all readers 😉