Make WordPress Core

Opened 7 years ago

Last modified 5 weeks ago

#40682 new defect (bug)

get_current_blog_id() and get_current_network_id() are loaded before absint()

Reported by: wonderboymusic's profile wonderboymusic Owned by:
Milestone: Awaiting Review 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 (4)

This ticket was mentioned in Slack in #core-multisite by flixos90. View the logs.


7 years ago

#2 @flixos90
7 years ago

I suggest moving get_current_blog_id() and get_current_network_id() to wp-includes/functions.php as a first step. These two are the only functions in wp-includes/load.php that use absint(), and they shouldn't be called there anyway.

However absint() is not the only function that is not available at this point. For get_current_network_id(), the function get_network() is not available either (get_main_network_id() uses that function as well btw), and for get_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.

#3 @johnjamesjacoby
5 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.


5 weeks 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.
Note: See TracTickets for help on using tickets.