Skip to content
Snippets Groups Projects
Commit f42a2dfd authored by root's avatar root Committed by lechuck
Browse files

Adding plugin exclude-plugins

parent 85f4cc22
No related branches found
No related tags found
No related merge requests found
<?php
/*
Plugin Name: Exclude Plugins
Plugin URI: http://itx.web.id/wordpress/plugins/exclude-plugins/
Description: Exclude plugins from appearing in plugins menu for normal user in WordPress multisite. This plugin is useful if you want to use plugins only for Super Admins while enabling some other plugins for normal user.
Author: itx
Version: 1.1.2
Author URI: http://itx.web.id
Network: true
Some lines inspired by Blue Network Plugins by r-a-y
*/
/* Copyright 2010 itx (http://itx.web.id/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
// filter plugins
add_filter( 'all_plugins', 'exclude_plugins' );
function exclude_plugins($plugins) {
if (is_super_admin()) return $plugins;
if (exclude_plugins_get_option('exclude_new')) return exclude_plugins_included($plugins);
else return array_diff_assoc($plugins, exclude_plugins_excluded($plugins));
}
function exclude_plugins_excluded($plugins){
$excluded_plugins = array();
$excluding=exclude_plugins_get_option('excluded_plugins');
if ($excluding){
foreach ( (array) $plugins as $plugin => $plugin_data) {
if (in_array($plugin,$excluding)){$excluded_plugins[$plugin]=$plugin_data;}
}
}
return $excluded_plugins;
}
function exclude_plugins_included($plugins){
$included_plugins = array();
$including = exclude_plugins_get_option('included_plugins');
if ($including){
foreach ( (array) $plugins as $plugin => $plugin_data) {
if (in_array($plugin,$including)){$included_plugins[$plugin]=$plugin_data;}
}
}
return $included_plugins;
}
add_action('admin_menu', 'exclude_plugins_menu');
function exclude_plugins_menu() {
if (is_multisite()){
if (is_super_admin()){
$page=add_plugins_page('Exclude Plugins', 'Exclude Plugins', 'manage_options', 'exclude_plugins', 'exclude_plugins_options');
add_action('admin_head-'.$page, 'exclude_plugins_colors');
} elseif(exclude_plugins_get_option('force_deactivate')) {
//this will force deactivation of currently excluded plugins for normal user
if (exclude_plugins_get_option('exclude_new')) deactivate_plugins(exclude_plugins_switch(exclude_plugins_get_option('included_plugins')));
else deactivate_plugins(exclude_plugins_get_option('excluded_plugins'));
}
} else {add_plugins_page('Exclude Plugins', 'Exclude Plugins', 'manage_options', 'exclude_plugins', 'exclude_plugins_no_multisite');}
}
function exclude_plugins_switch($from){
$all_plugins=exclude_plugins_no_network();
return array_diff(array_keys($all_plugins), (array)$from);
}
function exclude_plugins_no_network(){
$plugins = get_plugins();
$network_plugins = array();
foreach ( (array) $plugins as $plugin => $plugin_data) {
if ( is_network_only_plugin($plugin)) {
$network_plugins[$plugin] = $plugin_data;
}
}
return array_diff_assoc($plugins, $network_plugins);
}
function exclude_plugins_options() {
if (!is_super_admin()) {
wp_die( __('You do not have sufficient permissions to access this page.') );
}
if ( isset($_REQUEST['exclude_plugins_ex'])) {
check_admin_referer('exclude_plugins_save_options');
if ($_REQUEST['checked']){
if (exclude_plugins_get_option('exclude_new'))
exclude_plugins_update_db('included_plugins',array_diff((array)exclude_plugins_get_option('included_plugins'),$_REQUEST['checked']));
else exclude_plugins_update_db('excluded_plugins',array_merge((array)exclude_plugins_get_option('excluded_plugins'),$_REQUEST['checked']));
}
}
elseif ( isset($_REQUEST['exclude_plugins_in'])) {
check_admin_referer('exclude_plugins_save_options');
if ($_REQUEST['checked']){
if (exclude_plugins_get_option('exclude_new'))
exclude_plugins_update_db('included_plugins',array_merge((array)exclude_plugins_get_option('included_plugins'),$_REQUEST['checked']));
else exclude_plugins_update_db('excluded_plugins',array_diff((array)exclude_plugins_get_option('excluded_plugins'),$_REQUEST['checked']));
}
}elseif ( isset($_REQUEST['exclude_plugins_save'])) {
check_admin_referer('exclude_plugins_save_options');
$force_deactivate=($_REQUEST['force_deactivate'])?1:0;
exclude_plugins_update_db('force_deactivate',$force_deactivate);
//check if switching between
if (exclude_plugins_get_option('exclude_new')!=$_REQUEST['exclude_new']){
if ($_REQUEST['exclude_new']){ //switch to exclude new
exclude_plugins_update_db('included_plugins',exclude_plugins_switch(exclude_plugins_get_option('excluded_plugins')));
exclude_plugins_update_db('excluded_plugins','');
exclude_plugins_update_db('exclude_new',1);
} else {
exclude_plugins_update_db('excluded_plugins',exclude_plugins_switch(exclude_plugins_get_option('included_plugins')));
exclude_plugins_update_db('included_plugins','');
exclude_plugins_update_db('exclude_new',0);
}
}
}
$menu_perms = get_site_option( 'menu_items', array() );
if ( empty($menu_perms['plugins']) ){
$message = sprintf( __( 'These settings is useless if plugins menu not activated because all plugins are excluded by default. %s' ), '<a href="' . esc_url( admin_url( 'ms-options.php#menu' ) ) . '">' . __( 'Activate' ) . '</a>' );
echo "<div class='error'><p>$message</p></div>";
}
$plugins=exclude_plugins_no_network();
if (exclude_plugins_get_option('exclude_new')){
$included_plugins=exclude_plugins_included($plugins);
$excluded_plugins=array_diff_assoc($plugins, $included_plugins);
}else{
$excluded_plugins=exclude_plugins_excluded($plugins);
$included_plugins=array_diff_assoc($plugins, $excluded_plugins);
}
if (exclude_plugins_get_option('force_deactivate'))$fd_checked='checked="checked"';
if (exclude_plugins_get_option('exclude_new'))$en_checked='checked="checked"';
?>
<form method="post" action="">
<?php wp_nonce_field('exclude_plugins_save_options');?>
<hr />
<h3>Included Plugins</h3>
<p>Plugins in the list below are available for <strong>all sites</strong>.</p>
<p><input class="button-secondary" type="submit" value="Exclude Checked"
name="exclude_plugins_ex" id="exclude_plugins_ex" /></p>
<div id="included-plugins">
<?php print_plugins_table($included_plugins); ?>
</div>
<p><input class="button-secondary" type="submit" value="Exclude Checked"
name="exclude_plugins_ex" id="exclude_plugins_ex" /></p>
<hr />
<h3>Excluded Plugins</h3>
<p>Plugins in the list below are available only for <strong>Super Admin</strong>.</p>
<p><input class="button-secondary" type="submit" value="Include Checked"
name="exclude_plugins_in" id="exclude_plugins_in" /></p>
<div id="excluded-plugins">
<?php print_plugins_table($excluded_plugins); ?>
</div>
<p><input class="button-secondary" type="submit" value="Include Checked"
name="exclude_plugins_in" id="exclude_plugins_in" /></p>
<hr />
<table class="form-table">
<tr><th>Exclude Newly Installed Plugins</th><td>
<input type="checkbox" name="exclude_new" <?php echo $en_checked?>> Treat as excluded (only visible by Super Admins).
<p>This option allow you to treat newly installed/added plugins as excluded (if checked) or included (if unchecked).</p>
</td></tr>
<tr><th>Force Deactivate</th><td>
<input type="checkbox" name="force_deactivate" <?php echo $fd_checked?>> Force Deactivate
<p>This will force deactivating of all plugins that is excluded for normal user.</p>
<p>If you don't exclude plugins from normal user, they can activate the plugins.
Then if you exclude the plugins they still active although they can't deactivate it anymore because the plugins is not in the list.
If you force deactivate, the active plugins that is excluded from plugin list become deactivated once the admin enter admin interface.</p>
</td></tr>
</table>
<p><input class="button-primary" type="submit" value="Save Options"
name="exclude_plugins_save" id="exclude_plugins_save" /></p>
<hr />
</form>
<?php
}
function exclude_plugins_no_multisite() {
?>
<h3>No Multisite</h3>
<p>Excluded Plugins is especially built for WordPress multisite. You can get a guide how to enabling the multisite option <a href="http://itx.web.id/wordpress/mengaktifkan-opsi-multisite-dalam-wordpress-3-0/">here</a>.</p>
<?php
}
function exclude_plugins_update_db($name,$value){
global $wpdb;
$value=maybe_serialize($value);
$q="INSERT INTO ".$wpdb->base_prefix."exclude_plugins (option_name, option_value) VALUES ( %s, %s ) ON DUPLICATE KEY UPDATE option_value= %s ";
$wpdb->query($wpdb->prepare($q,$name,$value,$value));
}
function exclude_plugins_get_option($what){
global $wpdb;
$rows = $wpdb->get_row( "SELECT * FROM ".$wpdb->base_prefix."exclude_plugins where option_name='$what'" );
if($wpdb->last_error){
if(is_super_admin())echo "<div class='updated fade'>Exclude Plugins is not functioning. You have error in database: $wpdb->last_error</div>";
return;
}
$return=maybe_unserialize($rows->option_value);
if ($what=='excluded_plugins' && is_string($return)) $return=(array) $return;
return $return;
}
function exclude_plugins_colors() {
?>
<style type="text/css">
#excluded-plugins th, #excluded-plugins td {background-color:#FFF2F2 !important;}
#included-plugins th, #included-plugins td {background-color:#F2F2FF !important;}
#excluded-plugins .row-actions-visible ,#excluded-plugins .plugin-update-tr,
#included-plugins .row-actions-visible ,#included-plugins .plugin-update-tr {display: none;}
</style>
<?php
}
function exclude_plugins_install () {
global $wpdb;
$table_name = $wpdb->base_prefix . "exclude_plugins";
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
$sql = "CREATE TABLE " . $table_name . " (
option_name VARCHAR(255) NOT NULL,
option_value text NOT NULL,
PRIMARY KEY (option_name)
);";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
$q="INSERT INTO ".$table_name." (option_name, option_value) VALUES ('version', '1.1.2'),('force_deactivate','0'),('exclude_new','1')";
$wpdb->query($wpdb->prepare($q));
}
}
register_activation_hook(__FILE__,'exclude_plugins_install');
?>
\ No newline at end of file
=== Plugin Name ===
Tags: plugins, multisite, 3.0, wpmu, network, super admin, admin
Contributors: itx
Donate link: http://itx.web.id/donate/
Requires at least: 3.0
Tested up to: 3.0
Stable tag: 1.1.2
Exclude plugins from appearing in plugins menu for normal user in WordPress multisite.
== Description ==
WordPress 3.0 multisite allows us only to show or hide all of the plugins from normal user,
nothing else. If we want to allow all users to use some simple plugins, while hiding the
*super* plugins only for Super Admins or VIP users, we have to activate the plugin for all
network in order to make it work. Or else, we have to make them visible by all.
This is why we need Exclude Plugins. Exclude Plugins will exclude plugins from appearing
in plugins menu for normal user in WordPress multisite. This way, some plugins (excluded
plugins) will be available only for Super Admins, while other plugins (included plugins)
will be available for normal user.
If you're **not** using Network Mode/MultiSite in WordPress 3.0, you definitely **not** needing this plugin.
Here's [how to activate the multisite option](http://itx.web.id/wordpress/mengaktifkan-opsi-multisite-dalam-wordpress-3-0/).
For questions and bug report, please visit [Exclude Plugins page](http://itx.web.id/wordpress/plugins/exclude-plugins/).
== Installation ==
You can use the built in installer and upgrader, or you can install the plugin manually:
1. Download the plugin
2. Upload and extract the contents of exclude-plugins.zip to wp-content/plugins/ folder. You should get a folder called exclude-plugins.
3. Activate the Plugin in WP-Admin.
4. Goto Super Admin > Options > Menu Settings then enable administration menus for plugins.
5. Goto Plugins > Exclude Plugins to configure.
== Screenshots ==
1. Exclude Plugins admin interface.
== Frequently Asked Questions ==
For questions and bug report, please visit [Exclude Plugins page](http://itx.web.id/wordpress/plugins/exclude-plugins/).
== Changelog ==
= 1.1.2, 06 July 2010 =
* Bugfix: "Table ‘xxxxxx.wp_0_exclude_plugins’ doesn’t exist" error
= 1.1.1, 03 July 2010 =
* Bugfix: eliminating PHP warning "Warning: array_diff(): Argument #2 is not an array in .../wp-content/plugins/exclude-plugins/exclude-plugins.php on line 73"
= 1.1 =
* First Public Release
wp-content/plugins/exclude-plugins/screenshot-1.jpg

72.7 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment