-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwpmu-plugin-manager.php
More file actions
899 lines (776 loc) · 23.2 KB
/
wpmu-plugin-manager.php
File metadata and controls
899 lines (776 loc) · 23.2 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
<?php
/*
Plugin Name: WPMU Plugin Manager
Plugin URI: http://wordpress.org/plugins/wpmu-plugin-manager/
Description: Manage plugin access permissions across your entire multisite network.
Version: 1.1-beta
Author: WP-Cloud
Author URI: http://dev.wp-cloud.org
License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: wpmu-plugin-manager
Domain Path: /languages
Network: true
WPMU Plugin Manager
based on/forked from Multisite Plugin Manager by UglyRobot Web Development (http://uglyrobot.com)
Copyright (C) 2013-2019 WP-Cloud (http://dev.wp-cloud.org)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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, see <http://www.gnu.org/licenses/>.
*/
/**
* @author WP-Cloud <code@wp-cloud.org>
* @copyright Copyright (c) 2013-2019, WP-Cloud
* @license http://www.gnu.org/licenses/gpl-2.0.html GPLv2
* @package WPC\PluginManager
* @version 1.1-beta
*/
//avoid direct calls to this file
if ( !defined( 'ABSPATH' ) ) {
header( 'Status: 403 Forbidden' );
header( 'HTTP/1.1 403 Forbidden' );
exit();
}
/**
* Main class to run the plugin
*
* @since 1.0.0
*/
class WPC_PluginManager {
/**
* Current version of the plugin.
*
* @since 1.0.0
* @access public
* @var string $version
*/
public $version = '1.1-beta';
/**
* Hold the minimum permission to access plugin
*
* @since 1.0.0
* @access public
* @var string $permission
*/
public $permission;
/**
* Constructor. Hooks all interactions to initialize the class.
*
* @since 1.0.0
* @access public
*
* @see add_action()
* @see add_filter()
* @see is_admin()
* @see apply_filters()
*
* @return void
*/
public function __construct() {
if ( ! is_admin() ) {
return;
}
$this->permission = apply_filters( 'wpc_pm_cap', 'manage_network_plugins' );
add_action( 'plugins_loaded', array( $this, 'load_plugin_textdomain' ) );
add_action( 'network_admin_menu', array( $this, 'network_admin_menu' ) );
add_action( 'wpmu_new_blog', array( $this, 'new_blog' ), 50 );
add_action( 'wpmueditblogaction', array( $this, 'blog_options_form' ) );
add_action( 'wpmu_update_blog_options', array( $this, 'blog_options_form_process' ) );
add_action( 'admin_init', array( $this, 'remove_plugin_update_row' ) );
add_filter( 'plugin_row_meta' , array( $this, 'remove_plugin_meta' ), 10, 2 );
if ( ! ( defined( 'WP_CLI' ) && WP_CLI ) ) {
add_filter( 'all_plugins', array( $this, 'remove_plugins' ) );
}
add_filter( 'plugin_action_links', array( $this, 'action_links' ), 10, 4 );
// add_filter( 'active_plugins', array( $this, 'check_activated' ) );
} // END __construct()
/**
* Add admin menu item
*
* @since 0.1.0
* @access public
*
* @see add_action()
* @see add_submenu_page()
* @action network_admin_menu
*
* @return void
*/
public function network_admin_menu() {
add_submenu_page(
'plugins.php',
__( 'Manage Plugins', 'wpmu-plugin-manager' ),
__( 'Manage', 'wpmu-plugin-manager' ),
$this->permission,
'manage',
array( $this, 'admin_page' )
);
add_action( 'load-plugins_page_manage', array( $this, 'help_tabs' ) );
} // END network_admin_menu()
/**
* @todo
*
* @since 1.0.0
* @access public
*
* @see get_current_screen()
* @action load-plugins_page_manage
*
* @return string
*/
public function help_tabs() {
$screen = get_current_screen();
$screen->add_help_tab(
array(
'id' => 'wpc-plugin-manager_options',
'title' => __( 'Options', 'wpmu-plugin-manager' ),
'callback' => array( $this, 'option_tab')
)
);
} // END help_tabs()
/**
* @todo
*
* @since 0.1.0
* @access public
*
* @see _e()
*
* @return string
*/
public function option_tab() { ?>
<p>
<strong><?php _e( 'Auto Activation', 'wpmu-plugin-manager' ); ?></strong>
- <?php _e( 'When auto activation is on for a plugin, newly created blogs will have that plugin activated automatically. This does not affect existing blogs.', 'wpmu-plugin-manager' ); ?>
</p>
<p>
<strong><?php _e( 'User Control', 'wpmu-plugin-manager' ); ?></strong>
- <?php _e( 'When user control is enabled for a plugin, all users will be able to activate/deactivate the plugin through the <cite>Plugins</cite> menu. When you turn it off, users that have the plugin activated are grandfathered in, and will continue to have access until they deactivate it.', 'wpmu-plugin-manager' ); ?>
</p>
<p>
<strong><?php _e( 'Mass Activation/Deactivation', 'wpmu-plugin-manager' ); ?></strong>
- <?php _e( 'Mass activate and Mass deactivate buttons activate/deactivates the specified plugin for all blogs. This is different than the "Network Activate" option on the network plugins page, as users can later disable it and this only affects existing blogs. It also ignores the User Control option.', 'wpmu-plugin-manager' ); ?></p>
<?php
} // END option_tab()
/**
* @todo
*
* @since 1.0.0
* @access public
*
* @see _e()
* @see current_user_can()
* @see get_plugins()
* @see get_site_option()
* @see is_network_only_plugin()
* @see is_plugin_active_for_network()
* @see submit_button()
* @uses self::process_form()
*
* @return string
*/
public function admin_page() {
if ( ! current_user_can( $this->permission ) ) {
die( 'Nice Try!' );
}
$this->process_form();
?>
<div class="wrap">
<h1 class="wp-heading-inline"><?php _e( 'Plugin Management', 'wpmu-plugin-manager' ); ?></h1>
<hr class="wp-header-end">
<?php if ( isset( $_GET['updated'] ) ) { ?>
<div id="message" class="updated notice is-dismissible"><p><?php _e( 'Settings saved.' ); ?></p></div>
<?php } ?>
<form action="plugins.php?page=manage&updated=true" method="post">
<table class="wp-list-table widefat plugins" id="plugin-manager">
<thead>
<tr>
<th><?php _e( 'Name', 'wpmu-plugin-manager' ); ?></th>
<th><?php _e( 'Version', 'wpmu-plugin-manager' ); ?></th>
<th><?php _e( 'Author', 'wpmu-plugin-manager' ); ?></th>
<th title="<?php _e( 'Users may activate/deactivate', 'wpmu-plugin-manager' ); ?>">
<?php _e( 'User Control', 'wpmu-plugin-manager' ); ?>
</th>
<?php if ( $this->can_mass_process() ) { ?>
<th>
<?php _e( 'Mass Activate', 'wpmu-plugin-manager' ); ?>
</th>
<th>
<?php _e( 'Mass Deactivate', 'wpmu-plugin-manager' ); ?>
</th>
<?php } ?>
</tr>
</thead>
<tfoot>
<tr>
<th>
<?php _e( 'Name', 'wpmu-plugin-manager' ); ?>
</th>
<th>
<?php _e( 'Version', 'wpmu-plugin-manager' ); ?>
</th>
<th>
<?php _e( 'Author', 'wpmu-plugin-manager' ); ?>
</th>
<th title="<?php _e( 'Users may activate/deactivate', 'wpmu-plugin-manager' ); ?>">
<?php _e( 'User Control', 'wpmu-plugin-manager' ); ?>
</th>
<?php if ( $this->can_mass_process() ) { ?>
<th>
<?php _e( 'Mass Activate', 'wpmu-plugin-manager' ); ?>
</th>
<th>
<?php _e( 'Mass Deactivate', 'wpmu-plugin-manager' ); ?>
</th>
<?php } ?>
</tr>
</tfoot>
<?php
$plugins = get_plugins();
$auto_activate = (array)get_site_option( 'pm_auto_activate_list' );
$user_control = (array)get_site_option( 'pm_user_control_list' );
foreach ( $plugins as $file => $p ) {
//skip network plugins or network activated plugins
if ( is_network_only_plugin( $file ) || is_plugin_active_for_network( $file ) ) {
continue;
}
?>
<tbody>
<tr>
<td>
<?php echo $p['Name']?>
</td>
<td>
<?php echo $p['Version']?>
</td>
<td>
<?php echo $p['Author']?>
</td>
<td>
<?php
echo '<select name="control[' . $file . ']" />'."\n";
$u_checked = in_array( $file, $user_control );
$auto_checked = in_array( $file, $auto_activate );
if ( $u_checked ) {
$n_opt = '';
$s_opt = '';
$a_opt = ' selected="yes"';
$auto_opt = '';
} else if ( $auto_checked ) {
$n_opt = '';
$s_opt = '';
$a_opt = '';
$auto_opt = ' selected="yes"';
} else {
$n_opt = ' selected="yes"';
$s_opt = '';
$a_opt = '';
$auto_opt = '';
}
$opts = '<option value="none"' . $n_opt . '>' . __( 'None', 'wpmu-plugin-manager' ) . '</option>'."\n";
$opts .= '<option value="all"' . $a_opt . '>' . __( 'All Users', 'wpmu-plugin-manager' ) . '</option>'."\n";
$opts .= '<option value="auto"' . $auto_opt . '>' . __( 'Auto-Activate (All Users)', 'wpmu-plugin-manager' ) . '</option>'."\n";
echo $opts.'</select>';
?>
</td>
<?php if ( $this->can_mass_process() ) { ?>
<td>
<?php echo "<a href='plugins.php?page=manage&mass_activate=$file'>" . __( 'Activate All', 'wpmu-plugin-manager' ) . "</a>" ?>
</td>
<td>
<?php echo "<a href='plugins.php?page=manage&mass_deactivate=$file'>" . __( 'Deactivate All', 'wpmu-plugin-manager' ) . "</a>" ?>
</td>
<?php } ?>
</tr>
</tbody>
<?php } ?>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php
} //end admin_page()
/**
* @todo
*
* @since 1.0.0
* @access public
*
* @see current_user_can()
* @see remove_all_actions()
* @action plugin_row_meta
*
* @param array $plugin_meta
* @param array $plugin_file
* @return array
*/
public function remove_plugin_meta( $plugin_meta, $plugin_file ) {
if ( current_user_can( $this->permission ) ) {
return $plugin_meta;
} else {
remove_all_actions( "after_plugin_row_$plugin_file" );
return array();
}
} // END remove_plugin_meta()
/**
* @todo
*
* @since 1.0.0
* @access public
*
* @see current_user_can()
* @see remove_all_actions()
* @action admin_init
*
* @return void
*/
function remove_plugin_update_row() {
if ( !current_user_can( $this->permission ) ) {
remove_all_actions( 'after_plugin_row' );
}
} // END remove_plugin_update_row()
/**
* @todo
*
* @since 1.0.0
* @access public
*
* @see update_site_option()
* @uses self::mass_deactivate()
*
* @return void
*/
function process_form() {
if ( isset( $_GET['mass_activate'] ) ) {
$plugin = $_GET['mass_activate'];
$this->mass_activate($plugin);
}
if ( isset( $_GET['mass_deactivate'] ) ) {
$plugin = $_GET['mass_deactivate'];
$this->mass_deactivate( $plugin );
}
if ( isset( $_POST['control'] ) ) {
//create blank arrays
$user_control = array();
$auto_activate = array();
foreach ( $_POST['control'] as $plugin => $value ) {
if ( $value == 'none' ) {
//do nothing
} else if ( $value == 'all' ) {
$user_control[] = $plugin;
} else if ( $value == 'auto' ) {
$auto_activate[] = $plugin;
}
}
update_site_option( 'pm_user_control_list', array_unique( $user_control ) );
update_site_option( 'pm_auto_activate_list', array_unique( $auto_activate ) );
//can't save blank value via update_site_option
if ( ! $user_control ) {
update_site_option( 'pm_user_control_list', 'EMPTY' );
}
if ( ! $auto_activate ) {
update_site_option( 'pm_auto_activate_list', 'EMPTY' );
}
}
} // END process_form()
//options added to wpmu-blogs.php edit page. Overrides sitewide control settings for an individual blog.
/**
* @todo
*
* @since 1.0.0
* @access public
*
* @see __()
* @see _e()
* @see get_plugins()
* @see get_blog_option()
* @see is_network_only_plugin()
* @see is_plugin_active_for_network()
* @action blog_options_form
*
* @param string $blog_id
* @return string
*/
function blog_options_form( $blog_id ) {
$plugins = get_plugins();
$override_plugins = (array)get_blog_option( $blog_id, 'pm_plugin_override_list' );
?>
</table>
<h3><?php _e( 'Plugin Override Options', 'wpmu-plugin-manager' ) ?></h3>
<p style="padding:5px 10px 0 10px;margin:0;">
<?php printf( __( 'Checked plugins here will be accessible to this site, overriding the sitewide %sPlugin Management%s settings. Uncheck to return to sitewide settings.', 'wpmu-plugin-manager' ), '<a href="plugins.php?page=manage">', '</a>' ); ?>
</p>
<table class="widefat" style="margin:10px;width:95%;">
<thead>
<tr>
<th title="<?php _e( 'Blog users may activate/deactivate', 'wpmu-plugin-manager' ) ?>">
<?php _e( 'User Control', 'wpmu-plugin-manager' ) ?>
</th>
<th>
<?php _e( 'Name', 'wpmu-plugin-manager' ); ?>
</th>
<th>
<?php _e( 'Version', 'wpmu-plugin-manager' ); ?>
</th>
<th>
<?php _e( 'Author', 'wpmu-plugin-manager' ); ?>
</th>
</tr>
</thead>
<tfoot>
<tr>
<th title="<?php _e( 'Blog users may activate/deactivate', 'wpmu-plugin-manager' ) ?>">
<?php _e( 'User Control', 'wpmu-plugin-manager' ) ?>
</th>
<th>
<?php _e( 'Name', 'wpmu-plugin-manager' ); ?>
</th>
<th>
<?php _e( 'Version', 'wpmu-plugin-manager' ); ?>
</th>
<th>
<?php _e( 'Author', 'wpmu-plugin-manager' ); ?>
</th>
</tr>
</tfoot>
<?php
foreach ( $plugins as $file => $p ) {
//skip network plugins or network activated plugins
if ( is_network_only_plugin( $file ) || is_plugin_active_for_network( $file ) ) {
continue;
}
?>
<tr>
<td>
<?php
$checked = ( in_array( $file, $override_plugins ) ) ? 'checked="checked"' : '';
echo '<label><input name="plugins[' . $file . ']" type="checkbox" value="1" ' . $checked . '/> ' . __( 'Enable', 'wpmu-plugin-manager' ) . '</label>';
?>
</td>
<td>
<?php echo $p['Name']?>
</td>
<td>
<?php echo $p['Version']?>
</td>
<td>
<?php echo $p['Author']?>
</td>
</tr>
<?php
}
echo '</table>';
} // END blog_options_form()
//process options from wpmu-blogs.php edit page. Overrides sitewide control settings for an individual blog.
/**
* @todo
*
* @since 1.0.0
* @access public
*
* @see update_option()
* @action wpmu_update_blog_options
*
* @return void
*/
public function blog_options_form_process() {
$override_plugins = array();
if ( is_array( $_POST['plugins'] ) ) {
foreach ( (array)$_POST['plugins'] as $plugin => $value ) {
$override_plugins[] = $plugin;
}
update_option( 'pm_plugin_override_list', $override_plugins );
} else {
update_option( 'pm_plugin_override_list', array() );
}
} // END blog_options_form_process()
//activate on new blog
/**
* @todo
*
* @since 1.0.0
* @access public
*
* @see get_site_option()
* @see switch_to_blog()
* @see activate_plugins()
* @see restore_current_blog()
* @action wpmu_new_blog
*
* @param string $blog_id
* @return void
*/
function new_blog( $blog_id ) {
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
$auto_activate = (array)get_site_option( 'pm_auto_activate_list' );
if ( count( $auto_activate ) && $auto_activate[0] != 'EMPTY' ) {
switch_to_blog( $blog_id );
activate_plugins( $auto_activate, '', false ); //silently activate any plugins
restore_current_blog();
}
} // END new_blog()
/**
* @todo
*
* @since 1.0.0
* @access public
*
* @see __()
* @see _e()
* @see esc_html()
* @see switch_to_blog()
* @see activate_plugins()
* @see restore_current_blog()
* @see wp_is_large_network()
*
* @global object $wpdb
* @param string $plugin
* @return string
*/
public function mass_activate( $plugin ) {
if ( wp_is_large_network() ) { ?>
<div class="error">
<p><?php _e('Failed to mass activate: Your multisite network is too large for this function.', 'pm'); ?></p>
</div>
<?php
return false;
}
global $wpdb;
set_time_limit( 120 );
$blogs = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = {$wpdb->siteid} AND spam = 0" );
if ( $blogs ) {
foreach( $blogs as $blog_id ) {
switch_to_blog( $blog_id );
activate_plugin( $plugin ); //silently activate the plugin
restore_current_blog();
} ?>
<div id="message" class="updated notice is-dismissible">
<p>
<?php printf( __( '%s has been MASS ACTIVATED.', 'wpmu-plugin-manager' ), '<span style="color:#FF3300;">' . esc_html( $plugin ) . '</span>'); ?>
</p>
</div>
<?php
} else { ?>
<div class="error">
<p>
<?php _e( 'Failed to mass activate: error selecting blogs', 'wpmu-plugin-manager' ); ?>
</p>
</div>
<?php
}
} // END mass_activate()
/**
* @todo
*
* @since 1.0.0
* @access public
*
* @see __()
* @see _e()
* @see esc_html()
* @see switch_to_blog()
* @see deactivate_plugins()
* @see restore_current_blog()
* @see wp_is_large_network()
*
* @global object $wpdb
* @param string $plugin
* @return string
*/
function mass_deactivate( $plugin ) {
if ( wp_is_large_network() ) { ?>
<div class="error">
<p><?php _e('Failed to mass activate: Your multisite network is too large for this function.', 'wpmu-plugin-mnanager' ); ?></p>
</div>
<?php
return false;
}
global $wpdb;
set_time_limit( 120 );
$blogs = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = {$wpdb->siteid} AND spam = 0" );
if ( $blogs ) {
foreach ( $blogs as $blog_id ) {
switch_to_blog( $blog_id );
deactivate_plugins( $plugin, true ); //silently deactivate the plugin
restore_current_blog();
} ?>
<div id="message" class="updated notice is-dismissible">
<p>
<?php printf( __( '%s has been MASS DEACTIVATED.', 'wpmu-plugin-manager' ), '<span style="color:#FF3300;">' . esc_html( $plugin ) . '</span>'); ?>
</p>
</div>
<?php
} else { ?>
<div class="error">
<p>
<?php _e( 'Failed to mass deactivate: error selecting blogs', 'wpmu-plugin-manager' ); ?>
</p>
</div>
<?php
}
} // END mass_deactivate()
//remove plugins with no user control
/**
* @todo
*
* @since 1.0.0
* @access public
*
* @see current_user_can()
* @see get_site_option()
* @see get_option()
*
* @param string $all_plugins
* @return void
*/
function remove_plugins( $all_plugins ) {
if ( current_user_can( $this->permission ) ) { //don't filter siteadmin
return $all_plugins;
}
$auto_activate = (array)get_site_option( 'pm_auto_activate_list' );
$user_control = (array)get_site_option( 'pm_user_control_list' );
$override_plugins = (array)get_option( 'pm_plugin_override_list' );
foreach ( (array)$all_plugins as $plugin_file => $plugin_data ) {
if ( in_array( $plugin_file, $user_control ) || in_array( $plugin_file, $auto_activate ) || in_array( $plugin_file, $override_plugins ) ) {
//do nothing - leave it in
} else {
unset( $all_plugins[ $plugin_file ] ); //remove plugin
}
}
return $all_plugins;
} // END remove_plugins()
//plugin activate links
/**
* @todo
*
* @since 1.0.0
* @access public
*
* @see current_user_can()
* @see get_site_option()
* @see get_option()
* @action plugin_action_links
*
* @global ? $psts
* @global string $blog_id
* @param array $action_links
* @param string $plugin_file
* @param string $plugin_data
* @param string $context
* @return void
*/
function action_links( $action_links, $plugin_file, $plugin_data, $context ) {
// global $psts, $blog_id;
if ( current_user_can( $this->permission ) ) {
return $action_links;
}
$auto_activate = (array)get_site_option( 'pm_auto_activate_list' );
$user_control = (array)get_site_option( 'pm_user_control_list' );
$override_plugins = (array)get_option( 'pm_plugin_override_list' );
if ( $context != 'active' ) {
if ( in_array( $plugin_file, $user_control ) || in_array( $plugin_file, $auto_activate ) || in_array( $plugin_file, $override_plugins ) ) {
return $action_links;
}
}
return $action_links;
} // END action_links()
//use jquery to remove associated checkboxes to prevent mass activation (usability, not security)
/**
* @todo
*
* @since 1.0.0
* @access public
*
* @see esc_js()
*
* @param string $plugin_file
* @return void
*/
public function remove_checks( $plugin_file ) {
echo '<script type="text/javascript">jQuery("input:checkbox[value=\'' . esc_js( $plugin_file ). '\']).remove();</script>';
} // END remove_checks()
/*
Removes activated plugins that should not have been activated (multi). Single activations
are additionaly protected by a nonce field. Dirty hack in case someone uses firebug or
something to hack the post and simulate a bulk activation. I'd rather prevent
them from being activated in the first place, but there are no hooks for that! The
display will show the activated status, but really they are not. Only hacking attempts
will see this though! */
/**
* @todo
*
* @since 1.0.0
* @access public
*
* @see current_user_can()
* @see get_site_option()
* @see get_option()
* @see deactivate_plugins()
*
* @param array $active_plugins
* @return array
*/
function check_activated( $active_plugins ) {
if ( current_user_can( $this->permission ) ) {
return $active_plugins;
}
//only perform check right after activation hack attempt
if ( $_POST['action'] != 'activate-selected' && $_POST['action2'] != 'activate-selected' ) {
return $active_plugins;
}
$auto_activate = (array)get_site_option( 'pm_auto_activate_list' );
$user_control = (array)get_site_option( 'pm_user_control_list' );
$override_plugins = (array)get_option( 'pm_plugin_override_list' );
foreach ( (array)$active_plugins as $plugin_file => $plugin_data ) {
if ( in_array( $plugin_file, $user_control ) || in_array( $plugin_file, $auto_activate ) || in_array( $plugin_file, $override_plugins ) ) {
//do nothing - leave it in
} else {
deactivate_plugins( $plugin_file, true ); //silently remove any plugins
unset( $active_plugins[ $plugin_file ] );
}
}
return $active_plugins;
} // END check_activated()
/**
* Load the plugin's textdomain hooked to 'plugins_loaded'.
*
* @since 1.0.0
* @access public
*
* @see load_plugin_textdomain()
* @see plugin_basename()
* @action plugins_loaded
*
* @return void
*/
public function load_plugin_textdomain() {
load_plugin_textdomain(
'wpmu-plugin-manager',
false,
dirname( plugin_basename( __FILE__ ) ) . '/languages/'
);
} // END load_plugin_textdomain()
private function can_mass_process() {
if ( wp_is_large_network() ) {
$can = false;
} else {
$can = true;
}
return apply_filters( 'wpc_pm_mass_process_status', $can );
}
} // END class WPC_PluginManager
/**
* Instantiate the main class
*
* @since 1.0.0
* @access public
*
* @var object $wpc_pm holds the instantiated class {@uses WPC_PluginManager}
*/
$wpc_pm = new WPC_PluginManager();