PluginProbe
Plugin Load Filter / 2.3.1
Plugin Load Filter v2.3.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
← All changes | plugin-load-filter.php +280 -174 2.1.02.3.1 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.1.0
5 + Version: 2.3.1
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
@@ -23,11 +23,17 @@
23 23 * Style Sheet
24 24 **************************************************************************/
25 25 function plf_css() { ?>
26 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;}
27 + #activation-table { margin-top: 10px; border: 1px solid #eee;}
28 + #activation-table input[type=checkbox] { height: 25px; width: 25px; opacity: 0;}
29 + thead .plugins-name { background-color: aliceblue;}
30 + thead .device-type { background-color: oldlace;}
31 + thead .plugins-name, tbody .plugins-name { min-width: 172px; max-width: 172px;}
32 + thead .device-type, tbody .device-type { min-width: 36px; max-width: 36px; padding: 0;}
33 + .dashicons-yes:before { font-size: 20px; border: 1px solid #eee; background-color: whitesmoke;}
34 + .device-type label { color: whitesmoke; margin-left: -28px; }
35 + .device-type input[type="checkbox"]:checked + label .dashicons-yes:before { background-color: yellowgreen; }
30 36 </style>
31 37 <?php }
32 38
33 39 function jquery_tab_css() { ?>
@@ -49,17 +55,39 @@
49 55 .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 56 .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 57 .ui-state-active a, .ui-state-active a:link, .ui-state-active a:visited { color: #ffffff; text-decoration: none; }
52 58
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; }
59 + #wrap_registration-table, #wrap_activation-table { overflow-x:auto;}
60 + #registration-table input[type=radio], #activation-table input[type=checkbox] { height: 25px; width: 25px; opacity: 0;}
61 + thead, tbody { display: block;}
62 + .plugins-table-body { overflow-y:scroll; height:500px; }
63 + .widefat td, .widefat th { padding: 8px 4px;}
64 + thead .filter-plugins-name, thead .plugins-name { background-color: aliceblue;}
65 + .filter-none, .filter-admin, .filter-tmpl { background-color: oldlace;}
66 + thead .device-type { background-color: oldlace;}
67 + thead .tmpl-type { background-color: lavender;}
68 + thead .pformat { background-color: honeydew;}
69 + thead .tmpl-embed { background-color: lightyellow;}
70 + thead .tmpl-custom { background-color: lavenderblush;}
71 + thead .filter-plugins-name, tbody .filter-plugins-name { min-width: 260px; max-width: 260px;}
72 + thead .plugins-name, tbody .plugins-name { min-width: 180px; max-width: 180px;}
73 + thead .filter-type, tbody .filter-type { min-width: 100px; max-width: 100px;}
74 + thead .device-type, tbody .device-type, thead .tmpl-type, tbody .tmpl-type { min-width: 40px; max-width: 40px; }
75 + .filter-description { padding: 0 10px 20px 10px;}
76 + .exclude-pformat { padding: 16px 0 20px}
77 + .exclude-pformat label { white-space:nowrap;}
78 + .exclude-pformat span { margin-right: 12px; }
79 + .dashicons:before { font-size: 24px; }
80 + .radio-green label, .radio-red label, .tmpl-type label { color: #ddd; margin-left: -28px; }
56 81 .radio-green input[type="radio"]:checked + label { color: #339966; }
57 82 .radio-red input[type="radio"]:checked + label { color: #ff0000; }
58 - .altcheckbox input[type="checkbox"]:checked + label { color: #339966; }
83 + .tmpl-type input[type="checkbox"]:checked + label { color: #339966; }
84 + .dashicons-yes:before { font-size: 20px; border: 1px solid #eee; background-color: whitesmoke;}
85 + .device-type label { color: whitesmoke; margin-left: -28px; }
86 + .device-type input[type="checkbox"]:checked + label .dashicons-yes:before { background-color: yellowgreen; }
59 87 </style>
60 88 <?php }
61 -
89 +
62 90 /***************************************************************************
63 91 * Plugin Load Filter Option Setting
64 92 **************************************************************************/
65 93
@@ -67,14 +95,29 @@
67 95
68 96 load_plugin_textdomain('plf', false, basename( dirname( __FILE__ ) ).'/languages' );
69 97
70 98 $this->filter = get_option('plf_option');
99 + //v2.3.0 option change
100 + if(empty($this->filter['optver']) || $this->filter['optver'] < '2'){
101 + $this->filter['optver'] = '2';
102 +
103 + if(empty($this->filter['group']['desktop']) && empty($this->filter['group']['mobile'])){
104 + //For ver2.2.0 compatibility, set '_pagefilter' data to 'desktop' and 'mobile'
105 + if(!empty($this->filter['_pagefilter'])){
106 + $this->filter['group']['desktop'] = $this->filter['_pagefilter'];
107 + $this->filter['group']['mobile'] = $this->filter['_pagefilter'];
108 + }
109 + if(!empty($this->filter['_desktop'])){
110 + $this->filter['_desktop'] = null;
111 + }
112 + if(!empty($this->filter['_mobile'])){
113 + $this->filter['_mobile'] = null;
114 + }
115 + }
116 + }
117 +
71 118 if(is_admin()) {
72 119 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 120 add_action( 'add_meta_boxes', array(&$this, 'load_meta_boxes'), 10, 2 );
78 121 //plf-filter must-use plagin activete check
79 122 if(wp_mkdir_p( WPMU_PLUGIN_DIR )){
80 123 if ( !file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) {
@@ -79,14 +122,20 @@
79 122 if(wp_mkdir_p( WPMU_PLUGIN_DIR )){
80 123 if ( !file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) {
81 124 @copy(__DIR__ . '/mu-plugins/plf-filter.php', WPMU_PLUGIN_DIR . '/plf-filter.php');
82 125 }
126 + else {
127 + require_once(ABSPATH . 'wp-admin/includes/plugin.php');
128 + $dp = get_plugin_data( WPMU_PLUGIN_DIR . "/plf-filter.php", false, false );
129 + $sp = get_plugin_data( __DIR__ . '/mu-plugins/plf-filter.php', false, false );
130 + if(version_compare( $dp['Version'], $sp['Version'], '!=')){
131 + @copy(__DIR__ . '/mu-plugins/plf-filter.php', WPMU_PLUGIN_DIR . '/plf-filter.php');
132 + }
133 + }
83 134 }
84 135 register_deactivation_hook( __FILE__, 'Plf_setting::deactivation' );
85 136 register_uninstall_hook(__FILE__, 'Plf_setting::uninstall');
86 137 }
87 - add_action( 'save_post', array(&$this, 'plf_transient_clear') );
88 - add_action( 'deleted_post', array(&$this, 'plf_transient_clear') );
89 138 add_action( 'wp_ajax_plugin_load_filter', array(&$this, 'plf_ajax_postidfilter'));
90 139 }
91 140
92 141 //Plugin Deactivate
@@ -100,14 +149,8 @@
100 149 delete_option('plf_queryvars');
101 150 delete_option('plf_option' );
102 151 }
103 152
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 153 //Plugin Load Filter admin setting start
111 154 public function plf_admin_start() {
112 155 require_once(ABSPATH . 'wp-admin/includes/plugin.php');
113 156
@@ -168,9 +211,9 @@
168 211 if (current_user_can( 'edit_plugins' )) {
169 212 if( isset($_POST['edit_regist_filter']) ) {
170 213 if(isset($_POST['plfregist'])){
171 214 check_admin_referer('plugin_load_filter');
172 - foreach( array('_admin', '_desktop', '_mobile', '_pagefilter') as $item){
215 + foreach( array('_admin', '_pagefilter') as $item){
173 216 $plugins = array();
174 217 foreach ( $_POST['plfregist'] as $p_key => $val ) {
175 218 if($val == $item)
176 219 $plugins[$p_key] = $val;
@@ -201,9 +244,19 @@
201 244 }
202 245 $option["plugins"] = implode(",", array_keys($plugins));
203 246 $this->filter[$item] = $option;
204 247 }
205 - $this->filter['updated'] = strtotime("now");
248 + if(isset($_POST['plf_option']['exclude'])){
249 + $exclude = array();
250 + foreach ( $_POST['plf_option']['exclude'] as $ft => $v ) {
251 + if(!empty($v))
252 + $exclude[$ft] = true;
253 + }
254 + $this->filter['exclude'] = $exclude;
255 + }
256 + else {
257 + $this->filter['exclude'] = '';
258 + }
206 259 update_option('plf_option', $this->filter );
207 260 }
208 261 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page'));
209 262 exit;
@@ -209,12 +262,12 @@
209 262 exit;
210 263 }
211 264 elseif( isset($_POST['clear_regist_filter']) ) {
212 265 check_admin_referer('plugin_load_filter');
213 - foreach( array('_admin', '_desktop', '_mobile', '_pagefilter') as $item){
266 + foreach( array('_admin', '_pagefilter') as $item){
214 267 $this->filter[$item] = '';
215 268 }
216 - $this->filter['updated'] = strtotime("now");
269 + $this->filter['exclude'] = '';
217 270 update_option('plf_option', $this->filter );
218 271 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page'));
219 272 exit;
220 273 }
@@ -230,9 +283,8 @@
230 283 }
231 284 $option["plugins"] = implode(",", $plugins);
232 285 $this->filter['group'][$item] = $option;
233 286 }
234 - $this->filter['updated'] = strtotime("now");
235 287 update_option('plf_option', $this->filter );
236 288 }
237 289 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page&action=tab_1'));
238 290 exit;
@@ -242,9 +294,8 @@
242 294 $group = array_keys($_POST['plfactive']);
243 295 foreach( $group as $item){
244 296 $this->filter['group'][$item] = '';
245 297 }
246 - $this->filter['updated'] = strtotime("now");
247 298 update_option('plf_option', $this->filter );
248 299 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page&action=tab_1'));
249 300 exit;
250 301 }
@@ -295,72 +346,17 @@
295 346 static function altcheckbox($name, $value, $label = '') {
296 347 return "<input type='hidden' name='$name' value='0'><input type='checkbox' name='$name' value='1' " . checked( $value, 1, false ). "/><label> $label</label>";
297 348 }
298 349
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 350 public function plfregist_item($key, $val) {
353 351 $p_name = $this->pluginkey_to_name($key);
354 352 $opt_name = "plfregist[$key]";
355 353 ?>
356 354 <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>
355 + <td class="filter-plugins-name"><?php echo $p_name; ?></td>
356 + <td class="radio-green filter-type"><input type="radio" name="<?php echo $opt_name; ?>" value='' <?php checked('', $val); ?>/><label><span class="dashicons dashicons-admin-plugins"></span></label></td>
357 + <td class="radio-red filter-type"><input type="radio" name="<?php echo $opt_name; ?>" value="_admin" <?php checked('_admin', $val); ?>/><label><span class="dashicons dashicons-admin-plugins"></span></label></td>
358 + <td class="radio-red filter-type"><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 359 </tr>
364 360 <?php
365 361 }
366 362
@@ -366,19 +362,18 @@
366 362
367 363 //Filterring plugins select
368 364 public function plfregist_table($plugins, $filter) {
369 365 ?>
366 + <div id="wrap_registration-table">
370 367 <table id="registration-table" class="widefat">
371 368 <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>
369 + <tr><th class="filter-plugins-name"><?php _e('Plugins'); ?></th>
370 + <th class="filter-type filter-none"><?php _e('Normal Load', 'plf'); ?></th>
371 + <th class="filter-type filter-admin"><?php _e('Admin Filter', 'plf'); ?></th>
372 + <th class="filter-type filter-tmpl"><?php _e('Page Filter', 'plf'); ?></th>
378 373 </tr>
379 374 </thead>
380 - <tbody>
375 + <tbody class="plugins-table-body">
381 376 <?php
382 377 //plugins filter registoration table
383 378 $plist = array();
384 379 foreach ( $plugins as $p_key => $val ) {
@@ -385,9 +380,9 @@
385 380 $name = $this->pluginkey_to_name($p_key);
386 381 if(!empty($name))
387 382 $plist[$p_key] = '';
388 383 }
389 - foreach( array('_admin', '_desktop', '_mobile', '_pagefilter') as $item){
384 + foreach( array('_admin', '_pagefilter') as $item){
390 385 $parr = (!empty($filter[$item]['plugins'])) ? array_map("trim", explode(',', $filter[$item]['plugins'])) : array();
391 386 foreach ( $plist as $p_key => $val ) {
392 387 if(empty($val) && in_array($p_key, $parr))
393 388 $plist[$p_key] = $item;
@@ -421,47 +416,105 @@
421 416 }
422 417 ?>
423 418 </tbody>
424 419 </table>
420 + <br />
421 + <p><strong>[ Admin Filter ]</strong></p>
422 + <div class="filter-description"><?php _e('Plugins to be used only in admin mode.', 'plf'); ?></div>
423 + <p><strong>[ Page Filter ]</strong></p>
424 + <div class="filter-description">
425 + <?php _e('Plugins for selecting whether to activate each Page type or Post.', 'plf'); ?><br />
426 + <?php _e('Selected page filter plugins are once blocked, but is activated by "Page filter Activation" setting.', 'plf'); ?>
427 + <div class="exclude-pformat">
428 + <p><strong><?php _e( 'Exclude Post Format Type', 'plf' ); ?></strong><br />
429 + <?php _e('Choose Post Format Type you are not using. To exclude from Page Filter item subject.', 'plf'); ?>
430 + </p>
431 + <?php
432 + $html = '<div>';
433 + $pformat = array('image', 'gallery', 'video', 'audio', 'aside', 'status', 'quote', 'link', 'chat' );
434 + foreach ( $pformat as $type ) {
435 + $checked = (!empty($this->filter['exclude'][$type]))? $this->filter['exclude'][$type] : false;
436 + $label = "<span>$type</span>";
437 + $html .= self::checkbox("plf_option[exclude][$type]", $checked, $label);
438 + }
439 + $html .= '</div>';
440 + echo $html;
441 + ?>
442 + </div>
443 + </div>
444 + </div>
425 445 <?php
426 446 }
427 447
428 448 //Activate plugins select from Page Filter
449 + public function _plfactive_checkbox_row($p_key, $select_cvplugins, $chklist, $filter) {
450 +
451 + $selplugins = array_map("trim", explode(',', $select_cvplugins));
452 + $devlist = array('desktop','mobile');
453 + if(in_array( $p_key, $selplugins )){
454 + $p_name = $this->pluginkey_to_name($p_key);
455 + echo "<tr><td class='plugins-name'>$p_name</td>";
456 + foreach($devlist as $devtype){
457 + $checked = (empty($filter['group'][$devtype]['plugins']) || false === strpos($filter['group'][$devtype]['plugins'], $p_key))? false : true;
458 + echo '<td class="device-type">' . self::altcheckbox("plfactive[$devtype][$p_key]", $checked, '<span class="dashicons dashicons-yes"></span>') . '</td>';
459 + }
460 + foreach($chklist as $pgtype){
461 + $checked = (empty($filter['group'][$pgtype]['plugins']) || false === strpos($filter['group'][$pgtype]['plugins'], $p_key))? false : true;
462 + echo '<td class="tmpl-type">' . self::altcheckbox("plfactive[$pgtype][$p_key]", $checked, '<span class="dashicons dashicons-admin-plugins"></span>') . '</td>';
463 + }
464 + echo "</tr>";
465 + }
466 + }
467 +
429 468 public function plfactive_table($plugins, $select_cvplugins, $filter) {
430 469 if(empty($select_cvplugins))
431 470 return;
432 471
433 472 ?>
473 + <div id="wrap_activation-table">
434 474 <table id="activation-table" class="widefat">
435 475 <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>
476 + <tr><th class="plugins-name"><?php _e('Plugins'); ?></th>
477 + <th class="device-type"><span title="<?php _e('Desktop Device', 'plf'); ?>" class="dashicons dashicons-desktop"></span><br /><span style="font-size:xx-small">Desktop</span></th>
478 + <th class="device-type"><span title="<?php _e('Mobile Device', 'plf'); ?>" class="dashicons dashicons-smartphone"></span><br /><span style="font-size:xx-small">Mobile</span></th>
479 + <th class="tmpl-type"><span title="<?php _e('Home/Front-page', 'plf'); ?>" class="dashicons dashicons-admin-home"></span><br /><span style="font-size:xx-small">Home</span></th>
480 + <th class="tmpl-type"><span title="<?php _e('Archive page', 'plf'); ?>" class="dashicons dashicons-list-view"></span><br /><span style="font-size:xx-small">Archive</span></th>
481 + <th class="tmpl-type"><span title="<?php _e('Search page', 'plf'); ?>" class="dashicons dashicons-search"></span><br /><span style="font-size:xx-small">Search</span></th>
482 + <th class="tmpl-type"><span title="<?php _e('Attachment page', 'plf'); ?>" class="dashicons dashicons-media-default"></span><br /><span style="font-size:xx-small">Attach</span></th>
483 + <th class="tmpl-type"><span title="<?php _e('Page', 'plf'); ?>" class="dashicons dashicons-admin-page"></span><br /><span style="font-size:xx-small">Page</span></th>
484 + <th class="tmpl-type pformat"><span title="<?php _e('Post : ', 'plf'); _e('Standard', 'plf'); ?>" class="dashicons dashicons-admin-post"></span><br /><span style="font-size:xx-small">Post</span></th>
452 485 <?php
486 + $pformat = array('image', 'gallery', 'video', 'audio', 'aside', 'status', 'quote', 'link', 'chat' );
487 + $exclude = array();
488 + if(!empty($filter['exclude'])){
489 + foreach ( $filter['exclude'] as $type => $v) {
490 + if(!empty($v)){
491 + $exclude[] = $type;
492 + }
493 + }
494 + }
495 + foreach ( $pformat as $type) {
496 + if(!in_array($type, $exclude)){
497 + $title = __('Post : ', 'plf') . $type;
498 + $icon = ($type === "link")? "dashicons-admin-links" : "dashicons-format-$type";
499 + echo '<th class="tmpl-type pformat"><span title="' . $title . '" class="dashicons ' . $icon .'"></span><br /><span style="font-size:xx-small">' . $type .'</span></th>';
500 + }
501 + }
502 + if(function_exists('is_embed')){
503 + $title = __('WordPress Embed Content Card (API)', 'plf');
504 + echo "<th class='tmpl-type tmpl-embed'><span title='$title' style='font-size:xx-small'>Embed Content</span></th>";
505 + }
453 506 $post_types = get_post_types( array('public' => true, '_builtin' => false) );
454 507 foreach ( $post_types as $post_type ) {
455 508 if(!empty($post_type)){
456 509 $title = __('Custom Post : ', 'plf') . $post_type;
457 - echo "<th ><span title='$title' style='font-size:xx-small'>$post_type</span></th>";
510 + echo "<th class='tmpl-type tmpl-custom'><span title='$title' style='font-size:xx-small'>$post_type</span></th>";
458 511 }
459 512 }
460 513 ?>
461 514 </tr>
462 515 </thead>
463 - <tbody>
516 + <tbody class="plugins-table-body">
464 517 <?php
465 518 $nplugins = $jmodules = $cmodules = $allmodule = array();
466 519 foreach ( $plugins as $p_key => $p_data ) {
467 520 $p_name = $this->pluginkey_to_name($p_key);
@@ -473,11 +526,17 @@
473 526 $cmodules[] = $p_key;
474 527 else
475 528 $nplugins[] = $p_key;
476 529 }
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');
530 + $chklist = array('home', 'archive', 'search', 'attachment', 'page', 'post');
531 + foreach ( $pformat as $type) {
532 + if(!in_array($type, $exclude)){
533 + $chklist[] = "post-$type";
534 + }
535 + }
536 + if(function_exists('is_embed')){
537 + $chklist[] = 'content-card';
538 + }
480 539 $post_types = get_post_types( array('public' => true, '_builtin' => false) );
481 540 foreach ( $post_types as $post_type ) {
482 541 $chklist[] = $post_type;
483 542 }
@@ -483,45 +542,24 @@
483 542 }
484 543 foreach ( $nplugins as $p_key ) {
485 544 if(strpos($p_key, 'jetpack/') !== false){
486 545 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 - }
546 + $this->_plfactive_checkbox_row($p_key, $select_cvplugins, $chklist, $filter);
496 547 }
497 548 }
498 549 else if(strpos($p_key, 'celtispack/') !== false){
499 550 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 - }
551 + $this->_plfactive_checkbox_row($p_key, $select_cvplugins, $chklist, $filter);
509 552 }
510 553 }
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>";
554 + else {
555 + $this->_plfactive_checkbox_row($p_key, $select_cvplugins, $chklist, $filter);
519 556 }
520 557 }
521 558 ?>
522 559 </tbody>
523 560 </table>
561 + </div>
524 562 <?php
525 563 }
526 564
527 565 //Option Setting Form Display
@@ -535,28 +573,16 @@
535 573 <li><a href="#plf-activation-tab" ><?php _e('Page Filter Activation', 'plf'); ?></a></li>
536 574 </ul>
537 575 <form method="post" >
538 576 <?php wp_nonce_field( 'plugin_load_filter'); ?>
539 - <div id="plf-registration-tab" >
577 + <div id="plf-registration-tab" style="display : none;">
540 578 <?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 579 <p class="submit">
554 580 <input type="submit" class="button-primary" name="clear_regist_filter" value="<?php _e('Clear', 'plf'); ?>" />&nbsp;&nbsp;&nbsp;
555 581 <input type="submit" class="button-primary" name="edit_regist_filter" value="<?php _e('Filter Entry &raquo;', 'plf'); ?>" />
556 582 </p>
557 583 </div>
558 - <div id="plf-activation-tab" >
584 + <div id="plf-activation-tab" style="display : none;">
559 585 <?php
560 586 $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
561 587 if(!empty($pgfilter)){
562 588 $this->plfactive_table($this->plugins_inf, $pgfilter, $this->filter);
@@ -589,29 +615,107 @@
589 615 * Individual of the plug-in filter meta box for Post/Page/CustomPost
590 616 **************************************************************************/
591 617 function load_meta_boxes( $post_type, $post ) {
592 618 if ( current_user_can('edit_plugins', $post->ID) ) {
593 - add_meta_box( 'pluginfilterdiv', __( 'Page Filter Plugin', 'plf' ), array(&$this, 'plf_meta_box'), null, 'side' );
619 + add_meta_box( 'pluginfilterdiv', __( 'Page Filter Plugin', 'plf' ), array(&$this, 'plf_meta_box'), null, 'side' );
594 620 add_action( 'admin_head', array(&$this, 'plf_css' ));
595 621 add_action( 'admin_footer', array(&$this, 'plf_meta_script' ));
596 622 }
597 623 }
598 624
625 + //Plugin pagefilter Selected Checkbox (plugin and modules list)
626 + // $p_key
627 + // $select_cvplugins : csv string : pagefilter selected plugins
628 + // $checked_arcvplugins : array csv string : ['desktop']=desktop enable plugins, ['mobile']=mobile enable plugins
629 + function _pagefilter_plugins_checklist( $p_key, $select_cvplugins, $checked_arcvplugins ) {
630 +
631 + $html = '';
632 + $selplugins = array_map("trim", explode(',', $select_cvplugins));
633 + $device['desktop'] = $checked_arcvplugins['desktop'];
634 + $device['mobile'] = $checked_arcvplugins['mobile'];
635 + $devlist = array('desktop','mobile');
636 + if(in_array( $p_key, $selplugins )){
637 + $p_name = $this->pluginkey_to_name($p_key);
638 + $html .= "<tr><td class='plugins-name'>$p_name</td>";
639 + foreach($devlist as $devtype){
640 + $checked = (empty($device[$devtype]) || false === strpos($device[$devtype], $p_key))? false : true;
641 + $html .= "<td class='device-type $devtype'>" . self::altcheckbox("plf_option[$devtype][$p_key]", $checked, '<span class="dashicons dashicons-yes"></span>') . '</td>';
642 + }
643 + $html .= "</tr>";
644 + }
645 + return $html;
646 + }
647 +
648 + //Plugin pagefilter Selected Checkbox (plugin and modules list)
649 + // $plugins : array : all active plugins
650 + // $select_cvplugins : csv string : pagefilter selected plugins
651 + // $checked_arcvplugins : array csv string : ['desktop']=desktop enable plugins, ['mobile']=mobile enable plugins
652 + function pagefilter_plugins_checklist( $plugins, $select_cvplugins, $checked_arcvplugins ) {
653 +
654 + if(empty($select_cvplugins))
655 + return __('Page Filter is not registered', 'plf');
656 +
657 + $html = '<table id="activation-table">';
658 + $html .= '<thead>';
659 + $html .= '<tr><th class="plugins-name">'. __('Plugins') . '</th>';
660 + $html .= '<th class="device-type"><span title="'. __('Desktop Device', 'plf'). '" class="dashicons dashicons-desktop"></span><br /><span style="font-size:xx-small">Desktop</span></th>';
661 + $html .= '<th class="device-type"><span title="'. __('Mobile Device', 'plf'). '" class="dashicons dashicons-smartphone"></span><br /><span style="font-size:xx-small">Mobile</span></th>';
662 + $html .= '</tr>';
663 + $html .= '</thead>';
664 + $html .= '<tbody class="plugins-table-body meta-boxes-plugins-table">';
665 + $nplugins = $jmodules = $cmodules = array();
666 + foreach ( $plugins as $p_key => $p_data ) {
667 + $p_name = $this->pluginkey_to_name($p_key);
668 + if(empty($p_name))
669 + continue;
670 + if(strpos($p_key, 'jetpack_module/') !== false)
671 + $jmodules[] = $p_key;
672 + else if(strpos($p_key, 'celtispack_module/') !== false)
673 + $cmodules[] = $p_key;
674 + else
675 + $nplugins[] = $p_key;
676 + }
677 +
678 + foreach ( $nplugins as $p_key ) {
679 + if(strpos($p_key, 'jetpack/') !== false){
680 + foreach ( $jmodules as $p_key ) {
681 + $html .= $this->_pagefilter_plugins_checklist( $p_key, $select_cvplugins, $checked_arcvplugins );
682 + }
683 + }
684 + else if(strpos($p_key, 'celtispack/') !== false){
685 + foreach ( $cmodules as $p_key ) {
686 + $html .= $this->_pagefilter_plugins_checklist( $p_key, $select_cvplugins, $checked_arcvplugins );
687 + }
688 + }
689 + else {
690 + $html .= $this->_pagefilter_plugins_checklist( $p_key, $select_cvplugins, $checked_arcvplugins );
691 + }
692 + }
693 + $html .= '</tbody>';
694 + $html .= '</table>';
695 + return $html;
696 + }
697 +
599 698 function plf_meta_box( $post, $box ) {
600 699 if(is_object($post)){
601 - $default = array( 'filter' => 'default', 'plugins' => '');
602 700 $myfilter = get_post_meta( $post->ID, '_plugin_load_filter', true );
701 + //ver2.2.0 for compatibility, set 'plugins' data to 'desktop' and 'mobile'
702 + if(!empty($myfilter['plugins'])){
703 + $myfilter['desktop'] = $myfilter['plugins'];
704 + $myfilter['mobile'] = $myfilter['plugins'];
705 + unset($myfilter['plugins']);
706 + }
707 + $default = array( 'filter' => 'default', 'desktop' => '', 'mobile' => '');
603 708 $option = (!empty($myfilter))? $myfilter : $default;
604 709 $option = wp_parse_args( $option, $default);
710 + $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
605 711 $ajax_nonce = wp_create_nonce( 'plugin_load_filter-' . $post->ID );
606 - $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
607 712 ?>
608 713 <div id="plugin-filter-select">
609 714 <label><input type="radio" name="pagefilter" value="default" <?php checked('default', $option['filter']); ?>/><?php _e('Not Use', 'plf' ); ?></label>
610 715 <label><input type="radio" name="pagefilter" value="include" <?php checked('include', $option['filter']); ?>/><?php _e('Activate Plugins', 'plf'); ?></label>
611 - <br />
612 716 <div id="page-filter-stat">
613 - <?php echo $this->pagefilter_plugins_checklist( $this->plugins_inf, $pgfilter, $option['plugins'] ); ?>
717 + <?php echo $this->pagefilter_plugins_checklist( $this->plugins_inf, $pgfilter, $option ); ?>
614 718 </div>
615 719 <?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 720 </div>
617 721 <?php
@@ -625,29 +729,36 @@
625 729 if ( !current_user_can( 'edit_plugins', $pid ) )
626 730 wp_die( -1 );
627 731 check_ajax_referer( "plugin_load_filter-$pid" );
628 732
733 + $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
629 734 $option["filter"] = (empty($_POST['filter']))? 'default' : $_POST['filter'];
630 - $option["plugins"] = '';
631 - if('default' == $option["filter"])
735 + if('default' == $option["filter"]){
632 736 delete_post_meta( $pid, '_plugin_load_filter');
737 + }
633 738 else {
634 739 $plugins = array();
635 - if( preg_match_all('/plf_option\[plugins\]\[(.+?)\]/u', $_POST['plugins'], $matches)){
740 + if( preg_match_all('/plf_option\[desktop\]\[(.+?)\]/u', $_POST['desktop'], $matches)){
636 741 if(!empty($matches[1])){
637 742 foreach ($matches[1] as $plugin){
638 743 $plugins[] = $plugin;
639 744 }
640 - $option["plugins"] = implode(",", $plugins);
745 + $option["desktop"] = implode(",", $plugins);
641 746 }
642 747 }
748 + $plugins = array();
749 + if( preg_match_all('/plf_option\[mobile\]\[(.+?)\]/u', $_POST['mobile'], $matches)){
750 + if(!empty($matches[1])){
751 + foreach ($matches[1] as $plugin){
752 + $plugins[] = $plugin;
753 + }
754 + $option["mobile"] = implode(",", $plugins);
755 + }
756 + }
643 757 update_post_meta( $pid, '_plugin_load_filter', $option );
644 758 }
645 - //transient cache clear
646 - $this->plf_transient_clear();
647 759
648 - $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
649 - $html = $this->pagefilter_plugins_checklist( $this->plugins_inf, $pgfilter, $option['plugins'] );
760 + $html = $this->pagefilter_plugins_checklist( $this->plugins_inf, $pgfilter, $option );
650 761 wp_send_json_success($html);
651 762 }
652 763 wp_die( 0 );
653 764 }
@@ -665,13 +776,8 @@
665 776 <?php }
666 777
667 778 function plf_meta_script() { ?>
668 779 <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; };
780 + WPAddPagePluginLoadFilter = function(nonce){ jQuery.ajax({ type: 'POST', url: ajaxurl, data: { action: "plugin_load_filter", post_id : jQuery( '#post_ID' ).val(), _ajax_nonce: nonce, filter: jQuery("input[name='pagefilter']:checked").val(), desktop: jQuery('.meta-boxes-plugins-table td.desktop input:checked').map(function(){ return jQuery(this).attr("name"); }).get().join(','), mobile: jQuery('.meta-boxes-plugins-table td.mobile input:checked').map(function(){ return jQuery(this).attr("name"); }).get().join(','),}, dataType: 'json', success: function(response, dataType) { jQuery('#page-filter-stat').html(response.data); }}); return false; };
675 781 </script>
676 782 <?php }
677 783 }