PluginProbe
Plugin Load Filter / 4.4.0
Plugin Load Filter v4.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 +543 -421 3.3.04.4.0 View file →
@@ -1,16 +1,20 @@
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: 3.3.0
6 - Plugin URI: https://celtislab.net/wp_plugin_load_filter
5 + Version: 4.4.0
6 + Plugin URI: https://celtislab.net/en/wp-plugin-load-filter
7 7 Author: enomoto@celtislab
8 8 Author URI: https://celtislab.net/
9 + Requires at least: 6.3
10 + Tested up to: 7.0
11 + Requires PHP: 8.1
9 12 License: GPLv2
10 13 Text Domain: plf
11 14 Domain Path: /languages
12 15 */
16 +
13 17 defined( 'ABSPATH' ) || exit;
14 18
15 19 /***************************************************************************
16 20 * plugin activation / deactivation / uninstall
@@ -52,8 +56,9 @@
52 56
53 57 if ( !is_multisite()) {
54 58 delete_option('plf_queryvars');
55 59 delete_option('plf_option' );
60 + delete_option('plf_addon_options');
56 61 } else {
57 62 global $wpdb;
58 63 $current_blog_id = get_current_blog_id();
59 64 $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
@@ -60,8 +65,9 @@
60 65 foreach ( $blog_ids as $blog_id ) {
61 66 switch_to_blog( $blog_id );
62 67 delete_option('plf_queryvars');
63 68 delete_option('plf_option' );
69 + delete_option('plf_addon_options');
64 70 }
65 71 switch_to_blog( $current_blog_id );
66 72 }
67 73 if ( file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) {
@@ -75,10 +81,10 @@
75 81 $Plf_setting = new Plf_setting();
76 82
77 83 class Plf_setting {
78 84
79 - private $plugins_inf = ''; //active plugin/module infomation
80 - private $filter = array(); //filter option data
85 + static $plugins_inf = ''; //active plugin/module infomation
86 + static $filter = array(); //filter option data
81 87 private $tab_num = 0;
82 88
83 89 /***************************************************************************
84 90 * Style Sheet
@@ -87,10 +93,10 @@
87 93 <style type="text/css">
88 94 #plugin-filter-select {margin-top: 12px;}
89 95 #plugin-filter-select p {margin: 1em 0;}
90 96 #page-filter-stat { margin-top: 12px;}
91 - #activation-table { border: 1px solid #eee;}
92 - #activation-table th { font-size: 97%; text-align: center;}
97 + #activation-table { padding-bottom: 8px; border: 1px solid #eee;}
98 + #activation-table th { text-align: center;}
93 99 #activation-table td { font-size: 97%;}
94 100 #activation-table input[type=checkbox] { height: 25px; width: 25px; opacity: 0;}
95 101 #plf-post-locale-select { margin-top: 16px;}
96 102 thead .plugins-name { background-color: aliceblue;}
@@ -95,12 +101,13 @@
95 101 #plf-post-locale-select { margin-top: 16px;}
96 102 thead .plugins-name { background-color: aliceblue;}
97 103 thead .device-type { background-color: oldlace;}
98 104 thead .plugins-name, tbody .plugins-name { min-width: 144px; max-width: 200px; padding: 3px 3px 3px 5px;}
99 - thead .device-type, tbody .device-type { min-width: 40px; max-width: 40px; padding: 5px 1px 2px;}
105 + thead .device-type, tbody .device-type { min-width: 40px; max-width: 40px; text-align: center; padding: 5px 1px 2px;}
100 106 .dashicons-yes:before { font-size: 20px; border: 1px solid #eee; background-color: whitesmoke;}
101 - .device-type label { color: whitesmoke; margin-left: -28px; }
102 - .device-type input[type="checkbox"]:checked + label .dashicons-yes:before { background-color: yellowgreen; }
107 + .device-type label { color: whitesmoke; }
108 + input.altcheckbox[type="checkbox"] { -webkit-appearance: none; appearance: none; position: absolute;}
109 + .device-type input.altcheckbox[type="checkbox"]:checked + span.dashicons-yes:before { background-color: yellowgreen; }
103 110 .plf-option-info { font-size:12px; margin:10px 0; padding:3px; background-color:#fff8e5;}
104 111 .edit-post-locale-link span.dashicons { width: 0.8em; height: 0.8em; margin: -0.4em 0.1em 0; vertical-align: middle; text-decoration: initial;}
105 112 </style>
106 113 <?php }
@@ -126,16 +133,17 @@
126 133 .ui-state-active a, .ui-state-active a:link, .ui-state-active a:visited { color: #ffffff; text-decoration: none; }
127 134
128 135 #wrap_registration-table, #wrap_activation-table { overflow:auto; height:600px; position: relative;}
129 136 #registration-table input[type=radio], #registration-table input[type=checkbox], #activation-table input[type=checkbox] { height: 25px; width: 25px; opacity: 0;}
137 + #registration-table th {text-align: center;}
130 138 thead, tbody { display: block;}
131 139 .widefat * { word-wrap: break-word !important;}
132 140 .widefat thead { position:sticky; top:0px; z-index:1;}
133 141 .widefat tr:first-of-type th:first-of-type {position: sticky; left: 0px; text-align: left; background-color: aliceblue; z-index:3;}
134 - .widefat th { padding: 8px 2px 8px 6px;}
135 - .widefat td { padding: 8px 4px;}
142 + .widefat th { padding: 8px;}
143 + .widefat td { padding: 8px;}
136 144 .widefat td:first-of-type { position: sticky; left: 0px; text-align: left; background-color: white;}
137 - thead .filter-plugins-name, thead .plugins-name { background-color: aliceblue; }
145 + thead .filter-plugins-name, thead .plugins-name { background-color: aliceblue;}
138 146 thead .urlfilter { background-color: lavenderblush;}
139 147 .filter-none, .filter-admin, .filter-tmpl { background-color: honeydew;}
140 148 thead .device-type { background-color: oldlace;}
141 149 thead .ckbox-type { background-color: lavender;}
@@ -141,29 +149,30 @@
141 149 thead .ckbox-type { background-color: lavender;}
142 150 thead .pformat { background-color: honeydew;}
143 151 thead .tmpl-embed { background-color: lightyellow;}
144 152 thead .tmpl-custom { background-color: lavenderblush;}
145 - thead .filter-plugins-name, tbody .filter-plugins-name { min-width: 260px;}
153 + thead .filter-plugins-name, tbody .filter-plugins-name { min-width: 240px; max-width: 240px;}
146 154 thead .plugins-name, tbody .plugins-name { min-width: 180px; max-width: 180px;}
147 - thead .device-type, tbody .device-type, thead .ckbox-type, tbody .ckbox-type, thead .deny-type, tbody .deny-type { min-width: 40px; max-width: 40px; }
148 - thead .filter-type, tbody .filter-type { min-width: 56px; max-width: 56px;}
155 + thead .device-type, tbody .device-type, thead .ckbox-type, tbody .ckbox-type, thead .deny-type, tbody .deny-type { min-width: 40px; max-width: 40px; text-align: center;}
156 + thead .filter-type, tbody .filter-type { min-width: 56px; max-width: 56px; text-align:center;}
149 157 .urlfilter-description { padding: 0 10px 15px;}
150 - .filter-description { padding: 0 10px;}
151 - .exclude-pformat { padding: 5px 0 20px}
152 - .exclude-pformat label { white-space:nowrap;}
153 - .exclude-pformat span { margin-right: 12px; }
158 + .grid-row { display: flex; flex-flow: row wrap;}
159 + .filter-description { padding: 0 10px; width:62%;}
160 + .side-info { width: 30%; padding-left: 24px;}
161 + .ckbox-list { padding: 4px 0 12px}
162 + .ckbox-list label { white-space:nowrap;}
163 + .ckbox-list span { margin-right: 12px; }
154 164 .dashicons:before { font-size: 24px; }
155 - .radio-green label, .radio-red label, .ckbox-type label { color: #ddd; margin-left: -28px; }
156 - .radio-green input[type="radio"]:checked + label { color: #339966; }
157 - .radio-red input[type="radio"]:checked + label { color: tomato; }
158 - .ckbox-type input[type="checkbox"]:checked + label { color: #339966; }
159 - .dashicons-dismiss:before { background-color: yellowgreen; font-size: 20px; border-radius: 12px; }
160 - .deny-type label { color: yellowgreen; margin-left: -28px; }
161 - .deny-type input[type="checkbox"]:checked + label { color: tomato; }
165 + .radio-green label, .radio-red label { color: #ddd; margin-left: -32px; }
166 + .ckbox-type label { color: #ddd;}
167 + .radio-green input[type="radio"]:checked + span { color: #8bc34a; }
168 + .radio-red input[type="radio"]:checked + span { color: tomato; }
169 + .ckbox-type input[type="checkbox"]:checked + span { color: #4caf50; }
170 + .deny-type label { color: #4caf50;}
171 + .deny-type input.altcheckbox[type="checkbox"]:checked + span { color: #ddd; }
162 172 .dashicons-yes:before { font-size: 20px; border: 1px solid #eee; }
163 - .device-type label { color: whitesmoke; margin-left: -28px; }
164 - .device-type input[type="checkbox"]:checked + label .dashicons-yes:before { background-color: yellowgreen; }
165 - .language-option { margin-bottom: 28px; }
173 + .device-type input.altcheckbox[type="checkbox"]:checked + span.dashicons-yes:before { background-color: yellowgreen; }
174 + .option-item { margin-bottom: 28px; }
166 175 </style>
167 176 <?php }
168 177
169 178 /***************************************************************************
@@ -170,19 +179,18 @@
170 179 * Plugin Load Filter Option Setting
171 180 **************************************************************************/
172 181
173 182 public function __construct() {
174 -
175 - load_plugin_textdomain('plf', false, basename( dirname( __FILE__ ) ).'/languages' );
176 183
177 - $this->filter = get_option('plf_option');
178 - if(empty($this->filter['optver']) || $this->filter['optver'] < '2'){
179 - $this->filter['optver'] = '2';
184 + self::$filter = get_option('plf_option', array());
185 + if(empty(self::$filter['optver']) || self::$filter['optver'] < '2'){
186 + self::$filter['optver'] = '2';
180 187 //ここにデータフォーマットが変わった場合の変換処理を記述
181 188 }
182 - if(!empty($this->filter['language'])){
189 + if(!empty(self::$filter['language'])){
183 190 add_action( 'wp_head', array('Plf_setting', 'altenate_hreflang') );
184 191 }
192 +
185 193 if(is_admin()) {
186 194 add_action( 'plugins_loaded', array(&$this, 'plf_admin_start'), 9999 );
187 195 add_action( 'admin_init', array(&$this, 'action_posts'));
188 196 add_action( 'add_meta_boxes', array(&$this, 'load_meta_boxes'), 10, 2 );
@@ -193,47 +201,80 @@
193 201 //Plugin Load Filter admin setting start
194 202 public function plf_admin_start() {
195 203 require_once(ABSPATH . 'wp-admin/includes/plugin.php');
196 204
197 - $this->plugins_inf = get_plugins();
198 - $packplug = array();
199 - foreach ( $this->plugins_inf as $plugin_key => $a_plugin ) {
200 - if(is_plugin_inactive( $plugin_key )){
201 - unset($this->plugins_inf[$plugin_key]);
205 + self::$plugins_inf = get_plugins();
206 + //Ver4.0.0 でしか呼び出せないメソッドを呼び出さないよう新設した switch_theme があるかどうかで判定
207 + if(method_exists('Plf_filter', 'switch_theme')){
208 + if(class_exists('Plf_filter')){
209 + if ( is_multisite() )
210 + remove_filter('pre_site_option_active_sitewide_plugins', array('Plf_filter', 'active_sitewide_plugins'));
211 + remove_filter('pre_option_active_plugins', array('Plf_filter', 'active_plugins'));
202 212 }
203 - }
204 - //jetpack active module
205 - if(method_exists('Jetpack', 'get_module')){
206 - $modules = Jetpack::get_active_modules();
207 - $modules = array_diff( $modules, array( 'vaultpress' ) );
208 - foreach ( $modules as $key => $module_name ) {
209 - if(!empty($module_name)){
210 - $module = Jetpack::get_module( $module_name );
211 - if(!empty($module))
212 - $this->plugins_inf['jetpack_module/' . $module_name] = $module;
213 + foreach ( self::$plugins_inf as $plugin_key => $a_plugin ) {
214 + if(is_plugin_inactive( $plugin_key )){
215 + unset(self::$plugins_inf[$plugin_key]);
213 216 }
214 217 }
215 - }
216 - //celtispack active module
217 - if(method_exists('Celtispack', 'get_module')){
218 - $modules = Celtispack::get_active_modules();
219 - foreach ( $modules as $key => $module_name ) {
220 - if(!empty($module_name)){
221 - $this->plugins_inf['celtispack_module/' . $module_name] = Celtispack::get_module( $module_name );
218 + if(class_exists('Plf_filter')){
219 + if ( is_multisite() )
220 + add_filter('pre_site_option_active_sitewide_plugins', array('Plf_filter', 'active_sitewide_plugins'));
221 + add_filter('pre_option_active_plugins', array('Plf_filter', 'active_plugins'));
222 + }
223 +
224 + //jetpack active module
225 + if(method_exists('Jetpack', 'get_module')){
226 + if(class_exists('Plf_filter')){
227 + remove_filter('pre_option_jetpack_active_modules', array('Plf_filter', 'active_jetmodules'));
222 228 }
229 + $modules = Jetpack::get_active_modules();
230 + $modules = array_diff( $modules, array( 'vaultpress' ) );
231 + foreach ( $modules as $key => $module_name ) {
232 + if(!empty($module_name)){
233 + $module = Jetpack::get_module( $module_name );
234 + if(!empty($module))
235 + self::$plugins_inf['jetpack_module/' . $module_name] = $module;
236 + }
237 + }
238 + if(class_exists('Plf_filter')){
239 + add_filter('pre_option_jetpack_active_modules', array('Plf_filter', 'active_jetmodules'));
240 + }
223 241 }
242 + //celtispack active module
243 + if(method_exists('Celtispack', 'get_module')){
244 + if(class_exists('Plf_filter')){
245 + remove_filter('pre_option_celtispack_active_modules', array('Plf_filter', 'active_celtismodules'));
246 + }
247 + $modules = Celtispack::get_active_modules();
248 + foreach ( $modules as $key => $module_name ) {
249 + if(!empty($module_name)){
250 + self::$plugins_inf['celtispack_module/' . $module_name] = Celtispack::get_module( $module_name );
251 + }
252 + }
253 + if(class_exists('Plf_filter')){
254 + add_filter('pre_option_celtispack_active_modules', array('Plf_filter', 'active_celtismodules'));
255 + }
256 + }
257 + if ( empty( self::$plugins_inf ) )
258 + return;
224 259 }
225 - if ( empty( $this->plugins_inf ) )
226 - return;
227 260
228 261 add_action('admin_menu', array(&$this, 'plf_option_menu'));
229 262 }
230 263
264 + static function get_plugins_inf() {
265 + $inf = (!empty(self::$plugins_inf))? self::$plugins_inf : false;
266 + return $inf;
267 + }
268 +
231 269 //Plugins sub menu add
232 270 public function plf_option_menu() {
233 - $page = add_plugins_page( 'Plugin Load Filter', __('Plugin Load Filter', 'plf'), 'manage_options', 'plugin_load_filter_admin_manage_page', array(&$this,'plf_option_page'));
234 - add_action('admin_print_scripts-'.$page, array(&$this, 'plf_scripts'));
235 - add_action('admin_print_scripts-'.$page, array(&$this, 'deploy_mu_plugins'));
271 + if(current_user_can( 'activate_plugins' )){
272 + $page = add_menu_page( 'Plugin Load FIlter Settings', esc_html__('Plugin Load Filter', 'plf'), 'manage_options', 'plugin_load_filter_admin_manage_page', array(&$this, 'plf_option_page'), 'dashicons-filter', '65.1');
273 + add_submenu_page( 'plugin_load_filter_admin_manage_page', 'Plugin Load FIlter Settings', esc_html__('General Settings', 'plf'), 'manage_options', 'plugin_load_filter_admin_manage_page', array(&$this, 'plf_option_page') );
274 + add_action( 'admin_print_scripts-'.$page, array(&$this, 'plf_scripts') );
275 + add_action( 'admin_print_scripts-'.$page, array(&$this, 'deploy_mu_plugins'));
276 + }
236 277 }
237 278
238 279 //Plugin Load Filter setting page script
239 280 function plf_scripts() {
@@ -240,13 +281,12 @@
240 281 wp_enqueue_script( 'jquery' );
241 282 wp_enqueue_script( 'jquery-ui-core' );
242 283 wp_enqueue_script( 'jquery-ui-widget' );
243 284 wp_enqueue_script( 'jquery-ui-tabs' );
244 - wp_enqueue_script( 'postbox' );
245 285 add_action( 'admin_head', array(&$this, 'plf_css' ));
246 286 add_action( 'admin_head', array(&$this, 'jquery_tab_css' ));
247 287 add_action( 'admin_footer', array(&$this, 'activetab_script' ));
248 - add_action( 'admin_notices', array(&$this, 'plf_notice'));
288 + add_action( 'admin_notices', array('Plf_setting', 'plf_notice'));
249 289 }
250 290
251 291 //plf-filter.php mu-plugins module set
252 292 public function deploy_mu_plugins() {
@@ -265,12 +305,12 @@
265 305 }
266 306 }
267 307
268 308 //Notice Message display
269 - public function plf_notice() {
309 + static function plf_notice() {
270 310 $notice = get_transient('plf_notice');
271 311 if(!empty($notice)){
272 - echo "<div class='message error'><p>Plugin Load Filter : $notice</p></div>";
312 + echo '<div class="notice notice-warning"><p>Plugin Load Filter : ' . esc_html($notice) . '</p></div>';
273 313 delete_transient('plf_notice');
274 314 }
275 315 }
276 316
@@ -280,32 +320,41 @@
280 320 if( isset($_POST['edit_regist_filter']) ) {
281 321 if(isset($_POST['plfregist'])){
282 322 check_admin_referer('plugin_load_filter');
283 323 //url filter
284 - if(isset($_POST['plfurlkey'])){
285 - $urlkeys = array_keys($_POST['plfurlkey']);
286 - foreach( $urlkeys as $item){
287 - $plugins = array();
288 - foreach ( $_POST['plfurlkey'][$item] as $p_key => $val ) {
289 - if($val == '1')
290 - $plugins[] = $p_key;
324 + $groupkeys = (method_exists('Plf_filter', 'get_active_group'))? Plf_filter::get_active_group() : array();
325 + if(!empty($groupkeys) && isset($_POST['plfurlkey'])){
326 + $plfurlkey = $_POST['plfurlkey']; //array
327 + foreach( $groupkeys as $item){
328 + if(empty( $plfurlkey[$item])){
329 + self::$filter['plfurlkey'][$item]['plugins'] = '';
330 + } else {
331 + $plugins = array();
332 + foreach ( $plfurlkey[$item] as $p_key => $val ) {
333 + if($val == '1')
334 + $plugins[] = sanitize_text_field($p_key);
335 + }
336 + $option["plugins"] = implode(",", $plugins);
337 + self::$filter['plfurlkey'][$item] = $option;
291 338 }
292 - $option["plugins"] = implode(",", $plugins);
293 - $this->filter['plfurlkey'][$item] = $option;
294 339 }
295 340 }
296 341 //page type filter
297 342 foreach( array('_admin', '_pagefilter') as $item){
298 343 $plugins = array();
299 - foreach ( $_POST['plfregist'] as $p_key => $val ) {
300 - if($val == $item)
301 - $plugins[$p_key] = $val;
344 + $plfregist = $_POST['plfregist']; //array
345 + foreach ( $plfregist as $p_key => $val ) {
346 + if($val == $item){
347 + $p_key = sanitize_text_field($p_key);
348 + $plugins[$p_key] = sanitize_text_field($val);
349 + }
302 350 }
303 351 if($item == '_pagefilter'){
304 352 //If all modules is specified filter, in some cases you want to deactivate plugin itself.
305 353 $jbase = $cbase = '';
306 354 $jall = $call = true;
307 - foreach ( $_POST['plfregist'] as $p_key => $val ) {
355 + foreach ( $plfregist as $p_key => $val ) {
356 + $p_key = sanitize_text_field($p_key);
308 357 if(strpos($p_key, 'jetpack/') !== false)
309 358 $jbase = $p_key;
310 359 else if(strpos($p_key, 'celtispack/') !== false)
311 360 $cbase = $p_key;
@@ -324,103 +373,106 @@
324 373 if(!empty($cbase) && $call === false)
325 374 unset($plugins[$cbase]);
326 375 }
327 376 $option["plugins"] = implode(",", array_keys($plugins));
328 - $this->filter[$item] = $option;
377 + self::$filter[$item] = $option;
329 378 }
330 379 //exclude option
331 380 if(isset($_POST['plf_option']['exclude'])){
332 381 $exclude = array();
333 - foreach ( $_POST['plf_option']['exclude'] as $ft => $v ) {
334 - if(!empty($v))
382 + $optexcl = $_POST['plf_option']['exclude']; //array
383 + foreach ( $optexcl as $ft => $v ) {
384 + if(!empty($v)){
385 + $ft = sanitize_text_field($ft);
335 386 $exclude[$ft] = true;
387 + }
336 388 }
337 - $this->filter['exclude'] = $exclude;
389 + self::$filter['exclude'] = $exclude;
338 390 } else {
339 - $this->filter['exclude'] = array();
391 + self::$filter['exclude'] = array();
340 392 }
341 - //url filter keyword option
342 - //$items = array( 'amp', 'url_1', 'url_2', 'url_3' );
343 - $items = array( 'amp' );
344 - foreach ($items as $key) {
345 - $url_key = (isset($_POST['plf_option'][$key]))? $_POST['plf_option'][$key] : '';
346 - if(empty($url_key) || preg_match('#\A([a-zA-Z0-9_\-/\.\?=%]+)\Z#u', $url_key)){
347 - $this->filter['urlkey'][$key] = $url_key;
348 - } else {
349 - $notice = __('There are invalid characters in Keyword. Use characters include Alphanumeric, Hyphens, Underscores, slash, dot, question, equal, percent sign','plf');
350 - set_transient('plf_notice', $notice, 30);
393 +
394 + //hide singlr post filter for custom post type
395 + if(isset($_POST['plf_option']['hidecpt'])){
396 + $hidecpt = array();
397 + $optcpt = $_POST['plf_option']['hidecpt']; //array
398 + foreach ( $optcpt as $ft => $v ) {
399 + if(!empty($v)){
400 + $ft = sanitize_text_field($ft);
401 + $hidecpt[$ft] = true;
402 + }
351 403 }
404 + self::$filter['hidecpt'] = $hidecpt;
405 + } else {
406 + self::$filter['hidecpt'] = array();
352 407 }
353 - //trim & 空行 & 重複キー削除を行ってPHP_EOL 区切りの文字列へ戻す
354 - $keylist = (!empty($_POST['plf_option']['urlkeylist'])) ? stripslashes_from_strings_only(trim($_POST['plf_option']['urlkeylist'])) : '';
355 - $ar_key = (!empty($keylist))? array_filter( array_map("trim", explode(PHP_EOL, $keylist))) : array();
356 - if(!empty($ar_key)) {
357 - $ar_new = array();
358 - foreach ($ar_key as $key) {
359 - if(!in_array($key, $ar_new)){
360 - if(empty($key) || preg_match('#\A([a-zA-Z0-9_\-/\.\?=%]+)\Z#u', $key)){
361 - $ar_new[] = $key;
362 - } else {
363 - $notice = __('There are invalid characters in Keyword. Use characters include Alphanumeric, Hyphens, Underscores, slash, dot, question, equal, percent sign','plf');
364 - set_transient('plf_notice', $notice, 30);
365 - }
366 - }
367 - }
368 - $ar_key = $ar_new;
369 - }
370 - $this->filter['urlkeylist'] = (!empty($ar_key))? implode(PHP_EOL, $ar_key) : '';
371 408
409 + //admin bar (filtered stat)
410 + self::$filter['admin_bar'] = (isset($_POST['plf_option']['admin_bar']))? 1 : 0;
411 +
372 412 //Language option
373 - $this->filter['language'] = (isset($_POST['plf_option']['language']))? 1 : 0;
413 + self::$filter['language'] = (isset($_POST['plf_option']['language']))? 1 : 0;
374 414
375 - update_option('plf_option', $this->filter );
415 + //Ajax acceleration plugin filter (for plugin developers)
416 + self::$filter['ajax_accelfilter'] = (isset($_POST['plf_option']['ajax_accelfilter']))? 1 : 0;
417 +
418 + update_option('plf_option', self::$filter, 'no' );
376 419 }
377 420 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page'));
378 421 exit;
379 - }
380 - elseif( isset($_POST['clear_regist_filter']) ) {
422 +
423 + } elseif( isset($_POST['clear_regist_filter']) ) {
381 424 check_admin_referer('plugin_load_filter');
382 - if(!empty($this->filter['plfurlkey'])){
383 - foreach ($this->filter['plfurlkey'] as $key => $val) {
384 - unset($this->filter['plfurlkey'][$key]);
425 + if(!empty(self::$filter['plfurlkey'])){
426 + foreach (self::$filter['plfurlkey'] as $key => $val) {
427 + unset(self::$filter['plfurlkey'][$key]);
385 428 }
386 429 }
387 430 foreach( array('_admin', '_pagefilter') as $item){
388 - $this->filter[$item] = array();
431 + self::$filter[$item] = array();
389 432 }
390 - $this->filter['exclude'] = array();
391 - $this->filter['urlkey'] = array();
392 - $this->filter['urlkeylist'] = '';
393 - $this->filter['language'] = 0;
394 - update_option('plf_option', $this->filter );
433 + self::$filter['exclude'] = array();
434 + self::$filter['hidecpt'] = array();
435 +
436 + //old data unset
437 + if(isset(self::$filter['urlkey'])){
438 + unset(self::$filter['urlkey']);
439 + }
440 + if(isset(self::$filter['urlkeylist'])){
441 + unset(self::$filter['urlkeylist']);
442 + }
443 +
444 + self::$filter['admin_bar'] = 0;
445 + self::$filter['language'] = 0;
446 + self::$filter['ajax_accelfilter'] = 0;
447 + update_option('plf_option', self::$filter, 'no' );
395 448 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page'));
396 449 exit;
397 - }
398 - else if(isset($_POST['edit_activate_page_filter']) ) {
450 +
451 + } else if(isset($_POST['edit_activate_page_filter']) ) {
399 452 if(isset($_POST['plfactive'])){
400 453 check_admin_referer('plugin_load_filter');
401 - $group = array_keys($_POST['plfactive']);
454 + self::$filter['group'] = array();
455 + $plfactive = $_POST['plfactive']; //array
456 + $group = array_keys($plfactive);
402 457 foreach( $group as $item){
403 458 $plugins = array();
404 - foreach ( $_POST['plfactive'][$item] as $p_key => $val ) {
459 + foreach ( $plfactive[$item] as $p_key => $val ) {
405 460 if($val == '1')
406 - $plugins[] = $p_key;
407 - }
461 + $plugins[] = sanitize_text_field($p_key);
462 + }
408 463 $option["plugins"] = implode(",", $plugins);
409 - $this->filter['group'][$item] = $option;
464 + self::$filter['group'][$item] = $option;
410 465 }
411 - update_option('plf_option', $this->filter );
466 + update_option('plf_option', self::$filter, 'no' );
412 467 }
413 468 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page&action=tab_1'));
414 469 exit;
415 - }
416 - elseif( isset($_POST['clear_activate_page_filter']) ) {
470 +
471 + } elseif( isset($_POST['clear_activate_page_filter']) ) {
417 472 check_admin_referer('plugin_load_filter');
418 - $group = array_keys($_POST['plfactive']);
419 - foreach( $group as $item){
420 - $this->filter['group'][$item] = array();
421 - }
422 - update_option('plf_option', $this->filter );
473 + self::$filter['group'] = array();
474 + update_option('plf_option', self::$filter, 'no' );
423 475 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page&action=tab_1'));
424 476 exit;
425 477 }
426 478 if(!empty($_GET['action']) && $_GET['action']=='tab_1') {
@@ -430,58 +482,133 @@
430 482 }
431 483
432 484 //Plugin or Module key to name
433 485 // $type : list/smart/tree
434 - public function pluginkey_to_name( $infkey, $type='list') {
435 -
486 + static function pluginkey_to_name( $infkey, $type='list') {
436 487 $name = '';
437 488 if(strpos($infkey, 'jetpack_module/') !== false){
438 - if(!empty($this->plugins_inf[$infkey]['name'])){
489 + if(!empty(self::$plugins_inf[$infkey]['name'])){
439 490 $m_mark = ($type !== 'list')? '-' : 'Jetpack-';
440 491 if($type === 'smart') {
441 - if(empty($this->filter['_pagefilter']['plugins']) || strpos($this->filter['_pagefilter']['plugins'], 'jetpack/') === false)
442 - $name = $m_mark . $this->plugins_inf[$infkey]['name'];
492 + if(empty(self::$filter['_pagefilter']['plugins']) || strpos(self::$filter['_pagefilter']['plugins'], 'jetpack/') === false)
493 + $name = $m_mark . self::$plugins_inf[$infkey]['name'];
494 + } else {
495 + $name = $m_mark . self::$plugins_inf[$infkey]['name'];
443 496 }
444 - else
445 - $name = $m_mark . $this->plugins_inf[$infkey]['name'];
446 497 }
447 - }
448 - elseif(strpos($infkey, 'celtispack_module/') !== false){
449 - if(!empty($this->plugins_inf[$infkey]['Name'])){
498 + } elseif(strpos($infkey, 'celtispack_module/') !== false){
499 + if(!empty(self::$plugins_inf[$infkey]['Name'])){
450 500 $m_mark = ($type !== 'list')? '-' : 'Celtispack-';
451 501 if($type === 'smart') {
452 - if(empty($this->filter['_pagefilter']['plugins']) || strpos($this->filter['_pagefilter']['plugins'], 'celtispack/') === false)
453 - $name = $m_mark . $this->plugins_inf[$infkey]['Name'];
502 + if(empty(self::$filter['_pagefilter']['plugins']) || strpos(self::$filter['_pagefilter']['plugins'], 'celtispack/') === false)
503 + $name = $m_mark . self::$plugins_inf[$infkey]['Name'];
504 + } else {
505 + $name = $m_mark . self::$plugins_inf[$infkey]['Name'];
454 506 }
455 - else
456 - $name = $m_mark . $this->plugins_inf[$infkey]['Name'];
457 507 }
508 + } else {
509 + if(!empty(self::$plugins_inf[$infkey]['Name']))
510 + $name = self::$plugins_inf[$infkey]['Name'];
458 511 }
459 - else {
460 - if(!empty($this->plugins_inf[$infkey]['Name']))
461 - $name = $this->plugins_inf[$infkey]['Name'];
462 - }
463 512 return($name);
464 513 }
465 514
466 - //Checkbox
515 + // wp_kses() サニタイズで form,input,select タグを許可
516 + public static function get_allowed_tags() {
517 + global $allowedposttags;
518 + $allowed_tags = $allowedposttags;
519 + $allowed_tags['form'] = array( 'action' => true, 'accept' => true, 'accept-charset' => true, 'enctype' => true, 'method' => true, 'name' => true, 'target' => true );
520 + $allowed_tags['label'] = array( 'for' => true );
521 + $allowed_tags['input'] = array( 'type' => true, 'name' => true, 'value' => true, 'checked' => true);
522 + $allowed_tags['select'] = array( 'name' => true, 'multiple' => true );
523 + $allowed_tags['option'] = array( 'value' => true, 'selected' => true );
524 + $allowed_tags['button'] = array( 'href' => true, 'onclick' => true);
525 + $allowed_tags['a']['onclick'] = true;
526 + $allowed_tags = array_map( '_wp_add_global_attributes', $allowed_tags );
527 + return $allowed_tags;
528 + }
529 + //Checkbox for addon
467 530 static function checkbox($name, $value, $label = '') {
468 531 return "<label><input type='checkbox' name='$name' value='1' " . checked( $value, 1, false ). "/> $label</label>";
469 532 }
470 533 static function altcheckbox($name, $value, $label = '') {
471 - return "<input type='hidden' name='$name' value='0'><input type='checkbox' name='$name' value='1' " . checked( $value, 1, false ). "/><label> $label</label>";
534 + return "<label><input type='checkbox' name='$name' class='altcheckbox' value='1' " . checked( $value, 1, false ). "/> $label</label>";
472 535 }
473 536
537 + //dropdown list for addon
538 + static function dropdown($name, $items, $selected, $args = null, $display = false) {
539 + $defaults = array(
540 + 'id' => $name,
541 + 'none' => false,
542 + 'class' => null,
543 + 'multiple' => false,
544 + );
545 +
546 + if (!is_array($items))
547 + return;
548 +
549 + if (empty($items))
550 + $items = array();
551 +
552 + // Items is in key => value format. If value is itself an array, use only the 1st column
553 + foreach ($items as $key => &$value) {
554 + if (is_array($value))
555 + $value = array_shift($value);
556 + }
557 +
558 + extract(wp_parse_args($args, $defaults));
559 +
560 + // If 'none' arg provided, prepend a blank entry
561 + if ($none) {
562 + if ($none === true)
563 + $none = '&nbsp;';
564 + $items = array('' => $none) + $items; // Note that array_merge() won't work because it renumbers indexes!
565 + }
566 +
567 + if (!$id)
568 + $id = $name;
569 +
570 + $name = ($name) ? ' name="' . esc_html($name) . '"' : '';
571 + $id = ($id) ? ' id="' . esc_html($id) . '"' : '';
572 + $class = ($class)? ' class="'. esc_html($class). '"' : '';
573 + $multiple = ($multiple) ? ' multiple="multiple"' : '';
574 +
575 + $html = '<select' . $name . $id . $class . $multiple .'>';
576 + foreach ((array) $items as $key => $label) {
577 + $html .= '<option value="' . esc_html($key) . '" ' . selected($selected, $key, false) . '>' . esc_html($label) . '</option>';
578 + }
579 + $html .= '</select>';
580 + if($display){
581 + echo wp_kses( $html, array(
582 + 'select' => array( 'name' => true, 'id' => true, 'class' => true, 'multiple' => true ),
583 + 'option' => array( 'value' => true, 'selected' => true )
584 + ));
585 + } else {
586 + return $html;
587 + }
588 + }
589 +
590 + //安全な文字列から指定タグのみデコード(既存の翻訳ファイルへ影響せずにエスケープするために使用)
591 + //&lt;strong&gt;Type&lt;/strong&gt -> <strong>Type</strong>
592 + static function decode_safe_tag_e( $tag, $safe_str ) {
593 + $safe_str = preg_replace_callback( "|&lt;($tag.*)&gt;(.*)&lt;/($tag)&gt;|im", function($matches){
594 + $tag_attrs = str_replace( '&quot;', '"', $matches[1]);
595 + return '<' . $tag_attrs . '>' . $matches[2] . '</' . $matches[3] . '>';
596 + }, $safe_str);
597 + echo wp_kses_post($safe_str);
598 + }
599 +
474 600 public function plfregist_item($key, $chklist, $filter) {
475 - $p_name = $this->pluginkey_to_name($key);
601 + $p_name = self::pluginkey_to_name($key);
476 602 $opt_name = "plfregist[$key]";
477 603 ?>
478 - <tr id="plfregist_<?php echo $key; ?>">
479 - <td class="filter-plugins-name"><?php echo $p_name; ?></td>
604 + <tr id="plfregist_<?php echo esc_html($key); ?>">
605 + <td class="filter-plugins-name"><?php echo esc_html($p_name); ?></td>
480 606 <?php
481 607 foreach($chklist as $urlkey){
608 + $name = "plfurlkey[$urlkey][$key]";
482 609 $checked = (empty($filter['plfurlkey'][$urlkey]['plugins']) || false === strpos($filter['plfurlkey'][$urlkey]['plugins'], $key))? false : true;
483 - echo '<td class="deny-type filter-type">' . self::altcheckbox("plfurlkey[$urlkey][$key]", $checked, '<span class="dashicons dashicons-admin-plugins"></span>') . '</td>';
610 + echo '<td class="deny-type filter-type"><label><input type="checkbox" name="' . esc_html($name) . '" class="altcheckbox" value="1" ' . checked( $checked, 1, false ). '/> <span class="dashicons dashicons-admin-plugins"></span></label></td>';
484 611 }
485 612 $radio = '';
486 613 if(!empty($filter['_admin']['plugins']) && false !== strpos($filter['_admin']['plugins'], $key))
487 614 $radio = '_admin';
@@ -487,11 +614,11 @@
487 614 $radio = '_admin';
488 615 else if(!empty($filter['_pagefilter']['plugins']) && false !== strpos($filter['_pagefilter']['plugins'], $key))
489 616 $radio = '_pagefilter';
490 617 ?>
491 - <td class="radio-green filter-type"><input type="radio" name="<?php echo $opt_name; ?>" value='' <?php checked('', $radio); ?>/><label><span class="dashicons dashicons-admin-plugins"></span></label></td>
492 - <td class="radio-red filter-type"><input type="radio" name="<?php echo $opt_name; ?>" value="_admin" <?php checked('_admin', $radio); ?>/><label><span class="dashicons dashicons-admin-plugins"></span></label></td>
493 - <td class="radio-red filter-type"><input type="radio" name="<?php echo $opt_name; ?>" value="_pagefilter" <?php checked('_pagefilter', $radio); ?>/><label><span class="dashicons dashicons-admin-plugins"></span></label></td>
618 + <td class="radio-green filter-type"><label><input type="radio" name="<?php echo esc_html($opt_name); ?>" value='' <?php checked('', $radio); ?>/><span class="dashicons dashicons-admin-plugins"></span></label></td>
619 + <td class="radio-red filter-type"><label><input type="radio" name="<?php echo esc_html($opt_name); ?>" value="_admin" <?php checked('_admin', $radio); ?>/><span class="dashicons dashicons-admin-plugins"></span></label></td>
620 + <td class="radio-red filter-type"><label><input type="radio" name="<?php echo esc_html($opt_name); ?>" value="_pagefilter" <?php checked('_pagefilter', $radio); ?>/><span class="dashicons dashicons-admin-plugins"></span></label></td>
494 621 </tr>
495 622 <?php
496 623 }
497 624
@@ -501,43 +628,73 @@
501 628 <div id="wrap_registration-table">
502 629 <table id="registration-table" class="widefat">
503 630 <thead>
504 631 <?php
505 - //$items = array( 'amp' => 'AMP filter', 'url_1' => 'URL filter1', 'url_2' => 'URL filter2', 'url_3' => 'URL filter3' );
506 - $items = array( 'amp' => 'AMP filter' );
507 - $urlnum = 3;
508 - foreach ($items as $key => $label) {
509 - if(!empty($filter['urlkey'][$key]))
510 - $urlnum++;
511 - }
512 - $urlkey = (!empty($filter['urlkeylist']))? array_filter( array_map("trim", explode(PHP_EOL, $filter['urlkeylist']))) : array();
513 - $urlnum += count($urlkey);
632 + $groupkeys = (method_exists('Plf_filter', 'get_active_group'))? Plf_filter::get_active_group() : array();
633 + $urlnum = count($groupkeys);
514 634 ?>
515 635 <tr>
516 - <th class="filter-plugins-name" rowspan="2"><?php _e('Plugins'); ?></th>
517 - <th class="urlfilter" colspan="<?php echo $urlnum; ?>" style="font-weight:bold; font-size:smaller;"><?php _e('URL Filter for Expert', 'plf'); ?></th>
518 - <th class="filter-type filter-tmpl" colspan="3" style="font-weight:bold; font-size:smaller;"><?php _e('Page Type Filter', 'plf'); ?></th>
636 + <th class="filter-plugins-name" rowspan="2"><?php esc_html_e('Plugins', 'plf'); ?></th>
637 + <?php if($urlnum > 0) { ?>
638 + <th class="filter-type urlfilter" colspan="<?php echo esc_html($urlnum); ?>" style="font-weight:bold; font-size:smaller;"><?php esc_html_e('URL Group Filter', 'plf'); ?></th>
639 + <?php } ?>
640 + <th class="filter-type filter-tmpl" colspan="3" style="font-weight:bold; font-size:smaller;"><?php esc_html_e('Page Type Filter', 'plf'); ?></th>
519 641 </tr>
520 642 <tr>
521 - <th class="filter-type urlfilter"><span title="REST API filter Keyword : wp-json" style='font-size:smaller'><?php _e('REST API', 'plf'); ?></span></th>
522 - <th class="filter-type urlfilter"><span title="Heartbeat filter Keyword : admin-ajax(heartbeat)" style='font-size:smaller'><?php _e('Heartbeat', 'plf'); ?></span></th>
523 - <th class="filter-type urlfilter"><span title="Ajax filter Keyword : admin-ajax" style='font-size:smaller'><?php _e('Ajax', 'plf'); ?></span></th>
524 - <?php
525 - foreach ($items as $key => $label) {
526 - if(!empty($filter['urlkey'][$key])){
527 - $title = "$label Keyword : " . $filter['urlkey'][$key];
528 - echo "<th class='filter-type urlfilter'><span title='$title' style='font-size:smaller'>{$filter['urlkey'][$key]}</span></th>";
643 + <?php //Addon URL filter group key
644 + if($urlnum > 0) {
645 + foreach ( $groupkeys as $v) {
646 + $_flt = (method_exists('Plf_filter', 'get_slug_filter'))? Plf_filter::get_slug_filter( $v ) : array();
647 + $hint = '';
648 + foreach ($_flt as $_v) {
649 + $hint .= '[' . $_v['slug'] . '] ' . $_v['summary'] . PHP_EOL;
650 +
651 + if((int)$_v['targetpage'] === 1) {
652 + $post_type = (!empty($_v['post_type']))? $_v['post_type'] : '';
653 + $taxonomy = '';
654 + if(!empty($_v['taxonomies']) && !empty($_v['term'])){
655 + $taxonomy = " : {$_v['taxonomies']}({$_v['term']})";
656 + }
657 + if(!empty($post_type)){
658 + $hint .= 'Singular (' . $post_type . ')' . $taxonomy . PHP_EOL;
659 + } else {
660 + $hint .= 'Singular ' . $taxonomy . PHP_EOL;
661 + }
662 + } elseif((int)$_v['targetpage'] === 2) {
663 + if(!empty($_v['ajax_action'])){
664 + $hint .= 'Ajax request (' . $_v['ajax_action'] . ')' . PHP_EOL;
665 + } else {
666 + $hint .= 'Ajax request' . PHP_EOL;
667 + }
668 + }
669 +
670 + $hint .= 'url filter : ';
671 + $urlkey = (!empty($_v['url_path']))? array_filter( array_map("trim", explode(PHP_EOL, $_v['url_path']))) : array();
672 + if(!empty($urlkey)){
673 + foreach ($urlkey as $key) {
674 + $hint .= $key . ' ';
675 + }
676 + }
677 + $urlkey = (!empty($_v['url_q_and']))? array_filter( array_map("trim", explode(PHP_EOL, $_v['url_q_and']))) : array();
678 + if(!empty($urlkey)){
679 + foreach ($urlkey as $key) {
680 + $hint .= ' AND ' . $key;
681 + }
682 + }
683 + $urlkey = (!empty($filter['url_q_not']))? array_filter( array_map("trim", explode(PHP_EOL, $filter['url_q_not']))) : array();
684 + if(!empty($urlkey)){
685 + foreach ($urlkey as $key) {
686 + $hint .= ' NOT ' . $key;
687 + }
688 + }
689 + $hint .= PHP_EOL . PHP_EOL;
690 + }
691 + echo '<th class="filter-type urlfilter"><span title="' . esc_html($hint) . '" style="font-size:smaller">' . esc_html($v) . '</span></th>';
529 692 }
530 - }
531 - //汎用URLフィルタータイトル表示
532 - foreach ($urlkey as $key) {
533 - $title = "URL filter Keyword : " . $key;
534 - echo "<th class='filter-type urlfilter'><span title='$title' style='font-size:smaller'>{$key}</span></th>";
535 - }
536 - ?>
537 - <th class="filter-type filter-none"><span style="font-size:smaller"><?php _e('Normal Mode', 'plf'); ?></span></th>
538 - <th class="filter-type filter-admin"><span style="font-size:smaller"><?php _e('Admin Page', 'plf'); ?></span></th>
539 - <th class="filter-type filter-tmpl"><span style="font-size:smaller"><?php _e('Page Type', 'plf'); ?></span></th>
693 + } ?>
694 + <th class="filter-type filter-none"><span style="font-size:smaller"><?php esc_html_e('Normal', 'plf'); ?></span></th>
695 + <th class="filter-type filter-admin"><span style="font-size:smaller"><?php esc_html_e('Admin Type', 'plf'); ?></span></th>
696 + <th class="filter-type filter-tmpl"><span style="font-size:smaller"><?php esc_html_e('Page Type', 'plf'); ?></span></th>
540 697 </tr>
541 698 </thead>
542 699 <tbody class="plugins-table-body">
543 700 <?php
@@ -543,9 +700,9 @@
543 700 <?php
544 701 //plugins filter registoration table
545 702 $plist = array();
546 703 foreach ( $plugins as $p_key => $val ) {
547 - $name = $this->pluginkey_to_name($p_key);
704 + $name = self::pluginkey_to_name($p_key);
548 705 if(!empty($name))
549 706 $plist[$p_key] = '';
550 707 }
551 708 $jlist = $clist = array();
@@ -558,18 +715,15 @@
558 715 $clist[$p_key] = $plist[$p_key];
559 716 unset($plist[$p_key]);
560 717 }
561 718 }
562 - $chklist = array('wp-json','heartbeat','admin-ajax');
563 - foreach ($items as $key => $label) {
564 - if(!empty($filter['urlkey'][$key])){
719 + //Addon URL filter group key
720 + $chklist = array();
721 + if($urlnum > 0) {
722 + foreach ( $groupkeys as $key) {
565 723 $chklist[] = $key;
566 724 }
567 725 }
568 - //汎用URLフィルタータイトル表示
569 - foreach ($urlkey as $key) {
570 - $chklist[] = $key;
571 - }
572 726
573 727 foreach ( $plist as $p_key => $val ) {
574 728 $modules = array();
575 729 if(strpos($p_key, 'jetpack/') !== false)
@@ -578,9 +732,9 @@
578 732 $modules = $clist;
579 733 else
580 734 $this->plfregist_item($p_key, $chklist, $filter);
581 735 if(!empty($modules)){
582 - echo "<input type='hidden' name='plfregist[$p_key]' value='_pagefilter'>";
736 + echo '<input type="hidden" name="plfregist[' . esc_html($p_key) . ']" value="_pagefilter">';
583 737 foreach ( $modules as $m_key => $val) {
584 738 $this->plfregist_item($m_key, $chklist, $filter);
585 739 }
586 740 }
@@ -588,126 +742,97 @@
588 742 ?>
589 743 </tbody>
590 744 </table>
591 745 </div>
592 - <br />
593 -
594 - <div style="background-color: #fbf7dc; padding: 10px; margin: 20px 0;" >
595 - <p><strong><?php _e('Information about the URL Filter for Experts', 'plf')?></strong></p>
596 - <p><?php _e('From the next version, URL Filter for Expert will be removed from the standard feature and will be available as a new Add-on', 'plf')?></p>
597 - </div>
598 -
599 - <p><strong>[ URL Filter for Expert ]</strong></p>
600 - <div class="urlfilter-description">
601 - <p><?php _e('Normally all are active. It is used when there is a plugin that you want to deactive specially for requests such as REST API, Ajax, AMP, etc.', 'plf'); ?></p>
602 - <p><?php _e('REST API / Ajax / AMP / URL page judgment is done from REQUEST URI with regular expressions including keyword. <code>(/|&|\.|\?|=)keyword(/|&|\.|\?|=|$)</code>', 'plf'); ?><br />
603 - <?php _e('AMP / URL Setting the keyword enables the filter. [Valid characters: alphanumeric characters, hyphens (-), underscores (_), slash (/), dot(.), question(?), equal(=), percent sign(%) ]', 'plf'); ?></p>
604 - <p><span style='background-color: #fbf7dc; padding: 2px;'>
605 - <?php _e('AMP keyword filter', 'plf')?>
606 - </span></p>
746 + <p></p>
747 + <div class="grid-row">
748 + <div class="filter-description">
749 + <p><strong>[ <?php esc_html_e('Page Type Filter', 'plf'); ?> ]</strong></p>
750 + <?php self::decode_safe_tag_e( 'strong', esc_html__('<strong>Normal</strong> - Exclude plugin from Page Type filter', 'plf')); ?><br />
751 + <?php self::decode_safe_tag_e( 'strong', esc_html__('<strong>Admin Type</strong> - If you only use plugins for Admin pages.', 'plf')); ?><br />
752 + <?php self::decode_safe_tag_e( 'strong', esc_html__('<strong>Page Type</strong> - If you want to activate or deactivate plugins for each Page Type and Single page.', 'plf')); ?>
753 + <p>
607 754 <?php
608 - $items = array( 'amp' => __('In many cases, it is identified with "amp". (*AMP page display requires AMP plugin or theme)', 'plf') );
609 - $html = "";
610 - foreach ($items as $key => $label) {
611 - $html .= "<div>";
612 - $val = (!empty($this->filter['urlkey'][$key]))? $this->filter['urlkey'][$key] : '';
613 - $html .= "<input id='plf_option[$key]' class='medium-text' type='text' name='plf_option[$key]' value='$val' />";
614 - $html .= "<label style='margin-left:10px;'>$label</label>";
615 - $html .= "</div>";
616 - }
617 - echo $html;
618 - $urlkeylist = (!empty($this->filter['urlkeylist']))? esc_textarea($this->filter['urlkeylist']): '';
755 + $checked = (!empty(self::$filter['admin_bar']))? self::$filter['admin_bar'] : false;
756 + echo '<span class="admin-bar-option"><label><input type="checkbox" name="plf_option[admin_bar]" value="1" ' . checked( $checked, 1, false ) . '/> ' . esc_html__('Add a link to admin bar for displaying the plugins filtered status', 'plf') . '</label></span>';
619 757 ?>
620 - <p><span style='background-color: #fbf7dc; padding: 2px;'><?php _e('URL keyword filter (Register URL matching judgment keywords separated by line breaks)', 'plf'); ?></span></p>
621 - <div><textarea name="plf_option[urlkeylist]" rows="10" cols="30" id="urlkeylist" class="medium-text code"><?php echo $urlkeylist; ?></textarea></div>
622 - </div>
623 -
624 - <p><strong>[ Page Type Filter ]</strong></p>
625 - <div class="filter-description"><p><strong> Normal Mode</strong><br /><?php _e('Plugins load without Page Type Filtering.', 'plf'); ?></p></div>
626 - <div class="filter-description"><p><strong> Admin Page</strong><br /><?php _e('Plugins to be used only in admin page.', 'plf'); ?></p></div>
627 - <div class="filter-description"><p><strong> Page Type</strong><br />
628 - <?php _e('Plugins for selecting whether to activate each Page type or Post.', 'plf'); ?><br />
629 - <?php _e('Selected page type filter plugins are once blocked, but is activated by "Page Type filter Activation" setting.', 'plf'); ?></p>
630 - <div class="exclude-pformat">
631 - <p><strong><?php _e( 'Exclude Post Format Type', 'plf' ); ?></strong><br />
632 - <?php _e('Choose Post Format Type you are not using. To exclude from Page Type Filter item subject.', 'plf'); ?>
633 - </p>
634 - <?php
635 - $html = '<div>';
758 + </p>
759 + <p><?php esc_html_e('* Plugins with `Page Type Filter` selected are blocked, but you can Activate it for various Page type in the `Page Type Activation` and Single Page setting.', 'plf'); ?></p>
760 + <div class="ckbox-list">
761 + <p><?php self::decode_safe_tag_e( 'strong', esc_html__('<strong>Exclude Post Format Type</strong> - Choose Post Format Type you are not using. To exclude from Page Type item subject.', 'plf')); ?></p>
762 + <div>
763 + <?php
636 764 $pformat = array('image', 'gallery', 'video', 'audio', 'aside', 'status', 'quote', 'link', 'chat' );
637 765 foreach ( $pformat as $type ) {
638 - $checked = (!empty($this->filter['exclude'][$type]))? $this->filter['exclude'][$type] : false;
639 - $label = "<span>$type</span>";
640 - $html .= self::checkbox("plf_option[exclude][$type]", $checked, $label);
766 + $check = !empty(self::$filter['exclude'][$type])? true : false;
767 + ?>
768 + <label><input type="checkbox" name="<?php echo esc_html("plf_option[exclude][$type]"); ?>" <?php checked($check); ?>/> <span><?php echo esc_html($type); ?></span></label>
769 + <?php
641 770 }
642 - $html .= '</div>';
643 - echo $html;
644 - ?>
771 + ?>
772 + </div>
645 773 </div>
646 - </div>
647 - <p><strong>[ Post Language Locale ]</strong></p>
648 - <div class="filter-description">
649 - <p><?php _e('A very simple multilingual feature that uses MO translation files for the selected locale per Post/Page editing screen.','plf'); ?></p>
650 - <?php
651 - $checked = (!empty($this->filter['language']))? $this->filter['language'] : false;
652 - echo '<div class="language-option">' . self::checkbox("plf_option[language]", $checked, __('Language switching per post', 'plf') ) . '</div>';
653 - ?>
654 - </div>
655 - <?php
656 - }
657 -
658 - //Expert URL Filter Settings
659 - function metabox_settings_expert($object, $metabox) {
660 - if(empty($metabox['id']) || $metabox['id'] != 'metabox_plf_expert')
661 - return;
662 - ?>
663 - <div class="urlfilter-description">
664 - <p><?php _e('Normally all are active. It is used when there is a plugin that you want to deactive specially for requests such as REST API, Ajax, AMP, etc.', 'plf'); ?></p>
665 - <p><?php _e('REST API / Ajax / AMP / URL page judgment is done from REQUEST URI with regular expressions including keyword. <code>(/|&|\.|\?|=)keyword(/|&|\.|\?|=|$)</code>', 'plf'); ?><br />
666 - <?php _e('AMP / URL Setting the keyword enables the filter. [Valid characters: alphanumeric characters, hyphens (-), underscores (_), slash (/), dot(.), question(?), equal(=), percent sign(%) ]', 'plf'); ?></p>
667 - <p><span style='background-color: #fbf7dc; padding: 2px;'>
668 - <?php _e('AMP keyword filter', 'plf')?>
669 - </span></p>
774 + <div class="ckbox-list">
775 + <p><?php self::decode_safe_tag_e( 'strong', esc_html__('<strong>Hide Single Post Filters</strong> - Hide single-post filter settings box for custom post type edit page', 'plf')); ?></p>
776 + <div>
670 777 <?php
671 - $items = array( 'amp' => __('In many cases, it is identified with "amp". (*AMP page display requires AMP plugin or theme)', 'plf') );
672 - $html = "";
673 - foreach ($items as $key => $label) {
674 - $html .= "<div>";
675 - $val = (!empty($this->filter['urlkey'][$key]))? $this->filter['urlkey'][$key] : '';
676 - $html .= "<input id='plf_option[$key]' class='medium-text' type='text' name='plf_option[$key]' value='$val' />";
677 - $html .= "<label style='margin-left:10px;'>$label</label>";
678 - $html .= "</div>";
778 + $post_types = get_post_types( array('_builtin' => false), 'objects' );
779 + if(!empty($post_types)){
780 + foreach ( $post_types as $type ) {
781 + $check = !empty(self::$filter['hidecpt'][$type->name])? true : false;
782 + ?>
783 + <label><input type="checkbox" name="<?php echo esc_html("plf_option[hidecpt][$type->name]"); ?>" <?php checked($check); ?>/> <span><?php echo esc_html("{$type->labels->name} ({$type->name})"); ?></span></label>
784 + <?php
785 + }
786 + } else {
787 + esc_html_e('Custom post type not defined', 'plf');
679 788 }
680 - echo $html;
681 - $urlkeylist = (!empty($this->filter['urlkeylist']))? esc_textarea($this->filter['urlkeylist']): '';
682 789 ?>
683 - <p><span style='background-color: #fbf7dc; padding: 2px;'><?php _e('URL keyword filter (Register URL matching judgment keywords separated by line breaks)', 'plf'); ?></span></p>
684 - <div><textarea name="plf_option[urlkeylist]" rows="10" cols="30" id="urlkeylist" class="medium-text code"><?php echo $urlkeylist; ?></textarea></div>
790 + </div>
791 + </div>
792 + <p><strong>[ <?php esc_html_e('Post Language Locale', 'plf'); ?> ]</strong></p>
793 + <p><?php esc_html_e('A very simple multilingual feature that uses MO translation files for the selected locale per Post/Page editing screen.','plf'); ?></p>
794 + <?php
795 + $checked = (!empty(self::$filter['language']))? self::$filter['language'] : false;
796 + echo '<div class="option-item"><label><input type="checkbox" name="plf_option[language]" value="1" ' . checked( $checked, 1, false ) . '/> ' . esc_html__('Language switching per post', 'plf') . '</label></div>';
797 + ?>
798 +
799 + <?php //開発モード限定機能
800 + $devmode = wp_get_development_mode();
801 + if (!empty($devmode)) { ?>
802 + <p><strong>[ <?php esc_html_e('Ajax acceleration filter (Features for plugin developers)', 'plf'); ?> ]</strong></p>
803 + <p><?php esc_html_e('If you are implementing Ajax requests in your plugin development, you can deactivate unnecessary plugins and speed up Ajax by setting the plugin slugs to be activated to `_ajax_plf` in the request data.','plf'); ?></p>
804 + <?php
805 + $checked = (!empty(self::$filter['ajax_accelfilter']))? self::$filter['ajax_accelfilter'] : false;
806 + echo '<div class="option-item"><label><input type="checkbox" name="plf_option[ajax_accelfilter]" value="1" ' . checked( $checked, 1, false ) . '/> ' . esc_html__('Ajax acceleration filter', 'plf') . '</label></div>';
807 + } ?>
808 + </div>
809 + <div class="side-info">
810 + <?php if(! is_plugin_active('plugin-load-filter-addon/plugin-load-filter-addon.php')){ ?>
811 + <div style="background-color: #f0fff0; border:1px solid #70c370; padding:4px 20px; margin: 10px 0;" >
812 + <p><strong><?php esc_html_e('Introduction of Addon', 'plf'); ?></strong></p>
813 + <p><?php esc_html_e('Thank you for using Plugin Load Filter. We offer URL filtering as Addon. Please consider using Addon!', 'plf'); ?></p>
814 + <p><?php esc_html_e('See more information ', 'plf'); ?><a target="_blank" rel="noopener" href="https://celtislab.net/en/wp-plugin-load-filter-addon/"> Plugin Load Filter Addon</a></p>
685 815 </div>
686 - <form method="post" autocomplete="off">
687 - <?php wp_nonce_field( 'plf_expert'); ?>
688 - <table class="form-table">
689 - <tbody>
690 - <tr valign="top">
691 - <th width='20%' scope="row" ><label><?php _e('Bot keyword', 'yasakani'); ?></label></th>
692 - <td width='80%'>
693 - <p><label for="bot_key"><?php _e('Please set keywords to identify bot access from user agent. (comma separated)', 'yasakani'); ?></label></p>
694 - </td>
695 - </tr>
696 - <tr valign="top">
697 - <th width='20%' scope="row" ><label><?php _e('Bot Black Lists', 'yasakani'); ?></label></th>
698 - <td width='80%'>
699 - <p><label for="botblocklist"><?php _e('Block bot access that could not be restricted by robots.txt. If IP or User agent contains these strings, that access will be blocked. One word per line or IP.', 'yasakani'); ?></label></p>
700 - </td>
701 - </tr>
702 -
703 - </tbody>
704 - </table>
705 - <p class="metabox-submit"><input type="submit" class="button-primary" name="plf_expert" value="<?php _e('Option Save', 'plf'); ?>" /></p>
706 - </form>
707 - <?php
816 + <?php } ?>
817 + <?php if(! is_plugin_active('realtime-img-optimizer/realtime-img-optimizer.php')){ ?>
818 + <div style="background-color: #f0fff0; border:1px solid #70c370; padding:4px 20px; margin: 10px 0;" >
819 + <p><strong><?php esc_html_e('Introduction of Realtime Image Optimizer', 'plf'); ?></strong></p>
820 + <p><?php esc_html_e('We sell Image Optimization plugin. Reduce and speed up data size by converting to WebP / AVIF.', 'plf'); ?></p>
821 + <p><?php esc_html_e('See more information ', 'plf'); ?><a target="_blank" rel="noopener" href="https://celtislab.net/en/wp-realtime-image-optimizer/"> Realtime Image Optimizer</a></p>
822 + </div>
823 + <?php } ?>
824 + <?php if(! is_plugin_active('celtis-diff-monitor-backups/celtis-diff-monitor-backups.php')){ ?>
825 + <div style="background-color: #f0fff0; border:1px solid #70c370; padding:4px 20px; margin: 10px 0;" >
826 + <p><strong><?php esc_html_e('Introduction of DB/File Diff Monitor and Backups', 'plf'); ?></strong></p>
827 + <p><?php esc_html_e('A security and backup plugin that detects unauthorized changes and minimizes data loss with rapid recovery.', 'plf'); ?></p>
828 + <p><?php esc_html_e('See more information ', 'plf'); ?><a target="_blank" rel="noopener" href="https://celtislab.net/en/celtis-diff-monitor-backups/"> DB/File Diff Monitor and Backups</a></p>
829 + </div>
830 + <?php } ?>
831 + </div>
832 + </div>
833 + <?php
708 834 }
709 -
710 835
711 836 //Activate plugins select from Page Filter
712 837 public function _plfactive_checkbox_row($p_key, $select_cvplugins, $chklist, $filter) {
713 838
@@ -713,17 +838,19 @@
713 838
714 839 $selplugins = array_map("trim", explode(',', $select_cvplugins));
715 840 $devlist = array('desktop','mobile');
716 841 if(in_array( $p_key, $selplugins )){
717 - $p_name = $this->pluginkey_to_name($p_key);
718 - echo "<tr><td class='plugins-name'>$p_name</td>";
842 + $p_name = self::pluginkey_to_name($p_key);
843 + echo '<tr><td class="plugins-name">' . esc_html($p_name) . '</td>';
719 844 foreach($devlist as $devtype){
845 + $name = "plfactive[$devtype][$p_key]";
720 846 $checked = (empty($filter['group'][$devtype]['plugins']) || false === strpos($filter['group'][$devtype]['plugins'], $p_key))? false : true;
721 - echo '<td class="device-type">' . self::altcheckbox("plfactive[$devtype][$p_key]", $checked, '<span class="dashicons dashicons-yes"></span>') . '</td>';
847 + echo '<td class="device-type"><label><input type="checkbox" name="' . esc_html($name) . '" class="altcheckbox" value="1" ' . checked( $checked, 1, false ). '/> <span class="dashicons dashicons-yes"></span></label></td>';
722 848 }
723 849 foreach($chklist as $pgtype){
850 + $name = "plfactive[$pgtype][$p_key]";
724 851 $checked = (empty($filter['group'][$pgtype]['plugins']) || false === strpos($filter['group'][$pgtype]['plugins'], $p_key))? false : true;
725 - echo '<td class="ckbox-type">' . self::altcheckbox("plfactive[$pgtype][$p_key]", $checked, '<span class="dashicons dashicons-admin-plugins"></span>') . '</td>';
852 + echo '<td class="ckbox-type"><label><input type="checkbox" name="' . esc_html($name) . '" class="altcheckbox" value="1" ' . checked( $checked, 1, false ). '/> <span class="dashicons dashicons-admin-plugins"></span></label></td>';
726 853 }
727 854 echo "</tr>";
728 855 }
729 856 }
@@ -735,17 +862,17 @@
735 862 ?>
736 863 <div id="wrap_activation-table">
737 864 <table id="activation-table" class="widefat">
738 865 <thead>
739 - <tr><th class="plugins-name"><?php _e('Plugins'); ?></th>
740 - <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>
741 - <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>
742 - <th class="ckbox-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>
743 - <th class="ckbox-type"><span title="<?php _e('Archive page', 'plf'); ?>" class="dashicons dashicons-list-view"></span><br /><span style="font-size:xx-small">Archive</span></th>
744 - <th class="ckbox-type"><span title="<?php _e('Search page', 'plf'); ?>" class="dashicons dashicons-search"></span><br /><span style="font-size:xx-small">Search</span></th>
745 - <th class="ckbox-type"><span title="<?php _e('Attachment page', 'plf'); ?>" class="dashicons dashicons-media-default"></span><br /><span style="font-size:xx-small">Attach</span></th>
746 - <th class="ckbox-type"><span title="<?php _e('Page', 'plf'); ?>" class="dashicons dashicons-admin-page"></span><br /><span style="font-size:xx-small">Page</span></th>
747 - <th class="ckbox-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>
866 + <tr><th class="plugins-name"><?php esc_html_e('Plugins', 'plf'); ?></th>
867 + <th class="device-type"><span title="<?php esc_html_e('Desktop Device', 'plf'); ?>" class="dashicons dashicons-desktop"></span><br /><span style="font-size:xx-small">Desktop</span></th>
868 + <th class="device-type"><span title="<?php esc_html_e('Mobile Device', 'plf'); ?>" class="dashicons dashicons-smartphone"></span><br /><span style="font-size:xx-small">Mobile</span></th>
869 + <th class="ckbox-type"><span title="<?php esc_html_e('Home/Front-page', 'plf'); ?>" class="dashicons dashicons-admin-home"></span><br /><span style="font-size:xx-small">Home</span></th>
870 + <th class="ckbox-type"><span title="<?php esc_html_e('Archive page', 'plf'); ?>" class="dashicons dashicons-list-view"></span><br /><span style="font-size:xx-small">Archive</span></th>
871 + <th class="ckbox-type"><span title="<?php esc_html_e('Search page', 'plf'); ?>" class="dashicons dashicons-search"></span><br /><span style="font-size:xx-small">Search</span></th>
872 + <th class="ckbox-type"><span title="<?php esc_html_e('Attachment page', 'plf'); ?>" class="dashicons dashicons-media-default"></span><br /><span style="font-size:xx-small">Attach</span></th>
873 + <th class="ckbox-type"><span title="<?php esc_html_e('Page', 'plf'); ?>" class="dashicons dashicons-admin-page"></span><br /><span style="font-size:xx-small">Page</span></th>
874 + <th class="ckbox-type pformat"><span title="<?php esc_html_e('Post : ', 'plf'); esc_html_e('Standard', 'plf'); ?>" class="dashicons dashicons-admin-post"></span><br /><span style="font-size:xx-small">Post</span></th>
748 875 <?php
749 876 $pformat = array('image', 'gallery', 'video', 'audio', 'aside', 'status', 'quote', 'link', 'chat' );
750 877 $exclude = array();
751 878 if(!empty($filter['exclude'])){
@@ -756,22 +883,22 @@
756 883 }
757 884 }
758 885 foreach ( $pformat as $type) {
759 886 if(!in_array($type, $exclude)){
760 - $title = __('Post : ', 'plf') . $type;
887 + $title = esc_html__('Post : ', 'plf') . $type;
761 888 $icon = ($type === "link")? "dashicons-admin-links" : "dashicons-format-$type";
762 - echo '<th class="ckbox-type pformat"><span title="' . $title . '" class="dashicons ' . $icon .'"></span><br /><span style="font-size:xx-small">' . $type .'</span></th>';
889 + echo '<th class="ckbox-type pformat"><span title="' . esc_html($title) . '" class="dashicons ' . esc_html($icon) .'"></span><br /><span style="font-size:xx-small">' . esc_html($type) .'</span></th>';
763 890 }
764 891 }
765 892 if(function_exists('is_embed')){
766 - $title = __('WordPress Embed Content Card (API)', 'plf');
767 - echo "<th class='ckbox-type tmpl-embed'><span title='$title' style='font-size:xx-small'>Embed Content</span></th>";
893 + $title = esc_html__('WordPress Embed Content Card (API)', 'plf');
894 + echo '<th class="ckbox-type tmpl-embed"><span title="' . esc_html($title) . '" style="font-size:xx-small">Embed Content</span></th>';
768 895 }
769 896 $post_types = get_post_types( array('public' => true, '_builtin' => false) );
770 897 foreach ( $post_types as $post_type ) {
771 898 if(!empty($post_type)){
772 - $title = __('Custom Post : ', 'plf') . $post_type;
773 - echo "<th class='ckbox-type tmpl-custom'><span title='$title' style='font-size:xx-small'>$post_type</span></th>";
899 + $title = esc_html__('Custom Post : ', 'plf') . $post_type;
900 + echo '<th class="ckbox-type tmpl-custom"><span title="' . esc_html($title) . '" style="font-size:xx-small">' . esc_html($post_type) . '</span></th>';
774 901 }
775 902 }
776 903 ?>
777 904 </tr>
@@ -779,9 +906,9 @@
779 906 <tbody class="plugins-table-body">
780 907 <?php
781 908 $nplugins = $jmodules = $cmodules = $allmodule = array();
782 909 foreach ( $plugins as $p_key => $p_data ) {
783 - $p_name = $this->pluginkey_to_name($p_key);
910 + $p_name = self::pluginkey_to_name($p_key);
784 911 if(empty($p_name))
785 912 continue;
786 913 if(strpos($p_key, 'jetpack_module/') !== false)
787 914 $jmodules[] = $p_key;
@@ -828,68 +955,48 @@
828 955 //Option Setting Form Display
829 956 public function plf_option_page() {
830 957 $clear_dialog = __('Plugin Load Filter Settings\nClick OK to clear it.', 'plf');
831 958 ?>
832 - <h2><?php _e('Plugin Load Filter Settings', 'plf'); ?></h2>
959 + <h2><?php esc_html_e('Plugin Load Filter Settings', 'plf'); ?></h2>
833 960 <p></p>
834 961 <div id="plf-setting-tabs">
835 962 <ul>
836 - <li><a href="#plf-registration-tab" ><?php _e('Filter Registration', 'plf'); ?></a></li>
837 - <li><a href="#plf-activation-tab" ><?php _e('Page Type Filter Activation', 'plf'); ?></a></li>
963 + <li><a href="#plf-registration-tab" ><?php esc_html_e('Filter Registration', 'plf'); ?></a></li>
964 + <li><a href="#plf-activation-tab" ><?php esc_html_e('Page Type Activation', 'plf'); ?></a></li>
838 965 </ul>
839 - <div id="plf-registration-tab" style="display : none;">
966 + <div id="plf-registration-tab" style="display : none;">
840 967 <form method="post" autocomplete="off">
841 968 <?php wp_nonce_field( 'plugin_load_filter'); ?>
842 - <?php $this->plfregist_table($this->plugins_inf, $this->filter); ?>
969 + <?php $this->plfregist_table(self::$plugins_inf, self::$filter); ?>
843 970 <p class="submit">
844 - <input type="submit" class="button-primary" name="clear_regist_filter" value="<?php _e('Clear', 'plf'); ?>" onclick="return confirm('<?php echo $clear_dialog; ?>')" />&nbsp;&nbsp;&nbsp;
845 - <input type="submit" class="button-primary" name="edit_regist_filter" value="<?php _e('Filter Entry &raquo;', 'plf'); ?>" />
971 + <input type="submit" class="button-primary" name="clear_regist_filter" value="<?php esc_html_e('Clear', 'plf'); ?>" onclick="return confirm('<?php echo esc_html($clear_dialog); ?>')" />&nbsp;&nbsp;&nbsp;
972 + <input type="submit" class="button-primary" name="edit_regist_filter" value="<?php esc_html_e('Filter Entry &raquo;', 'plf'); ?>" />
846 973 </p>
847 974 </form>
848 -<?php
849 -/*
850 - <div class="wrap yasakani-settings">
851 - <?php
852 - add_meta_box('metabox_plf_expert', __('Expert URL Filter Settings', 'plf'), array($this, 'metabox_settings_expert'), 'plf_metabox_settings', 'normal');
853 - //add_meta_box('metabox_plf_pagetype', __('Page Type Filter Settings', 'plf'), array($this, 'metabox_settings_pagetype'), 'plf_metabox_settings', 'normal');
854 - ?>
855 - <div id="poststuff">
856 - <?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
857 - <?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?>
858 - <div id="post-body" class="metabox-holder columns-1">
859 - <div id="postbox-container-1" class="postbox-container">
860 - <?php do_meta_boxes( 'plf_metabox_settings', 'normal', null ); ?>
861 - </div>
862 - </div>
863 - </div>
864 - <script type='text/javascript'>
865 - jQuery(document).ready(function() { postboxes.add_postbox_toggles('plf_metabox_settings'); });
866 - </script>
867 - </div>
868 -*/
869 -?>
870 975 </div>
871 976 <div id="plf-activation-tab" style="display : none;">
872 977 <form method="post" autocomplete="off">
873 978 <?php wp_nonce_field( 'plugin_load_filter'); ?>
874 979 <?php
875 - $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
980 + $pgfilter = (!empty(self::$filter['_pagefilter']['plugins']))? self::$filter['_pagefilter']['plugins'] : array();
876 981 if(!empty($pgfilter)){
877 - $this->plfactive_table($this->plugins_inf, $pgfilter, $this->filter);
982 + $this->plfactive_table(self::$plugins_inf, $pgfilter, self::$filter);
878 983 ?>
879 984 <br />
880 - <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 type filter" registered plugins.', 'plf') ?><br />
881 - <?php _e('You can also select plugins to activate from Post/Page content editing screen.', 'plf') ?>
882 - </p>
985 + <p><?php
986 + self::decode_safe_tag_e( 'span', esc_html__('Select plugins to be activated for each page type by clicking on <span class="dashicons dashicons-admin-plugins"></span> mark from "page type filter" registered plugins.', 'plf'));
987 + ?><br />
988 + <?php esc_html_e('You can also select plugins to activate from Post/Page content editing screen.', 'plf') ?>
989 + </p>
883 990 <p class="submit">
884 - <input type="submit" class="button-primary" name="clear_activate_page_filter" value="<?php _e('Clear', 'plf'); ?>" onclick="return confirm('<?php echo $clear_dialog; ?>')" />&nbsp;&nbsp;&nbsp;
885 - <input type="submit" class="button-primary" name="edit_activate_page_filter" value="<?php _e('Activate Plugin Entry &raquo;', 'plf'); ?>" />
991 + <input type="submit" class="button-primary" name="clear_activate_page_filter" value="<?php esc_html_e('Clear', 'plf'); ?>" onclick="return confirm('<?php echo esc_html($clear_dialog); ?>')" />&nbsp;&nbsp;&nbsp;
992 + <input type="submit" class="button-primary" name="edit_activate_page_filter" value="<?php esc_html_e('Activate Plugin Entry &raquo;', 'plf'); ?>" />
886 993 </p>
887 994 <?php
888 995 } else {
889 996 ?>
890 997 <br />
891 - <p><span style="color: #ff0000;"><?php _e('Page Filter is not registered', 'plf') ?></span></p>
998 + <p><span style="color: #ff0000;"><?php esc_html_e('Page Filter is not registered', 'plf') ?></span></p>
892 999 <?php
893 1000 }
894 1001 ?>
895 1002 </form>
@@ -902,11 +1009,18 @@
902 1009 * Meta box
903 1010 * Individual of the plug-in filter meta box for Post/Page/CustomPost
904 1011 **************************************************************************/
905 1012 function load_meta_boxes( $post_type, $post ) {
906 - if ( current_user_can('activate_plugins', $post->ID) ) {
907 - add_meta_box( 'pluginfilterdiv', __( 'Plugin Load Filter', 'plf' ), array(&$this, 'plf_meta_box'), null, 'side' );
908 - //add_action( 'admin_head', array(&$this, 'plf_css' ));
1013 + if ( current_user_can('activate_plugins', $post->ID) ) {
1014 + $type = get_post_type();
1015 + $post_types = get_post_types( array('public' => true, '_builtin' => true) );
1016 + if(!in_array($type, $post_types)){
1017 + $custom_types = get_post_types( array('_builtin' => false) );
1018 + if(!in_array($type, $custom_types) || !empty(self::$filter['hidecpt'][$type])){
1019 + return;
1020 + }
1021 + }
1022 + add_meta_box( 'pluginfilterdiv', esc_html__( 'Plugin Load Filter', 'plf' ), array(&$this, 'plf_meta_box'), null, 'side' );
909 1023 add_action( 'admin_footer', array(&$this, 'plf_meta_script' ));
910 1024 }
911 1025 }
912 1026
@@ -921,13 +1035,14 @@
921 1035 $device['desktop'] = $checked_arcvplugins['desktop'];
922 1036 $device['mobile'] = $checked_arcvplugins['mobile'];
923 1037 $devlist = array('desktop','mobile');
924 1038 if(in_array( $p_key, $selplugins )){
925 - $p_name = $this->pluginkey_to_name($p_key);
1039 + $p_name = self::pluginkey_to_name($p_key);
926 1040 $html .= "<tr><td class='plugins-name'>$p_name</td>";
927 1041 foreach($devlist as $devtype){
1042 + $name = "plf_option[$devtype][$p_key]";
928 1043 $checked = (empty($device[$devtype]) || false === strpos($device[$devtype], $p_key))? false : true;
929 - $html .= "<td class='device-type $devtype'>" . self::altcheckbox("plf_option[$devtype][$p_key]", $checked, '<span class="dashicons dashicons-yes"></span>') . '</td>';
1044 + $html .= '<td class="device-type ' . esc_html($devtype) . '"><label><input type="checkbox" name="' . esc_html($name) . '" class="altcheckbox" value="1" ' . checked( $checked, 1, false ). '/> <span class="dashicons dashicons-yes"></span></label></td>';
930 1045 }
931 1046 $html .= "</tr>";
932 1047 }
933 1048 return $html;
@@ -939,21 +1054,21 @@
939 1054 // $checked_arcvplugins : array csv string : ['desktop']=desktop enable plugins, ['mobile']=mobile enable plugins
940 1055 function pagefilter_plugins_checklist( $plugins, $select_cvplugins, $checked_arcvplugins ) {
941 1056
942 1057 if(empty($select_cvplugins))
943 - return __('Page Filter is not registered', 'plf');
1058 + return esc_html__('Page Filter is not registered', 'plf');
944 1059
945 1060 $html = '<table id="activation-table">';
946 1061 $html .= '<thead>';
947 - $html .= '<tr><th class="plugins-name">'. __('Plugins') . '</th>';
948 - $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>';
949 - $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>';
1062 + $html .= '<tr><th class="plugins-name">'. esc_html__('Plugins') . '</th>';
1063 + $html .= '<th class="device-type"><span title="'. esc_html__('Desktop Device', 'plf'). '" class="dashicons dashicons-desktop"></span><br /><span style="font-size:xx-small">Desktop</span></th>';
1064 + $html .= '<th class="device-type"><span title="'. esc_html__('Mobile Device', 'plf'). '" class="dashicons dashicons-smartphone"></span><br /><span style="font-size:xx-small">Mobile</span></th>';
950 1065 $html .= '</tr>';
951 1066 $html .= '</thead>';
952 1067 $html .= '<tbody class="plugins-table-body meta-boxes-plugins-table">';
953 1068 $nplugins = $jmodules = $cmodules = array();
954 1069 foreach ( $plugins as $p_key => $p_data ) {
955 - $p_name = $this->pluginkey_to_name($p_key);
1070 + $p_name = self::pluginkey_to_name($p_key);
956 1071 if(empty($p_name))
957 1072 continue;
958 1073 if(strpos($p_key, 'jetpack_module/') !== false)
959 1074 $jmodules[] = $p_key;
@@ -985,12 +1100,17 @@
985 1100
986 1101 //get_locale に加えたフィルターフックを外してサイトのロケールを取得
987 1102 static function get_site_locale(){
988 1103 global $locale;
989 - remove_filter( 'locale', array('Plf_filter', 'post_locale') );
990 - $locale = null;
991 - $site_locale = get_locale();
992 - add_filter( 'locale', array('Plf_filter', 'post_locale') );
1104 + if(class_exists('Plf_filter')){
1105 + remove_filter( 'locale', array('Plf_filter', 'post_locale') );
1106 + $locale = null;
1107 + $site_locale = get_locale();
1108 + add_filter( 'locale', array('Plf_filter', 'post_locale') );
1109 + } else {
1110 + $locale = null;
1111 + $site_locale = get_locale();
1112 + }
993 1113 return $site_locale;
994 1114 }
995 1115
996 1116 function plf_meta_box( $post, $box ) {
@@ -996,33 +1116,33 @@
996 1116 function plf_meta_box( $post, $box ) {
997 1117 if(is_object($post)){
998 1118 $myfilter = get_post_meta( $post->ID, '_plugin_load_filter', true );
999 1119 //ver2.2.0 for compatibility, set 'plugins' data to 'desktop' and 'mobile'
1000 - if(!empty($myfilter['plugins'])){
1120 + if(is_array($myfilter) && !empty($myfilter['plugins'])){
1001 1121 $myfilter['desktop'] = $myfilter['plugins'];
1002 1122 $myfilter['mobile'] = $myfilter['plugins'];
1003 1123 unset($myfilter['plugins']);
1004 1124 }
1005 1125 $default = array( 'filter' => 'default', 'desktop' => '', 'mobile' => '');
1006 - $option = (!empty($myfilter))? $myfilter : $default;
1126 + $option = (!empty($myfilter) && is_array($myfilter))? $myfilter : $default;
1007 1127 $option = wp_parse_args( $option, $default);
1008 - $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
1128 + $pgfilter = (!empty(self::$filter['_pagefilter']['plugins']))? self::$filter['_pagefilter']['plugins'] : array();
1009 1129 $ajax_nonce = wp_create_nonce( 'plugin_load_filter-' . $post->ID );
1010 1130 $this->plf_css();
1011 1131 ?>
1012 1132 <div id="plugin-filter-select">
1013 - <p><?php _e( 'Plugin filters for this post' ); ?></p>
1014 - <label><input type="radio" name="pagefilter" value="default" <?php checked('default', $option['filter']); ?>/><?php _e('Not Use', 'plf' ); ?></label>
1015 - <label><input type="radio" name="pagefilter" value="include" <?php checked('include', $option['filter']); ?>/><?php _e('Use', 'plf'); ?></label>
1133 + <p><?php esc_html_e( 'Plugin filter for Single post', 'plf' ); ?></p>
1134 + <label><input type="radio" name="pagefilter" value="default" <?php checked('default', $option['filter']); ?>/><?php esc_html_e('Not Use', 'plf' ); ?></label>
1135 + <label><input type="radio" name="pagefilter" value="include" <?php checked('include', $option['filter']); ?>/><?php esc_html_e('Use', 'plf'); ?></label>
1016 1136 <div id="page-filter-stat">
1017 - <?php echo $this->pagefilter_plugins_checklist( $this->plugins_inf, $pgfilter, $option ); ?>
1137 + <?php echo wp_kses($this->pagefilter_plugins_checklist( self::$plugins_inf, $pgfilter, $option ), self::get_allowed_tags()); ?>
1018 1138 </div>
1019 - <div class="plf-option-info"><?php _e('Plugin Activate/Deactivate filtering for this Post only', 'plf'); ?></div>
1139 + <div class="plf-option-info"><?php esc_html_e('Plugin Activate/Deactivate filter for this Post only', 'plf'); ?></div>
1020 1140 <?php
1021 1141 $c_locale = $o_post_id = '';
1022 1142 $languages = array();
1023 1143 $locale_mode = 'style="display:none;"';
1024 - if(!empty($this->filter['language'])){
1144 + if(!empty(self::$filter['language'])){
1025 1145 $languages = get_available_languages();
1026 1146 $site_locale = self::get_site_locale();
1027 1147 //bogo と同じ _locale ポストメタデータ採用
1028 1148 $c_locale = get_post_meta( $post->ID, '_locale', true );
@@ -1035,12 +1155,13 @@
1035 1155 $o_post_id = get_post_meta( $post->ID, '_original_post_id', true );
1036 1156 $o_post_id = (is_numeric($o_post_id))? $o_post_id : '';
1037 1157 $locale_mode = '';
1038 1158 }
1159 + echo '<p class="hide-if-no-js"><a id="plugin-filter-submit" class="button" href="#pluginfilterdiv" onclick="WPAddPagePluginLoadFilter(\'' . esc_html($ajax_nonce) . '\');return false;" >'. esc_html__('Save') .'</a></p>';
1039 1160 ?>
1040 1161 <hr>
1041 - <div id="plf-post-locale-select" <?php echo $locale_mode; ?>>
1042 - <p><?php _e( 'Language of this post', 'plf' ); ?> <span class="dashicons dashicons-translation" aria-hidden="true"></span></p>
1162 + <div id="plf-post-locale-select" <?php echo esc_html($locale_mode); ?>>
1163 + <p><?php esc_html_e( 'Language of this post', 'plf' ); ?> <span class="dashicons dashicons-translation" aria-hidden="true"></span></p>
1043 1164 <?php
1044 1165 wp_dropdown_languages(
1045 1166 array(
1046 1167 'name' => 'plf_locale',
@@ -1050,10 +1171,10 @@
1050 1171 'show_available_translations' => false,
1051 1172 )
1052 1173 );
1053 1174 ?>
1054 - <p><?php _e( 'Original post ID for hreflang', 'plf' ); ?></p>
1055 - <input type="text" id="plf_original_post_id" name="plf_original_post_id" size="8" value="<?php echo $o_post_id; ?>" />
1175 + <p><?php esc_html_e( 'Original post ID for hreflang', 'plf' ); ?></p>
1176 + <input type="text" id="plf_original_post_id" name="plf_original_post_id" size="8" value="<?php echo esc_html($o_post_id); ?>" />
1056 1177 <div class="hflang-group-edit-lonk">
1057 1178 <?php
1058 1179 $id = (is_numeric($o_post_id))? $o_post_id : $post->ID;
1059 1180 global $wpdb;
@@ -1070,9 +1191,9 @@
1070 1191 $l = $site_locale;
1071 1192 }
1072 1193 $url = get_edit_post_link( $v );
1073 1194 if(!empty($url)){
1074 - echo '<p><a class="edit-post-locale-link" target="_blank" href="' . $url .'" rel="external noreferrer noopener">' . __('Edit Post') . " ($l) " . '<span class="dashicons dashicons-external" aria-hidden="true"></span></a></p>';
1195 + echo '<p><a class="edit-post-locale-link" target="_blank" href="' . esc_html($url) .'" rel="external noreferrer noopener">' . esc_html__('Edit Post') . ' (' . esc_html($l) . ') ' . '<span class="dashicons dashicons-external" aria-hidden="true"></span></a></p>';
1075 1196 }
1076 1197 }
1077 1198 }
1078 1199 }
@@ -1078,13 +1199,11 @@
1078 1199 }
1079 1200 }
1080 1201 ?>
1081 1202 </div>
1082 - <div class="plf-option-info"><?php _e('Use MO translation file for the selected locale. When Original Post ID is registered, posts with the same Original Post ID are treated as `hreflang` metadata group.', 'plf'); ?></div>
1203 + <div class="plf-option-info"><?php esc_html_e('Use MO translation file for the selected locale. When Original Post ID is registered, posts with the same Original Post ID are treated as `hreflang` metadata group.', 'plf'); ?></div>
1204 + <?php echo '<p class="hide-if-no-js"><a id="plugin-filter-submit" class="button" href="#pluginfilterdiv" onclick="WPAddPagePluginLoadFilter(\'' . esc_html($ajax_nonce) . '\');return false;" >'. esc_html__('Save') .'</a></p>'; ?>
1083 1205 </div>
1084 - <?php
1085 - 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>';
1086 - ?>
1087 1206 </div>
1088 1207 <?php
1089 1208 }
1090 1209 }
@@ -1096,20 +1215,25 @@
1096 1215 if ( !current_user_can( 'activate_plugins', $pid ) )
1097 1216 wp_die( -1 );
1098 1217 check_ajax_referer( "plugin_load_filter-$pid" );
1099 1218
1100 - if(!empty($this->filter['language'])){
1219 + if(!empty(self::$filter['language'])){
1101 1220 if(isset($_POST['locale'])){
1102 - $s_locale = (!empty($_POST['locale']))? $_POST['locale'] : 'en_US';
1221 + $s_locale = (!empty($_POST['locale']))? sanitize_text_field(wp_unslash($_POST['locale'])) : 'en_US';
1103 1222 $languages = get_available_languages();
1104 1223 $languages[] = 'en_US'; //add WP default locale
1105 1224 if ( in_array( $s_locale, $languages ) ) {
1106 1225 $g_locale = get_post_meta( $pid, '_locale', true );
1107 - remove_filter( 'locale', array('Plf_filter', 'post_locale') );
1108 1226 global $locale;
1109 - $locale = null;
1110 - $o_locale = get_locale();
1111 - add_filter( 'locale', array('Plf_filter', 'post_locale') );
1227 + if(class_exists('Plf_filter')){
1228 + remove_filter( 'locale', array('Plf_filter', 'post_locale') );
1229 + $locale = null;
1230 + $o_locale = get_locale();
1231 + add_filter( 'locale', array('Plf_filter', 'post_locale') );
1232 + } else {
1233 + $locale = null;
1234 + $o_locale = get_locale();
1235 + }
1112 1236 if($s_locale !== $g_locale){
1113 1237 if($s_locale === $o_locale){
1114 1238 delete_post_meta( $pid, '_locale');
1115 1239 } else {
@@ -1132,15 +1256,16 @@
1132 1256 }
1133 1257 }
1134 1258 }
1135 1259 }
1136 - $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
1137 - $option["filter"] = (empty($_POST['filter']))? 'default' : $_POST['filter'];
1260 + $pgfilter = (!empty(self::$filter['_pagefilter']['plugins']))? self::$filter['_pagefilter']['plugins'] : array();
1261 + $option["filter"] = (empty($_POST['filter']))? 'default' : sanitize_text_field(wp_unslash($_POST['filter']));
1138 1262 if('default' == $option["filter"]){
1139 1263 delete_post_meta( $pid, '_plugin_load_filter');
1140 1264 } else {
1141 1265 $plugins = array();
1142 - if( preg_match_all('/plf_option\[desktop\]\[(.+?)\]/u', $_POST['desktop'], $matches)){
1266 + $desktop = sanitize_text_field(wp_unslash($_POST['desktop']));
1267 + if( preg_match_all('/plf_option\[desktop\]\[(.+?)\]/u', $desktop, $matches)){
1143 1268 if(!empty($matches[1])){
1144 1269 foreach ($matches[1] as $plugin){
1145 1270 $plugins[] = $plugin;
1146 1271 }
@@ -1147,9 +1272,10 @@
1147 1272 $option["desktop"] = implode(",", $plugins);
1148 1273 }
1149 1274 }
1150 1275 $plugins = array();
1151 - if( preg_match_all('/plf_option\[mobile\]\[(.+?)\]/u', $_POST['mobile'], $matches)){
1276 + $mobile = sanitize_text_field(wp_unslash($_POST['mobile']));
1277 + if( preg_match_all('/plf_option\[mobile\]\[(.+?)\]/u', $mobile, $matches)){
1152 1278 if(!empty($matches[1])){
1153 1279 foreach ($matches[1] as $plugin){
1154 1280 $plugins[] = $plugin;
1155 1281 }
@@ -1158,15 +1284,14 @@
1158 1284 }
1159 1285 update_post_meta( $pid, '_plugin_load_filter', $option );
1160 1286 }
1161 1287
1162 - $html = $this->pagefilter_plugins_checklist( $this->plugins_inf, $pgfilter, $option );
1288 + $html = $this->pagefilter_plugins_checklist( self::$plugins_inf, $pgfilter, $option );
1163 1289 wp_send_json_success($html);
1164 1290 }
1165 1291 wp_die( 0 );
1166 1292 }
1167 1293
1168 -
1169 1294 //alternate hreflang meta tag
1170 1295 static function altenate_hreflang() {
1171 1296 if ( is_singular() ) {
1172 1297 global $post, $wpdb;
@@ -1198,9 +1323,9 @@
1198 1323 **************************************************************************/
1199 1324 function activetab_script() { ?>
1200 1325 <script type='text/javascript' >
1201 1326 /* <![CDATA[ */
1202 - var plf_activetab = <?php echo $this->tab_num; ?>
1327 + var plf_activetab = <?php echo esc_html($this->tab_num); ?>
1203 1328 /* ]]> */
1204 1329 jQuery(document).ready(function ($) {
1205 1330 plf_setting_tabs();
1206 1331 function plf_setting_tabs(){ $('#plf-setting-tabs').tabs({ active:plf_activetab, }); }
@@ -1208,9 +1333,8 @@
1208 1333 </script>
1209 1334 <?php }
1210 1335
1211 1336 function plf_meta_script() {
1212 - $reload_dialog = __('Plugin Load Filter setting has been updated.\nClick OK to reload the page.', 'plf');
1213 1337 ?>
1214 1338 <script type='text/javascript' >
1215 1339 WPAddPagePluginLoadFilter = function(nonce){
1216 1340 jQuery.ajax({
@@ -1229,16 +1353,14 @@
1229 1353 dataType: 'json',
1230 1354 }).then(
1231 1355 function (response, dataType) {
1232 1356 jQuery('#page-filter-stat').html(response.data);
1233 - if(window.confirm('<?php echo $reload_dialog; ?>')){
1357 + if(window.confirm('<?php esc_html_e('Plugin Load Filter setting has been updated.\nClick OK to reload the page.', 'plf'); ?>')){
1234 1358 location.reload();
1235 1359 }
1236 1360 },
1237 - function () {
1238 - //alert("ajax error");
1239 - }
1361 + function () { /* alert("ajax error"); */ }
1240 1362 );
1241 1363 };
1242 1364 </script>
1243 1365 <?php }
1244 -}
1366 +}