I use $_SERVER[\'DOCUMENT_ROOT\'].\"/lib/sft_required.php\"; to include the \'sft_required\' file in a PHP script. When I run this file using browser, it works fine but whe
Here is my solution for a similar problem that I dealt with.
$site_root_directory = substr( __DIR__, 0, strpos( __DIR__, "wp-content" ) );
In my case, I am running a cron that executes a file inside of my theme. (I don't load WordPress for the corn, so I do not have access to things like ABSPATH
).
This way I get my 'root directory' by using the first child folder inside of the root leading to my script, instead of working my way back from the script directory.
/var/more_directories/public_html/wp-content/themes/theme-name/includes/cron-jobs
/var/more_directories/public_html/
This means that I don't have to be worried about moving my script around, since it will always be somewhere under that first child folder.