PluginProbe
Plugin Load Filter / 2.2.0
Plugin Load Filter v2.2.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
plugin-load-filter / plugin-load-filter.php

plugin-load-filter.php in Plugin Load Filter 2.2.0, at plugin-load-filter.php

663 lines 35.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: plugin load filter
4 Description: Dynamically activate the selected plugins for each page. Response will be faster by filtering plugins.
5 Version: 2.2.0
6 Plugin URI: http://celtislab.net/wp_plugin_load_filter
7 Author: enomoto@celtislab
8 Author URI: http://celtislab.net/
9 License: GPLv2
10 Text Domain: plf
11 Domain Path: /languages
12 */
13
14 $Plf_setting = new Plf_setting();
15
16 class Plf_setting {
17
18 private $plugins_inf = ''; //active plugin/module infomation
19 private $filter = array(); //filter option data
20 private $tab_num = 0;
21
22 /***************************************************************************
23 * Style Sheet
24 **************************************************************************/
25 function plf_css() { ?>
26 <style type="text/css">
27 .plugins-list { max-width : 480px; min-height: 80px; max-height: 320px; overflow: auto; border: 1px solid #CEE1EF; padding:0.5em 0.5em;}
28 ul.plugins-list ul { margin-left: 20px; }
29 ul.plugins-list li { margin: 0; padding: 0; line-height: 22px; word-wrap: break-word;}
30 </style>
31 <?php }
32
33 function jquery_tab_css() { ?>
34 <style type="text/css">
35 .ui-helper-reset { margin: 0; padding: 0; border: 0; outline: 0; line-height: 1.5; text-decoration: none; font-size: 100%; list-style: none; }
36 .ui-helper-clearfix:before, .ui-helper-clearfix:after { content: ""; display: table; }
37 .ui-helper-clearfix:after { clear: both; }
38 .ui-helper-clearfix { zoom: 1; }
39 .ui-tabs { position: relative; padding: .2em; zoom: 1; } /* position: relative prevents IE scroll bug (element with position: relative inside container with overflow: auto appear as "fixed") */
40 .ui-tabs .ui-tabs-nav { margin: 1px 8px; padding: .2em .2em; }
41 .ui-tabs .ui-tabs-nav li { list-style: none; float: left; position: relative; top: 0; margin: 1px .3em 0 0; border-bottom: 0; padding: 0; white-space: nowrap; }
42 .ui-tabs .ui-tabs-nav li a { float: left; text-decoration: none; }
43 .ui-tabs .ui-tabs-nav li.ui-tabs-active { margin-bottom: -1px; padding-bottom: 1px; }
44 .ui-tabs .ui-tabs-panel { display: block; border-width: 0; background: none; }
45 .ui-tabs .ui-tabs-nav a { margin: 8px 10px; }
46 .ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { border: 1px solid #dddddd; background-color: #f4f4f4; font-weight: bold; color: #0073ea; }
47 .ui-state-default a, .ui-state-default a:link, .ui-state-default a:visited { color: #0073ea; text-decoration: none; }
48 .ui-state-hover, .ui-widget-content .ui-state-hover, .ui-widget-header .ui-state-hover, .ui-state-focus, .ui-widget-content .ui-state-focus,.ui-widget-header .ui-state-focus { border: 1px solid #0073ea; background-color: #0073ea; font-weight: bold; color: #ffffff; }
49 .ui-state-active, .ui-widget-content .ui-state-active, .ui-widget-header .ui-state-active { border: 1px solid #dddddd; background-color: #0073ea; font-weight: bold; color: #ffffff; }
50 .ui-state-hover a, .ui-state-hover a:hover, .ui-state-hover a:link, .ui-state-hover a:visited { color: #ffffff; text-decoration: none; }
51 .ui-state-active a, .ui-state-active a:link, .ui-state-active a:visited { color: #ffffff; text-decoration: none; }
52
53 #registration-table input[type=radio], #activation-table input[type=checkbox] { height: 25px; width: 25px; opacity: 0;}
54 .dashicons:before { font-size: 24px; }
55 .radio-green label, .radio-red label, .altcheckbox label { color: #ddd; margin-left: -28px; }
56 .radio-green input[type="radio"]:checked + label { color: #339966; }
57 .radio-red input[type="radio"]:checked + label { color: #ff0000; }
58 .altcheckbox input[type="checkbox"]:checked + label { color: #339966; }
59 </style>
60 <?php }
61
62 /***************************************************************************
63 * Plugin Load Filter Option Setting
64 **************************************************************************/
65
66 public function __construct() {
67
68 load_plugin_textdomain('plf', false, basename( dirname( __FILE__ ) ).'/languages' );
69
70 $this->filter = get_option('plf_option');
71 if(!empty($this->filter['updated'])){
72 $this->filter['updated'] = null; //v2.2.0 not used option clear
73 }
74
75 if(is_admin()) {
76 add_action( 'plugins_loaded', array(&$this, 'plf_admin_start'), 9999 );
77 add_action( 'add_meta_boxes', array(&$this, 'load_meta_boxes'), 10, 2 );
78 //plf-filter must-use plagin activete check
79 if(wp_mkdir_p( WPMU_PLUGIN_DIR )){
80 if ( !file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) {
81 @copy(__DIR__ . '/mu-plugins/plf-filter.php', WPMU_PLUGIN_DIR . '/plf-filter.php');
82 }
83 }
84 register_deactivation_hook( __FILE__, 'Plf_setting::deactivation' );
85 register_uninstall_hook(__FILE__, 'Plf_setting::uninstall');
86 }
87 add_action( 'wp_ajax_plugin_load_filter', array(&$this, 'plf_ajax_postidfilter'));
88 }
89
90 //Plugin Deactivate
91 public static function deactivation() {
92 if ( file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) {
93 @unlink( WPMU_PLUGIN_DIR . '/plf-filter.php' );
94 }
95 }
96 //Plugin Uninstall
97 public static function uninstall() {
98 delete_option('plf_queryvars');
99 delete_option('plf_option' );
100 }
101
102 //Plugin Load Filter admin setting start
103 public function plf_admin_start() {
104 require_once(ABSPATH . 'wp-admin/includes/plugin.php');
105
106 $this->plugins_inf = get_plugins();
107 $packplug = array();
108 foreach ( $this->plugins_inf as $plugin_key => $a_plugin ) {
109 if(is_plugin_inactive( $plugin_key )){
110 unset($this->plugins_inf[$plugin_key]);
111 }
112 }
113 //jetpack active module
114 if(method_exists('Jetpack', 'get_module')){
115 $modules = Jetpack::get_active_modules();
116 $modules = array_diff( $modules, array( 'vaultpress' ) );
117 foreach ( $modules as $key => $module_name ) {
118 if(!empty($module_name)){
119 $module = Jetpack::get_module( $module_name );
120 if(!empty($module))
121 $this->plugins_inf['jetpack_module/' . $module_name] = $module;
122 }
123 }
124 }
125 //celtispack active module
126 if(method_exists('Celtispack', 'get_module')){
127 $modules = Celtispack::get_active_modules();
128 foreach ( $modules as $key => $module_name ) {
129 if(!empty($module_name)){
130 $this->plugins_inf['celtispack_module/' . $module_name] = Celtispack::get_module( $module_name );
131 }
132 }
133 }
134 if ( empty( $this->plugins_inf ) )
135 return;
136
137 $this->action_posts(); //POST, GET Request Action
138 add_action('admin_menu', array(&$this, 'plf_option_menu'));
139 }
140
141 //Plugins sub menu add
142 public function plf_option_menu() {
143 $page = add_plugins_page( 'Plugin Load Filter', __('Plugin Load Filter', 'plf'), 'manage_options', 'plugin_load_filter_admin_manage_page', array(&$this,'plf_option_page'));
144 add_action('admin_print_scripts-'.$page, array(&$this, 'plf_scripts'));
145 }
146
147 //Plugin Load Filter setting page script
148 function plf_scripts() {
149 wp_enqueue_script( 'jquery' );
150 wp_enqueue_script( 'jquery-ui-core' );
151 wp_enqueue_script( 'jquery-ui-widget' );
152 wp_enqueue_script( 'jquery-ui-tabs' );
153 add_action( 'admin_head', array(&$this, 'plf_css' ));
154 add_action( 'admin_head', array(&$this, 'jquery_tab_css' ));
155 add_action( 'admin_footer', array(&$this, 'activetab_script' ));
156 }
157
158 //plugin filter option action request (add, update, delete)
159 function action_posts() {
160 if (current_user_can( 'edit_plugins' )) {
161 if( isset($_POST['edit_regist_filter']) ) {
162 if(isset($_POST['plfregist'])){
163 check_admin_referer('plugin_load_filter');
164 foreach( array('_admin', '_desktop', '_mobile', '_pagefilter') as $item){
165 $plugins = array();
166 foreach ( $_POST['plfregist'] as $p_key => $val ) {
167 if($val == $item)
168 $plugins[$p_key] = $val;
169 }
170 if($item == '_pagefilter'){
171 //If all modules is specified filter, in some cases you want to deactivate plugin itself.
172 $jbase = $cbase = '';
173 $jall = $call = true;
174 foreach ( $_POST['plfregist'] as $p_key => $val ) {
175 if(strpos($p_key, 'jetpack/') !== false)
176 $jbase = $p_key;
177 else if(strpos($p_key, 'celtispack/') !== false)
178 $cbase = $p_key;
179 else if(strpos($p_key, 'jetpack_module/') !== false){
180 if($val != '_pagefilter' && $val != '_admin'){
181 $jall = false;
182 }
183 }
184 else if(strpos($p_key, 'celtispack_module/') !== false){
185 if($val != '_pagefilter' && $val != '_admin')
186 $call = false;
187 }
188 }
189 if(!empty($jbase) && $jall === false)
190 unset($plugins[$jbase]);
191 if(!empty($cbase) && $call === false)
192 unset($plugins[$cbase]);
193 }
194 $option["plugins"] = implode(",", array_keys($plugins));
195 $this->filter[$item] = $option;
196 }
197 update_option('plf_option', $this->filter );
198 }
199 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page'));
200 exit;
201 }
202 elseif( isset($_POST['clear_regist_filter']) ) {
203 check_admin_referer('plugin_load_filter');
204 foreach( array('_admin', '_desktop', '_mobile', '_pagefilter') as $item){
205 $this->filter[$item] = '';
206 }
207 update_option('plf_option', $this->filter );
208 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page'));
209 exit;
210 }
211 else if(isset($_POST['edit_activate_page_filter']) ) {
212 if(isset($_POST['plfactive'])){
213 check_admin_referer('plugin_load_filter');
214 $group = array_keys($_POST['plfactive']);
215 foreach( $group as $item){
216 $plugins = array();
217 foreach ( $_POST['plfactive'][$item] as $p_key => $val ) {
218 if($val == '1')
219 $plugins[] = $p_key;
220 }
221 $option["plugins"] = implode(",", $plugins);
222 $this->filter['group'][$item] = $option;
223 }
224 update_option('plf_option', $this->filter );
225 }
226 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page&action=tab_1'));
227 exit;
228 }
229 elseif( isset($_POST['clear_activate_page_filter']) ) {
230 check_admin_referer('plugin_load_filter');
231 $group = array_keys($_POST['plfactive']);
232 foreach( $group as $item){
233 $this->filter['group'][$item] = '';
234 }
235 update_option('plf_option', $this->filter );
236 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page&action=tab_1'));
237 exit;
238 }
239 if(!empty($_GET['action']) && $_GET['action']=='tab_1') {
240 $this->tab_num = 1;
241 }
242 }
243 }
244
245 //Plugin or Module key to name
246 // $type : list/smart/tree
247 public function pluginkey_to_name( $infkey, $type='list') {
248
249 $name = '';
250 if(strpos($infkey, 'jetpack_module/') !== false){
251 if(!empty($this->plugins_inf[$infkey]['name'])){
252 $m_mark = ($type !== 'list')? '-' : 'Jetpack-';
253 if($type === 'smart') {
254 if(empty($this->filter['_pagefilter']['plugins']) || strpos($this->filter['_pagefilter']['plugins'], 'jetpack/') === false)
255 $name = $m_mark . $this->plugins_inf[$infkey]['name'];
256 }
257 else
258 $name = $m_mark . $this->plugins_inf[$infkey]['name'];
259 }
260 }
261 elseif(strpos($infkey, 'celtispack_module/') !== false){
262 if(!empty($this->plugins_inf[$infkey]['Name'])){
263 $m_mark = ($type !== 'list')? '-' : 'Celtispack-';
264 if($type === 'smart') {
265 if(empty($this->filter['_pagefilter']['plugins']) || strpos($this->filter['_pagefilter']['plugins'], 'celtispack/') === false)
266 $name = $m_mark . $this->plugins_inf[$infkey]['Name'];
267 }
268 else
269 $name = $m_mark . $this->plugins_inf[$infkey]['Name'];
270 }
271 }
272 else {
273 if(!empty($this->plugins_inf[$infkey]['Name']))
274 $name = $this->plugins_inf[$infkey]['Name'];
275 }
276 return($name);
277 }
278
279 //Checkbox
280 static function checkbox($name, $value, $label = '') {
281 return "<label><input type='checkbox' name='$name' value='1' " . checked( $value, 1, false ). "/> $label</label>";
282 }
283 static function altcheckbox($name, $value, $label = '') {
284 return "<input type='hidden' name='$name' value='0'><input type='checkbox' name='$name' value='1' " . checked( $value, 1, false ). "/><label> $label</label>";
285 }
286
287 //Plugin pagefilter Selected Checkbox (plugin and modules list)
288 // $plugins : array : all active plugins
289 // $select_cvplugins : csv string : pagefilter selected plugins
290 // $checked_cvplugins : csv string : checked plugins
291 function pagefilter_plugins_checklist( $plugins, $select_cvplugins, $checked_cvplugins ) {
292
293 if(empty($select_cvplugins))
294 return __('Page Filter is not registered', 'plf');
295
296 $nplugins = $jmodules = $cmodules = array();
297 foreach ( $plugins as $p_key => $p_data ) {
298 $p_name = $this->pluginkey_to_name($p_key);
299 if(empty($p_name))
300 continue;
301 if(strpos($p_key, 'jetpack_module/') !== false)
302 $jmodules[] = $p_key;
303 else if(strpos($p_key, 'celtispack_module/') !== false)
304 $cmodules[] = $p_key;
305 else
306 $nplugins[] = $p_key;
307 }
308 $selplugins = array_map("trim", explode(',', $select_cvplugins));
309 $chkplugins = array_map("trim", explode(',', $checked_cvplugins));
310 $html = '<ul class="plugins-list">';
311 foreach ( $nplugins as $p_key ) {
312 if(strpos($p_key, 'jetpack/') !== false){
313 foreach ( $jmodules as $p_key ) {
314 if(in_array( $p_key, $selplugins )){
315 $p_name = $this->pluginkey_to_name($p_key);
316 $checked = in_array( $p_key, $chkplugins ) ? true : false;
317 $html .= '<li>' . self::checkbox("plf_option[plugins][$p_key]", $checked, esc_attr($p_name)) . '</li>';
318 }
319 }
320 }
321 else if(strpos($p_key, 'celtispack/') !== false){
322 foreach ( $cmodules as $p_key ) {
323 if(in_array( $p_key, $selplugins )){
324 $p_name = $this->pluginkey_to_name($p_key);
325 $checked = in_array( $p_key, $chkplugins ) ? true : false;
326 $html .= '<li>' . self::checkbox("plf_option[plugins][$p_key]", $checked, esc_attr($p_name)) . '</li>';
327 }
328 }
329 }
330 else if(in_array( $p_key, $selplugins )) {
331 $p_name = $this->pluginkey_to_name($p_key);
332 $checked = in_array( $p_key, $chkplugins ) ? true : false;
333 $html .= '<li>' . self::checkbox("plf_option[plugins][$p_key]", $checked, esc_attr($p_name)) . '</li>';
334 }
335 }
336 $html .= '</ul>';
337 return $html;
338 }
339
340 public function plfregist_item($key, $val) {
341 $p_name = $this->pluginkey_to_name($key);
342 $opt_name = "plfregist[$key]";
343 ?>
344 <tr id="plfregist_<?php echo $key; ?>">
345 <td><?php echo $p_name; ?></td>
346 <td class="radio-green"><input type="radio" name="<?php echo $opt_name; ?>" value='' <?php checked('', $val); ?>/><label><span class="dashicons dashicons-admin-plugins"></span></label></td>
347 <td class="radio-red"><input type="radio" name="<?php echo $opt_name; ?>" value="_admin" <?php checked('_admin', $val); ?>/><label><span class="dashicons dashicons-admin-plugins"></span></label></td>
348 <td class="radio-red"><input type="radio" name="<?php echo $opt_name; ?>" value="_desktop" <?php checked('_desktop', $val); ?>/><label><span class="dashicons dashicons-admin-plugins"></span></label></td>
349 <td class="radio-red"><input type="radio" name="<?php echo $opt_name; ?>" value="_mobile" <?php checked('_mobile', $val); ?>/><label><span class="dashicons dashicons-admin-plugins"></span></label></td>
350 <td class="radio-red"><input type="radio" name="<?php echo $opt_name; ?>" value="_pagefilter" <?php checked('_pagefilter', $val); ?>/><label><span class="dashicons dashicons-admin-plugins"></span></label></td>
351 </tr>
352 <?php
353 }
354
355 //Filterring plugins select
356 public function plfregist_table($plugins, $filter) {
357 ?>
358 <table id="registration-table" class="widefat">
359 <thead>
360 <tr><th ><?php _e('Plugins'); ?></th>
361 <th ><?php _e('Normal Load', 'plf'); ?></th>
362 <th ><?php _e('Admin', 'plf'); ?></th>
363 <th ><?php _e('Desktop', 'plf'); ?></th>
364 <th ><?php _e('Mobile', 'plf'); ?></th>
365 <th ><?php _e('Page Filter', 'plf'); ?></th>
366 </tr>
367 </thead>
368 <tbody>
369 <?php
370 //plugins filter registoration table
371 $plist = array();
372 foreach ( $plugins as $p_key => $val ) {
373 $name = $this->pluginkey_to_name($p_key);
374 if(!empty($name))
375 $plist[$p_key] = '';
376 }
377 foreach( array('_admin', '_desktop', '_mobile', '_pagefilter') as $item){
378 $parr = (!empty($filter[$item]['plugins'])) ? array_map("trim", explode(',', $filter[$item]['plugins'])) : array();
379 foreach ( $plist as $p_key => $val ) {
380 if(empty($val) && in_array($p_key, $parr))
381 $plist[$p_key] = $item;
382 }
383 }
384 $jlist = $clist = array();
385 foreach ( $plist as $p_key => $val ) {
386 if(strpos($p_key, 'jetpack_module/') !== false){
387 $jlist[$p_key] = $plist[$p_key];
388 unset($plist[$p_key]);
389 }
390 else if(strpos($p_key, 'celtispack_module/') !== false){
391 $clist[$p_key] = $plist[$p_key];
392 unset($plist[$p_key]);
393 }
394 }
395 foreach ( $plist as $p_key => $val ) {
396 $modules = array();
397 if(strpos($p_key, 'jetpack/') !== false)
398 $modules = $jlist;
399 else if(strpos($p_key, 'celtispack/') !== false)
400 $modules = $clist;
401 else
402 $this->plfregist_item($p_key, $val);
403 if(!empty($modules)){
404 echo "<input type='hidden' name='plfregist[$p_key]' value='_pagefilter'>";
405 foreach ( $modules as $m_key => $val) {
406 $this->plfregist_item($m_key, $val);
407 }
408 }
409 }
410 ?>
411 </tbody>
412 </table>
413 <?php
414 }
415
416 //Activate plugins select from Page Filter
417 public function plfactive_table($plugins, $select_cvplugins, $filter) {
418 if(empty($select_cvplugins))
419 return;
420
421 ?>
422 <table id="activation-table" class="widefat">
423 <thead>
424 <tr><th ><?php _e('Plugins'); ?></th>
425 <th ><span title="<?php _e('Home/Front-page', 'plf'); ?>" class="dashicons dashicons-admin-home"></span><br /><span style="font-size:xx-small">Home</span></th>
426 <th ><span title="<?php _e('Archive page', 'plf'); ?>" class="dashicons dashicons-list-view"></span><br /><span style="font-size:xx-small">Archive</span></th>
427 <th ><span title="<?php _e('Search page', 'plf'); ?>" class="dashicons dashicons-search"></span><br /><span style="font-size:xx-small">Search</span></th>
428 <th ><span title="<?php _e('Attachment page', 'plf'); ?>" class="dashicons dashicons-media-default"></span><br /><span style="font-size:xx-small">Attach</span></th>
429 <th ><span title="<?php _e('Page', 'plf'); ?>" class="dashicons dashicons-admin-page"></span><br /><span style="font-size:xx-small">Page</span></th>
430 <th ><span title="<?php _e('Post : Standard', 'plf'); ?>" class="dashicons dashicons-admin-post"></span><br /><span style="font-size:xx-small">Post</span></th>
431 <th ><span title="<?php _e('Post : Image', 'plf'); ?>" class="dashicons dashicons-format-image"></span><br /><span style="font-size:xx-small">Image</span></th>
432 <th ><span title="<?php _e('Post : Gallery', 'plf'); ?>" class="dashicons dashicons-format-gallery"></span><br /><span style="font-size:xx-small">Gallery</span></th>
433 <th ><span title="<?php _e('Post : Video', 'plf'); ?>" class="dashicons dashicons-format-video"></span><br /><span style="font-size:xx-small">Video</span></th>
434 <th ><span title="<?php _e('Post : Audio', 'plf'); ?>" class="dashicons dashicons-format-audio"></span><br /><span style="font-size:xx-small">Audio</span></th>
435 <th ><span title="<?php _e('Post : Aside', 'plf'); ?>" class="dashicons dashicons-format-aside"></span><br /><span style="font-size:xx-small">Aside</span></th>
436 <th ><span title="<?php _e('Post : Quote', 'plf'); ?>" class="dashicons dashicons-format-quote"></span><br /><span style="font-size:xx-small">Quote</span></th>
437 <th ><span title="<?php _e('Post : Link', 'plf'); ?>" class="dashicons dashicons-admin-links"></span><br /><span style="font-size:xx-small">Link</span></th>
438 <th ><span title="<?php _e('Post : Status', 'plf'); ?>" class="dashicons dashicons-format-status"></span><br /><span style="font-size:xx-small">Status</span></th>
439 <th ><span title="<?php _e('Post : Chat', 'plf'); ?>" class="dashicons dashicons-format-chat"></span><br /><span style="font-size:xx-small">Chat</span></th>
440 <?php
441 $post_types = get_post_types( array('public' => true, '_builtin' => false) );
442 foreach ( $post_types as $post_type ) {
443 if(!empty($post_type)){
444 $title = __('Custom Post : ', 'plf') . $post_type;
445 echo "<th ><span title='$title' style='font-size:xx-small'>$post_type</span></th>";
446 }
447 }
448 ?>
449 </tr>
450 </thead>
451 <tbody>
452 <?php
453 $nplugins = $jmodules = $cmodules = $allmodule = array();
454 foreach ( $plugins as $p_key => $p_data ) {
455 $p_name = $this->pluginkey_to_name($p_key);
456 if(empty($p_name))
457 continue;
458 if(strpos($p_key, 'jetpack_module/') !== false)
459 $jmodules[] = $p_key;
460 else if(strpos($p_key, 'celtispack_module/') !== false)
461 $cmodules[] = $p_key;
462 else
463 $nplugins[] = $p_key;
464 }
465 $selplugins = array_map("trim", explode(',', $select_cvplugins));
466 $chklist = array('home', 'archive', 'search', 'attachment', 'page', 'post',
467 'post-image', 'post-gallery', 'post-video', 'post-audio', 'post-aside', 'post-quote', 'post-link', 'post-status', 'post-chat');
468 $post_types = get_post_types( array('public' => true, '_builtin' => false) );
469 foreach ( $post_types as $post_type ) {
470 $chklist[] = $post_type;
471 }
472 foreach ( $nplugins as $p_key ) {
473 if(strpos($p_key, 'jetpack/') !== false){
474 foreach ( $jmodules as $p_key ) {
475 if(in_array( $p_key, $selplugins )){
476 $p_name = $this->pluginkey_to_name($p_key);
477 echo "<tr><td>$p_name</td>";
478 foreach($chklist as $pgtype){
479 $checked = (empty($filter['group'][$pgtype]['plugins']) || false === strpos($filter['group'][$pgtype]['plugins'], $p_key))? false : true;
480 echo '<td class="altcheckbox">' . self::altcheckbox("plfactive[$pgtype][$p_key]", $checked, '<span class="dashicons dashicons-admin-plugins"></span>') . '</td>';
481 }
482 echo "</tr>";
483 }
484 }
485 }
486 else if(strpos($p_key, 'celtispack/') !== false){
487 foreach ( $cmodules as $p_key ) {
488 if(in_array( $p_key, $selplugins )){
489 $p_name = $this->pluginkey_to_name($p_key);
490 echo "<tr><td>$p_name</td>";
491 foreach($chklist as $pgtype){
492 $checked = (empty($filter['group'][$pgtype]['plugins']) || false === strpos($filter['group'][$pgtype]['plugins'], $p_key))? false : true;
493 echo '<td class="altcheckbox">' . self::altcheckbox("plfactive[$pgtype][$p_key]", $checked, '<span class="dashicons dashicons-admin-plugins"></span>') . '</td>';
494 }
495 echo "</tr>";
496 }
497 }
498 }
499 else if(in_array( $p_key, $selplugins )) {
500 $p_name = $this->pluginkey_to_name($p_key);
501 echo "<tr><td>$p_name</td>";
502 foreach($chklist as $pgtype){
503 $checked = (empty($filter['group'][$pgtype]['plugins']) || false === strpos($filter['group'][$pgtype]['plugins'], $p_key))? false : true;
504 echo '<td class="altcheckbox">' . self::altcheckbox("plfactive[$pgtype][$p_key]", $checked, '<span class="dashicons dashicons-admin-plugins"></span>') . '</td>';
505 }
506 echo "</tr>";
507 }
508 }
509 ?>
510 </tbody>
511 </table>
512 <?php
513 }
514
515 //Option Setting Form Display
516 public function plf_option_page() {
517 ?>
518 <h2><?php _e('Plugin Load Filter Settings', 'plf'); ?></h2>
519 <p></p>
520 <div id="plf-setting-tabs">
521 <ul>
522 <li><a href="#plf-registration-tab" ><?php _e('Filter Registration', 'plf'); ?></a></li>
523 <li><a href="#plf-activation-tab" ><?php _e('Page Filter Activation', 'plf'); ?></a></li>
524 </ul>
525 <form method="post" >
526 <?php wp_nonce_field( 'plugin_load_filter'); ?>
527 <div id="plf-registration-tab" >
528 <?php $this->plfregist_table($this->plugins_inf, $this->filter); ?>
529 <br />
530 <p><?php _e('If you want to filter the loading of plugins, click select <span class="dashicons dashicons-admin-plugins"></span> mark of the filter type.', 'plf') ?></p>
531 <p><strong>[ Admin Filter ]</strong><br />
532 <?php _e('Plugins to be used only in admin mode.', 'plf'); ?><br />
533 </p>
534 <p><strong>[ Desktop/Mobile Filter ]</strong><br />
535 <?php _e('Plugins to be used only in desktop/moble device. (wp_is_mobile function use)', 'plf'); ?><br />
536 </p>
537 <p><strong>[ Page Filter ]</strong><br />
538 <?php _e('Plugins for selecting whether to activate each Page type or Post.', 'plf'); ?><br />
539 <?php _e('Selected page filter plugins are once blocked, but is activated by "Page filter Activation" setting.', 'plf'); ?><br />
540 </p>
541 <p class="submit">
542 <input type="submit" class="button-primary" name="clear_regist_filter" value="<?php _e('Clear', 'plf'); ?>" />&nbsp;&nbsp;&nbsp;
543 <input type="submit" class="button-primary" name="edit_regist_filter" value="<?php _e('Filter Entry &raquo;', 'plf'); ?>" />
544 </p>
545 </div>
546 <div id="plf-activation-tab" >
547 <?php
548 $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
549 if(!empty($pgfilter)){
550 $this->plfactive_table($this->plugins_inf, $pgfilter, $this->filter);
551 ?>
552 <br />
553 <p><?php _e('Select plugins to be activated for each page type by clicking on <span class="dashicons dashicons-admin-plugins"></span> mark from "page filter" registered plugins.', 'plf') ?><br />
554 <?php _e('You can also select plugins to activate from Post/Page content editing screen.', 'plf') ?>
555 </p>
556 <p class="submit">
557 <input type="submit" class="button-primary" name="clear_activate_page_filter" value="<?php _e('Clear', 'plf'); ?>" />&nbsp;&nbsp;&nbsp;
558 <input type="submit" class="button-primary" name="edit_activate_page_filter" value="<?php _e('Activate Plugin Entry &raquo;', 'plf'); ?>" />
559 </p>
560 <?php
561 }
562 else {
563 ?>
564 <br />
565 <p><span style="color: #ff0000;"><?php _e('Page Filter is not registered', 'plf') ?></span></p>
566 <?php
567 }
568 ?>
569 </div>
570 </form>
571 </div>
572 <?php
573 }
574
575 /***************************************************************************
576 * Meta box
577 * Individual of the plug-in filter meta box for Post/Page/CustomPost
578 **************************************************************************/
579 function load_meta_boxes( $post_type, $post ) {
580 if ( current_user_can('edit_plugins', $post->ID) ) {
581 add_meta_box( 'pluginfilterdiv', __( 'Page Filter Plugin', 'plf' ), array(&$this, 'plf_meta_box'), null, 'side' );
582 add_action( 'admin_head', array(&$this, 'plf_css' ));
583 add_action( 'admin_footer', array(&$this, 'plf_meta_script' ));
584 }
585 }
586
587 function plf_meta_box( $post, $box ) {
588 if(is_object($post)){
589 $default = array( 'filter' => 'default', 'plugins' => '');
590 $myfilter = get_post_meta( $post->ID, '_plugin_load_filter', true );
591 $option = (!empty($myfilter))? $myfilter : $default;
592 $option = wp_parse_args( $option, $default);
593 $ajax_nonce = wp_create_nonce( 'plugin_load_filter-' . $post->ID );
594 $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
595 ?>
596 <div id="plugin-filter-select">
597 <label><input type="radio" name="pagefilter" value="default" <?php checked('default', $option['filter']); ?>/><?php _e('Not Use', 'plf' ); ?></label>
598 <label><input type="radio" name="pagefilter" value="include" <?php checked('include', $option['filter']); ?>/><?php _e('Activate Plugins', 'plf'); ?></label>
599 <br />
600 <div id="page-filter-stat">
601 <?php echo $this->pagefilter_plugins_checklist( $this->plugins_inf, $pgfilter, $option['plugins'] ); ?>
602 </div>
603 <?php echo '<p class="hide-if-no-js"><a id="plugin-filter-submit" class="button" href="#pluginfilterdiv" onclick="WPAddPagePluginLoadFilter(\'' . $ajax_nonce . '\');return false;" >'. __('Save') .'</a></p>'; ?>
604 </div>
605 <?php
606 }
607 }
608
609 //wp_ajax_plugin_load_filter called function
610 function plf_ajax_postidfilter() {
611 if ( isset($_POST['post_id']) ) {
612 $pid = (int) $_POST['post_id'];
613 if ( !current_user_can( 'edit_plugins', $pid ) )
614 wp_die( -1 );
615 check_ajax_referer( "plugin_load_filter-$pid" );
616
617 $option["filter"] = (empty($_POST['filter']))? 'default' : $_POST['filter'];
618 $option["plugins"] = '';
619 if('default' == $option["filter"])
620 delete_post_meta( $pid, '_plugin_load_filter');
621 else {
622 $plugins = array();
623 if( preg_match_all('/plf_option\[plugins\]\[(.+?)\]/u', $_POST['plugins'], $matches)){
624 if(!empty($matches[1])){
625 foreach ($matches[1] as $plugin){
626 $plugins[] = $plugin;
627 }
628 $option["plugins"] = implode(",", $plugins);
629 }
630 }
631 update_post_meta( $pid, '_plugin_load_filter', $option );
632 }
633
634 $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
635 $html = $this->pagefilter_plugins_checklist( $this->plugins_inf, $pgfilter, $option['plugins'] );
636 wp_send_json_success($html);
637 }
638 wp_die( 0 );
639 }
640
641 /***************************************************************************
642 * Javascript
643 **************************************************************************/
644 function activetab_script() { ?>
645 <script type='text/javascript' >
646 /* <![CDATA[ */
647 var plf_activetab = <?php echo $this->tab_num; ?>
648 /* ]]> */
649 jQuery(document).ready(function ($) { plf_setting_tabs(); function plf_setting_tabs(){ $('#plf-setting-tabs').tabs({ active:plf_activetab, }); }});
650 </script>
651 <?php }
652
653 function plf_meta_script() { ?>
654 <script type='text/javascript' >
655 WPAddPagePluginLoadFilter = function(nonce){
656 jQuery.ajax({ type: 'POST', url: ajaxurl,
657 data: {action: "plugin_load_filter", post_id : jQuery( '#post_ID' ).val(), _ajax_nonce: nonce, filter: jQuery("input[name='pagefilter']:checked").val(), plugins: jQuery('.plugins-list li input:checked').map(function(){ return jQuery(this).attr("name"); }).get().join(','), }, dataType: 'json',
658 success: function(response, dataType) { jQuery('#page-filter-stat').html(response.data); }
659 });
660 return false; };
661 </script>
662 <?php }
663 }