Php Constant Inside Js File
I am facing a problem that I can not understand . During a plugin development I am including a file.js.php (register/enqueue).
Solution 1:
Being that this is being included like JavaScript, your file.js.php
needs to reference the Wordpress library in order to access those constants. Currently, as your code stands, it does not have any references to those constants.
__FILE__
does not need to access anything from Wordpress, which is why it works as expected.
You will need to include some require
or include
statements referencing the specific Wordpress PHP files you need at the top of file.js.php
.
Edit
Use the following at the top of your file.js.php file to get access to those constants:
$home_dir = preg_replace('^wp-content/plugins/[a-z0-9\-/]+^', '', getcwd());
include($home_dir . 'wp-load.php');
Post a Comment for "Php Constant Inside Js File"