Search code examples
phpwordpressmultisite

Wordpress Multisite brakes wp-load.php


I'm trying to write a small tool using php. This temporarily connects to one of two Wordpress systems on the same web space by loading the wp-load.php of the needed Wordpress-Installation.

Both systems are standalone multisite installations, which are not connected. The folder structure on the server looks like this:

/ -> WordPress install 1
/foldername/ -> WordPress install 2
/toolname/ -> Tool

With Wordpress installation 1 it works just fine. It does not work on Wordpress installation 2. The error logs give the following error:

[14-Apr-2022 07:25:37 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /usr/local/www/apache24/noexec/domainname/_offer/includes/functions.php: 596) in /usr/local/www/apache24/noexec/domainname/luxuscharter/wp-includes/ms-settings.php on line 79

But: the function on this line is a simple calculation function, which doesn't do anything relating to that problem. I think the problem is related to the specific wordpress installation. If i remove the mutlisite-data from the wp-config of Wordpress-Installation 2, it works just fine.

UPDATE I managed to load the file with setting the path differently, which seems to work so far. But no i get the response that Wordpress can't etablish the database-Connection. Any ideas?


Solution

  • I found the answer to my problem myself as the answer given here didn't help me.

    It turned out that it was due to the subfolder installation and not, as stated here, to one of the functions or the database connection, or the header information being sent.

    WP-load probably does not recognize the corresponding affiliation to the Wordpress system if it is a subfolder installation. The following steps helped me:

    a) create a sunrise.php in the wp-content folder of the subfolder installation

    Code:

    <?php if (strpos($_SERVER['REQUEST_URI'],'/subfolderinstallation') === false) $_SERVER['REQUEST_URI'] = '/subfolderinstallation/'; } ?>
    

    b) Add to the wp-config.php install the following line:

    define( 'SUNRISE', 'on' );
    

    c) Load both of the following files for the php-file to recognize the right paths

         require_once('../../luxuscharter/wp-blog-header.php');
         require_once  "../../luxuscharter/wp-load.php";
    

    I'm pretty sure you don't have to do all of the steps above, but that's exactly how it worked for me.