PluginProbe
Plugin Load Filter / 2.3.1
Plugin Load Filter v2.3.1
trunk 2.0.0 2.0.1 2.1.0 2.2.0 2.2.1 2.3.0 2.3.1 2.4.0 2.4.1 2.5.1 3.3.0 4.0.6 4.1.1 4.2.0 4.3.0 4.3.1 4.4.0
← All changes | plugin-load-filter.php +157 -618 3.3.02.3.1 View file →
@@ -1,78 +1,17 @@
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: 2.3.1
6 + Plugin URI: http://celtislab.net/wp_plugin_load_filter
7 7 Author: enomoto@celtislab
8 - Author URI: https://celtislab.net/
8 + Author URI: http://celtislab.net/
9 9 License: GPLv2
10 10 Text Domain: plf
11 11 Domain Path: /languages
12 12 */
13 -defined( 'ABSPATH' ) || exit;
14 13
15 -/***************************************************************************
16 - * plugin activation / deactivation / uninstall
17 - **************************************************************************/
18 -if(is_admin()){
19 - //deactivation
20 - function plugin_load_filter_deactivation( $network_deactivating ) {
21 - $act = false;
22 - if (is_multisite()) {
23 - if(! $network_deactivating){
24 - global $wpdb;
25 - $current_blog_id = get_current_blog_id();
26 - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
27 - foreach ( $blog_ids as $blog_id ) {
28 - if($blog_id == $current_blog_id){
29 - //current site
30 - }
31 - else {
32 - //other site active check
33 - switch_to_blog( $blog_id );
34 - if ( is_plugin_active( plugin_basename( __FILE__ )))
35 - $act = true;
36 - }
37 - }
38 - switch_to_blog( $current_blog_id );
39 - }
40 - }
41 - if($act === false){
42 - flush_rewrite_rules(); //options data 'rewrite_rules' clear for remake.
43 - if ( file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) {
44 - @unlink( WPMU_PLUGIN_DIR . '/plf-filter.php' );
45 - }
46 - }
47 - }
48 - register_deactivation_hook( __FILE__, 'plugin_load_filter_deactivation' );
49 -
50 - //uninstall
51 - function plugin_load_filter_uninstall() {
52 -
53 - if ( !is_multisite()) {
54 - delete_option('plf_queryvars');
55 - delete_option('plf_option' );
56 - } else {
57 - global $wpdb;
58 - $current_blog_id = get_current_blog_id();
59 - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
60 - foreach ( $blog_ids as $blog_id ) {
61 - switch_to_blog( $blog_id );
62 - delete_option('plf_queryvars');
63 - delete_option('plf_option' );
64 - }
65 - switch_to_blog( $current_blog_id );
66 - }
67 - if ( file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) {
68 - @unlink( WPMU_PLUGIN_DIR . '/plf-filter.php' );
69 - }
70 - }
71 - register_uninstall_hook(__FILE__, 'plugin_load_filter_uninstall');
72 -
73 -}
74 -
75 14 $Plf_setting = new Plf_setting();
76 15
77 16 class Plf_setting {
78 17
@@ -78,31 +17,23 @@
78 17
79 18 private $plugins_inf = ''; //active plugin/module infomation
80 19 private $filter = array(); //filter option data
81 20 private $tab_num = 0;
82 -
21 +
83 22 /***************************************************************************
84 23 * Style Sheet
85 24 **************************************************************************/
86 25 function plf_css() { ?>
87 26 <style type="text/css">
88 - #plugin-filter-select {margin-top: 12px;}
89 - #plugin-filter-select p {margin: 1em 0;}
90 - #page-filter-stat { margin-top: 12px;}
91 - #activation-table { border: 1px solid #eee;}
92 - #activation-table th { font-size: 97%; text-align: center;}
93 - #activation-table td { font-size: 97%;}
27 + #activation-table { margin-top: 10px; border: 1px solid #eee;}
94 28 #activation-table input[type=checkbox] { height: 25px; width: 25px; opacity: 0;}
95 - #plf-post-locale-select { margin-top: 16px;}
96 29 thead .plugins-name { background-color: aliceblue;}
97 30 thead .device-type { background-color: oldlace;}
98 - 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;}
31 + thead .plugins-name, tbody .plugins-name { min-width: 172px; max-width: 172px;}
32 + thead .device-type, tbody .device-type { min-width: 36px; max-width: 36px; padding: 0;}
100 33 .dashicons-yes:before { font-size: 20px; border: 1px solid #eee; background-color: whitesmoke;}
101 34 .device-type label { color: whitesmoke; margin-left: -28px; }
102 - .device-type input[type="checkbox"]:checked + label .dashicons-yes:before { background-color: yellowgreen; }
103 - .plf-option-info { font-size:12px; margin:10px 0; padding:3px; background-color:#fff8e5;}
104 - .edit-post-locale-link span.dashicons { width: 0.8em; height: 0.8em; margin: -0.4em 0.1em 0; vertical-align: middle; text-decoration: initial;}
35 + .device-type input[type="checkbox"]:checked + label .dashicons-yes:before { background-color: yellowgreen; }
105 36 </style>
106 37 <?php }
107 38
108 39 function jquery_tab_css() { ?>
@@ -124,46 +55,36 @@
124 55 .ui-state-active, .ui-widget-content .ui-state-active, .ui-widget-header .ui-state-active { border: 1px solid #dddddd; background-color: #0073ea; font-weight: bold; color: #ffffff; }
125 56 .ui-state-hover a, .ui-state-hover a:hover, .ui-state-hover a:link, .ui-state-hover a:visited { color: #ffffff; text-decoration: none; }
126 57 .ui-state-active a, .ui-state-active a:link, .ui-state-active a:visited { color: #ffffff; text-decoration: none; }
127 58
128 - #wrap_registration-table, #wrap_activation-table { overflow:auto; height:600px; position: relative;}
129 - #registration-table input[type=radio], #registration-table input[type=checkbox], #activation-table input[type=checkbox] { height: 25px; width: 25px; opacity: 0;}
59 + #wrap_registration-table, #wrap_activation-table { overflow-x:auto;}
60 + #registration-table input[type=radio], #activation-table input[type=checkbox] { height: 25px; width: 25px; opacity: 0;}
130 61 thead, tbody { display: block;}
131 - .widefat * { word-wrap: break-word !important;}
132 - .widefat thead { position:sticky; top:0px; z-index:1;}
133 - .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;}
136 - .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; }
138 - thead .urlfilter { background-color: lavenderblush;}
139 - .filter-none, .filter-admin, .filter-tmpl { background-color: honeydew;}
62 + .plugins-table-body { overflow-y:scroll; height:500px; }
63 + .widefat td, .widefat th { padding: 8px 4px;}
64 + thead .filter-plugins-name, thead .plugins-name { background-color: aliceblue;}
65 + .filter-none, .filter-admin, .filter-tmpl { background-color: oldlace;}
140 66 thead .device-type { background-color: oldlace;}
141 - thead .ckbox-type { background-color: lavender;}
67 + thead .tmpl-type { background-color: lavender;}
142 68 thead .pformat { background-color: honeydew;}
143 69 thead .tmpl-embed { background-color: lightyellow;}
144 70 thead .tmpl-custom { background-color: lavenderblush;}
145 - thead .filter-plugins-name, tbody .filter-plugins-name { min-width: 260px;}
71 + thead .filter-plugins-name, tbody .filter-plugins-name { min-width: 260px; max-width: 260px;}
146 72 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;}
149 - .urlfilter-description { padding: 0 10px 15px;}
150 - .filter-description { padding: 0 10px;}
151 - .exclude-pformat { padding: 5px 0 20px}
73 + thead .filter-type, tbody .filter-type { min-width: 100px; max-width: 100px;}
74 + thead .device-type, tbody .device-type, thead .tmpl-type, tbody .tmpl-type { min-width: 40px; max-width: 40px; }
75 + .filter-description { padding: 0 10px 20px 10px;}
76 + .exclude-pformat { padding: 16px 0 20px}
152 77 .exclude-pformat label { white-space:nowrap;}
153 78 .exclude-pformat span { margin-right: 12px; }
154 79 .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; }
162 - .dashicons-yes:before { font-size: 20px; border: 1px solid #eee; }
80 + .radio-green label, .radio-red label, .tmpl-type label { color: #ddd; margin-left: -28px; }
81 + .radio-green input[type="radio"]:checked + label { color: #339966; }
82 + .radio-red input[type="radio"]:checked + label { color: #ff0000; }
83 + .tmpl-type input[type="checkbox"]:checked + label { color: #339966; }
84 + .dashicons-yes:before { font-size: 20px; border: 1px solid #eee; background-color: whitesmoke;}
163 85 .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; }
86 + .device-type input[type="checkbox"]:checked + label .dashicons-yes:before { background-color: yellowgreen; }
166 87 </style>
167 88 <?php }
168 89
169 90 /***************************************************************************
@@ -172,25 +93,64 @@
172 93
173 94 public function __construct() {
174 95
175 96 load_plugin_textdomain('plf', false, basename( dirname( __FILE__ ) ).'/languages' );
176 -
97 +
177 98 $this->filter = get_option('plf_option');
99 + //v2.3.0 option change
178 100 if(empty($this->filter['optver']) || $this->filter['optver'] < '2'){
179 101 $this->filter['optver'] = '2';
180 - //ここにデータフォーマットが変わった場合の変換処理を記述
102 +
103 + if(empty($this->filter['group']['desktop']) && empty($this->filter['group']['mobile'])){
104 + //For ver2.2.0 compatibility, set '_pagefilter' data to 'desktop' and 'mobile'
105 + if(!empty($this->filter['_pagefilter'])){
106 + $this->filter['group']['desktop'] = $this->filter['_pagefilter'];
107 + $this->filter['group']['mobile'] = $this->filter['_pagefilter'];
108 + }
109 + if(!empty($this->filter['_desktop'])){
110 + $this->filter['_desktop'] = null;
111 + }
112 + if(!empty($this->filter['_mobile'])){
113 + $this->filter['_mobile'] = null;
114 + }
115 + }
181 116 }
182 - if(!empty($this->filter['language'])){
183 - add_action( 'wp_head', array('Plf_setting', 'altenate_hreflang') );
184 - }
117 +
185 118 if(is_admin()) {
186 119 add_action( 'plugins_loaded', array(&$this, 'plf_admin_start'), 9999 );
187 - add_action( 'admin_init', array(&$this, 'action_posts'));
188 120 add_action( 'add_meta_boxes', array(&$this, 'load_meta_boxes'), 10, 2 );
121 + //plf-filter must-use plagin activete check
122 + if(wp_mkdir_p( WPMU_PLUGIN_DIR )){
123 + if ( !file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) {
124 + @copy(__DIR__ . '/mu-plugins/plf-filter.php', WPMU_PLUGIN_DIR . '/plf-filter.php');
125 + }
126 + else {
127 + require_once(ABSPATH . 'wp-admin/includes/plugin.php');
128 + $dp = get_plugin_data( WPMU_PLUGIN_DIR . "/plf-filter.php", false, false );
129 + $sp = get_plugin_data( __DIR__ . '/mu-plugins/plf-filter.php', false, false );
130 + if(version_compare( $dp['Version'], $sp['Version'], '!=')){
131 + @copy(__DIR__ . '/mu-plugins/plf-filter.php', WPMU_PLUGIN_DIR . '/plf-filter.php');
132 + }
133 + }
134 + }
135 + register_deactivation_hook( __FILE__, 'Plf_setting::deactivation' );
136 + register_uninstall_hook(__FILE__, 'Plf_setting::uninstall');
189 137 }
190 138 add_action( 'wp_ajax_plugin_load_filter', array(&$this, 'plf_ajax_postidfilter'));
191 139 }
192 140
141 + //Plugin Deactivate
142 + public static function deactivation() {
143 + if ( file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) {
144 + @unlink( WPMU_PLUGIN_DIR . '/plf-filter.php' );
145 + }
146 + }
147 + //Plugin Uninstall
148 + public static function uninstall() {
149 + delete_option('plf_queryvars');
150 + delete_option('plf_option' );
151 + }
152 +
193 153 //Plugin Load Filter admin setting start
194 154 public function plf_admin_start() {
195 155 require_once(ABSPATH . 'wp-admin/includes/plugin.php');
196 156
@@ -224,8 +184,9 @@
224 184 }
225 185 if ( empty( $this->plugins_inf ) )
226 186 return;
227 187
188 + $this->action_posts(); //POST, GET Request Action
228 189 add_action('admin_menu', array(&$this, 'plf_option_menu'));
229 190 }
230 191
231 192 //Plugins sub menu add
@@ -231,9 +192,8 @@
231 192 //Plugins sub menu add
232 193 public function plf_option_menu() {
233 194 $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 195 add_action('admin_print_scripts-'.$page, array(&$this, 'plf_scripts'));
235 - add_action('admin_print_scripts-'.$page, array(&$this, 'deploy_mu_plugins'));
236 196 }
237 197
238 198 //Plugin Load Filter setting page script
239 199 function plf_scripts() {
@@ -240,61 +200,19 @@
240 200 wp_enqueue_script( 'jquery' );
241 201 wp_enqueue_script( 'jquery-ui-core' );
242 202 wp_enqueue_script( 'jquery-ui-widget' );
243 203 wp_enqueue_script( 'jquery-ui-tabs' );
244 - wp_enqueue_script( 'postbox' );
245 204 add_action( 'admin_head', array(&$this, 'plf_css' ));
246 205 add_action( 'admin_head', array(&$this, 'jquery_tab_css' ));
247 206 add_action( 'admin_footer', array(&$this, 'activetab_script' ));
248 - add_action( 'admin_notices', array(&$this, 'plf_notice'));
249 207 }
250 -
251 - //plf-filter.php mu-plugins module set
252 - public function deploy_mu_plugins() {
253 - if(wp_mkdir_p( WPMU_PLUGIN_DIR )){
254 - if ( !file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) {
255 - @copy(__DIR__ . '/mu-plugins/plf-filter.php', WPMU_PLUGIN_DIR . '/plf-filter.php');
256 - }
257 - else {
258 - require_once(ABSPATH . 'wp-admin/includes/plugin.php');
259 - $dp = get_plugin_data( WPMU_PLUGIN_DIR . "/plf-filter.php", false, false );
260 - $sp = get_plugin_data( __DIR__ . '/mu-plugins/plf-filter.php', false, false );
261 - if(version_compare( $dp['Version'], $sp['Version'], '!=')){
262 - @copy(__DIR__ . '/mu-plugins/plf-filter.php', WPMU_PLUGIN_DIR . '/plf-filter.php');
263 - }
264 - }
265 - }
266 - }
267 -
268 - //Notice Message display
269 - public function plf_notice() {
270 - $notice = get_transient('plf_notice');
271 - if(!empty($notice)){
272 - echo "<div class='message error'><p>Plugin Load Filter : $notice</p></div>";
273 - delete_transient('plf_notice');
274 - }
275 - }
276 208
277 209 //plugin filter option action request (add, update, delete)
278 210 function action_posts() {
279 - if (current_user_can( 'activate_plugins' )) {
211 + if (current_user_can( 'edit_plugins' )) {
280 212 if( isset($_POST['edit_regist_filter']) ) {
281 213 if(isset($_POST['plfregist'])){
282 214 check_admin_referer('plugin_load_filter');
283 - //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;
291 - }
292 - $option["plugins"] = implode(",", $plugins);
293 - $this->filter['plfurlkey'][$item] = $option;
294 - }
295 - }
296 - //page type filter
297 215 foreach( array('_admin', '_pagefilter') as $item){
298 216 $plugins = array();
299 217 foreach ( $_POST['plfregist'] as $p_key => $val ) {
300 218 if($val == $item)
@@ -326,9 +244,8 @@
326 244 }
327 245 $option["plugins"] = implode(",", array_keys($plugins));
328 246 $this->filter[$item] = $option;
329 247 }
330 - //exclude option
331 248 if(isset($_POST['plf_option']['exclude'])){
332 249 $exclude = array();
333 250 foreach ( $_POST['plf_option']['exclude'] as $ft => $v ) {
334 251 if(!empty($v))
@@ -334,45 +251,12 @@
334 251 if(!empty($v))
335 252 $exclude[$ft] = true;
336 253 }
337 254 $this->filter['exclude'] = $exclude;
338 - } else {
339 - $this->filter['exclude'] = array();
340 255 }
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);
351 - }
256 + else {
257 + $this->filter['exclude'] = '';
352 258 }
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 -
372 - //Language option
373 - $this->filter['language'] = (isset($_POST['plf_option']['language']))? 1 : 0;
374 -
375 259 update_option('plf_option', $this->filter );
376 260 }
377 261 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page'));
378 262 exit;
@@ -378,20 +262,12 @@
378 262 exit;
379 263 }
380 264 elseif( isset($_POST['clear_regist_filter']) ) {
381 265 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]);
385 - }
386 - }
387 266 foreach( array('_admin', '_pagefilter') as $item){
388 - $this->filter[$item] = array();
267 + $this->filter[$item] = '';
389 268 }
390 - $this->filter['exclude'] = array();
391 - $this->filter['urlkey'] = array();
392 - $this->filter['urlkeylist'] = '';
393 - $this->filter['language'] = 0;
269 + $this->filter['exclude'] = '';
394 270 update_option('plf_option', $this->filter );
395 271 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page'));
396 272 exit;
397 273 }
@@ -416,9 +292,9 @@
416 292 elseif( isset($_POST['clear_activate_page_filter']) ) {
417 293 check_admin_referer('plugin_load_filter');
418 294 $group = array_keys($_POST['plfactive']);
419 295 foreach( $group as $item){
420 - $this->filter['group'][$item] = array();
296 + $this->filter['group'][$item] = '';
421 297 }
422 298 update_option('plf_option', $this->filter );
423 299 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page&action=tab_1'));
424 300 exit;
@@ -469,33 +345,22 @@
469 345 }
470 346 static function altcheckbox($name, $value, $label = '') {
471 347 return "<input type='hidden' name='$name' value='0'><input type='checkbox' name='$name' value='1' " . checked( $value, 1, false ). "/><label> $label</label>";
472 348 }
473 -
474 - public function plfregist_item($key, $chklist, $filter) {
349 +
350 + public function plfregist_item($key, $val) {
475 351 $p_name = $this->pluginkey_to_name($key);
476 352 $opt_name = "plfregist[$key]";
477 353 ?>
478 354 <tr id="plfregist_<?php echo $key; ?>">
479 355 <td class="filter-plugins-name"><?php echo $p_name; ?></td>
480 - <?php
481 - foreach($chklist as $urlkey){
482 - $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>';
484 - }
485 - $radio = '';
486 - if(!empty($filter['_admin']['plugins']) && false !== strpos($filter['_admin']['plugins'], $key))
487 - $radio = '_admin';
488 - else if(!empty($filter['_pagefilter']['plugins']) && false !== strpos($filter['_pagefilter']['plugins'], $key))
489 - $radio = '_pagefilter';
490 - ?>
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>
356 + <td class="radio-green filter-type"><input type="radio" name="<?php echo $opt_name; ?>" value='' <?php checked('', $val); ?>/><label><span class="dashicons dashicons-admin-plugins"></span></label></td>
357 + <td class="radio-red filter-type"><input type="radio" name="<?php echo $opt_name; ?>" value="_admin" <?php checked('_admin', $val); ?>/><label><span class="dashicons dashicons-admin-plugins"></span></label></td>
358 + <td class="radio-red filter-type"><input type="radio" name="<?php echo $opt_name; ?>" value="_pagefilter" <?php checked('_pagefilter', $val); ?>/><label><span class="dashicons dashicons-admin-plugins"></span></label></td>
494 359 </tr>
495 360 <?php
496 361 }
497 -
362 +
498 363 //Filterring plugins select
499 364 public function plfregist_table($plugins, $filter) {
500 365 ?>
501 366 <div id="wrap_registration-table">
@@ -500,45 +365,13 @@
500 365 ?>
501 366 <div id="wrap_registration-table">
502 367 <table id="registration-table" class="widefat">
503 368 <thead>
504 - <?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);
514 - ?>
515 - <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>
369 + <tr><th class="filter-plugins-name"><?php _e('Plugins'); ?></th>
370 + <th class="filter-type filter-none"><?php _e('Normal Load', 'plf'); ?></th>
371 + <th class="filter-type filter-admin"><?php _e('Admin Filter', 'plf'); ?></th>
372 + <th class="filter-type filter-tmpl"><?php _e('Page Filter', 'plf'); ?></th>
519 373 </tr>
520 - <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>";
529 - }
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>
540 - </tr>
541 374 </thead>
542 375 <tbody class="plugins-table-body">
543 376 <?php
544 377 //plugins filter registoration table
@@ -547,8 +380,15 @@
547 380 $name = $this->pluginkey_to_name($p_key);
548 381 if(!empty($name))
549 382 $plist[$p_key] = '';
550 383 }
384 + foreach( array('_admin', '_pagefilter') as $item){
385 + $parr = (!empty($filter[$item]['plugins'])) ? array_map("trim", explode(',', $filter[$item]['plugins'])) : array();
386 + foreach ( $plist as $p_key => $val ) {
387 + if(empty($val) && in_array($p_key, $parr))
388 + $plist[$p_key] = $item;
389 + }
390 + }
551 391 $jlist = $clist = array();
552 392 foreach ( $plist as $p_key => $val ) {
553 393 if(strpos($p_key, 'jetpack_module/') !== false){
554 394 $jlist[$p_key] = $plist[$p_key];
@@ -558,19 +398,8 @@
558 398 $clist[$p_key] = $plist[$p_key];
559 399 unset($plist[$p_key]);
560 400 }
561 401 }
562 - $chklist = array('wp-json','heartbeat','admin-ajax');
563 - foreach ($items as $key => $label) {
564 - if(!empty($filter['urlkey'][$key])){
565 - $chklist[] = $key;
566 - }
567 - }
568 - //汎用URLフィルタータイトル表示
569 - foreach ($urlkey as $key) {
570 - $chklist[] = $key;
571 - }
572 -
573 402 foreach ( $plist as $p_key => $val ) {
574 403 $modules = array();
575 404 if(strpos($p_key, 'jetpack/') !== false)
576 405 $modules = $jlist;
@@ -576,13 +405,13 @@
576 405 $modules = $jlist;
577 406 else if(strpos($p_key, 'celtispack/') !== false)
578 407 $modules = $clist;
579 408 else
580 - $this->plfregist_item($p_key, $chklist, $filter);
409 + $this->plfregist_item($p_key, $val);
581 410 if(!empty($modules)){
582 411 echo "<input type='hidden' name='plfregist[$p_key]' value='_pagefilter'>";
583 412 foreach ( $modules as $m_key => $val) {
584 - $this->plfregist_item($m_key, $chklist, $filter);
413 + $this->plfregist_item($m_key, $val);
585 414 }
586 415 }
587 416 }
588 417 ?>
@@ -587,50 +416,18 @@
587 416 }
588 417 ?>
589 418 </tbody>
590 419 </table>
591 - </div>
592 420 <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>
607 - <?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']): '';
619 - ?>
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 />
421 + <p><strong>[ Admin Filter ]</strong></p>
422 + <div class="filter-description"><?php _e('Plugins to be used only in admin mode.', 'plf'); ?></div>
423 + <p><strong>[ Page Filter ]</strong></p>
424 + <div class="filter-description">
628 425 <?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>
426 + <?php _e('Selected page filter plugins are once blocked, but is activated by "Page filter Activation" setting.', 'plf'); ?>
630 427 <div class="exclude-pformat">
631 428 <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'); ?>
429 + <?php _e('Choose Post Format Type you are not using. To exclude from Page Filter item subject.', 'plf'); ?>
633 430 </p>
634 431 <?php
635 432 $html = '<div>';
636 433 $pformat = array('image', 'gallery', 'video', 'audio', 'aside', 'status', 'quote', 'link', 'chat' );
@@ -643,72 +440,12 @@
643 440 echo $html;
644 441 ?>
645 442 </div>
646 443 </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 444 </div>
655 445 <?php
656 446 }
657 447
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>
670 - <?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>";
679 - }
680 - echo $html;
681 - $urlkeylist = (!empty($this->filter['urlkeylist']))? esc_textarea($this->filter['urlkeylist']): '';
682 - ?>
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>
685 - </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
708 - }
709 -
710 -
711 448 //Activate plugins select from Page Filter
712 449 public function _plfactive_checkbox_row($p_key, $select_cvplugins, $chklist, $filter) {
713 450
714 451 $selplugins = array_map("trim", explode(',', $select_cvplugins));
@@ -721,9 +458,9 @@
721 458 echo '<td class="device-type">' . self::altcheckbox("plfactive[$devtype][$p_key]", $checked, '<span class="dashicons dashicons-yes"></span>') . '</td>';
722 459 }
723 460 foreach($chklist as $pgtype){
724 461 $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>';
462 + echo '<td class="tmpl-type">' . self::altcheckbox("plfactive[$pgtype][$p_key]", $checked, '<span class="dashicons dashicons-admin-plugins"></span>') . '</td>';
726 463 }
727 464 echo "</tr>";
728 465 }
729 466 }
@@ -738,14 +475,14 @@
738 475 <thead>
739 476 <tr><th class="plugins-name"><?php _e('Plugins'); ?></th>
740 477 <th class="device-type"><span title="<?php _e('Desktop Device', 'plf'); ?>" class="dashicons dashicons-desktop"></span><br /><span style="font-size:xx-small">Desktop</span></th>
741 478 <th class="device-type"><span title="<?php _e('Mobile Device', 'plf'); ?>" class="dashicons dashicons-smartphone"></span><br /><span style="font-size:xx-small">Mobile</span></th>
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>
479 + <th class="tmpl-type"><span title="<?php _e('Home/Front-page', 'plf'); ?>" class="dashicons dashicons-admin-home"></span><br /><span style="font-size:xx-small">Home</span></th>
480 + <th class="tmpl-type"><span title="<?php _e('Archive page', 'plf'); ?>" class="dashicons dashicons-list-view"></span><br /><span style="font-size:xx-small">Archive</span></th>
481 + <th class="tmpl-type"><span title="<?php _e('Search page', 'plf'); ?>" class="dashicons dashicons-search"></span><br /><span style="font-size:xx-small">Search</span></th>
482 + <th class="tmpl-type"><span title="<?php _e('Attachment page', 'plf'); ?>" class="dashicons dashicons-media-default"></span><br /><span style="font-size:xx-small">Attach</span></th>
483 + <th class="tmpl-type"><span title="<?php _e('Page', 'plf'); ?>" class="dashicons dashicons-admin-page"></span><br /><span style="font-size:xx-small">Page</span></th>
484 + <th class="tmpl-type pformat"><span title="<?php _e('Post : ', 'plf'); _e('Standard', 'plf'); ?>" class="dashicons dashicons-admin-post"></span><br /><span style="font-size:xx-small">Post</span></th>
748 485 <?php
749 486 $pformat = array('image', 'gallery', 'video', 'audio', 'aside', 'status', 'quote', 'link', 'chat' );
750 487 $exclude = array();
751 488 if(!empty($filter['exclude'])){
@@ -758,20 +495,20 @@
758 495 foreach ( $pformat as $type) {
759 496 if(!in_array($type, $exclude)){
760 497 $title = __('Post : ', 'plf') . $type;
761 498 $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>';
499 + echo '<th class="tmpl-type pformat"><span title="' . $title . '" class="dashicons ' . $icon .'"></span><br /><span style="font-size:xx-small">' . $type .'</span></th>';
763 500 }
764 501 }
765 502 if(function_exists('is_embed')){
766 503 $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>";
504 + echo "<th class='tmpl-type tmpl-embed'><span title='$title' style='font-size:xx-small'>Embed Content</span></th>";
768 505 }
769 506 $post_types = get_post_types( array('public' => true, '_builtin' => false) );
770 507 foreach ( $post_types as $post_type ) {
771 508 if(!empty($post_type)){
772 509 $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>";
510 + echo "<th class='tmpl-type tmpl-custom'><span title='$title' style='font-size:xx-small'>$post_type</span></th>";
774 511 }
775 512 }
776 513 ?>
777 514 </tr>
@@ -826,9 +563,8 @@
826 563 }
827 564
828 565 //Option Setting Form Display
829 566 public function plf_option_page() {
830 - $clear_dialog = __('Plugin Load Filter Settings\nClick OK to clear it.', 'plf');
831 567 ?>
832 568 <h2><?php _e('Plugin Load Filter Settings', 'plf'); ?></h2>
833 569 <p></p>
834 570 <div id="plf-setting-tabs">
@@ -833,68 +569,44 @@
833 569 <p></p>
834 570 <div id="plf-setting-tabs">
835 571 <ul>
836 572 <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>
573 + <li><a href="#plf-activation-tab" ><?php _e('Page Filter Activation', 'plf'); ?></a></li>
838 574 </ul>
575 + <form method="post" >
576 + <?php wp_nonce_field( 'plugin_load_filter'); ?>
839 577 <div id="plf-registration-tab" style="display : none;">
840 - <form method="post" autocomplete="off">
841 - <?php wp_nonce_field( 'plugin_load_filter'); ?>
842 - <?php $this->plfregist_table($this->plugins_inf, $this->filter); ?>
578 + <?php $this->plfregist_table($this->plugins_inf, $this->filter); ?>
579 + <p class="submit">
580 + <input type="submit" class="button-primary" name="clear_regist_filter" value="<?php _e('Clear', 'plf'); ?>" />&nbsp;&nbsp;&nbsp;
581 + <input type="submit" class="button-primary" name="edit_regist_filter" value="<?php _e('Filter Entry &raquo;', 'plf'); ?>" />
582 + </p>
583 + </div>
584 + <div id="plf-activation-tab" style="display : none;">
585 + <?php
586 + $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
587 + if(!empty($pgfilter)){
588 + $this->plfactive_table($this->plugins_inf, $pgfilter, $this->filter);
589 + ?>
590 + <br />
591 + <p><?php _e('Select plugins to be activated for each page type by clicking on <span class="dashicons dashicons-admin-plugins"></span> mark from "page filter" registered plugins.', 'plf') ?><br />
592 + <?php _e('You can also select plugins to activate from Post/Page content editing screen.', 'plf') ?>
593 + </p>
843 594 <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'); ?>" />
595 + <input type="submit" class="button-primary" name="clear_activate_page_filter" value="<?php _e('Clear', 'plf'); ?>" />&nbsp;&nbsp;&nbsp;
596 + <input type="submit" class="button-primary" name="edit_activate_page_filter" value="<?php _e('Activate Plugin Entry &raquo;', 'plf'); ?>" />
846 597 </p>
847 - </form>
848 -<?php
849 -/*
850 - <div class="wrap yasakani-settings">
851 598 <?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');
599 + }
600 + else {
854 601 ?>
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 - </div>
871 - <div id="plf-activation-tab" style="display : none;">
872 - <form method="post" autocomplete="off">
873 - <?php wp_nonce_field( 'plugin_load_filter'); ?>
602 + <br />
603 + <p><span style="color: #ff0000;"><?php _e('Page Filter is not registered', 'plf') ?></span></p>
874 604 <?php
875 - $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
876 - if(!empty($pgfilter)){
877 - $this->plfactive_table($this->plugins_inf, $pgfilter, $this->filter);
878 - ?>
879 - <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>
883 - <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'); ?>" />
886 - </p>
887 - <?php
888 - } else {
889 - ?>
890 - <br />
891 - <p><span style="color: #ff0000;"><?php _e('Page Filter is not registered', 'plf') ?></span></p>
892 - <?php
893 - }
894 - ?>
895 - </form>
605 + }
606 + ?>
896 607 </div>
608 + </form>
897 609 </div>
898 610 <?php
899 611 }
900 612
@@ -902,11 +614,11 @@
902 614 * Meta box
903 615 * Individual of the plug-in filter meta box for Post/Page/CustomPost
904 616 **************************************************************************/
905 617 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' ));
618 + if ( current_user_can('edit_plugins', $post->ID) ) {
619 + add_meta_box( 'pluginfilterdiv', __( 'Page Filter Plugin', 'plf' ), array(&$this, 'plf_meta_box'), null, 'side' );
620 + add_action( 'admin_head', array(&$this, 'plf_css' ));
909 621 add_action( 'admin_footer', array(&$this, 'plf_meta_script' ));
910 622 }
911 623 }
912 624
@@ -982,18 +694,8 @@
982 694 $html .= '</table>';
983 695 return $html;
984 696 }
985 697
986 - //get_locale に加えたフィルターフックを外してサイトのロケールを取得
987 - static function get_site_locale(){
988 - 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') );
993 - return $site_locale;
994 - }
995 -
996 698 function plf_meta_box( $post, $box ) {
997 699 if(is_object($post)){
998 700 $myfilter = get_post_meta( $post->ID, '_plugin_load_filter', true );
999 701 //ver2.2.0 for compatibility, set 'plugins' data to 'desktop' and 'mobile'
@@ -1006,86 +708,17 @@
1006 708 $option = (!empty($myfilter))? $myfilter : $default;
1007 709 $option = wp_parse_args( $option, $default);
1008 710 $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
1009 711 $ajax_nonce = wp_create_nonce( 'plugin_load_filter-' . $post->ID );
1010 - $this->plf_css();
1011 712 ?>
1012 - <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>
1016 - <div id="page-filter-stat">
1017 - <?php echo $this->pagefilter_plugins_checklist( $this->plugins_inf, $pgfilter, $option ); ?>
1018 - </div>
1019 - <div class="plf-option-info"><?php _e('Plugin Activate/Deactivate filtering for this Post only', 'plf'); ?></div>
1020 - <?php
1021 - $c_locale = $o_post_id = '';
1022 - $languages = array();
1023 - $locale_mode = 'style="display:none;"';
1024 - if(!empty($this->filter['language'])){
1025 - $languages = get_available_languages();
1026 - $site_locale = self::get_site_locale();
1027 - //bogo と同じ _locale ポストメタデータ採用
1028 - $c_locale = get_post_meta( $post->ID, '_locale', true );
1029 - if(empty($c_locale)){
1030 - $c_locale = $site_locale;
1031 - }
1032 - if ( ! in_array( $c_locale, $languages ) ) {
1033 - $c_locale = '';
1034 - }
1035 - $o_post_id = get_post_meta( $post->ID, '_original_post_id', true );
1036 - $o_post_id = (is_numeric($o_post_id))? $o_post_id : '';
1037 - $locale_mode = '';
1038 - }
1039 - ?>
1040 - <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>
1043 - <?php
1044 - wp_dropdown_languages(
1045 - array(
1046 - 'name' => 'plf_locale',
1047 - 'id' => 'plf_locale',
1048 - 'selected' => $c_locale,
1049 - 'languages' => $languages,
1050 - 'show_available_translations' => false,
1051 - )
1052 - );
1053 - ?>
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; ?>" />
1056 - <div class="hflang-group-edit-lonk">
1057 - <?php
1058 - $id = (is_numeric($o_post_id))? $o_post_id : $post->ID;
1059 - global $wpdb;
1060 - $ids = $wpdb->get_row($wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_original_post_id' AND meta_value = %d", $id ), ARRAY_N);
1061 - if(is_array($ids)){
1062 - if(!in_array((string)$id, $ids)){
1063 - $ids[] = (string)$id;
1064 - }
1065 - if(count($ids) > 1){
1066 - foreach ($ids as $v) {
1067 - if( $post->ID != $v){
1068 - $l = get_post_meta( $v, '_locale', true );
1069 - if(empty($l)){
1070 - $l = $site_locale;
1071 - }
1072 - $url = get_edit_post_link( $v );
1073 - 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>';
1075 - }
1076 - }
1077 - }
1078 - }
1079 - }
1080 - ?>
1081 - </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>
1083 - </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 - ?>
713 + <div id="plugin-filter-select">
714 + <label><input type="radio" name="pagefilter" value="default" <?php checked('default', $option['filter']); ?>/><?php _e('Not Use', 'plf' ); ?></label>
715 + <label><input type="radio" name="pagefilter" value="include" <?php checked('include', $option['filter']); ?>/><?php _e('Activate Plugins', 'plf'); ?></label>
716 + <div id="page-filter-stat">
717 + <?php echo $this->pagefilter_plugins_checklist( $this->plugins_inf, $pgfilter, $option ); ?>
1087 718 </div>
719 + <?php echo '<p class="hide-if-no-js"><a id="plugin-filter-submit" class="button" href="#pluginfilterdiv" onclick="WPAddPagePluginLoadFilter(\'' . $ajax_nonce . '\');return false;" >'. __('Save') .'</a></p>'; ?>
720 + </div>
1088 721 <?php
1089 722 }
1090 723 }
1091 724
@@ -1092,53 +725,18 @@
1092 725 //wp_ajax_plugin_load_filter called function
1093 726 function plf_ajax_postidfilter() {
1094 727 if ( isset($_POST['post_id']) ) {
1095 728 $pid = (int) $_POST['post_id'];
1096 - if ( !current_user_can( 'activate_plugins', $pid ) )
729 + if ( !current_user_can( 'edit_plugins', $pid ) )
1097 730 wp_die( -1 );
1098 731 check_ajax_referer( "plugin_load_filter-$pid" );
1099 732
1100 - if(!empty($this->filter['language'])){
1101 - if(isset($_POST['locale'])){
1102 - $s_locale = (!empty($_POST['locale']))? $_POST['locale'] : 'en_US';
1103 - $languages = get_available_languages();
1104 - $languages[] = 'en_US'; //add WP default locale
1105 - if ( in_array( $s_locale, $languages ) ) {
1106 - $g_locale = get_post_meta( $pid, '_locale', true );
1107 - remove_filter( 'locale', array('Plf_filter', 'post_locale') );
1108 - global $locale;
1109 - $locale = null;
1110 - $o_locale = get_locale();
1111 - add_filter( 'locale', array('Plf_filter', 'post_locale') );
1112 - if($s_locale !== $g_locale){
1113 - if($s_locale === $o_locale){
1114 - delete_post_meta( $pid, '_locale');
1115 - } else {
1116 - update_post_meta( $pid, '_locale', $s_locale );
1117 - }
1118 - }
1119 - }
1120 - }
1121 - if(isset($_POST['original_post_id'])){
1122 - if(empty($_POST['original_post_id'])){
1123 - delete_post_meta( $pid, '_original_post_id');
1124 - } elseif(preg_match( '/([0-9]+)?/', $_POST['original_post_id'], $match )){
1125 - $o_id = (int)$match[1];
1126 - $post = get_post($o_id);
1127 - if(is_object($post)){
1128 - $g_id = get_post_meta( $pid, '_original_post_id', true );
1129 - if($o_id !== $g_id){
1130 - update_post_meta( $pid, '_original_post_id', $o_id );
1131 - }
1132 - }
1133 - }
1134 - }
1135 - }
1136 733 $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
1137 734 $option["filter"] = (empty($_POST['filter']))? 'default' : $_POST['filter'];
1138 735 if('default' == $option["filter"]){
1139 736 delete_post_meta( $pid, '_plugin_load_filter');
1140 - } else {
737 + }
738 + else {
1141 739 $plugins = array();
1142 740 if( preg_match_all('/plf_option\[desktop\]\[(.+?)\]/u', $_POST['desktop'], $matches)){
1143 741 if(!empty($matches[1])){
1144 742 foreach ($matches[1] as $plugin){
@@ -1164,36 +762,8 @@
1164 762 }
1165 763 wp_die( 0 );
1166 764 }
1167 765
1168 -
1169 - //alternate hreflang meta tag
1170 - static function altenate_hreflang() {
1171 - if ( is_singular() ) {
1172 - global $post, $wpdb;
1173 - $pid = $post->ID;
1174 - $oid = get_post_meta( $pid, '_original_post_id', true );
1175 - $oid = (is_numeric($oid))? $oid : $pid;
1176 - $ids = $wpdb->get_row($wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_original_post_id' AND meta_value = %d", $oid ), ARRAY_N);
1177 - if(is_array($ids)){
1178 - if(!in_array((string)$oid, $ids)){
1179 - $ids[] = (string)$oid;
1180 - }
1181 - if(count($ids) > 1){
1182 - $site_locale = self::get_site_locale();
1183 - foreach ($ids as $id) {
1184 - $l = get_post_meta( $id, '_locale', true );
1185 - if(empty($l)){
1186 - $l = $site_locale;
1187 - }
1188 - $url = get_permalink( $id );
1189 - echo '<link rel="alternate" hreflang="' . esc_attr($l) . '" href="' . esc_url($url) .'" />' . PHP_EOL;
1190 - }
1191 - }
1192 - }
1193 - }
1194 - }
1195 -
1196 766 /***************************************************************************
1197 767 * Javascript
1198 768 **************************************************************************/
1199 769 function activetab_script() { ?>
@@ -1200,45 +770,14 @@
1200 770 <script type='text/javascript' >
1201 771 /* <![CDATA[ */
1202 772 var plf_activetab = <?php echo $this->tab_num; ?>
1203 773 /* ]]> */
1204 - jQuery(document).ready(function ($) {
1205 - plf_setting_tabs();
1206 - function plf_setting_tabs(){ $('#plf-setting-tabs').tabs({ active:plf_activetab, }); }
1207 - });
774 + jQuery(document).ready(function ($) { plf_setting_tabs(); function plf_setting_tabs(){ $('#plf-setting-tabs').tabs({ active:plf_activetab, }); }});
1208 775 </script>
1209 776 <?php }
1210 777
1211 - function plf_meta_script() {
1212 - $reload_dialog = __('Plugin Load Filter setting has been updated.\nClick OK to reload the page.', 'plf');
1213 - ?>
778 + function plf_meta_script() { ?>
1214 779 <script type='text/javascript' >
1215 - WPAddPagePluginLoadFilter = function(nonce){
1216 - jQuery.ajax({
1217 - type: 'POST',
1218 - url: ajaxurl,
1219 - data: {
1220 - action: "plugin_load_filter",
1221 - post_id : jQuery( '#post_ID' ).val(),
1222 - _ajax_nonce: nonce,
1223 - locale: jQuery("select[name='plf_locale']").val(),
1224 - original_post_id: jQuery("input[name='plf_original_post_id']").val(),
1225 - filter: jQuery("input[name='pagefilter']:checked").val(),
1226 - desktop: jQuery('.meta-boxes-plugins-table td.desktop input:checked').map(function(){ return jQuery(this).attr("name"); }).get().join(','),
1227 - mobile: jQuery('.meta-boxes-plugins-table td.mobile input:checked').map(function(){ return jQuery(this).attr("name"); }).get().join(','),
1228 - },
1229 - dataType: 'json',
1230 - }).then(
1231 - function (response, dataType) {
1232 - jQuery('#page-filter-stat').html(response.data);
1233 - if(window.confirm('<?php echo $reload_dialog; ?>')){
1234 - location.reload();
1235 - }
1236 - },
1237 - function () {
1238 - //alert("ajax error");
1239 - }
1240 - );
1241 - };
780 + WPAddPagePluginLoadFilter = function(nonce){ jQuery.ajax({ type: 'POST', url: ajaxurl, data: { action: "plugin_load_filter", post_id : jQuery( '#post_ID' ).val(), _ajax_nonce: nonce, filter: jQuery("input[name='pagefilter']:checked").val(), desktop: jQuery('.meta-boxes-plugins-table td.desktop input:checked').map(function(){ return jQuery(this).attr("name"); }).get().join(','), mobile: jQuery('.meta-boxes-plugins-table td.mobile input:checked').map(function(){ return jQuery(this).attr("name"); }).get().join(','),}, dataType: 'json', success: function(response, dataType) { jQuery('#page-filter-stat').html(response.data); }}); return false; };
1242 781 </script>
1243 782 <?php }
1244 783 }