Can't include wp-blog-header.php in external plugin's file under multisite
-
I create a plugin, and it needs to have a php file, which needs be launched by CRON. And this php file need to use native WP functions.
To include this ability in that php file, I use the following code:
$file_root_directory = dirname(__FILE__); //get current file direct path $target_string_array = explode('wp-content', $file_root_directory); //it is the way, how I get site directory require_once ($target_string_array[0] . 'wp-blog-header.php'); //include native wp functions
This code works good when I use the plugin on usual single site installation.
But, when I install this plugin on multisite network and try to launch that php file – the script just breaks execution on line with “require_once” without even any error.If I try to include any other php files – they are included successfully (these files just contain php functions and do nothing until they are not called).
How I understood that php file aborted execution on line with include “wp-blog-header.php”, despite the script does not generate any error:
I just used this code and made a log:
file_put_contents(dirname(__FILE__) . '/log.txt', 'point 1' . "\r\n\r\n", FILE_APPEND); $file_root_directory = dirname(__FILE__); //get current file direct path file_put_contents(dirname(__FILE__) . '/log.txt', 'point 2' . "\r\n\r\n", FILE_APPEND); $target_string_array = explode('wp-content', $file_root_directory); //it is the way, how I get site directory file_put_contents(dirname(__FILE__) . '/log.txt', 'point 3' . "\r\n\r\n", FILE_APPEND); require_once($target_string_array[0] . 'wp-blog-header.php'); //include native wp functions file_put_contents(dirname(__FILE__) . '/log.txt', 'point 4' . "\r\n\r\n", FILE_APPEND);
The last point was “point 3”.
Due to the fact, that the plugin works successfully on my local server (both – on single installation and multisite mode) but refuses to work on external server, I decided that the problem is in wp-config.php or in .htaccess files (apparently, some of the apach module that causes that bug in external server is disabled in the local server)
But I can’t see any suspicious in those files.
In the wp-cofig.php I aded the following lines (accordingly to the multisite installation guide):
define('WP_ALLOW_MULTISITE', true); define('MULTISITE', true); define('SUBDOMAIN_INSTALL', false); define('DOMAIN_CURRENT_SITE', 'site-name.org'); define('PATH_CURRENT_SITE', '/'); define('SITE_ID_CURRENT_SITE', 1); define('BLOG_ID_CURRENT_SITE', 1);
just before comment line:
/* That's all, stop editing! Happy blogging. */
The .htaccess looks like the following:
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] # add a trailing slash to /wp-admin RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L] RewriteRule . index.php [L] </IfModule> # END WordPress
On the local server and on the external server I use Sub-Directory for sites in network. And all other plugin’s functionality works properly on both (like a wp hooks, sending data, working with database, etc). The problem is only when I try to launch that file, and exactly during including wp-blog-header.php, and only in external server.
Any one have some ideas, where I should to dig?
- The topic ‘Can't include wp-blog-header.php in external plugin's file under multisite’ is closed to new replies.