Opened 5 years ago
Closed 5 years ago
#29678 closed defect (bug) (duplicate)
Multisite SHORTINIT from outside PATH_CURRENT_SITE
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.9 |
Component: | Networks and Sites | Keywords: | |
Focuses: | multisite | Cc: | |
PR Number: |
Description
We are using Wordpress SHORTINIT to integrate user capabilities and logged status in a custom intranet with the following code :
define('SHORTINIT', true); define('WP_USE_THEMES', false); require_once '/home/www/extranet/wp-load.php'; require_once ABSPATH . WPINC . '/formatting.php'; require_once ABSPATH . WPINC . '/capabilities.php'; require_once ABSPATH . WPINC . '/user.php'; require_once ABSPATH . WPINC . '/meta.php'; require_once ABSPATH . WPINC . '/post.php'; require_once ABSPATH . WPINC . '/pluggable.php'; wp_cookie_constants();
/home/www
is our DOCUMENT_ROOT- PATH_CURRENT_SITE is defined with
/extranet
subdirectory - we need to include this snippet from
/intranet
subdirectory (for example).
Our WP 3.6.1 worked fine this way but when we updated, WP printed the message Error establishing a database connection
then exited.
As a workaround, we replaced line 65 in the file /wp-includes/ms-settings.php
:
$current_blog = get_site_by_path( $domain, $path, 1 );
with the following
$current_blog = get_site_by_path( $domain, PATH_CURRENT_SITE);
We stated that this was a bug, because it worked before ;-).
Change History (7)
#3
@
5 years ago
It was broken because wp-includes/ms-settings.php is always trying to search a blog on the path /intranet whereas my multisite Wordpress constant PATH_CURRENT_SITE
is setup with /extranet.
wp-includes/ms-settings.php is testing if ( empty( $current_blog ) )
:
- this variable was setup by
$current_blog = get_site_by_path( $domain, $path, 1 );
$path
is initialized with$_SERVER['REQUEST_URI']
which contains /intranet- /intranet is a path unknown by my WP multisite installation (because it's under /extranet)
- because of this,
$current_blog
isNULL
And finally this is firing ms_not_installed()
function on line 159 of wp-includes/ms-settings.php.
According to me, you highlighted another issue that the error message displayed by ms_not_installed()
is not reflecting what really happens in this case when it sets $title = __( 'Error establishing a database connection' );
ms_not_installed()
is located in file wp-includes/ms-load.php at line 393
#4
@
5 years ago
- Keywords reporter-feedback removed
- Milestone changed from Awaiting Review to 4.0.1
- Version changed from 4.0 to 3.9
Introduced in [27359]. Sounds like a regression, moving for investigation.
#5
@
5 years ago
I think #27999 is related as well. Possibly duplicate.
I haven't tried to replicate the issue yet—but PATH_CURRENT_SITE
(/extranet
) is only responsible for the network. Retrieving the site by get_site_by_path()
with the requested URI (/intranet
) is still going to happen unless $_SERVER['REQUEST_URI']
is manually set.
#6
@
5 years ago
You're right, it looks like a duplicate of #27999.
My workaround is in the last else
when nothing in $_SERVER['REQUEST_URI']
path matches PATH_CURRENT_SITE
constant.
Then, it loads the default PATH_CURRENT_SITE
instead of the first segment of $_SERVER['REQUEST_URI']
which will be wrong in our case.
If we are in a path that is not related to WP Multisite installation, loading the default site seems to be a logic behavior and it works well for me.
Hmm, I don't see how changing that line would fix the particular issue. get_site_by_path() is still going to do a DB connection attempt either way. Perhaps this suggests something deeper in your setup?
I don't think there is anything there we would fix; SHORTINIT isn't really supported and while we aim not to break existing usage of it, I don't quite see what it broke.