Wordpress include(“../../../wp-blog-header”); failing

后端 未结 4 1978
慢半拍i
慢半拍i 2020-12-19 20:03

I am currently working on a plugin for Wordpress involving lots of .php files. I see that for my AddShift.php file, we are successfully importing the blog header using the f

相关标签:
4条回答
  • 2020-12-19 20:34

    Yes - I believe wordpress operates a security mechanism on content in the wp-content directory, I had the same problem with themes. The workaround I used was to include with absolute path names.

    0 讨论(0)
  • 2020-12-19 20:41

    You should try using the WP_PLUGIN_URL constant provided by wordpress. For example, you can define you actual plugin url like this:

    define('MyPLUGIN_URL', WP_PLUGIN_URL.'/plugin_folder/'); 
    

    and then use it in your calls like:

    include(MyPLUGIN_URL."wp-blog-header.php");
    

    Thats how i solve the problem, sorry for late answer but it might help the next ones checking in.

    0 讨论(0)
  • 2020-12-19 20:52

    This is your solution to get the real path in plugin file

    <?php
    $scriptPath = dirname(__FILE__);
     $path = realpath($scriptPath . '/./');
     $filepath = explode("wp-content",$path);
    // print_r($filepath);
    define('WP_USE_THEMES', false);
    require(''.$filepath[0].'/wp-blog-header.php');
    
    0 讨论(0)
  • 2020-12-19 20:55

    it works, do as suggested and use an absolute url, i used

    include("wp-content/themes/YOUR_THEME/DESIRED_FILE.php");

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