diff --git a/src/wp-includes/class-wp-plugin-dependencies.php b/src/wp-includes/class-wp-plugin-dependencies.php index c96b98d08b550..fab7406622a11 100644 --- a/src/wp-includes/class-wp-plugin-dependencies.php +++ b/src/wp-includes/class-wp-plugin-dependencies.php @@ -477,7 +477,7 @@ public static function check_plugin_dependencies_during_ajax() { ); } - if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) { + if ( isset( $status['activateUrl'] ) && is_multisite() && current_user_can( 'manage_network_plugins' ) ) { $status['activateUrl'] = add_query_arg( array( 'networkwide' => 1 ), $status['activateUrl'] ); } diff --git a/tests/phpunit/tests/ajax/wpAjaxCheckPluginDependencies.php b/tests/phpunit/tests/ajax/wpAjaxCheckPluginDependencies.php index 70dda155a4d79..9e27c0987d95b 100644 --- a/tests/phpunit/tests/ajax/wpAjaxCheckPluginDependencies.php +++ b/tests/phpunit/tests/ajax/wpAjaxCheckPluginDependencies.php @@ -273,8 +273,7 @@ public function test_should_not_return_activate_url_for_user_without_capability( * Tests that no activation URL is returned for a plugin that is already active. * * @ticket 65819 - * - * @group ms-excluded + * @ticket 66346 */ public function test_should_not_return_activate_url_for_active_plugin() { wp_set_current_user( self::$admin_id ); @@ -290,6 +289,27 @@ public function test_should_not_return_activate_url_for_active_plugin() { $this->assertArrayNotHasKey( 'activateUrl', $response['data'], 'No activation URL should be returned.' ); } + /** + * Tests that no activation URL is returned for a plugin that is network-activated. + * + * @ticket 66346 + * + * @group ms-required + */ + public function test_should_not_return_activate_url_for_network_active_plugin() { + wp_set_current_user( self::$admin_id ); + + $this->set_installed_plugins( array( 'dependent/dependent.php' => '' ) ); + update_site_option( 'active_sitewide_plugins', array( 'dependent/dependent.php' => time() ) ); + + $_POST['slug'] = 'dependent'; + + $response = $this->make_request(); + + $this->assertTrue( $response['success'], 'The request should succeed.' ); + $this->assertArrayNotHasKey( 'activateUrl', $response['data'], 'No activation URL should be returned.' ); + } + /** * Tests that a plugin whose dependencies are all active returns success. *