When I develop plugins I test them on multiple versions of WordPress by symlinking my plugin directory in the different wp-content
directories. This is great since I only have to edit the files once, but it breaks an important construct to generate references to resources in my plugin: __FILE__
refers to the physical plugin location, not the one in wp-content
. How should I solve this?
My directory structure looks like this:
/path/to/wordpress/development/dir/
plugin-development/
monkeyman-rewrite-analyzer/
monkeyman-rewrite-analyzer.php
js/
monkeyman-rewrite-analyzer.js
versions/
3.1/
wp-content/
plugins/
monkeyman-rewrite-analyzer
as a symlink to the above plugin
3.1-multi-dir/
wp-content/
plugins/
monkeyman-rewrite-analyzer
as a symlink to the above plugin
3.1-multi-domain/
wp-content/
plugins/
monkeyman-rewrite-analyzer
as a symlink to the above plugin
If I want to enqueue the Javascript file, I should use plugins_url( 'monkeyman-rewrite-analyzer.js', [base file] )
, but using __FILE__
here will not work, because the actual file path will be /path/to/wordpress/development/dir/plugin-development/monkeyman-rewrite-analyzer/monkeyman-rewrite-analyzer.php
, not /path/to/wordpress/development/dir/versions/*/wp-content/plugins/monkeyman-rewrite-analyzer/monkeyman-rewrite-analyzer.php
, so WordPress cannot strip the first part out and generate a URL relative to the WordPress installation.