Make WordPress Core

Opened 22 months ago

Last modified 20 months ago

#40682 new defect (bug)

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

Reported by: wonderboymusic Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.5
Component: Networks and Sites Keywords: needs-patch
Focuses: multisite Cc:


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 (2)

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

20 months ago

#2 @flixos90
20 months 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.

Note: See TracTickets for help on using tickets.