PluginProbe
Plugin Load Filter / 2.4.0
Plugin Load Filter v2.4.0
trunk 2.0.0 2.0.1 2.1.0 2.2.0 2.2.1 2.3.0 2.3.1 2.4.0 2.4.1 2.5.1 3.3.0 4.0.6 4.1.1 4.2.0 4.3.0 4.3.1 4.4.0
← All changes | plugin-load-filter.php +512 -353 2.0.12.4.0 View file →
@@ -1,9 +1,9 @@
1 1 <?php
2 2 /*
3 3 Plugin Name: plugin load filter
4 4 Description: Dynamically activate the selected plugins for each page. Response will be faster by filtering plugins.
5 - Version: 2.0.0
5 + Version: 2.4.0
6 6 Plugin URI: http://celtislab.net/wp_plugin_load_filter
7 7 Author: enomoto@celtislab
8 8 Author URI: http://celtislab.net/
9 9 License: GPLv2
@@ -9,15 +9,92 @@
9 9 License: GPLv2
10 10 Text Domain: plf
11 11 Domain Path: /languages
12 12 */
13 +defined( 'ABSPATH' ) || exit;
13 14
15 +/***************************************************************************
16 + * plugin activation / deactivation / uninstall
17 + **************************************************************************/
18 +if(is_admin()){
19 + function plugin_load_filter_activation( $network_wide ) {
20 + //plf-filter must-use plagin activete check
21 + if(wp_mkdir_p( WPMU_PLUGIN_DIR )){
22 + if ( !file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) {
23 + @copy(__DIR__ . '/mu-plugins/plf-filter.php', WPMU_PLUGIN_DIR . '/plf-filter.php');
24 + }
25 + else {
26 + require_once(ABSPATH . 'wp-admin/includes/plugin.php');
27 + $dp = get_plugin_data( WPMU_PLUGIN_DIR . "/plf-filter.php", false, false );
28 + $sp = get_plugin_data( __DIR__ . '/mu-plugins/plf-filter.php', false, false );
29 + if(version_compare( $dp['Version'], $sp['Version'], '!=')){
30 + @copy(__DIR__ . '/mu-plugins/plf-filter.php', WPMU_PLUGIN_DIR . '/plf-filter.php');
31 + }
32 + }
33 + }
34 + }
35 + register_activation_hook( __FILE__, 'plugin_load_filter_activation' );
36 +
37 + //deactivation
38 + function plugin_load_filter_deactivation( $network_deactivating ) {
39 + $act = false;
40 + if (is_multisite()) {
41 + if(! $network_deactivating){
42 + global $wpdb;
43 + $current_blog_id = get_current_blog_id();
44 + $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
45 + foreach ( $blog_ids as $blog_id ) {
46 + if($blog_id == $current_blog_id){
47 + //current site
48 + }
49 + else {
50 + //other site active check
51 + switch_to_blog( $blog_id );
52 + if ( is_plugin_active( plugin_basename( __FILE__ )))
53 + $act = true;
54 + }
55 + }
56 + switch_to_blog( $current_blog_id );
57 + }
58 + }
59 + if($act === false){
60 + if ( file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) {
61 + @unlink( WPMU_PLUGIN_DIR . '/plf-filter.php' );
62 + }
63 + }
64 + }
65 + register_deactivation_hook( __FILE__, 'plugin_load_filter_deactivation' );
66 +
67 + //uninstall
68 + function plugin_load_filter_uninstall() {
69 +
70 + if ( !is_multisite()) {
71 + delete_option('plf_queryvars');
72 + delete_option('plf_option' );
73 + } else {
74 + global $wpdb;
75 + $current_blog_id = get_current_blog_id();
76 + $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
77 + foreach ( $blog_ids as $blog_id ) {
78 + switch_to_blog( $blog_id );
79 + delete_option('plf_queryvars');
80 + delete_option('plf_option' );
81 + }
82 + switch_to_blog( $current_blog_id );
83 + }
84 + if ( file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) {
85 + @unlink( WPMU_PLUGIN_DIR . '/plf-filter.php' );
86 + }
87 + }
88 + register_uninstall_hook(__FILE__, 'plugin_load_filter_uninstall');
89 +
90 +}
91 +
14 92 $Plf_setting = new Plf_setting();
15 93
16 94 class Plf_setting {
17 95
18 96 private $plugins_inf = ''; //active plugin/module infomation
19 - private $editem = false;
20 97 private $filter = array(); //filter option data
21 98 private $tab_num = 0;
22 99
23 100 /***************************************************************************
@@ -24,11 +101,17 @@
24 101 * Style Sheet
25 102 **************************************************************************/
26 103 function plf_css() { ?>
27 104 <style type="text/css">
28 - .plugins-list { max-width : 480px; min-height: 80px; max-height: 320px; overflow: auto; border: 1px solid #CEE1EF; padding:0.5em 0.5em;}
29 - ul.plugins-list ul { margin-left: 20px; }
30 - ul.plugins-list li { margin: 0; padding: 0; line-height: 22px; word-wrap: break-word;}
105 + #activation-table { margin-top: 10px; border: 1px solid #eee;}
106 + #activation-table input[type=checkbox] { height: 25px; width: 25px; opacity: 0;}
107 + thead .plugins-name { background-color: aliceblue;}
108 + thead .device-type { background-color: oldlace;}
109 + thead .plugins-name, tbody .plugins-name { min-width: 172px; max-width: 172px;}
110 + thead .device-type, tbody .device-type { min-width: 36px; max-width: 36px; padding: 0;}
111 + .dashicons-yes:before { font-size: 20px; border: 1px solid #eee; background-color: whitesmoke;}
112 + .device-type label { color: whitesmoke; margin-left: -28px; }
113 + .device-type input[type="checkbox"]:checked + label .dashicons-yes:before { background-color: yellowgreen; }
31 114 </style>
32 115 <?php }
33 116
34 117 function jquery_tab_css() { ?>
@@ -49,11 +132,40 @@
49 132 .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; }
50 133 .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; }
51 134 .ui-state-hover a, .ui-state-hover a:hover, .ui-state-hover a:link, .ui-state-hover a:visited { color: #ffffff; text-decoration: none; }
52 135 .ui-state-active a, .ui-state-active a:link, .ui-state-active a:visited { color: #ffffff; text-decoration: none; }
136 +
137 + #wrap_registration-table, #wrap_activation-table { overflow-x:auto;}
138 + #registration-table input[type=radio], #activation-table input[type=checkbox] { height: 25px; width: 25px; opacity: 0;}
139 + thead, tbody { display: block;}
140 + .plugins-table-body { overflow-y:scroll; height:500px; }
141 + .widefat td, .widefat th { padding: 8px 4px;}
142 + thead .filter-plugins-name, thead .plugins-name { background-color: aliceblue;}
143 + .filter-none, .filter-admin, .filter-tmpl { background-color: oldlace;}
144 + thead .device-type { background-color: oldlace;}
145 + thead .tmpl-type { background-color: lavender;}
146 + thead .pformat { background-color: honeydew;}
147 + thead .tmpl-embed { background-color: lightyellow;}
148 + thead .tmpl-custom { background-color: lavenderblush;}
149 + thead .filter-plugins-name, tbody .filter-plugins-name { min-width: 260px; max-width: 260px;}
150 + thead .plugins-name, tbody .plugins-name { min-width: 180px; max-width: 180px;}
151 + thead .filter-type, tbody .filter-type { min-width: 100px; max-width: 100px;}
152 + thead .device-type, tbody .device-type, thead .tmpl-type, tbody .tmpl-type { min-width: 40px; max-width: 40px; }
153 + .filter-description { padding: 0 10px 20px 10px;}
154 + .exclude-pformat { padding: 16px 0 20px}
155 + .exclude-pformat label { white-space:nowrap;}
156 + .exclude-pformat span { margin-right: 12px; }
157 + .dashicons:before { font-size: 24px; }
158 + .radio-green label, .radio-red label, .tmpl-type label { color: #ddd; margin-left: -28px; }
159 + .radio-green input[type="radio"]:checked + label { color: #339966; }
160 + .radio-red input[type="radio"]:checked + label { color: #ff0000; }
161 + .tmpl-type input[type="checkbox"]:checked + label { color: #339966; }
162 + .dashicons-yes:before { font-size: 20px; border: 1px solid #eee; background-color: whitesmoke;}
163 + .device-type label { color: whitesmoke; margin-left: -28px; }
164 + .device-type input[type="checkbox"]:checked + label .dashicons-yes:before { background-color: yellowgreen; }
53 165 </style>
54 166 <?php }
55 -
167 +
56 168 /***************************************************************************
57 169 * Plugin Load Filter Option Setting
58 170 **************************************************************************/
59 171
@@ -61,47 +173,35 @@
61 173
62 174 load_plugin_textdomain('plf', false, basename( dirname( __FILE__ ) ).'/languages' );
63 175
64 176 $this->filter = get_option('plf_option');
177 + //v2.3.0 option change
178 + if(empty($this->filter['optver']) || $this->filter['optver'] < '2'){
179 + $this->filter['optver'] = '2';
180 +
181 + if(empty($this->filter['group']['desktop']) && empty($this->filter['group']['mobile'])){
182 + //For ver2.2.0 compatibility, set '_pagefilter' data to 'desktop' and 'mobile'
183 + if(!empty($this->filter['_pagefilter'])){
184 + $this->filter['group']['desktop'] = $this->filter['_pagefilter'];
185 + $this->filter['group']['mobile'] = $this->filter['_pagefilter'];
186 + }
187 + if(!empty($this->filter['_desktop'])){
188 + $this->filter['_desktop'] = null;
189 + }
190 + if(!empty($this->filter['_mobile'])){
191 + $this->filter['_mobile'] = null;
192 + }
193 + }
194 + }
195 +
65 196 if(is_admin()) {
66 197 add_action( 'plugins_loaded', array(&$this, 'plf_admin_start'), 9999 );
67 - add_action( 'update_option_plf_option', array(&$this, 'plf_transient_clear') );
68 - add_action( 'update_option_active_plugins', array(&$this, 'plf_transient_clear') );
69 - add_action( 'update_option_jetpack_active_modules', array(&$this, 'plf_transient_clear') );
70 - add_action( 'update_option_celtispack_active_modules', array(&$this, 'plf_transient_clear') );
198 + add_action( 'admin_init', array(&$this, 'action_posts'));
71 199 add_action( 'add_meta_boxes', array(&$this, 'load_meta_boxes'), 10, 2 );
72 - //plf-filter must-use plagin activete check
73 - if(wp_mkdir_p( WPMU_PLUGIN_DIR )){
74 - if ( !file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) {
75 - @copy(__DIR__ . '/mu-plugins/plf-filter.php', WPMU_PLUGIN_DIR . '/plf-filter.php');
76 - }
77 - }
78 - register_deactivation_hook( __FILE__, 'Plf_setting::deactivation' );
79 - register_uninstall_hook(__FILE__, 'Plf_setting::uninstall');
80 200 }
81 - add_action( 'save_post', array(&$this, 'plf_transient_clear') );
82 - add_action( 'deleted_post', array(&$this, 'plf_transient_clear') );
83 201 add_action( 'wp_ajax_plugin_load_filter', array(&$this, 'plf_ajax_postidfilter'));
84 202 }
85 203
86 - //Plugin Deactivate
87 - public static function deactivation() {
88 - if ( file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) {
89 - @unlink( WPMU_PLUGIN_DIR . '/plf-filter.php' );
90 - }
91 - }
92 - //Plugin Uninstall
93 - public static function uninstall() {
94 - delete_option('plf_queryvars');
95 - delete_option('plf_option' );
96 - }
97 -
98 - //Disable the transient cache by changing the update time
99 - public function plf_transient_clear() {
100 - $this->filter['updated'] = strtotime("now");
101 - update_option('plf_option', $this->filter );
102 - }
103 -
104 204 //Plugin Load Filter admin setting start
105 205 public function plf_admin_start() {
106 206 require_once(ABSPATH . 'wp-admin/includes/plugin.php');
107 207
@@ -135,9 +235,8 @@
135 235 }
136 236 if ( empty( $this->plugins_inf ) )
137 237 return;
138 238
139 - $this->action_posts(); //POST, GET Request Action
140 239 add_action('admin_menu', array(&$this, 'plf_option_menu'));
141 240 }
142 241
143 242 //Plugins sub menu add
@@ -158,22 +257,56 @@
158 257 }
159 258
160 259 //plugin filter option action request (add, update, delete)
161 260 function action_posts() {
162 - if (current_user_can( 'edit_plugins' )) {
261 + if (current_user_can( 'activate_plugins' )) {
163 262 if( isset($_POST['edit_regist_filter']) ) {
164 - if(isset($_POST['plf_option']['_tag'])){
263 + if(isset($_POST['plfregist'])){
165 264 check_admin_referer('plugin_load_filter');
166 - $option["plugins"] = '';
167 - if(isset($_POST['plf_option']['plugins'])){
265 + foreach( array('_admin', '_pagefilter') as $item){
168 266 $plugins = array();
169 - foreach($_POST['plf_option']['plugins'] as $plugin => $val) {
170 - $plugins[] = $plugin;
267 + foreach ( $_POST['plfregist'] as $p_key => $val ) {
268 + if($val == $item)
269 + $plugins[$p_key] = $val;
171 270 }
172 - $option["plugins"] = implode(",", $plugins);
271 + if($item == '_pagefilter'){
272 + //If all modules is specified filter, in some cases you want to deactivate plugin itself.
273 + $jbase = $cbase = '';
274 + $jall = $call = true;
275 + foreach ( $_POST['plfregist'] as $p_key => $val ) {
276 + if(strpos($p_key, 'jetpack/') !== false)
277 + $jbase = $p_key;
278 + else if(strpos($p_key, 'celtispack/') !== false)
279 + $cbase = $p_key;
280 + else if(strpos($p_key, 'jetpack_module/') !== false){
281 + if($val != '_pagefilter' && $val != '_admin'){
282 + $jall = false;
283 + }
284 + }
285 + else if(strpos($p_key, 'celtispack_module/') !== false){
286 + if($val != '_pagefilter' && $val != '_admin')
287 + $call = false;
288 + }
289 + }
290 + if(!empty($jbase) && $jall === false)
291 + unset($plugins[$jbase]);
292 + if(!empty($cbase) && $call === false)
293 + unset($plugins[$cbase]);
294 + }
295 + $option["plugins"] = implode(",", array_keys($plugins));
296 + $this->filter[$item] = $option;
173 297 }
174 - $this->filter[$_POST['plf_option']['_tag']] = $option;
175 - $this->filter['updated'] = strtotime("now");
298 + if(isset($_POST['plf_option']['exclude'])){
299 + $exclude = array();
300 + foreach ( $_POST['plf_option']['exclude'] as $ft => $v ) {
301 + if(!empty($v))
302 + $exclude[$ft] = true;
303 + }
304 + $this->filter['exclude'] = $exclude;
305 + }
306 + else {
307 + $this->filter['exclude'] = '';
308 + }
176 309 update_option('plf_option', $this->filter );
177 310 }
178 311 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page'));
179 312 exit;
@@ -178,83 +311,54 @@
178 311 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page'));
179 312 exit;
180 313 }
181 314 elseif( isset($_POST['clear_regist_filter']) ) {
315 + check_admin_referer('plugin_load_filter');
316 + foreach( array('_admin', '_pagefilter') as $item){
317 + $this->filter[$item] = '';
318 + }
319 + $this->filter['exclude'] = '';
320 + update_option('plf_option', $this->filter );
182 321 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page'));
183 322 exit;
184 323 }
185 - else if( isset($_POST['new_page_filter']) || isset($_POST['edit_page_filter']) ) {
186 - if(isset($_POST['plf_option']['tag'])){
324 + else if(isset($_POST['edit_activate_page_filter']) ) {
325 + if(isset($_POST['plfactive'])){
187 326 check_admin_referer('plugin_load_filter');
188 - $option["plugins"] = '';
189 - if(isset($_POST['plf_option']['plugins'])){
327 + $group = array_keys($_POST['plfactive']);
328 + foreach( $group as $item){
190 329 $plugins = array();
191 - foreach($_POST['plf_option']['plugins'] as $plugin => $val) {
192 - $plugins[] = $plugin;
330 + foreach ( $_POST['plfactive'][$item] as $p_key => $val ) {
331 + if($val == '1')
332 + $plugins[] = $p_key;
193 333 }
194 334 $option["plugins"] = implode(",", $plugins);
335 + $this->filter['group'][$item] = $option;
195 336 }
196 - $this->filter['group'][$_POST['plf_option']['tag']] = $option;
197 - $this->filter['updated'] = strtotime("now");
198 337 update_option('plf_option', $this->filter );
199 338 }
200 339 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page&action=tab_1'));
201 340 exit;
202 341 }
203 - elseif( isset($_POST['clear_page_filter']) ) {
342 + elseif( isset($_POST['clear_activate_page_filter']) ) {
343 + check_admin_referer('plugin_load_filter');
344 + $group = array_keys($_POST['plfactive']);
345 + foreach( $group as $item){
346 + $this->filter['group'][$item] = '';
347 + }
348 + update_option('plf_option', $this->filter );
204 349 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page&action=tab_1'));
205 350 exit;
206 351 }
207 - else if (!empty($_GET['action'])) {
208 - if( $_GET['action']=='edit_filter_table') {
209 - $this->editem = $_GET['item'];
210 - $this->tab_num = (0 === strpos($_GET['item'], '_'))? 0 : 1;
211 - }
212 - elseif( $_GET['action']=='del_filter_table') {
213 - if( !empty( $_GET['item'])){
214 - check_admin_referer( 'plugin_load_filter' );
215 - $tab_action = '';
216 - if(0 === strpos($_GET['item'], '_')){
217 - unset($this->filter[$_GET['item']]);
218 - }
219 - else {
220 - unset($this->filter['group'][$_GET['item']]);
221 - $tab_action = '&action=tab_1';
222 - }
223 - $this->filter['updated'] = strtotime("now");
224 - update_option('plf_option', $this->filter );
225 - }
226 - header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page'.$tab_action));
227 - exit;
228 - }
229 - elseif( $_GET['action']=='tab_1') {
230 - $this->tab_num = 1;
231 - }
352 + if(!empty($_GET['action']) && $_GET['action']=='tab_1') {
353 + $this->tab_num = 1;
232 354 }
233 355 }
234 356 }
235 357
236 - public function filter_stat( $sw, $stat) {
237 - if( $sw === 'exclude') {
238 - if(empty($stat))
239 - $str = '<span style="color: #339966;">"Page filter plugins Activate"</span>';
240 - else
241 - $str = '<span style="color: #ff0000;">' . $stat. '</span>';
242 - }
243 - elseif( $sw === 'include') {
244 - if(empty($stat))
245 - $str = '<span style="color: #ff0000;">"Page filter plugins Deactivate"</span>';
246 - else
247 - $str = '<span style="color: #339966;">' . $stat. '</span>';
248 - }
249 - else
250 - $str = $stat;
251 - return $str;
252 - }
253 -
254 358 //Plugin or Module key to name
255 - // $type : smart/csv/list/tree
256 - public function pluginkey_to_name( $infkey, $type='smart') {
359 + // $type : list/smart/tree
360 + public function pluginkey_to_name( $infkey, $type='list') {
257 361
258 362 $name = '';
259 363 if(strpos($infkey, 'jetpack_module/') !== false){
260 364 if(!empty($this->plugins_inf[$infkey]['name'])){
@@ -288,88 +392,183 @@
288 392 //Checkbox
289 393 static function checkbox($name, $value, $label = '') {
290 394 return "<label><input type='checkbox' name='$name' value='1' " . checked( $value, 1, false ). "/> $label</label>";
291 395 }
292 - //DropdownList
293 - static function dropdown($name, $items, $selected, $args=null) {
294 - $defaults = array( 'id' => $name, 'class' => "", 'multiple' => false );
295 - foreach($items as $key => &$value) {
296 - if (is_array($value))
297 - $value = array_shift($value);
298 - }
299 - $opt = wp_parse_args($args, $defaults);
300 - $name = ($name) ? "name='$name'" : "";
301 - $id = ($opt['id']) ? "id='${opt['id']}'" : "";
302 - $class = ($opt['class']) ? "class='${opt['class']}'" : "";
303 - $multiple = ($opt['multiple']) ? "multiple='multiple'" : "";
304 -
305 - $html = "<select $name $id $class $multiple >";
306 - foreach ((array)$items as $key => $label) {
307 - $key = esc_attr($key);
308 - $label = esc_attr($label);
309 - $html .= "<option value='$key' " . selected($selected, $key, false) . ">$label</option>";
310 - }
311 - $html .= "</select>";
312 - return $html;
396 + static function altcheckbox($name, $value, $label = '') {
397 + return "<input type='hidden' name='$name' value='0'><input type='checkbox' name='$name' value='1' " . checked( $value, 1, false ). "/><label> $label</label>";
313 398 }
314 399
315 - //Plugin Select Checkbox (plugin-modules tree)
316 - // $plugins : array : all active plugins
317 - // $checked_cvplugins : csv string : checked plugins
318 - function plugins_checklist( $plugins, $checked_cvplugins ) {
319 -
320 - $nplugins = $jmodules = $cmodules = array();
321 - $type = 'tree';
322 - foreach ( $plugins as $p_key => $p_data ) {
323 - $p_name = $this->pluginkey_to_name($p_key, $type);
324 - if(empty($p_name))
325 - continue;
326 - if(strpos($p_key, 'jetpack_module/') !== false)
327 - $jmodules[] = $p_key;
328 - else if(strpos($p_key, 'celtispack_module/') !== false)
329 - $cmodules[] = $p_key;
330 - else
331 - $nplugins[] = $p_key;
400 + public function plfregist_item($key, $val) {
401 + $p_name = $this->pluginkey_to_name($key);
402 + $opt_name = "plfregist[$key]";
403 + ?>
404 + <tr id="plfregist_<?php echo $key; ?>">
405 + <td class="filter-plugins-name"><?php echo $p_name; ?></td>
406 + <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>
407 + <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>
408 + <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>
409 + </tr>
410 + <?php
411 + }
412 +
413 + //Filterring plugins select
414 + public function plfregist_table($plugins, $filter) {
415 + ?>
416 + <div id="wrap_registration-table">
417 + <table id="registration-table" class="widefat">
418 + <thead>
419 + <tr><th class="filter-plugins-name"><?php _e('Plugins'); ?></th>
420 + <th class="filter-type filter-none"><?php _e('Normal Load', 'plf'); ?></th>
421 + <th class="filter-type filter-admin"><?php _e('Admin Filter', 'plf'); ?></th>
422 + <th class="filter-type filter-tmpl"><?php _e('Page Filter', 'plf'); ?></th>
423 + </tr>
424 + </thead>
425 + <tbody class="plugins-table-body">
426 + <?php
427 + //plugins filter registoration table
428 + $plist = array();
429 + foreach ( $plugins as $p_key => $val ) {
430 + $name = $this->pluginkey_to_name($p_key);
431 + if(!empty($name))
432 + $plist[$p_key] = '';
332 433 }
333 - $chkplugins = array_map("trim", explode(',', $checked_cvplugins));
334 - $html = '<ul class="plugins-list">';
335 - foreach ( $nplugins as $p_key ) {
336 - $p_name = $this->pluginkey_to_name($p_key, $type);
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 -
434 + foreach( array('_admin', '_pagefilter') as $item){
435 + $parr = (!empty($filter[$item]['plugins'])) ? array_map("trim", explode(',', $filter[$item]['plugins'])) : array();
436 + foreach ( $plist as $p_key => $val ) {
437 + if(empty($val) && in_array($p_key, $parr))
438 + $plist[$p_key] = $item;
439 + }
440 + }
441 + $jlist = $clist = array();
442 + foreach ( $plist as $p_key => $val ) {
443 + if(strpos($p_key, 'jetpack_module/') !== false){
444 + $jlist[$p_key] = $plist[$p_key];
445 + unset($plist[$p_key]);
446 + }
447 + else if(strpos($p_key, 'celtispack_module/') !== false){
448 + $clist[$p_key] = $plist[$p_key];
449 + unset($plist[$p_key]);
450 + }
451 + }
452 + foreach ( $plist as $p_key => $val ) {
340 453 $modules = array();
341 454 if(strpos($p_key, 'jetpack/') !== false)
342 - $modules = $jmodules;
455 + $modules = $jlist;
343 456 else if(strpos($p_key, 'celtispack/') !== false)
344 - $modules = $cmodules;
457 + $modules = $clist;
458 + else
459 + $this->plfregist_item($p_key, $val);
345 460 if(!empty($modules)){
346 - $html .= '<ul class="modules-list">';
347 - foreach ( $modules as $m_key ) {
348 - $m_name = $this->pluginkey_to_name($m_key, $type);
349 - $mchecked = ($checked || in_array( $m_key, $chkplugins )) ? true : false;
350 - $html .= '<li>' . self::checkbox("plf_option[plugins][$m_key]", $mchecked, esc_attr($m_name)) . '</li>';
461 + echo "<input type='hidden' name='plfregist[$p_key]' value='_pagefilter'>";
462 + foreach ( $modules as $m_key => $val) {
463 + $this->plfregist_item($m_key, $val);
351 464 }
352 - $html .= '</ul>';
353 465 }
354 466 }
355 - $html .= '</ul>';
356 - return $html;
467 + ?>
468 + </tbody>
469 + </table>
470 + <br />
471 + <p><strong>[ Admin Filter ]</strong></p>
472 + <div class="filter-description"><?php _e('Plugins to be used only in admin mode.', 'plf'); ?></div>
473 + <p><strong>[ Page Filter ]</strong></p>
474 + <div class="filter-description">
475 + <?php _e('Plugins for selecting whether to activate each Page type or Post.', 'plf'); ?><br />
476 + <?php _e('Selected page filter plugins are once blocked, but is activated by "Page filter Activation" setting.', 'plf'); ?>
477 + <div class="exclude-pformat">
478 + <p><strong><?php _e( 'Exclude Post Format Type', 'plf' ); ?></strong><br />
479 + <?php _e('Choose Post Format Type you are not using. To exclude from Page Filter item subject.', 'plf'); ?>
480 + </p>
481 + <?php
482 + $html = '<div>';
483 + $pformat = array('image', 'gallery', 'video', 'audio', 'aside', 'status', 'quote', 'link', 'chat' );
484 + foreach ( $pformat as $type ) {
485 + $checked = (!empty($this->filter['exclude'][$type]))? $this->filter['exclude'][$type] : false;
486 + $label = "<span>$type</span>";
487 + $html .= self::checkbox("plf_option[exclude][$type]", $checked, $label);
488 + }
489 + $html .= '</div>';
490 + echo $html;
491 + ?>
492 + </div>
493 + </div>
494 + </div>
495 + <?php
357 496 }
358 497
359 - //Plugin pagefilter Selected Checkbox (plugin and modules list)
360 - // $plugins : array : all active plugins
361 - // $select_cvplugins : csv string : pagefilter selected plugins
362 - // $checked_cvplugins : csv string : checked plugins
363 - function pagefilter_plugins_checklist( $plugins, $select_cvplugins, $checked_cvplugins ) {
364 -
498 + //Activate plugins select from Page Filter
499 + public function _plfactive_checkbox_row($p_key, $select_cvplugins, $chklist, $filter) {
500 +
501 + $selplugins = array_map("trim", explode(',', $select_cvplugins));
502 + $devlist = array('desktop','mobile');
503 + if(in_array( $p_key, $selplugins )){
504 + $p_name = $this->pluginkey_to_name($p_key);
505 + echo "<tr><td class='plugins-name'>$p_name</td>";
506 + foreach($devlist as $devtype){
507 + $checked = (empty($filter['group'][$devtype]['plugins']) || false === strpos($filter['group'][$devtype]['plugins'], $p_key))? false : true;
508 + echo '<td class="device-type">' . self::altcheckbox("plfactive[$devtype][$p_key]", $checked, '<span class="dashicons dashicons-yes"></span>') . '</td>';
509 + }
510 + foreach($chklist as $pgtype){
511 + $checked = (empty($filter['group'][$pgtype]['plugins']) || false === strpos($filter['group'][$pgtype]['plugins'], $p_key))? false : true;
512 + echo '<td class="tmpl-type">' . self::altcheckbox("plfactive[$pgtype][$p_key]", $checked, '<span class="dashicons dashicons-admin-plugins"></span>') . '</td>';
513 + }
514 + echo "</tr>";
515 + }
516 + }
517 +
518 + public function plfactive_table($plugins, $select_cvplugins, $filter) {
365 519 if(empty($select_cvplugins))
366 - return __('Page Filter is not registered', 'plf');
520 + return;
367 521
522 + ?>
523 + <div id="wrap_activation-table">
524 + <table id="activation-table" class="widefat">
525 + <thead>
526 + <tr><th class="plugins-name"><?php _e('Plugins'); ?></th>
527 + <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>
528 + <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>
529 + <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>
530 + <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>
531 + <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>
532 + <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>
533 + <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>
534 + <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>
535 + <?php
536 + $pformat = array('image', 'gallery', 'video', 'audio', 'aside', 'status', 'quote', 'link', 'chat' );
537 + $exclude = array();
538 + if(!empty($filter['exclude'])){
539 + foreach ( $filter['exclude'] as $type => $v) {
540 + if(!empty($v)){
541 + $exclude[] = $type;
542 + }
543 + }
544 + }
545 + foreach ( $pformat as $type) {
546 + if(!in_array($type, $exclude)){
547 + $title = __('Post : ', 'plf') . $type;
548 + $icon = ($type === "link")? "dashicons-admin-links" : "dashicons-format-$type";
549 + echo '<th class="tmpl-type pformat"><span title="' . $title . '" class="dashicons ' . $icon .'"></span><br /><span style="font-size:xx-small">' . $type .'</span></th>';
550 + }
551 + }
552 + if(function_exists('is_embed')){
553 + $title = __('WordPress Embed Content Card (API)', 'plf');
554 + echo "<th class='tmpl-type tmpl-embed'><span title='$title' style='font-size:xx-small'>Embed Content</span></th>";
555 + }
556 + $post_types = get_post_types( array('public' => true, '_builtin' => false) );
557 + foreach ( $post_types as $post_type ) {
558 + if(!empty($post_type)){
559 + $title = __('Custom Post : ', 'plf') . $post_type;
560 + echo "<th class='tmpl-type tmpl-custom'><span title='$title' style='font-size:xx-small'>$post_type</span></th>";
561 + }
562 + }
563 + ?>
564 + </tr>
565 + </thead>
566 + <tbody class="plugins-table-body">
567 + <?php
368 568 $nplugins = $jmodules = $cmodules = $allmodule = array();
369 - $type = 'list';
370 569 foreach ( $plugins as $p_key => $p_data ) {
371 - $p_name = $this->pluginkey_to_name($p_key, $type);
570 + $p_name = $this->pluginkey_to_name($p_key);
372 571 if(empty($p_name))
373 572 continue;
374 573 if(strpos($p_key, 'jetpack_module/') !== false)
375 574 $jmodules[] = $p_key;
@@ -374,80 +573,43 @@
374 573 if(strpos($p_key, 'jetpack_module/') !== false)
375 574 $jmodules[] = $p_key;
376 575 else if(strpos($p_key, 'celtispack_module/') !== false)
377 576 $cmodules[] = $p_key;
378 - else {
379 - if(strpos($p_key, 'jetpack/') !== false && strpos($select_cvplugins, $p_key) !== false)
380 - $allmodule['jetpack'] = $p_key;
381 - else if(strpos($p_key, 'celtispack/') !== false && strpos($select_cvplugins, $p_key) !== false)
382 - $allmodule['celtispack'] = $p_key;
383 - else
384 - $nplugins[] = $p_key;
385 - }
577 + else
578 + $nplugins[] = $p_key;
386 579 }
387 - $selplugins = array_map("trim", explode(',', $select_cvplugins));
388 - $chkplugins = array_map("trim", explode(',', $checked_cvplugins));
389 - $html = '<ul class="plugins-list">';
390 - foreach ( $nplugins as $p_key ) {
391 - if(in_array( $p_key, $selplugins )) {
392 - $p_name = $this->pluginkey_to_name($p_key, $type);
393 - $checked = in_array( $p_key, $chkplugins ) ? true : false;
394 - $html .= '<li>' . self::checkbox("plf_option[plugins][$p_key]", $checked, esc_attr($p_name)) . '</li>';
580 + $chklist = array('home', 'archive', 'search', 'attachment', 'page', 'post');
581 + foreach ( $pformat as $type) {
582 + if(!in_array($type, $exclude)){
583 + $chklist[] = "post-$type";
395 584 }
396 585 }
397 - foreach ( $jmodules as $p_key ) {
398 - if(!empty($allmodule['jetpack']) || in_array( $p_key, $selplugins )){
399 - $p_name = $this->pluginkey_to_name($p_key, $type);
400 - $checked = in_array( $p_key, $chkplugins ) ? true : false;
401 - $html .= '<li>' . self::checkbox("plf_option[plugins][$p_key]", $checked, esc_attr($p_name)) . '</li>';
402 - }
586 + if(function_exists('is_embed')){
587 + $chklist[] = 'content-card';
403 588 }
404 - foreach ( $cmodules as $p_key ) {
405 - if(!empty($allmodule['celtispack']) || in_array( $p_key, $selplugins )){
406 - $p_name = $this->pluginkey_to_name($p_key, $type);
407 - $checked = in_array( $p_key, $chkplugins ) ? true : false;
408 - $html .= '<li>' . self::checkbox("plf_option[plugins][$p_key]", $checked, esc_attr($p_name)) . '</li>';
409 - }
589 + $post_types = get_post_types( array('public' => true, '_builtin' => false) );
590 + foreach ( $post_types as $post_type ) {
591 + $chklist[] = $post_type;
410 592 }
411 - $html .= '</ul>';
412 - return $html;
413 - }
414 -
415 - //Plugin Filter Table
416 - public function plf_table($tags, $default) {
417 - ?>
418 - <table class="widefat">
419 - <thead>
420 - <tr><th width="12%"><?php _e('Type'); ?></th><th width="76%"><?php _e('Plugins'); ?></th><th width="12%" colspan="2">&nbsp;</th></tr>
421 - </thead>
422 - <tbody>
423 - <?php
424 - if(!empty($tags)){
425 - foreach( $tags as $ptag => $val ) {
426 - $opt = wp_parse_args( $val, $default);
427 - $plugins = array_map("trim", explode(',', $opt['plugins']));
428 - $plist = '';
429 - $type = ($ptag == '_pagefilter')? 'smart' : 'csv';
430 - foreach ( $plugins as $p_key ) {
431 - $p_name = $this->pluginkey_to_name($p_key, $type);
432 - if(!empty($p_name)){
433 - $sep = (empty($plist))? '' : ', ';
434 - $plist .= $sep . esc_attr($p_name);
435 - }
593 + foreach ( $nplugins as $p_key ) {
594 + if(strpos($p_key, 'jetpack/') !== false){
595 + foreach ( $jmodules as $p_key ) {
596 + $this->_plfactive_checkbox_row($p_key, $select_cvplugins, $chklist, $filter);
436 597 }
437 - if(!empty($ptag)){
438 - echo '<tr id="plf_filter_' .$ptag. '">';
439 - echo '<td>'.$ptag.'</td>';
440 - echo '<td>'. $this->filter_stat($opt['filter'], $plist).'</td>';
441 - echo '<td><a class="view" href="'. wp_nonce_url("plugins.php?page=plugin_load_filter_admin_manage_page&amp;action=edit_filter_table&amp;item=$ptag", "plugin_load_filter") . '">' . __( 'Edit' ) . '</a></td>';
442 - echo '<td><a class="delete" href="'. wp_nonce_url("plugins.php?page=plugin_load_filter_admin_manage_page&amp;action=del_filter_table&amp;item=$ptag", "plugin_load_filter") . '">' . __( 'Delete' ) . '</a></td>';
443 - echo '</tr>';
598 + }
599 + else if(strpos($p_key, 'celtispack/') !== false){
600 + foreach ( $cmodules as $p_key ) {
601 + $this->_plfactive_checkbox_row($p_key, $select_cvplugins, $chklist, $filter);
444 602 }
445 603 }
604 + else {
605 + $this->_plfactive_checkbox_row($p_key, $select_cvplugins, $chklist, $filter);
606 + }
446 607 }
447 608 ?>
448 609 </tbody>
449 610 </table>
611 + </div>
450 612 <?php
451 613 }
452 614
453 615 //Option Setting Form Display
@@ -459,123 +621,40 @@
459 621 <ul>
460 622 <li><a href="#plf-registration-tab" ><?php _e('Filter Registration', 'plf'); ?></a></li>
461 623 <li><a href="#plf-activation-tab" ><?php _e('Page Filter Activation', 'plf'); ?></a></li>
462 624 </ul>
463 - <form method="post" >
625 + <form method="post" autocomplete="off">
464 626 <?php wp_nonce_field( 'plugin_load_filter'); ?>
465 - <div id="plf-registration-tab" >
466 - <?php
467 - $default = array( 'filter' => 'exclude', 'plugins' => '');
468 - $base = array();
469 - foreach($this->filter as $item => $val){
470 - if(0 === strpos($item, '_'))
471 - $base[$item] = $this->filter[$item];
472 - }
473 - $this->plf_table($base, $default);
474 -
475 - $itemtag = '';
476 - $option = $default;
477 - if( !empty($this->editem) ) {
478 - $itemtag = $this->editem;
479 - $option = $this->filter[$itemtag];
480 - }
481 - $option = wp_parse_args( $option, $default);
482 - ?>
483 - <br />
484 - <p><strong>[ Admin Filter ]</strong><br />
485 - <?php _e('Register the plugins to be used only in admin mode.', 'plf'); ?><br />
486 - </p>
487 - <p><strong>[ Desktop/Mobile Filter ]</strong><br />
488 - <?php _e('Register the plugins to be used only in desktop/moble device. (wp_is_mobile function use)', 'plf'); ?><br />
489 - </p>
490 - <p><strong>[ Page Filter ]</strong><br />
491 - <?php _e('Register the plugins for selecting whether to activate each Page type or Post.', 'plf'); ?><br />
492 - <?php _e('Page Filter registration plugins are once blocked, but is activated by "Page filter Activation" setting.', 'plf'); ?><br />
493 - </p>
494 - <p><?php _e('<strong>[Note]</strong> Running condition is unknown plugin, please do not register. Unregistered plugins are usually loaded.', 'plf') ?></p>
495 - <table width="100%" cellspacing="2" cellpadding="5" class="editform form-table">
496 - <tbody>
497 - <tr>
498 - <th valign="top" scope="row"><label for="plugin"><?php _e('Filter Type', 'plf'); ?>:</label></th>
499 - <td>
500 - <label><input type="radio" name="plf_option[_tag]" value="_admin" <?php checked('_admin', $itemtag); ?>/><?php _e('Admin', 'plf'); ?></label>
501 - <label><input type="radio" name="plf_option[_tag]" value="_desktop" <?php checked('_desktop', $itemtag); ?>/><?php _e('Desktop', 'plf'); ?></label>
502 - <label><input type="radio" name="plf_option[_tag]" value="_mobile" <?php checked('_mobile', $itemtag); ?>/><?php _e('Mobile', 'plf'); ?></label>
503 - <label><input type="radio" name="plf_option[_tag]" value="_pagefilter" <?php checked('_pagefilter', $itemtag); ?>/><?php _e('Page Filter', 'plf'); ?></label>
504 - <br />
505 - <?php echo $this->plugins_checklist( $this->plugins_inf, $option['plugins'] ); ?>
506 - </td>
507 - </tr>
508 - <tr>
509 - </tr>
510 - </tbody>
511 - </table>
627 + <div id="plf-registration-tab" style="display : none;">
628 + <?php $this->plfregist_table($this->plugins_inf, $this->filter); ?>
512 629 <p class="submit">
513 630 <input type="submit" class="button-primary" name="clear_regist_filter" value="<?php _e('Clear', 'plf'); ?>" />&nbsp;&nbsp;&nbsp;
514 - <input type="submit" class="button-primary" name="edit_regist_filter" value="<?php _e('Entry &raquo;', 'plf'); ?>" />
631 + <input type="submit" class="button-primary" name="edit_regist_filter" value="<?php _e('Filter Entry &raquo;', 'plf'); ?>" />
515 632 </p>
516 633 </div>
517 - <div id="plf-activation-tab" >
634 + <div id="plf-activation-tab" style="display : none;">
518 635 <?php
519 - $default = array( 'filter' => 'include', 'plugins' => '');
520 - $cgroup = (!empty($this->filter['group']))? $this->filter['group'] : array();
521 636 $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
522 - $this->plf_table( $cgroup, $default);
523 - $itemtag = '';
524 - $option = $default;
525 - $action = 'new_page_filter';
526 - if( !empty($this->editem) ) {
527 - $itemtag = $this->editem;
528 - $option = $cgroup[$itemtag];
529 - $action = 'edit_page_filter';
637 + if(!empty($pgfilter)){
638 + $this->plfactive_table($this->plugins_inf, $pgfilter, $this->filter);
639 + ?>
640 + <br />
641 + <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 />
642 + <?php _e('You can also select plugins to activate from Post/Page content editing screen.', 'plf') ?>
643 + </p>
644 + <p class="submit">
645 + <input type="submit" class="button-primary" name="clear_activate_page_filter" value="<?php _e('Clear', 'plf'); ?>" />&nbsp;&nbsp;&nbsp;
646 + <input type="submit" class="button-primary" name="edit_activate_page_filter" value="<?php _e('Activate Plugin Entry &raquo;', 'plf'); ?>" />
647 + </p>
648 + <?php
530 649 }
531 - $option = wp_parse_args( $option, $default);
650 + else {
651 + ?>
652 + <br />
653 + <p><span style="color: #ff0000;"><?php _e('Page Filter is not registered', 'plf') ?></span></p>
654 + <?php
655 + }
532 656 ?>
533 - <br />
534 - <p><?php _e('Select the plugin from "Page Filter" registration to activate in each Page type.', 'plf') ?><br />
535 - <?php _e('Can be selected plugins to activate from Post content editing screen.', 'plf') ?>
536 - </p>
537 - <table width="100%" cellspacing="2" cellpadding="5" class="editform form-table">
538 - <tbody>
539 - <tr>
540 - <th valign="top" scope="row"><label for="plugintag"><?php _e( 'Page type', 'plf'); ?></label></th>
541 - <td><?php
542 - $slist = array('home' => __('Home/Front-page', 'plf'),
543 - 'archive' => __('Archive page', 'plf'),
544 - 'search' => __('Search page', 'plf'),
545 - 'attachment' => __('Attachment page', 'plf'),
546 - 'page' => __('Page', 'plf'),
547 - 'post' => __('Post : Standard', 'plf'),
548 - 'post-aside' => __('Post : Aside', 'plf'),
549 - 'post-image' => __('Post : Image', 'plf'),
550 - 'post-video' => __('Post : Video', 'plf'),
551 - 'post-quote' => __('Post : Quote', 'plf'),
552 - 'post-link' => __('Post : Link', 'plf'),
553 - 'post-gallery'=> __('Post : Gallery', 'plf'),
554 - 'post-status' => __('Post : Status', 'plf'),
555 - 'post-audio' => __('Post : Audio', 'plf'),
556 - 'post-chat' => __('Post : Chat', 'plf'));
557 - $post_types = get_post_types( array('public' => true, '_builtin' => false) );
558 - foreach ( $post_types as $post_type ) {
559 - if(!empty($post_type))
560 - $slist[$post_type] = __('Custom Post : ', 'plf') . $post_type;
561 - }
562 - echo self::dropdown('plf_option[tag]', $slist, $itemtag );
563 - ?>
564 - </td>
565 - </tr>
566 - <tr>
567 - <th valign="top" scope="row"><label for="plugin"><?php _e('Activate Plugins', 'plf'); ?>:</label></th>
568 - <td>
569 - <?php echo $this->pagefilter_plugins_checklist( $this->plugins_inf, $pgfilter, $option['plugins'] ); ?>
570 - </td>
571 - </tr>
572 - </tbody>
573 - </table>
574 - <p class="submit">
575 - <input type="submit" class="button-primary" name="clear_page_filter" value="<?php _e('Clear', 'plf'); ?>" />&nbsp;&nbsp;&nbsp;
576 - <input type="submit" class="button-primary" name="<?php echo $action ?>" value="<?php _e('Entry &raquo;', 'plf'); ?>" />
577 - </p>
578 657 </div>
579 658 </form>
580 659 </div>
581 660 <?php
@@ -585,30 +664,108 @@
585 664 * Meta box
586 665 * Individual of the plug-in filter meta box for Post/Page/CustomPost
587 666 **************************************************************************/
588 667 function load_meta_boxes( $post_type, $post ) {
589 - if ( current_user_can('edit_plugins', $post->ID) ) {
590 - add_meta_box( 'pluginfilterdiv', __( 'Page Filter Plugin', 'plf' ), array(&$this, 'plf_meta_box'), null, 'side' );
668 + if ( current_user_can('activate_plugins', $post->ID) ) {
669 + add_meta_box( 'pluginfilterdiv', __( 'Page Filter Plugin', 'plf' ), array(&$this, 'plf_meta_box'), null, 'side' );
591 670 add_action( 'admin_head', array(&$this, 'plf_css' ));
592 671 add_action( 'admin_footer', array(&$this, 'plf_meta_script' ));
593 672 }
594 673 }
595 674
675 + //Plugin pagefilter Selected Checkbox (plugin and modules list)
676 + // $p_key
677 + // $select_cvplugins : csv string : pagefilter selected plugins
678 + // $checked_arcvplugins : array csv string : ['desktop']=desktop enable plugins, ['mobile']=mobile enable plugins
679 + function _pagefilter_plugins_checklist( $p_key, $select_cvplugins, $checked_arcvplugins ) {
680 +
681 + $html = '';
682 + $selplugins = array_map("trim", explode(',', $select_cvplugins));
683 + $device['desktop'] = $checked_arcvplugins['desktop'];
684 + $device['mobile'] = $checked_arcvplugins['mobile'];
685 + $devlist = array('desktop','mobile');
686 + if(in_array( $p_key, $selplugins )){
687 + $p_name = $this->pluginkey_to_name($p_key);
688 + $html .= "<tr><td class='plugins-name'>$p_name</td>";
689 + foreach($devlist as $devtype){
690 + $checked = (empty($device[$devtype]) || false === strpos($device[$devtype], $p_key))? false : true;
691 + $html .= "<td class='device-type $devtype'>" . self::altcheckbox("plf_option[$devtype][$p_key]", $checked, '<span class="dashicons dashicons-yes"></span>') . '</td>';
692 + }
693 + $html .= "</tr>";
694 + }
695 + return $html;
696 + }
697 +
698 + //Plugin pagefilter Selected Checkbox (plugin and modules list)
699 + // $plugins : array : all active plugins
700 + // $select_cvplugins : csv string : pagefilter selected plugins
701 + // $checked_arcvplugins : array csv string : ['desktop']=desktop enable plugins, ['mobile']=mobile enable plugins
702 + function pagefilter_plugins_checklist( $plugins, $select_cvplugins, $checked_arcvplugins ) {
703 +
704 + if(empty($select_cvplugins))
705 + return __('Page Filter is not registered', 'plf');
706 +
707 + $html = '<table id="activation-table">';
708 + $html .= '<thead>';
709 + $html .= '<tr><th class="plugins-name">'. __('Plugins') . '</th>';
710 + $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>';
711 + $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>';
712 + $html .= '</tr>';
713 + $html .= '</thead>';
714 + $html .= '<tbody class="plugins-table-body meta-boxes-plugins-table">';
715 + $nplugins = $jmodules = $cmodules = array();
716 + foreach ( $plugins as $p_key => $p_data ) {
717 + $p_name = $this->pluginkey_to_name($p_key);
718 + if(empty($p_name))
719 + continue;
720 + if(strpos($p_key, 'jetpack_module/') !== false)
721 + $jmodules[] = $p_key;
722 + else if(strpos($p_key, 'celtispack_module/') !== false)
723 + $cmodules[] = $p_key;
724 + else
725 + $nplugins[] = $p_key;
726 + }
727 +
728 + foreach ( $nplugins as $p_key ) {
729 + if(strpos($p_key, 'jetpack/') !== false){
730 + foreach ( $jmodules as $p_key ) {
731 + $html .= $this->_pagefilter_plugins_checklist( $p_key, $select_cvplugins, $checked_arcvplugins );
732 + }
733 + }
734 + else if(strpos($p_key, 'celtispack/') !== false){
735 + foreach ( $cmodules as $p_key ) {
736 + $html .= $this->_pagefilter_plugins_checklist( $p_key, $select_cvplugins, $checked_arcvplugins );
737 + }
738 + }
739 + else {
740 + $html .= $this->_pagefilter_plugins_checklist( $p_key, $select_cvplugins, $checked_arcvplugins );
741 + }
742 + }
743 + $html .= '</tbody>';
744 + $html .= '</table>';
745 + return $html;
746 + }
747 +
596 748 function plf_meta_box( $post, $box ) {
597 749 if(is_object($post)){
598 - $default = array( 'filter' => 'default', 'plugins' => '');
599 750 $myfilter = get_post_meta( $post->ID, '_plugin_load_filter', true );
751 + //ver2.2.0 for compatibility, set 'plugins' data to 'desktop' and 'mobile'
752 + if(!empty($myfilter['plugins'])){
753 + $myfilter['desktop'] = $myfilter['plugins'];
754 + $myfilter['mobile'] = $myfilter['plugins'];
755 + unset($myfilter['plugins']);
756 + }
757 + $default = array( 'filter' => 'default', 'desktop' => '', 'mobile' => '');
600 758 $option = (!empty($myfilter))? $myfilter : $default;
601 759 $option = wp_parse_args( $option, $default);
760 + $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
602 761 $ajax_nonce = wp_create_nonce( 'plugin_load_filter-' . $post->ID );
603 - $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
604 762 ?>
605 763 <div id="plugin-filter-select">
606 764 <label><input type="radio" name="pagefilter" value="default" <?php checked('default', $option['filter']); ?>/><?php _e('Not Use', 'plf' ); ?></label>
607 765 <label><input type="radio" name="pagefilter" value="include" <?php checked('include', $option['filter']); ?>/><?php _e('Activate Plugins', 'plf'); ?></label>
608 - <br />
609 766 <div id="page-filter-stat">
610 - <?php echo $this->pagefilter_plugins_checklist( $this->plugins_inf, $pgfilter, $option['plugins'] ); ?>
767 + <?php echo $this->pagefilter_plugins_checklist( $this->plugins_inf, $pgfilter, $option ); ?>
611 768 </div>
612 769 <?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>'; ?>
613 770 </div>
614 771 <?php
@@ -618,33 +775,40 @@
618 775 //wp_ajax_plugin_load_filter called function
619 776 function plf_ajax_postidfilter() {
620 777 if ( isset($_POST['post_id']) ) {
621 778 $pid = (int) $_POST['post_id'];
622 - if ( !current_user_can( 'edit_plugins', $pid ) )
779 + if ( !current_user_can( 'activate_plugins', $pid ) )
623 780 wp_die( -1 );
624 781 check_ajax_referer( "plugin_load_filter-$pid" );
625 782
783 + $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
626 784 $option["filter"] = (empty($_POST['filter']))? 'default' : $_POST['filter'];
627 - $option["plugins"] = '';
628 - if('default' == $option["filter"])
785 + if('default' == $option["filter"]){
629 786 delete_post_meta( $pid, '_plugin_load_filter');
787 + }
630 788 else {
631 789 $plugins = array();
632 - if( preg_match_all('/plf_option\[plugins\]\[(.+?)\]/u', $_POST['plugins'], $matches)){
790 + if( preg_match_all('/plf_option\[desktop\]\[(.+?)\]/u', $_POST['desktop'], $matches)){
633 791 if(!empty($matches[1])){
634 792 foreach ($matches[1] as $plugin){
635 793 $plugins[] = $plugin;
636 794 }
637 - $option["plugins"] = implode(",", $plugins);
795 + $option["desktop"] = implode(",", $plugins);
638 796 }
639 797 }
798 + $plugins = array();
799 + if( preg_match_all('/plf_option\[mobile\]\[(.+?)\]/u', $_POST['mobile'], $matches)){
800 + if(!empty($matches[1])){
801 + foreach ($matches[1] as $plugin){
802 + $plugins[] = $plugin;
803 + }
804 + $option["mobile"] = implode(",", $plugins);
805 + }
806 + }
640 807 update_post_meta( $pid, '_plugin_load_filter', $option );
641 808 }
642 - //transient cache clear
643 - $this->plf_transient_clear();
644 809
645 - $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
646 - $html = $this->pagefilter_plugins_checklist( $this->plugins_inf, $pgfilter, $option['plugins'] );
810 + $html = $this->pagefilter_plugins_checklist( $this->plugins_inf, $pgfilter, $option );
647 811 wp_send_json_success($html);
648 812 }
649 813 wp_die( 0 );
650 814 }
@@ -662,13 +826,8 @@
662 826 <?php }
663 827
664 828 function plf_meta_script() { ?>
665 829 <script type='text/javascript' >
666 - WPAddPagePluginLoadFilter = function(nonce){
667 - jQuery.ajax({ type: 'POST', url: ajaxurl,
668 - 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',
669 - success: function(response, dataType) { jQuery('#page-filter-stat').html(response.data); }
670 - });
671 - return false; };
830 + 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; };
672 831 </script>
673 832 <?php }
674 833 }