From 80f1bf0fe40714165a40b4afafaaeaa0b56d6a47 Mon Sep 17 00:00:00 2001 From: Bishal Shrestha <57122064+bishalsthadev@users.noreply.github.com> Date: Sun, 20 Sep 2026 09:49:56 +0545 Subject: [PATCH] Plugins: Fix wp_edit_theme_plugin_file() to detect network-active plugins. $is_active only checked the site-level active_plugins option, so the fatal-error loopback check was silently skipped for network-active plugins. Use is_plugin_active() instead, which already accounts for network activation. --- src/wp-admin/includes/file.php | 6 +-- tests/phpunit/tests/admin/includesFile.php | 45 ++++++++++++++++++++++ 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/wp-admin/includes/file.php b/src/wp-admin/includes/file.php index ef5a5025bef22..79a08bb2b9cba 100644 --- a/src/wp-admin/includes/file.php +++ b/src/wp-admin/includes/file.php @@ -425,11 +425,7 @@ function wp_edit_theme_plugin_file( $args ) { $real_file = WP_PLUGIN_DIR . '/' . $file; - $is_active = in_array( - $plugin, - (array) get_option( 'active_plugins', array() ), - true - ); + $is_active = is_plugin_active( $plugin ); } elseif ( ! empty( $args['theme'] ) ) { $stylesheet = $args['theme']; diff --git a/tests/phpunit/tests/admin/includesFile.php b/tests/phpunit/tests/admin/includesFile.php index fab002c5e5e2c..62e0e0ef4038d 100644 --- a/tests/phpunit/tests/admin/includesFile.php +++ b/tests/phpunit/tests/admin/includesFile.php @@ -463,4 +463,49 @@ function () { '.tmp', ); } + + /** + * @ticket 66129 + * @group multisite + * @group ms-required + */ + public function test_wp_edit_theme_plugin_file_runs_loopback_check_for_network_active_plugin() { + $user_id = self::factory()->user->create(); + grant_super_admin( $user_id ); + wp_set_current_user( $user_id ); + + $plugin = 'hello.php'; + activate_plugin( $plugin, '', true ); + + $loopback_requested = false; + add_filter( + 'pre_http_request', + function ( $preempt, $parsed_args, $url ) use ( &$loopback_requested ) { + if ( str_contains( $url, 'wp_scrape_key' ) ) { + $loopback_requested = true; + return array( + 'body' => '', + 'response' => array( 'code' => 200 ), + ); + } + return $preempt; + }, + 10, + 3 + ); + + wp_edit_theme_plugin_file( + array( + 'plugin' => $plugin, + 'file' => $plugin, + 'newcontent' => file_get_contents( WP_PLUGIN_DIR . '/' . $plugin ), + 'nonce' => wp_create_nonce( 'edit-plugin_' . $plugin ), + ) + ); + + deactivate_plugins( $plugin ); + revoke_super_admin( $user_id ); + + $this->assertTrue( $loopback_requested, 'Editing a network-active plugin file should trigger the fatal-error loopback check.' ); + } }