-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin-manager.php
More file actions
executable file
·124 lines (97 loc) · 3.53 KB
/
plugin-manager.php
File metadata and controls
executable file
·124 lines (97 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/*
Plugin Name: Multisite Plugin Manager
Plugin URI: http://github.com/earnjam/multisite-plugin-manager
Description: Manage the ability for site administrators to activate plugins on individual sites on a multisite network
Version: 1.0
Author: William Earnhardt
Author URI: http://wearnhardt.com
Network: true
*/
class MultisitePluginManager {
// WP_List_Table object;
public $plugin_manager_table;
function __construct() {
// Hooks for the dashboard settings page
add_action( 'network_admin_menu', array( &$this, 'add_menu' ) );
// Hooks for hiding disabled plugins
add_filter( 'all_plugins', array( &$this, 'remove_plugins' ) );
add_filter( 'plugin_row_meta' , array( &$this, 'remove_plugin_meta' ), 10, 2 );
add_action( 'admin_init', array( &$this, 'remove_plugin_update_row' ) );
}
/**
* Adds our submenu page to the network admin for controlling plugin visibility
*/
function add_menu() {
$hook = add_submenu_page( 'plugins.php', 'Plugin Availability', 'Plugin Availability', 'manage_network_options', 'plugin-manager', array( &$this, 'plugin_management_page' ) );
add_action( "load-$hook", [ $this, 'screen_option' ] );
}
/**
* Initialize our WP_List_Table and adds any screen options
*/
function screen_option() {
require dirname( __FILE__ ) . '/class-plugin-manager-table.php';
$this->plugin_manager_table = new Plugin_Manager_Table();
}
/**
* Plugin settings page
*/
public function plugin_management_page() {
?>
<div class="wrap">
<h1>Manage Plugin Availability</h1>
<p>Set whether plugins are available for activation by administrators on individual sites. Excludes network activated and must-use plugins.</p>
<?php $this->plugin_manager_table->process(); ?>
<?php $this->plugin_manager_table->views(); ?>
<form method="post">
<?php
$this->plugin_manager_table->prepare_items();
$this->plugin_manager_table->display();
?>
</form>
</div>
<?php
}
/**
* Removes any plugin meta information for single site admins
* @param array $plugin_meta The array having default links for the plugin.
* @param string $plugin_file The name of the plugin file.
* @return array Filtered array having default links for the plugin.
*/
function remove_plugin_meta( $plugin_meta, $plugin_file ) {
if ( is_network_admin() || is_super_admin() ) {
return $plugin_meta;
} else {
remove_all_actions( "after_plugin_row_$plugin_file" );
return array();
}
}
/**
* Removes any hooks that fire after plugin rows for single site admins
*/
function remove_plugin_update_row() {
if ( ! is_network_admin() && ! is_super_admin() ) {
remove_all_actions( 'after_plugin_row' );
}
}
/**
* Hides plugins that are disabled and inactive from single site admins
* @param array $all_plugins List of installed plugins
* @return array Filtered list of installed plugins
*/
function remove_plugins( $all_plugins ) {
// Don't filter Super Admins
if ( is_super_admin() ) {
return $all_plugins;
}
$enabled_plugins = get_site_option( 'mpm_enabled_plugins', array() );
$active_plugins = get_option( 'active_plugins', array() );
foreach ( (array)$all_plugins as $plugin => $data) {
if ( ! isset( $enabled_plugins[$plugin] ) && ! in_array( $plugin, $active_plugins ) ) {
unset( $all_plugins[$plugin] ); //remove plugin
}
}
return $all_plugins;
}
}
$multisite_plugin_manager = new MultisitePluginManager();