PluginProbe
Plugin Load Filter / 2.4.0
Plugin Load Filter v2.4.0
trunk 2.0.0 2.0.1 2.1.0 2.2.0 2.2.1 2.3.0 2.3.1 2.4.0 2.4.1 2.5.1 3.3.0 4.0.6 4.1.1 4.2.0 4.3.0 4.3.1 4.4.0
← All changes | plugin-load-filter.php +84 -26 2.3.02.4.0 View file →
@@ -1,9 +1,9 @@
1 1 <?php
2 2 /*
3 3 Plugin Name: plugin load filter
4 4 Description: Dynamically activate the selected plugins for each page. Response will be faster by filtering plugins.
5 - Version: 2.3.0
5 + Version: 2.4.0
6 6 Plugin URI: http://celtislab.net/wp_plugin_load_filter
7 7 Author: enomoto@celtislab
8 8 Author URI: http://celtislab.net/
9 9 License: GPLv2
@@ -9,9 +9,87 @@
9 9 License: GPLv2
10 10 Text Domain: plf
11 11 Domain Path: /languages
12 12 */
13 +defined( 'ABSPATH' ) || exit;
13 14
15 +/***************************************************************************
16 + * plugin activation / deactivation / uninstall
17 + **************************************************************************/
18 +if(is_admin()){
19 + function plugin_load_filter_activation( $network_wide ) {
20 + //plf-filter must-use plagin activete check
21 + if(wp_mkdir_p( WPMU_PLUGIN_DIR )){
22 + if ( !file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) {
23 + @copy(__DIR__ . '/mu-plugins/plf-filter.php', WPMU_PLUGIN_DIR . '/plf-filter.php');
24 + }
25 + else {
26 + require_once(ABSPATH . 'wp-admin/includes/plugin.php');
27 + $dp = get_plugin_data( WPMU_PLUGIN_DIR . "/plf-filter.php", false, false );
28 + $sp = get_plugin_data( __DIR__ . '/mu-plugins/plf-filter.php', false, false );
29 + if(version_compare( $dp['Version'], $sp['Version'], '!=')){
30 + @copy(__DIR__ . '/mu-plugins/plf-filter.php', WPMU_PLUGIN_DIR . '/plf-filter.php');
31 + }
32 + }
33 + }
34 + }
35 + register_activation_hook( __FILE__, 'plugin_load_filter_activation' );
36 +
37 + //deactivation
38 + function plugin_load_filter_deactivation( $network_deactivating ) {
39 + $act = false;
40 + if (is_multisite()) {
41 + if(! $network_deactivating){
42 + global $wpdb;
43 + $current_blog_id = get_current_blog_id();
44 + $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
45 + foreach ( $blog_ids as $blog_id ) {
46 + if($blog_id == $current_blog_id){
47 + //current site
48 + }
49 + else {
50 + //other site active check
51 + switch_to_blog( $blog_id );
52 + if ( is_plugin_active( plugin_basename( __FILE__ )))
53 + $act = true;
54 + }
55 + }
56 + switch_to_blog( $current_blog_id );
57 + }
58 + }
59 + if($act === false){
60 + if ( file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) {
61 + @unlink( WPMU_PLUGIN_DIR . '/plf-filter.php' );
62 + }
63 + }
64 + }
65 + register_deactivation_hook( __FILE__, 'plugin_load_filter_deactivation' );
66 +
67 + //uninstall
68 + function plugin_load_filter_uninstall() {
69 +
70 + if ( !is_multisite()) {
71 + delete_option('plf_queryvars');
72 + delete_option('plf_option' );
73 + } else {
74 + global $wpdb;
75 + $current_blog_id = get_current_blog_id();
76 + $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
77 + foreach ( $blog_ids as $blog_id ) {
78 + switch_to_blog( $blog_id );
79 + delete_option('plf_queryvars');
80 + delete_option('plf_option' );
81 + }
82 + switch_to_blog( $current_blog_id );
83 + }
84 + if ( file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) {
85 + @unlink( WPMU_PLUGIN_DIR . '/plf-filter.php' );
86 + }
87 + }
88 + register_uninstall_hook(__FILE__, 'plugin_load_filter_uninstall');
89 +
90 +}
91 +
14 92 $Plf_setting = new Plf_setting();
15 93
16 94 class Plf_setting {
17 95
@@ -116,33 +194,14 @@
116 194 }
117 195
118 196 if(is_admin()) {
119 197 add_action( 'plugins_loaded', array(&$this, 'plf_admin_start'), 9999 );
198 + add_action( 'admin_init', array(&$this, 'action_posts'));
120 199 add_action( 'add_meta_boxes', array(&$this, 'load_meta_boxes'), 10, 2 );
121 - //plf-filter must-use plagin activete check
122 - if(wp_mkdir_p( WPMU_PLUGIN_DIR )){
123 - if ( !file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) {
124 - @copy(__DIR__ . '/mu-plugins/plf-filter.php', WPMU_PLUGIN_DIR . '/plf-filter.php');
125 - }
126 - }
127 - register_deactivation_hook( __FILE__, 'Plf_setting::deactivation' );
128 - register_uninstall_hook(__FILE__, 'Plf_setting::uninstall');
129 200 }
130 201 add_action( 'wp_ajax_plugin_load_filter', array(&$this, 'plf_ajax_postidfilter'));
131 202 }
132 203
133 - //Plugin Deactivate
134 - public static function deactivation() {
135 - if ( file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) {
136 - @unlink( WPMU_PLUGIN_DIR . '/plf-filter.php' );
137 - }
138 - }
139 - //Plugin Uninstall
140 - public static function uninstall() {
141 - delete_option('plf_queryvars');
142 - delete_option('plf_option' );
143 - }
144 -
145 204 //Plugin Load Filter admin setting start
146 205 public function plf_admin_start() {
147 206 require_once(ABSPATH . 'wp-admin/includes/plugin.php');
148 207
@@ -176,9 +235,8 @@
176 235 }
177 236 if ( empty( $this->plugins_inf ) )
178 237 return;
179 238
180 - $this->action_posts(); //POST, GET Request Action
181 239 add_action('admin_menu', array(&$this, 'plf_option_menu'));
182 240 }
183 241
184 242 //Plugins sub menu add
@@ -199,9 +257,9 @@
199 257 }
200 258
201 259 //plugin filter option action request (add, update, delete)
202 260 function action_posts() {
203 - if (current_user_can( 'edit_plugins' )) {
261 + if (current_user_can( 'activate_plugins' )) {
204 262 if( isset($_POST['edit_regist_filter']) ) {
205 263 if(isset($_POST['plfregist'])){
206 264 check_admin_referer('plugin_load_filter');
207 265 foreach( array('_admin', '_pagefilter') as $item){
@@ -563,9 +621,9 @@
563 621 <ul>
564 622 <li><a href="#plf-registration-tab" ><?php _e('Filter Registration', 'plf'); ?></a></li>
565 623 <li><a href="#plf-activation-tab" ><?php _e('Page Filter Activation', 'plf'); ?></a></li>
566 624 </ul>
567 - <form method="post" >
625 + <form method="post" autocomplete="off">
568 626 <?php wp_nonce_field( 'plugin_load_filter'); ?>
569 627 <div id="plf-registration-tab" style="display : none;">
570 628 <?php $this->plfregist_table($this->plugins_inf, $this->filter); ?>
571 629 <p class="submit">
@@ -606,9 +664,9 @@
606 664 * Meta box
607 665 * Individual of the plug-in filter meta box for Post/Page/CustomPost
608 666 **************************************************************************/
609 667 function load_meta_boxes( $post_type, $post ) {
610 - if ( current_user_can('edit_plugins', $post->ID) ) {
668 + if ( current_user_can('activate_plugins', $post->ID) ) {
611 669 add_meta_box( 'pluginfilterdiv', __( 'Page Filter Plugin', 'plf' ), array(&$this, 'plf_meta_box'), null, 'side' );
612 670 add_action( 'admin_head', array(&$this, 'plf_css' ));
613 671 add_action( 'admin_footer', array(&$this, 'plf_meta_script' ));
614 672 }
@@ -717,9 +775,9 @@
717 775 //wp_ajax_plugin_load_filter called function
718 776 function plf_ajax_postidfilter() {
719 777 if ( isset($_POST['post_id']) ) {
720 778 $pid = (int) $_POST['post_id'];
721 - if ( !current_user_can( 'edit_plugins', $pid ) )
779 + if ( !current_user_can( 'activate_plugins', $pid ) )
722 780 wp_die( -1 );
723 781 check_ajax_referer( "plugin_load_filter-$pid" );
724 782
725 783 $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();