PluginProbe
Plugin Load Filter / 2.2.1
Plugin Load Filter v2.2.1
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.1, at plugin-load-filter.php

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