I am debugging a problem that is unique to Microsoft IIS, specifically IIS10, but I don't know whether other versions of IIS also have this problem. I have a problem with a WordPress plugin, that works correctly when I run it on an Apache server, or in my Local by Flywheel test environment on any of the Apache/Linux/nginx web servers.
The problem involves the PHP built-in constant __FILE__ to a symbolically linked folder.
I created symbolic link to my plugin development folder as the following:
Website is here: c:\inetpub\my-web-site
The plugin lives here: c:\users\me\onedrive\plugins\my-plugin
I created a symbolic link in the folder:
c:\inetpub\my-web-site\wp-content\plugins
using the following commands on the command line.
c:
cd \inetpub\my-web-site\wp-content\plugins
mklink /J my-plugin c:\users\me\onedrive\plugins\my-plugin
The web server sees the plugin folder as:
c:\inetpub\my-web-site\wp-content\plugins\my-plugin
That's the simple part.
In PHP, from inside a WordPress website, the PHP constant __FILE__ (IIS only) returns the wrong path. Specifically, calling PHP constant __FILE__ returns the wrong path.
Add this code:
$path = __FILE__;
To this file:
c:\inetpub\my-web-site\wp-content\plugins\my-plugin\my-plugin.php
Both $path will return:
c:\users\me\onedrive\plugins\my-plugin\my-plugin.php
I expected __FILE__ to return:
c:\inetpub\my-web-site\wp-content\plugins\my-plugin\my-plugin.php
In other words, on IIS10, the PHP constant __FILE__ returns the physical (target) path to the symbolically linked folder as seen by the operating system, not the physical path to the files as seen by the web server.
As it stands, this completely defeats the purpose of using symbolically linked folders in IIS.
My question: Does anybody know 1) Is there a remedy to this? 2) is there a work around which does not involve the use of WP_CONTENT_DIR? and 3) Am I missing something?