Plugins in symlinked directories?

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.

4

The problem can partially be addressed with a must-use plugin hooking into the plugins_url filter.

It won’t handle all other cases where plugin_basename() is used, such as register_activation_hook() and co.

More info: http://core.trac.wordpress.org/ticket/16953

Leave a Comment