Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/wp-admin/includes/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
45 changes: 45 additions & 0 deletions tests/phpunit/tests/admin/includesFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
activate_plugin( $plugin, '', true );
$this->assertNull( activate_plugin( $plugin, '', true ) );


$loopback_requested = false;
add_filter(
'pre_http_request',
function ( $preempt, $parsed_args, $url ) use ( &$loopback_requested ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function ( $preempt, $parsed_args, $url ) use ( &$loopback_requested ) {
static function ( $preempt, array $parsed_args, string $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 ),
)
);
Comment on lines +497 to +504

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this assert that the return value is true as well?


deactivate_plugins( $plugin );
revoke_super_admin( $user_id );

Comment on lines +506 to +508

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These shouldn't be needed. The they are automatically cleaned up.

Suggested change
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.' );
}
}
Loading