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 +182 -106 4.2.04.4.0 View file →
@@ -1,15 +1,15 @@
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: 4.2.0
5 + Version: 4.4.0
6 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: 5.3
10 - Tested up to: 6.7
11 - Requires PHP: 7.2
9 + Requires at least: 6.3
10 + Tested up to: 7.0
11 + Requires PHP: 8.1
12 12 License: GPLv2
13 13 Text Domain: plf
14 14 Domain Path: /languages
15 15 */
@@ -157,11 +157,11 @@
157 157 .urlfilter-description { padding: 0 10px 15px;}
158 158 .grid-row { display: flex; flex-flow: row wrap;}
159 159 .filter-description { padding: 0 10px; width:62%;}
160 160 .side-info { width: 30%; padding-left: 24px;}
161 - .exclude-pformat { padding: 5px 0 20px}
162 - .exclude-pformat label { white-space:nowrap;}
163 - .exclude-pformat span { margin-right: 12px; }
161 + .ckbox-list { padding: 4px 0 12px}
162 + .ckbox-list label { white-space:nowrap;}
163 + .ckbox-list span { margin-right: 12px; }
164 164 .dashicons:before { font-size: 24px; }
165 165 .radio-green label, .radio-red label { color: #ddd; margin-left: -32px; }
166 166 .ckbox-type label { color: #ddd;}
167 167 .radio-green input[type="radio"]:checked + span { color: #8bc34a; }
@@ -166,9 +166,8 @@
166 166 .ckbox-type label { color: #ddd;}
167 167 .radio-green input[type="radio"]:checked + span { color: #8bc34a; }
168 168 .radio-red input[type="radio"]:checked + span { color: tomato; }
169 169 .ckbox-type input[type="checkbox"]:checked + span { color: #4caf50; }
170 - /* .dashicons-dismiss:before { background-color: yellowgreen; font-size: 20px; border-radius: 12px; } */
171 170 .deny-type label { color: #4caf50;}
172 171 .deny-type input.altcheckbox[type="checkbox"]:checked + span { color: #ddd; }
173 172 .dashicons-yes:before { font-size: 20px; border: 1px solid #eee; }
174 173 .device-type input.altcheckbox[type="checkbox"]:checked + span.dashicons-yes:before { background-color: yellowgreen; }
@@ -181,10 +180,8 @@
181 180 **************************************************************************/
182 181
183 182 public function __construct() {
184 183
185 - add_action('init', function(){ load_plugin_textdomain('plf', false, basename( dirname( __FILE__ ) ).'/languages' ); }, 1);
186 -
187 184 self::$filter = get_option('plf_option', array());
188 185 if(empty(self::$filter['optver']) || self::$filter['optver'] < '2'){
189 186 self::$filter['optver'] = '2';
190 187 //ここにデータフォーマットが変わった場合の変換処理を記述
@@ -311,9 +308,9 @@
311 308 //Notice Message display
312 309 static function plf_notice() {
313 310 $notice = get_transient('plf_notice');
314 311 if(!empty($notice)){
315 - echo '<div class="notice notice-warning"><p>Plugin Load Filter : ' . $notice . '</p></div>';
312 + echo '<div class="notice notice-warning"><p>Plugin Load Filter : ' . esc_html($notice) . '</p></div>';
316 313 delete_transient('plf_notice');
317 314 }
318 315 }
319 316
@@ -325,17 +322,17 @@
325 322 check_admin_referer('plugin_load_filter');
326 323 //url filter
327 324 $groupkeys = (method_exists('Plf_filter', 'get_active_group'))? Plf_filter::get_active_group() : array();
328 325 if(!empty($groupkeys) && isset($_POST['plfurlkey'])){
329 - $urlkeys = array_keys($_POST['plfurlkey']);
326 + $plfurlkey = $_POST['plfurlkey']; //array
330 327 foreach( $groupkeys as $item){
331 - if(empty( $_POST['plfurlkey'][$item])){
328 + if(empty( $plfurlkey[$item])){
332 329 self::$filter['plfurlkey'][$item]['plugins'] = '';
333 330 } else {
334 331 $plugins = array();
335 - foreach ( $_POST['plfurlkey'][$item] as $p_key => $val ) {
332 + foreach ( $plfurlkey[$item] as $p_key => $val ) {
336 333 if($val == '1')
337 - $plugins[] = $p_key;
334 + $plugins[] = sanitize_text_field($p_key);
338 335 }
339 336 $option["plugins"] = implode(",", $plugins);
340 337 self::$filter['plfurlkey'][$item] = $option;
341 338 }
@@ -343,17 +340,21 @@
343 340 }
344 341 //page type filter
345 342 foreach( array('_admin', '_pagefilter') as $item){
346 343 $plugins = array();
347 - foreach ( $_POST['plfregist'] as $p_key => $val ) {
348 - if($val == $item)
349 - $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 + }
350 350 }
351 351 if($item == '_pagefilter'){
352 352 //If all modules is specified filter, in some cases you want to deactivate plugin itself.
353 353 $jbase = $cbase = '';
354 354 $jall = $call = true;
355 - foreach ( $_POST['plfregist'] as $p_key => $val ) {
355 + foreach ( $plfregist as $p_key => $val ) {
356 + $p_key = sanitize_text_field($p_key);
356 357 if(strpos($p_key, 'jetpack/') !== false)
357 358 $jbase = $p_key;
358 359 else if(strpos($p_key, 'celtispack/') !== false)
359 360 $cbase = $p_key;
@@ -377,16 +378,34 @@
377 378 }
378 379 //exclude option
379 380 if(isset($_POST['plf_option']['exclude'])){
380 381 $exclude = array();
381 - foreach ( $_POST['plf_option']['exclude'] as $ft => $v ) {
382 - 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);
383 386 $exclude[$ft] = true;
387 + }
384 388 }
385 389 self::$filter['exclude'] = $exclude;
386 390 } else {
387 391 self::$filter['exclude'] = array();
388 392 }
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 + }
403 + }
404 + self::$filter['hidecpt'] = $hidecpt;
405 + } else {
406 + self::$filter['hidecpt'] = array();
407 + }
389 408
390 409 //admin bar (filtered stat)
391 410 self::$filter['admin_bar'] = (isset($_POST['plf_option']['admin_bar']))? 1 : 0;
392 411
@@ -395,9 +414,9 @@
395 414
396 415 //Ajax acceleration plugin filter (for plugin developers)
397 416 self::$filter['ajax_accelfilter'] = (isset($_POST['plf_option']['ajax_accelfilter']))? 1 : 0;
398 417
399 - update_option('plf_option', self::$filter );
418 + update_option('plf_option', self::$filter, 'no' );
400 419 }
401 420 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page'));
402 421 exit;
403 422
@@ -411,8 +430,9 @@
411 430 foreach( array('_admin', '_pagefilter') as $item){
412 431 self::$filter[$item] = array();
413 432 }
414 433 self::$filter['exclude'] = array();
434 + self::$filter['hidecpt'] = array();
415 435
416 436 //old data unset
417 437 if(isset(self::$filter['urlkey'])){
418 438 unset(self::$filter['urlkey']);
@@ -423,9 +443,9 @@
423 443
424 444 self::$filter['admin_bar'] = 0;
425 445 self::$filter['language'] = 0;
426 446 self::$filter['ajax_accelfilter'] = 0;
427 - update_option('plf_option', self::$filter );
447 + update_option('plf_option', self::$filter, 'no' );
428 448 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page'));
429 449 exit;
430 450
431 451 } else if(isset($_POST['edit_activate_page_filter']) ) {
@@ -431,19 +451,20 @@
431 451 } else if(isset($_POST['edit_activate_page_filter']) ) {
432 452 if(isset($_POST['plfactive'])){
433 453 check_admin_referer('plugin_load_filter');
434 454 self::$filter['group'] = array();
435 - $group = array_keys($_POST['plfactive']);
455 + $plfactive = $_POST['plfactive']; //array
456 + $group = array_keys($plfactive);
436 457 foreach( $group as $item){
437 458 $plugins = array();
438 - foreach ( $_POST['plfactive'][$item] as $p_key => $val ) {
459 + foreach ( $plfactive[$item] as $p_key => $val ) {
439 460 if($val == '1')
440 - $plugins[] = $p_key;
461 + $plugins[] = sanitize_text_field($p_key);
441 462 }
442 463 $option["plugins"] = implode(",", $plugins);
443 464 self::$filter['group'][$item] = $option;
444 465 }
445 - update_option('plf_option', self::$filter );
466 + update_option('plf_option', self::$filter, 'no' );
446 467 }
447 468 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page&action=tab_1'));
448 469 exit;
449 470
@@ -449,9 +470,9 @@
449 470
450 471 } elseif( isset($_POST['clear_activate_page_filter']) ) {
451 472 check_admin_referer('plugin_load_filter');
452 473 self::$filter['group'] = array();
453 - update_option('plf_option', self::$filter );
474 + update_option('plf_option', self::$filter, 'no' );
454 475 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page&action=tab_1'));
455 476 exit;
456 477 }
457 478 if(!empty($_GET['action']) && $_GET['action']=='tab_1') {
@@ -490,25 +511,37 @@
490 511 }
491 512 return($name);
492 513 }
493 514
494 - //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
495 530 static function checkbox($name, $value, $label = '') {
496 531 return "<label><input type='checkbox' name='$name' value='1' " . checked( $value, 1, false ). "/> $label</label>";
497 532 }
498 533 static function altcheckbox($name, $value, $label = '') {
499 - //return "<input type='hidden' name='$name' value='0'><input type='checkbox' name='$name' value='1' " . checked( $value, 1, false ). "/><label> $label</label>";
500 534 return "<label><input type='checkbox' name='$name' class='altcheckbox' value='1' " . checked( $value, 1, false ). "/> $label</label>";
501 535 }
502 536
503 - //dropdown list
504 - static function dropdown($name, $items, $selected, $args = null) {
537 + //dropdown list for addon
538 + static function dropdown($name, $items, $selected, $args = null, $display = false) {
505 539 $defaults = array(
506 540 'id' => $name,
507 541 'none' => false,
508 542 'class' => null,
509 543 'multiple' => false,
510 - 'select_attr' => ""
511 544 );
512 545
513 546 if (!is_array($items))
514 547 return;
@@ -533,33 +566,36 @@
533 566
534 567 if (!$id)
535 568 $id = $name;
536 569
537 - $name = ($name) ? "name='$name'" : "";
538 - $id = ($id) ? "id='$id'" : "";
539 - $class = ($class) ? "class='$class'" : "";
540 - $multiple = ($multiple) ? "multiple='multiple'" : "";
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"' : '';
541 574
542 - $html = "<select $name $id $class $multiple $select_attr>";
543 -
575 + $html = '<select' . $name . $id . $class . $multiple .'>';
544 576 foreach ((array) $items as $key => $label) {
545 - $key = esc_attr($key);
546 - $label = esc_attr($label);
547 -
548 - $html .= "<option value='$key' " . selected($selected, $key, false) . ">$label</option>";
577 + $html .= '<option value="' . esc_html($key) . '" ' . selected($selected, $key, false) . '>' . esc_html($label) . '</option>';
549 578 }
550 - $html .= "</select>";
551 - return $html;
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 + }
552 588 }
553 -
589 +
554 590 //安全な文字列から指定タグのみデコード(既存の翻訳ファイルへ影響せずにエスケープするために使用)
555 591 //&lt;strong&gt;Type&lt;/strong&gt -> <strong>Type</strong>
556 - static function decode_safe_tag( $tag, $safe_str ) {
592 + static function decode_safe_tag_e( $tag, $safe_str ) {
557 593 $safe_str = preg_replace_callback( "|&lt;($tag.*)&gt;(.*)&lt;/($tag)&gt;|im", function($matches){
558 594 $tag_attrs = str_replace( '&quot;', '"', $matches[1]);
559 595 return '<' . $tag_attrs . '>' . $matches[2] . '</' . $matches[3] . '>';
560 596 }, $safe_str);
561 - return $safe_str;
597 + echo wp_kses_post($safe_str);
562 598 }
563 599
564 600 public function plfregist_item($key, $chklist, $filter) {
565 601 $p_name = self::pluginkey_to_name($key);
@@ -564,14 +600,15 @@
564 600 public function plfregist_item($key, $chklist, $filter) {
565 601 $p_name = self::pluginkey_to_name($key);
566 602 $opt_name = "plfregist[$key]";
567 603 ?>
568 - <tr id="plfregist_<?php echo $key; ?>">
569 - <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>
570 606 <?php
571 607 foreach($chklist as $urlkey){
608 + $name = "plfurlkey[$urlkey][$key]";
572 609 $checked = (empty($filter['plfurlkey'][$urlkey]['plugins']) || false === strpos($filter['plfurlkey'][$urlkey]['plugins'], $key))? false : true;
573 - 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>';
574 611 }
575 612 $radio = '';
576 613 if(!empty($filter['_admin']['plugins']) && false !== strpos($filter['_admin']['plugins'], $key))
577 614 $radio = '_admin';
@@ -577,11 +614,11 @@
577 614 $radio = '_admin';
578 615 else if(!empty($filter['_pagefilter']['plugins']) && false !== strpos($filter['_pagefilter']['plugins'], $key))
579 616 $radio = '_pagefilter';
580 617 ?>
581 - <td class="radio-green filter-type"><label><input type="radio" name="<?php echo $opt_name; ?>" value='' <?php checked('', $radio); ?>/><span class="dashicons dashicons-admin-plugins"></span></label></td>
582 - <td class="radio-red filter-type"><label><input type="radio" name="<?php echo $opt_name; ?>" value="_admin" <?php checked('_admin', $radio); ?>/><span class="dashicons dashicons-admin-plugins"></span></label></td>
583 - <td class="radio-red filter-type"><label><input type="radio" name="<?php echo $opt_name; ?>" value="_pagefilter" <?php checked('_pagefilter', $radio); ?>/><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>
584 621 </tr>
585 622 <?php
586 623 }
587 624
@@ -595,11 +632,11 @@
595 632 $groupkeys = (method_exists('Plf_filter', 'get_active_group'))? Plf_filter::get_active_group() : array();
596 633 $urlnum = count($groupkeys);
597 634 ?>
598 635 <tr>
599 - <th class="filter-plugins-name" rowspan="2"><?php esc_html_e('Plugins'); ?></th>
636 + <th class="filter-plugins-name" rowspan="2"><?php esc_html_e('Plugins', 'plf'); ?></th>
600 637 <?php if($urlnum > 0) { ?>
601 - <th class="filter-type urlfilter" colspan="<?php echo $urlnum; ?>" style="font-weight:bold; font-size:smaller;"><?php esc_html_e('URL Group Filter', 'plf'); ?></th>
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>
602 639 <?php } ?>
603 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>
604 641 </tr>
605 642 <tr>
@@ -650,9 +687,9 @@
650 687 }
651 688 }
652 689 $hint .= PHP_EOL . PHP_EOL;
653 690 }
654 - echo "<th class='filter-type urlfilter'><span title='$hint' style='font-size:smaller'>{$v}</span></th>";
691 + echo '<th class="filter-type urlfilter"><span title="' . esc_html($hint) . '" style="font-size:smaller">' . esc_html($v) . '</span></th>';
655 692 }
656 693 } ?>
657 694 <th class="filter-type filter-none"><span style="font-size:smaller"><?php esc_html_e('Normal', 'plf'); ?></span></th>
658 695 <th class="filter-type filter-admin"><span style="font-size:smaller"><?php esc_html_e('Admin Type', 'plf'); ?></span></th>
@@ -695,9 +732,9 @@
695 732 $modules = $clist;
696 733 else
697 734 $this->plfregist_item($p_key, $chklist, $filter);
698 735 if(!empty($modules)){
699 - echo "<input type='hidden' name='plfregist[$p_key]' value='_pagefilter'>";
736 + echo '<input type="hidden" name="plfregist[' . esc_html($p_key) . ']" value="_pagefilter">';
700 737 foreach ( $modules as $m_key => $val) {
701 738 $this->plfregist_item($m_key, $chklist, $filter);
702 739 }
703 740 }
@@ -709,45 +746,66 @@
709 746 <p></p>
710 747 <div class="grid-row">
711 748 <div class="filter-description">
712 749 <p><strong>[ <?php esc_html_e('Page Type Filter', 'plf'); ?> ]</strong></p>
713 - <?php echo self::decode_safe_tag( 'strong', esc_html__('<strong>Normal</strong> - Exclude plugin from Page Type filter', 'plf')); ?><br />
714 - <?php echo self::decode_safe_tag( 'strong', esc_html__('<strong>Admin Type</strong> - If you only use plugins for Admin pages.', 'plf')); ?><br />
715 - <?php echo self::decode_safe_tag( 'strong', esc_html__('<strong>Page Type</strong> - If you want to activate or deactivate plugins for each Page Type and Single page.', 'plf')); ?>
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')); ?>
716 753 <p>
717 754 <?php
718 755 $checked = (!empty(self::$filter['admin_bar']))? self::$filter['admin_bar'] : false;
719 - echo '<span class="admin-bar-option">' . self::checkbox("plf_option[admin_bar]", $checked, esc_html__('Add a link to admin bar for displaying the plugins filtered status', 'plf') ) . '</span>';
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>';
720 757 ?>
721 758 </p>
722 - <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>
723 -
724 - <div class="exclude-pformat">
725 - <p><?php echo self::decode_safe_tag( '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>
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>
726 763 <?php
727 - $html = '<div>';
728 764 $pformat = array('image', 'gallery', 'video', 'audio', 'aside', 'status', 'quote', 'link', 'chat' );
729 765 foreach ( $pformat as $type ) {
730 - $checked = (!empty(self::$filter['exclude'][$type]))? self::$filter['exclude'][$type] : false;
731 - $label = "<span>$type</span>";
732 - $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
733 770 }
734 - $html .= '</div>';
735 - echo $html;
736 771 ?>
772 + </div>
737 773 </div>
738 - <p><strong>[ <?php esc_html_e('Ajax acceleration filter (Features for plugin developers)', 'plf'); ?> ]</strong></p>
739 - <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>
740 - <?php
741 - $checked = (!empty(self::$filter['ajax_accelfilter']))? self::$filter['ajax_accelfilter'] : false;
742 - echo '<div class="option-item">' . self::checkbox("plf_option[ajax_accelfilter]", $checked, esc_html__('Ajax acceleration filter', 'plf') ) . '</div>';
743 - ?>
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>
777 + <?php
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');
788 + }
789 + ?>
790 + </div>
791 + </div>
744 792 <p><strong>[ <?php esc_html_e('Post Language Locale', 'plf'); ?> ]</strong></p>
745 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>
746 794 <?php
747 795 $checked = (!empty(self::$filter['language']))? self::$filter['language'] : false;
748 - echo '<div class="option-item">' . self::checkbox("plf_option[language]", $checked, esc_html__('Language switching per post', 'plf') ) . '</div>';
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>';
749 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 + } ?>
750 808 </div>
751 809 <div class="side-info">
752 810 <?php if(! is_plugin_active('plugin-load-filter-addon/plugin-load-filter-addon.php')){ ?>
753 811 <div style="background-color: #f0fff0; border:1px solid #70c370; padding:4px 20px; margin: 10px 0;" >
@@ -762,8 +820,15 @@
762 820 <p><?php esc_html_e('We sell Image Optimization plugin. Reduce and speed up data size by converting to WebP / AVIF.', 'plf'); ?></p>
763 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>
764 822 </div>
765 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 } ?>
766 831 </div>
767 832 </div>
768 833 <?php
769 834 }
@@ -774,16 +839,18 @@
774 839 $selplugins = array_map("trim", explode(',', $select_cvplugins));
775 840 $devlist = array('desktop','mobile');
776 841 if(in_array( $p_key, $selplugins )){
777 842 $p_name = self::pluginkey_to_name($p_key);
778 - echo "<tr><td class='plugins-name'>$p_name</td>";
843 + echo '<tr><td class="plugins-name">' . esc_html($p_name) . '</td>';
779 844 foreach($devlist as $devtype){
845 + $name = "plfactive[$devtype][$p_key]";
780 846 $checked = (empty($filter['group'][$devtype]['plugins']) || false === strpos($filter['group'][$devtype]['plugins'], $p_key))? false : true;
781 - 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>';
782 848 }
783 849 foreach($chklist as $pgtype){
850 + $name = "plfactive[$pgtype][$p_key]";
784 851 $checked = (empty($filter['group'][$pgtype]['plugins']) || false === strpos($filter['group'][$pgtype]['plugins'], $p_key))? false : true;
785 - 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>';
786 853 }
787 854 echo "</tr>";
788 855 }
789 856 }
@@ -795,9 +862,9 @@
795 862 ?>
796 863 <div id="wrap_activation-table">
797 864 <table id="activation-table" class="widefat">
798 865 <thead>
799 - <tr><th class="plugins-name"><?php esc_html_e('Plugins'); ?></th>
866 + <tr><th class="plugins-name"><?php esc_html_e('Plugins', 'plf'); ?></th>
800 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>
801 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>
802 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>
803 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>
@@ -818,20 +885,20 @@
818 885 foreach ( $pformat as $type) {
819 886 if(!in_array($type, $exclude)){
820 887 $title = esc_html__('Post : ', 'plf') . $type;
821 888 $icon = ($type === "link")? "dashicons-admin-links" : "dashicons-format-$type";
822 - 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>';
823 890 }
824 891 }
825 892 if(function_exists('is_embed')){
826 893 $title = esc_html__('WordPress Embed Content Card (API)', 'plf');
827 - echo "<th class='ckbox-type tmpl-embed'><span title='$title' style='font-size:xx-small'>Embed Content</span></th>";
894 + echo '<th class="ckbox-type tmpl-embed"><span title="' . esc_html($title) . '" style="font-size:xx-small">Embed Content</span></th>';
828 895 }
829 896 $post_types = get_post_types( array('public' => true, '_builtin' => false) );
830 897 foreach ( $post_types as $post_type ) {
831 898 if(!empty($post_type)){
832 899 $title = esc_html__('Custom Post : ', 'plf') . $post_type;
833 - echo "<th class='ckbox-type tmpl-custom'><span title='$title' style='font-size:xx-small'>$post_type</span></th>";
900 + echo '<th class="ckbox-type tmpl-custom"><span title="' . esc_html($title) . '" style="font-size:xx-small">' . esc_html($post_type) . '</span></th>';
834 901 }
835 902 }
836 903 ?>
837 904 </tr>
@@ -886,9 +953,9 @@
886 953 }
887 954
888 955 //Option Setting Form Display
889 956 public function plf_option_page() {
890 - $clear_dialog = esc_html__('Plugin Load Filter Settings\nClick OK to clear it.', 'plf');
957 + $clear_dialog = __('Plugin Load Filter Settings\nClick OK to clear it.', 'plf');
891 958 ?>
892 959 <h2><?php esc_html_e('Plugin Load Filter Settings', 'plf'); ?></h2>
893 960 <p></p>
894 961 <div id="plf-setting-tabs">
@@ -900,9 +967,9 @@
900 967 <form method="post" autocomplete="off">
901 968 <?php wp_nonce_field( 'plugin_load_filter'); ?>
902 969 <?php $this->plfregist_table(self::$plugins_inf, self::$filter); ?>
903 970 <p class="submit">
904 - <input type="submit" class="button-primary" name="clear_regist_filter" value="<?php esc_html_e('Clear', 'plf'); ?>" onclick="return confirm('<?php echo $clear_dialog; ?>')" />&nbsp;&nbsp;&nbsp;
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;
905 972 <input type="submit" class="button-primary" name="edit_regist_filter" value="<?php esc_html_e('Filter Entry &raquo;', 'plf'); ?>" />
906 973 </p>
907 974 </form>
908 975 </div>
@@ -915,14 +982,14 @@
915 982 $this->plfactive_table(self::$plugins_inf, $pgfilter, self::$filter);
916 983 ?>
917 984 <br />
918 985 <p><?php
919 - echo self::decode_safe_tag( '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'));
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'));
920 987 ?><br />
921 988 <?php esc_html_e('You can also select plugins to activate from Post/Page content editing screen.', 'plf') ?>
922 989 </p>
923 990 <p class="submit">
924 - <input type="submit" class="button-primary" name="clear_activate_page_filter" value="<?php esc_html_e('Clear', 'plf'); ?>" onclick="return confirm('<?php echo $clear_dialog; ?>')" />&nbsp;&nbsp;&nbsp;
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;
925 992 <input type="submit" class="button-primary" name="edit_activate_page_filter" value="<?php esc_html_e('Activate Plugin Entry &raquo;', 'plf'); ?>" />
926 993 </p>
927 994 <?php
928 995 } else {
@@ -942,11 +1009,18 @@
942 1009 * Meta box
943 1010 * Individual of the plug-in filter meta box for Post/Page/CustomPost
944 1011 **************************************************************************/
945 1012 function load_meta_boxes( $post_type, $post ) {
946 - if ( current_user_can('activate_plugins', $post->ID) ) {
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 + }
947 1022 add_meta_box( 'pluginfilterdiv', esc_html__( 'Plugin Load Filter', 'plf' ), array(&$this, 'plf_meta_box'), null, 'side' );
948 - //add_action( 'admin_head', array(&$this, 'plf_css' ));
949 1023 add_action( 'admin_footer', array(&$this, 'plf_meta_script' ));
950 1024 }
951 1025 }
952 1026
@@ -964,10 +1038,11 @@
964 1038 if(in_array( $p_key, $selplugins )){
965 1039 $p_name = self::pluginkey_to_name($p_key);
966 1040 $html .= "<tr><td class='plugins-name'>$p_name</td>";
967 1041 foreach($devlist as $devtype){
1042 + $name = "plf_option[$devtype][$p_key]";
968 1043 $checked = (empty($device[$devtype]) || false === strpos($device[$devtype], $p_key))? false : true;
969 - $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>';
970 1045 }
971 1046 $html .= "</tr>";
972 1047 }
973 1048 return $html;
@@ -1058,9 +1133,9 @@
1058 1133 <p><?php esc_html_e( 'Plugin filter for Single post', 'plf' ); ?></p>
1059 1134 <label><input type="radio" name="pagefilter" value="default" <?php checked('default', $option['filter']); ?>/><?php esc_html_e('Not Use', 'plf' ); ?></label>
1060 1135 <label><input type="radio" name="pagefilter" value="include" <?php checked('include', $option['filter']); ?>/><?php esc_html_e('Use', 'plf'); ?></label>
1061 1136 <div id="page-filter-stat">
1062 - <?php echo $this->pagefilter_plugins_checklist( self::$plugins_inf, $pgfilter, $option ); ?>
1137 + <?php echo wp_kses($this->pagefilter_plugins_checklist( self::$plugins_inf, $pgfilter, $option ), self::get_allowed_tags()); ?>
1063 1138 </div>
1064 1139 <div class="plf-option-info"><?php esc_html_e('Plugin Activate/Deactivate filter for this Post only', 'plf'); ?></div>
1065 1140 <?php
1066 1141 $c_locale = $o_post_id = '';
@@ -1080,12 +1155,12 @@
1080 1155 $o_post_id = get_post_meta( $post->ID, '_original_post_id', true );
1081 1156 $o_post_id = (is_numeric($o_post_id))? $o_post_id : '';
1082 1157 $locale_mode = '';
1083 1158 }
1084 - echo '<p class="hide-if-no-js"><a id="plugin-filter-submit" class="button" href="#pluginfilterdiv" onclick="WPAddPagePluginLoadFilter(\'' . $ajax_nonce . '\');return false;" >'. esc_html__('Save') .'</a></p>';
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>';
1085 1160 ?>
1086 1161 <hr>
1087 - <div id="plf-post-locale-select" <?php echo $locale_mode; ?>>
1162 + <div id="plf-post-locale-select" <?php echo esc_html($locale_mode); ?>>
1088 1163 <p><?php esc_html_e( 'Language of this post', 'plf' ); ?> <span class="dashicons dashicons-translation" aria-hidden="true"></span></p>
1089 1164 <?php
1090 1165 wp_dropdown_languages(
1091 1166 array(
@@ -1097,9 +1172,9 @@
1097 1172 )
1098 1173 );
1099 1174 ?>
1100 1175 <p><?php esc_html_e( 'Original post ID for hreflang', 'plf' ); ?></p>
1101 - <input type="text" id="plf_original_post_id" name="plf_original_post_id" size="8" value="<?php echo $o_post_id; ?>" />
1176 + <input type="text" id="plf_original_post_id" name="plf_original_post_id" size="8" value="<?php echo esc_html($o_post_id); ?>" />
1102 1177 <div class="hflang-group-edit-lonk">
1103 1178 <?php
1104 1179 $id = (is_numeric($o_post_id))? $o_post_id : $post->ID;
1105 1180 global $wpdb;
@@ -1116,9 +1191,9 @@
1116 1191 $l = $site_locale;
1117 1192 }
1118 1193 $url = get_edit_post_link( $v );
1119 1194 if(!empty($url)){
1120 - echo '<p><a class="edit-post-locale-link" target="_blank" href="' . $url .'" rel="external noreferrer noopener">' . esc_html__('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>';
1121 1196 }
1122 1197 }
1123 1198 }
1124 1199 }
@@ -1125,9 +1200,9 @@
1125 1200 }
1126 1201 ?>
1127 1202 </div>
1128 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>
1129 - <?php echo '<p class="hide-if-no-js"><a id="plugin-filter-submit" class="button" href="#pluginfilterdiv" onclick="WPAddPagePluginLoadFilter(\'' . $ajax_nonce . '\');return false;" >'. esc_html__('Save') .'</a></p>'; ?>
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>'; ?>
1130 1205 </div>
1131 1206 </div>
1132 1207 <?php
1133 1208 }
@@ -1142,9 +1217,9 @@
1142 1217 check_ajax_referer( "plugin_load_filter-$pid" );
1143 1218
1144 1219 if(!empty(self::$filter['language'])){
1145 1220 if(isset($_POST['locale'])){
1146 - $s_locale = (!empty($_POST['locale']))? $_POST['locale'] : 'en_US';
1221 + $s_locale = (!empty($_POST['locale']))? sanitize_text_field(wp_unslash($_POST['locale'])) : 'en_US';
1147 1222 $languages = get_available_languages();
1148 1223 $languages[] = 'en_US'; //add WP default locale
1149 1224 if ( in_array( $s_locale, $languages ) ) {
1150 1225 $g_locale = get_post_meta( $pid, '_locale', true );
@@ -1182,14 +1257,15 @@
1182 1257 }
1183 1258 }
1184 1259 }
1185 1260 $pgfilter = (!empty(self::$filter['_pagefilter']['plugins']))? self::$filter['_pagefilter']['plugins'] : array();
1186 - $option["filter"] = (empty($_POST['filter']))? 'default' : $_POST['filter'];
1261 + $option["filter"] = (empty($_POST['filter']))? 'default' : sanitize_text_field(wp_unslash($_POST['filter']));
1187 1262 if('default' == $option["filter"]){
1188 1263 delete_post_meta( $pid, '_plugin_load_filter');
1189 1264 } else {
1190 1265 $plugins = array();
1191 - 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)){
1192 1268 if(!empty($matches[1])){
1193 1269 foreach ($matches[1] as $plugin){
1194 1270 $plugins[] = $plugin;
1195 1271 }
@@ -1196,9 +1272,10 @@
1196 1272 $option["desktop"] = implode(",", $plugins);
1197 1273 }
1198 1274 }
1199 1275 $plugins = array();
1200 - 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)){
1201 1278 if(!empty($matches[1])){
1202 1279 foreach ($matches[1] as $plugin){
1203 1280 $plugins[] = $plugin;
1204 1281 }
@@ -1246,9 +1323,9 @@
1246 1323 **************************************************************************/
1247 1324 function activetab_script() { ?>
1248 1325 <script type='text/javascript' >
1249 1326 /* <![CDATA[ */
1250 - var plf_activetab = <?php echo $this->tab_num; ?>
1327 + var plf_activetab = <?php echo esc_html($this->tab_num); ?>
1251 1328 /* ]]> */
1252 1329 jQuery(document).ready(function ($) {
1253 1330 plf_setting_tabs();
1254 1331 function plf_setting_tabs(){ $('#plf-setting-tabs').tabs({ active:plf_activetab, }); }
@@ -1256,9 +1333,8 @@
1256 1333 </script>
1257 1334 <?php }
1258 1335
1259 1336 function plf_meta_script() {
1260 - $reload_dialog = esc_html__('Plugin Load Filter setting has been updated.\nClick OK to reload the page.', 'plf');
1261 1337 ?>
1262 1338 <script type='text/javascript' >
1263 1339 WPAddPagePluginLoadFilter = function(nonce){
1264 1340 jQuery.ajax({
@@ -1277,9 +1353,9 @@
1277 1353 dataType: 'json',
1278 1354 }).then(
1279 1355 function (response, dataType) {
1280 1356 jQuery('#page-filter-stat').html(response.data);
1281 - 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'); ?>')){
1282 1358 location.reload();
1283 1359 }
1284 1360 },
1285 1361 function () { /* alert("ajax error"); */ }