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

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