#40682 closed defect (bug) (fixed)
get_current_blog_id() and get_current_network_id() are loaded before absint()
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.7 | Priority: | normal |
Severity: | normal | Version: | 3.5 |
Component: | Networks and Sites | Keywords: | has-patch |
Focuses: | multisite | Cc: |
Description
In r21484, these functions were moved to wp-includes/load.php
. Regardless of when they are *supposed* to be called, they are available to be called by cache plugins before absint()
exists in the ether. If caching plugins are indeed accessing global $blog_id
this early, seems like a race condition somewhere.
Change History (7)
This ticket was mentioned in Slack in #core-multisite by flixos90. View the logs.
8 years ago
#3
@
6 years ago
I suggest moving get_current_blog_id() and get_current_network_id() to wp-includes/functions.php as a first step
Unfortunately this will break more than it fixes.
Caching plugins will commonly need to access the current blog ID and current network ID to build their unique cache keys, so the stack of function calls needs to be available before advanced-cache.php
is loaded via wp-settings.php
.
I believe @wonderboymusic is correct that not only is a race condition occurring, both of the get_current_blog_id()
and get_current_network_id()
functions should not contain any function calls or just-in-time setting/calculation of these variables – they probably need to be set already and simply return global values.
That said, the simpler fix for this exact issue might just be to relocate absint()
to load.php
. That's sufficient for Super Cache and Spider Cache in my testing.
This ticket was mentioned in PR #6859 on WordPress/wordpress-develop by @geekofshire.
9 months ago
#4
- Keywords has-patch added; needs-patch removed
Ticket Link: https://core.trac.wordpress.org/ticket/40682
- Moved absint to load.php from functions.php to avoid dependent function like get_current_blog_id() and get_current_network_id() loading before it.
#6
@
5 months ago
- Owner set to peterwilsoncc
- Resolution set to fixed
- Status changed from new to closed
In 59242:
I suggest moving
get_current_blog_id()
andget_current_network_id()
towp-includes/functions.php
as a first step. These two are the only functions inwp-includes/load.php
that useabsint()
, and they shouldn't be called there anyway.However
absint()
is not the only function that is not available at this point. Forget_current_network_id()
, the functionget_network()
is not available either (get_main_network_id()
uses that function as well btw), and forget_current_blog_id()
the$blog_id
global won't be set when called early.These multisite-API-related parts should probably be handled afterwards in a separate ticket, as there are many other functions in core that assume the functions are available. The other thing is, even if they were available they wouldn't work that early as the multisite bootstrap process would not have been completed yet. We should investigate checking something like
did_action( 'ms_loaded' )
in such functions to make sure they fail gracefully.