diff --git a/includes/Admin/Admin_Page.php b/includes/Admin/Admin_Page.php
index 24736828b..668de860a 100644
--- a/includes/Admin/Admin_Page.php
+++ b/includes/Admin/Admin_Page.php
@@ -54,8 +54,11 @@ public function __construct( Admin_AJAX $admin_ajax ) {
* @since 1.0.0
*/
public function add_hooks() {
- add_action( 'admin_menu', array( $this, 'add_and_initialize_page' ) );
- add_filter( 'plugin_action_links', array( $this, 'filter_plugin_action_links' ), 10, 4 );
+ $admin_menu_hook = is_multisite() ? 'network_admin_menu' : 'admin_menu';
+ $plugin_action_link_hook = is_multisite() ? 'network_admin_plugin_action_links' : 'plugin_action_links';
+
+ add_action( $admin_menu_hook, array( $this, 'add_and_initialize_page' ) );
+ add_filter( $plugin_action_link_hook, array( $this, 'filter_plugin_action_links' ), 10, 4 );
add_action( 'admin_enqueue_scripts', array( $this, 'add_jump_to_line_code_editor' ) );
$this->admin_ajax->add_hooks();
@@ -64,13 +67,18 @@ public function add_hooks() {
/**
* Adds the admin page under the tools menu.
*
+ * @since n.e.x.t Added multisite support.
* @since 1.0.0
*/
public function add_page() {
- $this->hook_suffix = add_management_page(
+ $admin_parent_page = is_multisite() ? 'settings.php' : 'tools.php';
+ $capabilities = is_multisite() ? 'manage_network_plugins' : 'activate_plugins';
+
+ $this->hook_suffix = add_submenu_page(
+ $admin_parent_page,
__( 'Plugin Check', 'plugin-check' ),
__( 'Plugin Check', 'plugin-check' ),
- 'activate_plugins',
+ $capabilities,
'plugin-check',
array( $this, 'render_page' )
);
@@ -307,7 +315,13 @@ public function filter_plugin_action_links( $actions, $plugin_file, $plugin_data
return $actions;
}
- if ( current_user_can( 'activate_plugins' ) ) {
+ if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
+ $actions[] = sprintf(
+ '%2$s',
+ esc_url( network_admin_url( "settings.php?page=plugin-check&plugin={$plugin_file}" ) ),
+ esc_html__( 'Check this plugin', 'plugin-check' )
+ );
+ } elseif ( current_user_can( 'activate_plugins' ) ) {
$actions[] = sprintf(
'%2$s',
esc_url( admin_url( "tools.php?page=plugin-check&plugin={$plugin_file}" ) ),
diff --git a/tests/phpunit/tests/Admin/Admin_Page_Tests.php b/tests/phpunit/tests/Admin/Admin_Page_Tests.php
index d7c4e011d..5777694ef 100644
--- a/tests/phpunit/tests/Admin/Admin_Page_Tests.php
+++ b/tests/phpunit/tests/Admin/Admin_Page_Tests.php
@@ -23,8 +23,11 @@ public function set_up() {
public function test_add_hooks() {
$this->admin_page->add_hooks();
- $this->assertEquals( 10, has_action( 'admin_menu', array( $this->admin_page, 'add_and_initialize_page' ) ) );
- $this->assertEquals( 10, has_filter( 'plugin_action_links', array( $this->admin_page, 'filter_plugin_action_links' ) ) );
+ $admin_menu_hook = is_multisite() ? 'network_admin_menu' : 'admin_menu';
+ $plugin_action_link_hook = is_multisite() ? 'network_admin_plugin_action_links' : 'plugin_action_links';
+
+ $this->assertEquals( 10, has_action( $admin_menu_hook, array( $this->admin_page, 'add_and_initialize_page' ) ) );
+ $this->assertEquals( 10, has_filter( $plugin_action_link_hook, array( $this->admin_page, 'filter_plugin_action_links' ) ) );
}
public function test_add_and_initialize_page() {
@@ -35,8 +38,10 @@ public function test_add_and_initialize_page() {
$admin_user = self::factory()->user->create( array( 'role' => 'administrator' ) );
+ $expected_parent_page = 'tools.php';
if ( is_multisite() ) {
grant_super_admin( $admin_user );
+ $expected_parent_page = 'settings.php';
}
wp_set_current_user( $admin_user );
@@ -50,7 +55,7 @@ public function test_add_and_initialize_page() {
set_current_screen( $current_screen );
$this->assertArrayHasKey( 'plugin-check', $parent_pages );
- $this->assertEquals( 'tools.php', $parent_pages['plugin-check'] );
+ $this->assertEquals( $expected_parent_page, $parent_pages['plugin-check'] );
$this->assertNotFalse( has_action( "load-{$page_hook}", array( $this->admin_page, 'initialize_page' ) ) );
}