I have a JS/PHP file combined in file.js.php in a wordpress plugin.
The problem is - that I need to include a wordpress file in order to be able to use the GLOBALS and wp functions .
My question has 2 parts :
1 - which file is the best one to include (security, performance etc..)
2 - how can I find he path to said file - presuming I can not use plugins_url() befor including it to identify the path or wp root ?
For now I am using :
include("../../../../wp-load.php");
or
require_once (dirname(dirname(dirname(dirname(dirname ( __FILE__))))).'/wp-config.php');
But of course it is a semi-hard coded method . It will not guarantee nothing if the CONTENT" or "PLUGINS" dir was moved ...
The problem was outlined and surfaced while resolving this question : PHP constant inside JS file