PHP constant inside JS file

后端 未结 1 342
你的背包
你的背包 2021-01-18 08:12

I am facing a problem that I can not understand .

During a plugin development I am including a file.js.php (register/enqueue).



        
相关标签:
1条回答
  • 2021-01-18 09:01

    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');
    

    Source

    0 讨论(0)
提交回复
热议问题