From 5a42367752fce88e67efb1ee6675fa4ad811d4fc Mon Sep 17 00:00:00 2001 From: ArkaPrabhaChowdhury Date: Fri, 7 Aug 2026 17:33:17 +0530 Subject: [PATCH 1/2] Administration: Guard network admin bootstrap on single sites --- src/wp-admin/network/admin.php | 7 +-- tests/phpunit/tests/admin/wpNetworkAdmin.php | 55 ++++++++++++++++++++ 2 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 tests/phpunit/tests/admin/wpNetworkAdmin.php diff --git a/src/wp-admin/network/admin.php b/src/wp-admin/network/admin.php index 30332152ec69c..927f5da51ee2c 100644 --- a/src/wp-admin/network/admin.php +++ b/src/wp-admin/network/admin.php @@ -9,14 +9,15 @@ define( 'WP_NETWORK_ADMIN', true ); -/** Load WordPress Administration Bootstrap */ -require_once dirname( __DIR__ ) . '/admin.php'; - +/** Load WordPress Bootstrap */ +require_once dirname( __DIR__, 2 ) . '/wp-load.php'; // Do not remove this check. It is required by individual network admin pages. if ( ! is_multisite() ) { wp_die( __( 'Multisite support is not enabled.' ) ); } +/** Load WordPress Administration Bootstrap */ +require_once dirname( __DIR__ ) . '/admin.php'; $redirect_network_admin_request = ( 0 !== strcasecmp( $current_blog->domain, $current_site->domain ) || 0 !== strcasecmp( $current_blog->path, $current_site->path ) ); /** diff --git a/tests/phpunit/tests/admin/wpNetworkAdmin.php b/tests/phpunit/tests/admin/wpNetworkAdmin.php new file mode 100644 index 0000000000000..1985d3938aaaa --- /dev/null +++ b/tests/phpunit/tests/admin/wpNetworkAdmin.php @@ -0,0 +1,55 @@ +markTestSkipped( 'This test is for single site installations.' ); + } + + $plugin_page_loaded = false; + add_action( + 'network_admin_menu', + function () use ( &$plugin_page_loaded ) { + add_menu_page( + 'Test Plugin Page', + 'Test Plugin Page', + 'manage_options', + 'test-plugin-page', + function () use ( &$plugin_page_loaded ) { + $plugin_page_loaded = true; + } + ); + } + ); + + $_GET['page'] = 'test-plugin-page'; + + try { + require ABSPATH . 'wp-admin/network/admin.php'; + $this->fail( 'The network administration bootstrap should stop on a single site.' ); + } catch ( WPDieException $exception ) { + $this->assertSame( 'Multisite support is not enabled.', $exception->getMessage() ); + } + + $this->assertFalse( $plugin_page_loaded ); + } +} From 9f88918b09aaaf0333efa8540627d88a5ac24f77 Mon Sep 17 00:00:00 2001 From: ArkaPrabhaChowdhury Date: Fri, 7 Aug 2026 18:08:00 +0530 Subject: [PATCH 2/2] Administration: Avoid reloading WordPress in network bootstrap --- src/wp-admin/network/admin.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/wp-admin/network/admin.php b/src/wp-admin/network/admin.php index 927f5da51ee2c..5c191d78fc320 100644 --- a/src/wp-admin/network/admin.php +++ b/src/wp-admin/network/admin.php @@ -9,8 +9,10 @@ define( 'WP_NETWORK_ADMIN', true ); -/** Load WordPress Bootstrap */ -require_once dirname( __DIR__, 2 ) . '/wp-load.php'; +if ( ! defined( 'ABSPATH' ) ) { + /** Load WordPress Bootstrap */ + require_once dirname( __DIR__, 2 ) . '/wp-load.php'; +} // Do not remove this check. It is required by individual network admin pages. if ( ! is_multisite() ) { wp_die( __( 'Multisite support is not enabled.' ) );