PHP, __FILE__ and symlinks

By Ninad Pundalik

I’ve made this mistake so many times, that I have to note it down somewhere and not make it again.

Problem: I play with WordPress on and off, and use git (+Github) for version control. I clone the repository to my home directory, where I keep all my repositories, and then symlink the repository from the WordPress’s plugin directory. However, all the functions that are used to derive the path to the plugin directory rely on the __FILE__ magical constant. The __FILE__ constant always resolves to the absolute path, which leads to a 404 error (if you’re loading JS scripts), or worse, failed includes.

Solution: Clone the git repository directly to the plugin folder goddamnit!

Reference: []