1

i use slim with wordpress. This worked flawlessly so far. Well almost. Once I changed to multisite I had to start fake creating $_SERVER variables faking a domain name. But it worked finally.

What I had to use was this:

  global $_SERVER;
  $_SERVER['HTTP_HOST'] = 'www.mydomain.com';
  $_SERVER['REQUEST_URI'] = '/';
  require_once(  __DIR__ .'/../../../wp-load.php' );

it feels wrong and very clumsy, but not using it would lead to an error see here (or does this count as crosspost too?):

https://stackoverflow.com/questions/37755976/wordpress-multisite-breaks-including-require-of-wp-load-php

But now i ran into the following problem:

https://stackoverflow.com/questions/37912920/wp-load-php-disabling-the-ob-flush-to-work-correctly

now is it somehow possible to get access to all wordpress functions without using wp-load.php?

the problem i am facing is that wp-load.php somehow alters the response object so that I am no longer able to flush to it (see link note: i think i found a solution to the problem. My question still remains: is there a more correct way to the wordpress functions instead of wp-load.php?)

  • it is considered to be a bad taste to cross post. At least be nice to the people here and post the relevant code here. – Mark Kaplun Jun 20 '16 at 4:14
  • technically speaking, those are 2 different questions. I have read somewhere in plugin dev, that you cannot submit a plugin loading wp-load.php. While this, fair enough, makes no sense for a plugin, eventually there exists a solution i didn't think of. I will edit my question to include the hack I used to make wp-load.php work for multisite – Toskan Jun 20 '16 at 6:36
1

Pretty much wp-load.php is the only way to go. I don't think there is really another way to load the WordPress functions safely...

You can account for path variations by recursively including it from any file where you need it though... eg.

function file_find_require($file,$folder=null) {
    if ($folder === null) {$folder = dirname(__FILE__);}
    $path = $folder.DIRECTORY_SEPARATOR.$file;
    if (file_exists($path)) {require($path); return $folder;}
    else {
        $upfolder = file_find_require($file,dirname($folder));
        if ($upfolder != '') {return $upfolder;}
    }
}

$rootpath = file_find_require('wp-load.php');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.