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 +246 -728 4.0.62.3.1 View file →
@@ -1,111 +1,39 @@
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.0.6
6 - Plugin URI: https://celtislab.net/en/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 - delete_option('plf_addon_options');
57 - } else {
58 - global $wpdb;
59 - $current_blog_id = get_current_blog_id();
60 - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
61 - foreach ( $blog_ids as $blog_id ) {
62 - switch_to_blog( $blog_id );
63 - delete_option('plf_queryvars');
64 - delete_option('plf_option' );
65 - delete_option('plf_addon_options');
66 - }
67 - switch_to_blog( $current_blog_id );
68 - }
69 - if ( file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) {
70 - @unlink( WPMU_PLUGIN_DIR . '/plf-filter.php' );
71 - }
72 - }
73 - register_uninstall_hook(__FILE__, 'plugin_load_filter_uninstall');
74 -
75 -}
76 -
77 14 $Plf_setting = new Plf_setting();
78 15
79 16 class Plf_setting {
80 17
81 - static $plugins_inf = ''; //active plugin/module infomation
82 - static $filter = array(); //filter option data
18 + private $plugins_inf = ''; //active plugin/module infomation
19 + private $filter = array(); //filter option data
83 20 private $tab_num = 0;
84 -
21 +
85 22 /***************************************************************************
86 23 * Style Sheet
87 24 **************************************************************************/
88 25 function plf_css() { ?>
89 26 <style type="text/css">
90 - #plugin-filter-select {margin-top: 12px;}
91 - #plugin-filter-select p {margin: 1em 0;}
92 - #page-filter-stat { margin-top: 12px;}
93 - #activation-table { padding-bottom: 8px; border: 1px solid #eee;}
94 - #activation-table th { text-align: center;}
95 - #activation-table td { font-size: 97%;}
27 + #activation-table { margin-top: 10px; border: 1px solid #eee;}
96 28 #activation-table input[type=checkbox] { height: 25px; width: 25px; opacity: 0;}
97 - #plf-post-locale-select { margin-top: 16px;}
98 29 thead .plugins-name { background-color: aliceblue;}
99 30 thead .device-type { background-color: oldlace;}
100 - thead .plugins-name, tbody .plugins-name { min-width: 144px; max-width: 200px; padding: 3px 3px 3px 5px;}
101 - thead .device-type, tbody .device-type { min-width: 40px; max-width: 40px; text-align: center; 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;}
102 33 .dashicons-yes:before { font-size: 20px; border: 1px solid #eee; background-color: whitesmoke;}
103 - .device-type label { color: whitesmoke; }
104 - input.altcheckbox[type="checkbox"] { -webkit-appearance: none; appearance: none; position: absolute;}
105 - .device-type input.altcheckbox[type="checkbox"]:checked + span.dashicons-yes:before { background-color: yellowgreen; }
106 - .plf-option-info { font-size:12px; margin:10px 0; padding:3px; background-color:#fff8e5;}
107 - .edit-post-locale-link span.dashicons { width: 0.8em; height: 0.8em; margin: -0.4em 0.1em 0; vertical-align: middle; text-decoration: initial;}
34 + .device-type label { color: whitesmoke; margin-left: -28px; }
35 + .device-type input[type="checkbox"]:checked + label .dashicons-yes:before { background-color: yellowgreen; }
108 36 </style>
109 37 <?php }
110 38
111 39 function jquery_tab_css() { ?>
@@ -127,49 +55,36 @@
127 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; }
128 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; }
129 57 .ui-state-active a, .ui-state-active a:link, .ui-state-active a:visited { color: #ffffff; text-decoration: none; }
130 58
131 - #wrap_registration-table, #wrap_activation-table { overflow:auto; height:600px; position: relative;}
132 - #registration-table input[type=radio], #registration-table input[type=checkbox], #activation-table input[type=checkbox] { height: 25px; width: 25px; opacity: 0;}
133 - #registration-table th {text-align: center;}
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;}
134 61 thead, tbody { display: block;}
135 - .widefat * { word-wrap: break-word !important;}
136 - .widefat thead { position:sticky; top:0px; z-index:1;}
137 - .widefat tr:first-of-type th:first-of-type {position: sticky; left: 0px; text-align: left; background-color: aliceblue; z-index:3;}
138 - .widefat th { padding: 8px;}
139 - .widefat td { padding: 8px;}
140 - .widefat td:first-of-type { position: sticky; left: 0px; text-align: left; background-color: white;}
62 + .plugins-table-body { overflow-y:scroll; height:500px; }
63 + .widefat td, .widefat th { padding: 8px 4px;}
141 64 thead .filter-plugins-name, thead .plugins-name { background-color: aliceblue;}
142 - thead .urlfilter { background-color: lavenderblush;}
143 - .filter-none, .filter-admin, .filter-tmpl { background-color: honeydew;}
65 + .filter-none, .filter-admin, .filter-tmpl { background-color: oldlace;}
144 66 thead .device-type { background-color: oldlace;}
145 - thead .ckbox-type { background-color: lavender;}
67 + thead .tmpl-type { background-color: lavender;}
146 68 thead .pformat { background-color: honeydew;}
147 69 thead .tmpl-embed { background-color: lightyellow;}
148 70 thead .tmpl-custom { background-color: lavenderblush;}
149 - thead .filter-plugins-name, tbody .filter-plugins-name { min-width: 240px; max-width: 240px;}
71 + thead .filter-plugins-name, tbody .filter-plugins-name { min-width: 260px; max-width: 260px;}
150 72 thead .plugins-name, tbody .plugins-name { min-width: 180px; max-width: 180px;}
151 - thead .device-type, tbody .device-type, thead .ckbox-type, tbody .ckbox-type, thead .deny-type, tbody .deny-type { min-width: 40px; max-width: 40px; text-align: center;}
152 - thead .filter-type, tbody .filter-type { min-width: 56px; max-width: 56px; text-align:center;}
153 - .urlfilter-description { padding: 0 10px 15px;}
154 - .grid-row { display: flex; flex-flow: row wrap;}
155 - .filter-description { padding: 0 10px; width:62%;}
156 - .side-info { width: 30%; padding-left: 24px;}
157 - .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}
158 77 .exclude-pformat label { white-space:nowrap;}
159 78 .exclude-pformat span { margin-right: 12px; }
160 79 .dashicons:before { font-size: 24px; }
161 - .radio-green label, .radio-red label { color: #ddd; margin-left: -32px; }
162 - .ckbox-type label { color: #ddd;}
163 - .radio-green input[type="radio"]:checked + span { color: #8bc34a; }
164 - .radio-red input[type="radio"]:checked + span { color: tomato; }
165 - .ckbox-type input[type="checkbox"]:checked + span { color: #4caf50; }
166 - /* .dashicons-dismiss:before { background-color: yellowgreen; font-size: 20px; border-radius: 12px; } */
167 - .deny-type label { color: #4caf50;}
168 - .deny-type input.altcheckbox[type="checkbox"]:checked + span { color: #ddd; }
169 - .dashicons-yes:before { font-size: 20px; border: 1px solid #eee; }
170 - .device-type input.altcheckbox[type="checkbox"]:checked + span.dashicons-yes:before { background-color: yellowgreen; }
171 - .language-option { margin-bottom: 28px; }
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;}
85 + .device-type label { color: whitesmoke; margin-left: -28px; }
86 + .device-type input[type="checkbox"]:checked + label .dashicons-yes:before { background-color: yellowgreen; }
172 87 </style>
173 88 <?php }
174 89
175 90 /***************************************************************************
@@ -178,101 +93,107 @@
178 93
179 94 public function __construct() {
180 95
181 96 load_plugin_textdomain('plf', false, basename( dirname( __FILE__ ) ).'/languages' );
182 -
183 - self::$filter = get_option('plf_option');
184 - if(empty(self::$filter['optver']) || self::$filter['optver'] < '2'){
185 - self::$filter['optver'] = '2';
186 - //ここにデータフォーマットが変わった場合の変換処理を記述
97 +
98 + $this->filter = get_option('plf_option');
99 + //v2.3.0 option change
100 + if(empty($this->filter['optver']) || $this->filter['optver'] < '2'){
101 + $this->filter['optver'] = '2';
102 +
103 + if(empty($this->filter['group']['desktop']) && empty($this->filter['group']['mobile'])){
104 + //For ver2.2.0 compatibility, set '_pagefilter' data to 'desktop' and 'mobile'
105 + if(!empty($this->filter['_pagefilter'])){
106 + $this->filter['group']['desktop'] = $this->filter['_pagefilter'];
107 + $this->filter['group']['mobile'] = $this->filter['_pagefilter'];
108 + }
109 + if(!empty($this->filter['_desktop'])){
110 + $this->filter['_desktop'] = null;
111 + }
112 + if(!empty($this->filter['_mobile'])){
113 + $this->filter['_mobile'] = null;
114 + }
115 + }
187 116 }
188 - if(!empty(self::$filter['language'])){
189 - add_action( 'wp_head', array('Plf_setting', 'altenate_hreflang') );
190 - }
117 +
191 118 if(is_admin()) {
192 119 add_action( 'plugins_loaded', array(&$this, 'plf_admin_start'), 9999 );
193 - add_action( 'admin_init', array(&$this, 'action_posts'));
194 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');
195 137 }
196 138 add_action( 'wp_ajax_plugin_load_filter', array(&$this, 'plf_ajax_postidfilter'));
197 139 }
198 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 +
199 153 //Plugin Load Filter admin setting start
200 154 public function plf_admin_start() {
201 155 require_once(ABSPATH . 'wp-admin/includes/plugin.php');
202 156
203 - self::$plugins_inf = get_plugins();
204 - //Ver4.0.0 でしか呼び出せないメソッドを呼び出さないよう新設した switch_theme があるかどうかで判定
205 - if(method_exists('Plf_filter', 'switch_theme')){
206 - if(class_exists('Plf_filter')){
207 - if ( is_multisite() )
208 - remove_filter('pre_site_option_active_sitewide_plugins', array('Plf_filter', 'active_sitewide_plugins'));
209 - remove_filter('pre_option_active_plugins', array('Plf_filter', 'active_plugins'));
157 + $this->plugins_inf = get_plugins();
158 + $packplug = array();
159 + foreach ( $this->plugins_inf as $plugin_key => $a_plugin ) {
160 + if(is_plugin_inactive( $plugin_key )){
161 + unset($this->plugins_inf[$plugin_key]);
210 162 }
211 - foreach ( self::$plugins_inf as $plugin_key => $a_plugin ) {
212 - if(is_plugin_inactive( $plugin_key )){
213 - unset(self::$plugins_inf[$plugin_key]);
163 + }
164 + //jetpack active module
165 + if(method_exists('Jetpack', 'get_module')){
166 + $modules = Jetpack::get_active_modules();
167 + $modules = array_diff( $modules, array( 'vaultpress' ) );
168 + foreach ( $modules as $key => $module_name ) {
169 + if(!empty($module_name)){
170 + $module = Jetpack::get_module( $module_name );
171 + if(!empty($module))
172 + $this->plugins_inf['jetpack_module/' . $module_name] = $module;
214 173 }
215 174 }
216 - if(class_exists('Plf_filter')){
217 - if ( is_multisite() )
218 - add_filter('pre_site_option_active_sitewide_plugins', array('Plf_filter', 'active_sitewide_plugins'));
219 - add_filter('pre_option_active_plugins', array('Plf_filter', 'active_plugins'));
220 - }
221 -
222 - //jetpack active module
223 - if(method_exists('Jetpack', 'get_module')){
224 - if(class_exists('Plf_filter')){
225 - remove_filter('pre_option_jetpack_active_modules', array('Plf_filter', 'active_jetmodules'));
175 + }
176 + //celtispack active module
177 + if(method_exists('Celtispack', 'get_module')){
178 + $modules = Celtispack::get_active_modules();
179 + foreach ( $modules as $key => $module_name ) {
180 + if(!empty($module_name)){
181 + $this->plugins_inf['celtispack_module/' . $module_name] = Celtispack::get_module( $module_name );
226 182 }
227 - $modules = Jetpack::get_active_modules();
228 - $modules = array_diff( $modules, array( 'vaultpress' ) );
229 - foreach ( $modules as $key => $module_name ) {
230 - if(!empty($module_name)){
231 - $module = Jetpack::get_module( $module_name );
232 - if(!empty($module))
233 - self::$plugins_inf['jetpack_module/' . $module_name] = $module;
234 - }
235 - }
236 - if(class_exists('Plf_filter')){
237 - add_filter('pre_option_jetpack_active_modules', array('Plf_filter', 'active_jetmodules'));
238 - }
239 183 }
240 - //celtispack active module
241 - if(method_exists('Celtispack', 'get_module')){
242 - if(class_exists('Plf_filter')){
243 - remove_filter('pre_option_celtispack_active_modules', array('Plf_filter', 'active_celtismodules'));
244 - }
245 - $modules = Celtispack::get_active_modules();
246 - foreach ( $modules as $key => $module_name ) {
247 - if(!empty($module_name)){
248 - self::$plugins_inf['celtispack_module/' . $module_name] = Celtispack::get_module( $module_name );
249 - }
250 - }
251 - if(class_exists('Plf_filter')){
252 - add_filter('pre_option_celtispack_active_modules', array('Plf_filter', 'active_celtismodules'));
253 - }
254 - }
255 - if ( empty( self::$plugins_inf ) )
256 - return;
257 184 }
185 + if ( empty( $this->plugins_inf ) )
186 + return;
258 187
188 + $this->action_posts(); //POST, GET Request Action
259 189 add_action('admin_menu', array(&$this, 'plf_option_menu'));
260 190 }
261 191
262 - static function get_plugins_inf() {
263 - $inf = (!empty(self::$plugins_inf))? self::$plugins_inf : false;
264 - return $inf;
265 - }
266 -
267 192 //Plugins sub menu add
268 193 public function plf_option_menu() {
269 - if(current_user_can( 'activate_plugins' )){
270 - $page = add_menu_page( 'Plugin Load FIlter Settings', __('Plugin Load Filter', 'plf'), 'manage_options', 'plugin_load_filter_admin_manage_page', array(&$this, 'plf_option_page'), 'dashicons-filter', '65.1');
271 - add_submenu_page( 'plugin_load_filter_admin_manage_page', 'Plugin Load FIlter Settings', __('General Settings', 'plf'), 'manage_options', 'plugin_load_filter_admin_manage_page', array(&$this, 'plf_option_page') );
272 - add_action( 'admin_print_scripts-'.$page, array(&$this, 'plf_scripts') );
273 - add_action( 'admin_print_scripts-'.$page, array(&$this, 'deploy_mu_plugins'));
274 - }
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'));
195 + add_action('admin_print_scripts-'.$page, array(&$this, 'plf_scripts'));
275 196 }
276 197
277 198 //Plugin Load Filter setting page script
278 199 function plf_scripts() {
@@ -282,62 +203,16 @@
282 203 wp_enqueue_script( 'jquery-ui-tabs' );
283 204 add_action( 'admin_head', array(&$this, 'plf_css' ));
284 205 add_action( 'admin_head', array(&$this, 'jquery_tab_css' ));
285 206 add_action( 'admin_footer', array(&$this, 'activetab_script' ));
286 - add_action( 'admin_notices', array('Plf_setting', 'plf_notice'));
287 207 }
288 -
289 - //plf-filter.php mu-plugins module set
290 - public function deploy_mu_plugins() {
291 - if(wp_mkdir_p( WPMU_PLUGIN_DIR )){
292 - if ( !file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) {
293 - @copy(__DIR__ . '/mu-plugins/plf-filter.php', WPMU_PLUGIN_DIR . '/plf-filter.php');
294 - }
295 - else {
296 - require_once(ABSPATH . 'wp-admin/includes/plugin.php');
297 - $dp = get_plugin_data( WPMU_PLUGIN_DIR . "/plf-filter.php", false, false );
298 - $sp = get_plugin_data( __DIR__ . '/mu-plugins/plf-filter.php', false, false );
299 - if(version_compare( $dp['Version'], $sp['Version'], '!=')){
300 - @copy(__DIR__ . '/mu-plugins/plf-filter.php', WPMU_PLUGIN_DIR . '/plf-filter.php');
301 - }
302 - }
303 - }
304 - }
305 -
306 - //Notice Message display
307 - static function plf_notice() {
308 - $notice = get_transient('plf_notice');
309 - if(!empty($notice)){
310 - echo '<div class="notice notice-warning"><p>Plugin Load Filter : ' . $notice . '</p></div>';
311 - delete_transient('plf_notice');
312 - }
313 - }
314 208
315 209 //plugin filter option action request (add, update, delete)
316 210 function action_posts() {
317 - if (current_user_can( 'activate_plugins' )) {
211 + if (current_user_can( 'edit_plugins' )) {
318 212 if( isset($_POST['edit_regist_filter']) ) {
319 213 if(isset($_POST['plfregist'])){
320 214 check_admin_referer('plugin_load_filter');
321 - //url filter
322 - $groupkeys = (method_exists('Plf_filter', 'get_active_group'))? Plf_filter::get_active_group() : array();
323 - if(!empty($groupkeys)){
324 - $urlkeys = array_keys($_POST['plfurlkey']);
325 - foreach( $groupkeys as $item){
326 - if(empty( $_POST['plfurlkey'][$item])){
327 - self::$filter['plfurlkey'][$item]['plugins'] = '';
328 - } else {
329 - $plugins = array();
330 - foreach ( $_POST['plfurlkey'][$item] as $p_key => $val ) {
331 - if($val == '1')
332 - $plugins[] = $p_key;
333 - }
334 - $option["plugins"] = implode(",", $plugins);
335 - self::$filter['plfurlkey'][$item] = $option;
336 - }
337 - }
338 - }
339 - //page type filter
340 215 foreach( array('_admin', '_pagefilter') as $item){
341 216 $plugins = array();
342 217 foreach ( $_POST['plfregist'] as $p_key => $val ) {
343 218 if($val == $item)
@@ -367,11 +242,10 @@
367 242 if(!empty($cbase) && $call === false)
368 243 unset($plugins[$cbase]);
369 244 }
370 245 $option["plugins"] = implode(",", array_keys($plugins));
371 - self::$filter[$item] = $option;
246 + $this->filter[$item] = $option;
372 247 }
373 - //exclude option
374 248 if(isset($_POST['plf_option']['exclude'])){
375 249 $exclude = array();
376 250 foreach ( $_POST['plf_option']['exclude'] as $ft => $v ) {
377 251 if(!empty($v))
@@ -376,54 +250,31 @@
376 250 foreach ( $_POST['plf_option']['exclude'] as $ft => $v ) {
377 251 if(!empty($v))
378 252 $exclude[$ft] = true;
379 253 }
380 - self::$filter['exclude'] = $exclude;
381 - } else {
382 - self::$filter['exclude'] = array();
254 + $this->filter['exclude'] = $exclude;
383 255 }
384 -
385 - //admin bar (filtered stat)
386 - self::$filter['admin_bar'] = (isset($_POST['plf_option']['admin_bar']))? 1 : 0;
387 -
388 - //Language option
389 - self::$filter['language'] = (isset($_POST['plf_option']['language']))? 1 : 0;
390 -
391 - update_option('plf_option', self::$filter );
256 + else {
257 + $this->filter['exclude'] = '';
258 + }
259 + update_option('plf_option', $this->filter );
392 260 }
393 261 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page'));
394 262 exit;
395 -
396 - } elseif( isset($_POST['clear_regist_filter']) ) {
263 + }
264 + elseif( isset($_POST['clear_regist_filter']) ) {
397 265 check_admin_referer('plugin_load_filter');
398 - if(!empty(self::$filter['plfurlkey'])){
399 - foreach (self::$filter['plfurlkey'] as $key => $val) {
400 - unset(self::$filter['plfurlkey'][$key]);
401 - }
402 - }
403 266 foreach( array('_admin', '_pagefilter') as $item){
404 - self::$filter[$item] = array();
267 + $this->filter[$item] = '';
405 268 }
406 - self::$filter['exclude'] = array();
407 -
408 - //old data unset
409 - if(isset(self::$filter['urlkey'])){
410 - unset(self::$filter['urlkey']);
411 - }
412 - if(isset(self::$filter['urlkeylist'])){
413 - unset(self::$filter['urlkeylist']);
414 - }
415 -
416 - self::$filter['admin_bar'] = 0;
417 - self::$filter['language'] = 0;
418 - update_option('plf_option', self::$filter );
269 + $this->filter['exclude'] = '';
270 + update_option('plf_option', $this->filter );
419 271 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page'));
420 272 exit;
421 -
422 - } else if(isset($_POST['edit_activate_page_filter']) ) {
273 + }
274 + else if(isset($_POST['edit_activate_page_filter']) ) {
423 275 if(isset($_POST['plfactive'])){
424 276 check_admin_referer('plugin_load_filter');
425 - self::$filter['group'] = array();
426 277 $group = array_keys($_POST['plfactive']);
427 278 foreach( $group as $item){
428 279 $plugins = array();
429 280 foreach ( $_POST['plfactive'][$item] as $p_key => $val ) {
@@ -428,21 +279,24 @@
428 279 $plugins = array();
429 280 foreach ( $_POST['plfactive'][$item] as $p_key => $val ) {
430 281 if($val == '1')
431 282 $plugins[] = $p_key;
432 - }
283 + }
433 284 $option["plugins"] = implode(",", $plugins);
434 - self::$filter['group'][$item] = $option;
285 + $this->filter['group'][$item] = $option;
435 286 }
436 - update_option('plf_option', self::$filter );
287 + update_option('plf_option', $this->filter );
437 288 }
438 289 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page&action=tab_1'));
439 290 exit;
440 -
441 - } elseif( isset($_POST['clear_activate_page_filter']) ) {
291 + }
292 + elseif( isset($_POST['clear_activate_page_filter']) ) {
442 293 check_admin_referer('plugin_load_filter');
443 - self::$filter['group'] = array();
444 - update_option('plf_option', self::$filter );
294 + $group = array_keys($_POST['plfactive']);
295 + foreach( $group as $item){
296 + $this->filter['group'][$item] = '';
297 + }
298 + update_option('plf_option', $this->filter );
445 299 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page&action=tab_1'));
446 300 exit;
447 301 }
448 302 if(!empty($_GET['action']) && $_GET['action']=='tab_1') {
@@ -452,34 +306,37 @@
452 306 }
453 307
454 308 //Plugin or Module key to name
455 309 // $type : list/smart/tree
456 - static function pluginkey_to_name( $infkey, $type='list') {
310 + public function pluginkey_to_name( $infkey, $type='list') {
311 +
457 312 $name = '';
458 313 if(strpos($infkey, 'jetpack_module/') !== false){
459 - if(!empty(self::$plugins_inf[$infkey]['name'])){
314 + if(!empty($this->plugins_inf[$infkey]['name'])){
460 315 $m_mark = ($type !== 'list')? '-' : 'Jetpack-';
461 316 if($type === 'smart') {
462 - if(empty(self::$filter['_pagefilter']['plugins']) || strpos(self::$filter['_pagefilter']['plugins'], 'jetpack/') === false)
463 - $name = $m_mark . self::$plugins_inf[$infkey]['name'];
464 - } else {
465 - $name = $m_mark . self::$plugins_inf[$infkey]['name'];
317 + if(empty($this->filter['_pagefilter']['plugins']) || strpos($this->filter['_pagefilter']['plugins'], 'jetpack/') === false)
318 + $name = $m_mark . $this->plugins_inf[$infkey]['name'];
466 319 }
320 + else
321 + $name = $m_mark . $this->plugins_inf[$infkey]['name'];
467 322 }
468 - } elseif(strpos($infkey, 'celtispack_module/') !== false){
469 - if(!empty(self::$plugins_inf[$infkey]['Name'])){
323 + }
324 + elseif(strpos($infkey, 'celtispack_module/') !== false){
325 + if(!empty($this->plugins_inf[$infkey]['Name'])){
470 326 $m_mark = ($type !== 'list')? '-' : 'Celtispack-';
471 327 if($type === 'smart') {
472 - if(empty(self::$filter['_pagefilter']['plugins']) || strpos(self::$filter['_pagefilter']['plugins'], 'celtispack/') === false)
473 - $name = $m_mark . self::$plugins_inf[$infkey]['Name'];
474 - } else {
475 - $name = $m_mark . self::$plugins_inf[$infkey]['Name'];
328 + if(empty($this->filter['_pagefilter']['plugins']) || strpos($this->filter['_pagefilter']['plugins'], 'celtispack/') === false)
329 + $name = $m_mark . $this->plugins_inf[$infkey]['Name'];
476 330 }
331 + else
332 + $name = $m_mark . $this->plugins_inf[$infkey]['Name'];
477 333 }
478 - } else {
479 - if(!empty(self::$plugins_inf[$infkey]['Name']))
480 - $name = self::$plugins_inf[$infkey]['Name'];
481 334 }
335 + else {
336 + if(!empty($this->plugins_inf[$infkey]['Name']))
337 + $name = $this->plugins_inf[$infkey]['Name'];
338 + }
482 339 return($name);
483 340 }
484 341
485 342 //Checkbox
@@ -486,87 +343,24 @@
486 343 static function checkbox($name, $value, $label = '') {
487 344 return "<label><input type='checkbox' name='$name' value='1' " . checked( $value, 1, false ). "/> $label</label>";
488 345 }
489 346 static function altcheckbox($name, $value, $label = '') {
490 - //return "<input type='hidden' name='$name' value='0'><input type='checkbox' name='$name' value='1' " . checked( $value, 1, false ). "/><label> $label</label>";
491 - return "<label><input type='checkbox' name='$name' class='altcheckbox' value='1' " . checked( $value, 1, false ). "/> $label</label>";
347 + return "<input type='hidden' name='$name' value='0'><input type='checkbox' name='$name' value='1' " . checked( $value, 1, false ). "/><label> $label</label>";
492 348 }
493 -
494 - //dropdown list
495 - static function dropdown($name, $items, $selected, $args = null) {
496 - $defaults = array(
497 - 'id' => $name,
498 - 'none' => false,
499 - 'class' => null,
500 - 'multiple' => false,
501 - 'select_attr' => ""
502 - );
503 -
504 - if (!is_array($items))
505 - return;
506 -
507 - if (empty($items))
508 - $items = array();
509 -
510 - // Items is in key => value format. If value is itself an array, use only the 1st column
511 - foreach ($items as $key => &$value) {
512 - if (is_array($value))
513 - $value = array_shift($value);
514 - }
515 -
516 - extract(wp_parse_args($args, $defaults));
517 -
518 - // If 'none' arg provided, prepend a blank entry
519 - if ($none) {
520 - if ($none === true)
521 - $none = '&nbsp;';
522 - $items = array('' => $none) + $items; // Note that array_merge() won't work because it renumbers indexes!
523 - }
524 -
525 - if (!$id)
526 - $id = $name;
527 -
528 - $name = ($name) ? "name='$name'" : "";
529 - $id = ($id) ? "id='$id'" : "";
530 - $class = ($class) ? "class='$class'" : "";
531 - $multiple = ($multiple) ? "multiple='multiple'" : "";
532 -
533 - $html = "<select $name $id $class $multiple $select_attr>";
534 -
535 - foreach ((array) $items as $key => $label) {
536 - $key = esc_attr($key);
537 - $label = esc_attr($label);
538 -
539 - $html .= "<option value='$key' " . selected($selected, $key, false) . ">$label</option>";
540 - }
541 - $html .= "</select>";
542 - return $html;
543 - }
544 -
545 - public function plfregist_item($key, $chklist, $filter) {
546 - $p_name = self::pluginkey_to_name($key);
349 +
350 + public function plfregist_item($key, $val) {
351 + $p_name = $this->pluginkey_to_name($key);
547 352 $opt_name = "plfregist[$key]";
548 353 ?>
549 354 <tr id="plfregist_<?php echo $key; ?>">
550 355 <td class="filter-plugins-name"><?php echo $p_name; ?></td>
551 - <?php
552 - foreach($chklist as $urlkey){
553 - $checked = (empty($filter['plfurlkey'][$urlkey]['plugins']) || false === strpos($filter['plfurlkey'][$urlkey]['plugins'], $key))? false : true;
554 - echo '<td class="deny-type filter-type">' . self::altcheckbox("plfurlkey[$urlkey][$key]", $checked, '<span class="dashicons dashicons-admin-plugins"></span>') . '</td>';
555 - }
556 - $radio = '';
557 - if(!empty($filter['_admin']['plugins']) && false !== strpos($filter['_admin']['plugins'], $key))
558 - $radio = '_admin';
559 - else if(!empty($filter['_pagefilter']['plugins']) && false !== strpos($filter['_pagefilter']['plugins'], $key))
560 - $radio = '_pagefilter';
561 - ?>
562 - <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>
563 - <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>
564 - <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>
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>
565 359 </tr>
566 360 <?php
567 361 }
568 -
362 +
569 363 //Filterring plugins select
570 364 public function plfregist_table($plugins, $filter) {
571 365 ?>
572 366 <div id="wrap_registration-table">
@@ -571,75 +365,13 @@
571 365 ?>
572 366 <div id="wrap_registration-table">
573 367 <table id="registration-table" class="widefat">
574 368 <thead>
575 - <?php
576 - $groupkeys = (method_exists('Plf_filter', 'get_active_group'))? Plf_filter::get_active_group() : array();
577 - $urlnum = count($groupkeys);
578 - ?>
579 - <tr>
580 - <th class="filter-plugins-name" rowspan="2"><?php _e('Plugins'); ?></th>
581 - <?php if($urlnum > 0) { ?>
582 - <th class="filter-type urlfilter" colspan="<?php echo $urlnum; ?>" style="font-weight:bold; font-size:smaller;"><?php _e('URL Group Filter', 'plf'); ?></th>
583 - <?php } ?>
584 - <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>
585 373 </tr>
586 - <tr>
587 - <?php //Addon URL filter group key
588 - if($urlnum > 0) {
589 - foreach ( $groupkeys as $v) {
590 - $_flt = (method_exists('Plf_filter', 'get_slug_filter'))? Plf_filter::get_slug_filter( $v ) : array();
591 - $hint = '';
592 - foreach ($_flt as $_v) {
593 - $hint .= '[' . $_v['slug'] . '] ' . $_v['summary'] . PHP_EOL;
594 -
595 - if((int)$_v['targetpage'] === 1) {
596 - $post_type = (!empty($_v['post_type']))? $_v['post_type'] : '';
597 - $taxonomy = '';
598 - if(!empty($_v['taxonomies']) && !empty($_v['term'])){
599 - $taxonomy = " : {$_v['taxonomies']}({$_v['term']})";
600 - }
601 - if(!empty($post_type)){
602 - $hint .= 'Singular (' . $post_type . ')' . $taxonomy . PHP_EOL;
603 - } else {
604 - $hint .= 'Singular ' . $taxonomy . PHP_EOL;
605 - }
606 - } elseif((int)$_v['targetpage'] === 2) {
607 - if(!empty($_v['ajax_action'])){
608 - $hint .= 'Ajax request (' . $_v['ajax_action'] . ')' . PHP_EOL;
609 - } else {
610 - $hint .= 'Ajax request' . PHP_EOL;
611 - }
612 - }
613 -
614 - $hint .= 'url filter : ';
615 - $urlkey = (!empty($_v['url_path']))? array_filter( array_map("trim", explode(PHP_EOL, $_v['url_path']))) : array();
616 - if(!empty($urlkey)){
617 - foreach ($urlkey as $key) {
618 - $hint .= $key . ' ';
619 - }
620 - }
621 - $urlkey = (!empty($_v['url_q_and']))? array_filter( array_map("trim", explode(PHP_EOL, $_v['url_q_and']))) : array();
622 - if(!empty($urlkey)){
623 - foreach ($urlkey as $key) {
624 - $hint .= ' AND ' . $key;
625 - }
626 - }
627 - $urlkey = (!empty($filter['url_q_not']))? array_filter( array_map("trim", explode(PHP_EOL, $filter['url_q_not']))) : array();
628 - if(!empty($urlkey)){
629 - foreach ($urlkey as $key) {
630 - $hint .= ' NOT ' . $key;
631 - }
632 - }
633 - $hint .= PHP_EOL . PHP_EOL;
634 - }
635 - echo "<th class='filter-type urlfilter'><span title='$hint' style='font-size:smaller'>{$v}</span></th>";
636 - }
637 - } ?>
638 - <th class="filter-type filter-none"><span style="font-size:smaller"><?php _e('Normal', 'plf'); ?></span></th>
639 - <th class="filter-type filter-admin"><span style="font-size:smaller"><?php _e('Admin Type', 'plf'); ?></span></th>
640 - <th class="filter-type filter-tmpl"><span style="font-size:smaller"><?php _e('Page Type', 'plf'); ?></span></th>
641 - </tr>
642 374 </thead>
643 375 <tbody class="plugins-table-body">
644 376 <?php
645 377 //plugins filter registoration table
@@ -644,12 +376,19 @@
644 376 <?php
645 377 //plugins filter registoration table
646 378 $plist = array();
647 379 foreach ( $plugins as $p_key => $val ) {
648 - $name = self::pluginkey_to_name($p_key);
380 + $name = $this->pluginkey_to_name($p_key);
649 381 if(!empty($name))
650 382 $plist[$p_key] = '';
651 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 + }
652 391 $jlist = $clist = array();
653 392 foreach ( $plist as $p_key => $val ) {
654 393 if(strpos($p_key, 'jetpack_module/') !== false){
655 394 $jlist[$p_key] = $plist[$p_key];
@@ -659,16 +398,8 @@
659 398 $clist[$p_key] = $plist[$p_key];
660 399 unset($plist[$p_key]);
661 400 }
662 401 }
663 - //Addon URL filter group key
664 - $chklist = array();
665 - if($urlnum > 0) {
666 - foreach ( $groupkeys as $key) {
667 - $chklist[] = $key;
668 - }
669 - }
670 -
671 402 foreach ( $plist as $p_key => $val ) {
672 403 $modules = array();
673 404 if(strpos($p_key, 'jetpack/') !== false)
674 405 $modules = $jlist;
@@ -674,13 +405,13 @@
674 405 $modules = $jlist;
675 406 else if(strpos($p_key, 'celtispack/') !== false)
676 407 $modules = $clist;
677 408 else
678 - $this->plfregist_item($p_key, $chklist, $filter);
409 + $this->plfregist_item($p_key, $val);
679 410 if(!empty($modules)){
680 411 echo "<input type='hidden' name='plfregist[$p_key]' value='_pagefilter'>";
681 412 foreach ( $modules as $m_key => $val) {
682 - $this->plfregist_item($m_key, $chklist, $filter);
413 + $this->plfregist_item($m_key, $val);
683 414 }
684 415 }
685 416 }
686 417 ?>
@@ -685,67 +416,36 @@
685 416 }
686 417 ?>
687 418 </tbody>
688 419 </table>
689 - </div>
690 - <p></p>
691 - <div class="grid-row">
692 - <div class="filter-description">
693 - <p><strong>[ <?php _e('Page Type Filter', 'plf'); ?> ]</strong></p>
694 - <?php _e('<strong>Normal</strong> - Exclude plugin from Page Type filter', 'plf'); ?><br />
695 - <?php _e('<strong>Admin Type</strong> - If you only use plugins for Admin pages.', 'plf'); ?><br />
696 - <?php _e('<strong>Page Type</strong> - If you want to activate or deactivate plugins for each Page Type and Single page.', 'plf'); ?>
697 - <p>
698 - <?php
699 - $checked = (!empty(self::$filter['admin_bar']))? self::$filter['admin_bar'] : false;
700 - echo '<span class="admin-bar-option">' . self::checkbox("plf_option[admin_bar]", $checked, __('Add a link to admin bar for displaying the plugins filtered status', 'plf') ) . '</span>';
701 - ?>
702 - </p>
703 - <p><?php _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>
704 -
420 + <br />
421 + <p><strong>[ Admin Filter ]</strong></p>
422 + <div class="filter-description"><?php _e('Plugins to be used only in admin mode.', 'plf'); ?></div>
423 + <p><strong>[ Page Filter ]</strong></p>
424 + <div class="filter-description">
425 + <?php _e('Plugins for selecting whether to activate each Page type or Post.', 'plf'); ?><br />
426 + <?php _e('Selected page filter plugins are once blocked, but is activated by "Page filter Activation" setting.', 'plf'); ?>
705 427 <div class="exclude-pformat">
706 - <p><?php _e('<strong>Exclude Post Format Type</strong> - Choose Post Format Type you are not using. To exclude from Page Type item subject.', 'plf'); ?></p>
707 - <?php
428 + <p><strong><?php _e( 'Exclude Post Format Type', 'plf' ); ?></strong><br />
429 + <?php _e('Choose Post Format Type you are not using. To exclude from Page Filter item subject.', 'plf'); ?>
430 + </p>
431 + <?php
708 432 $html = '<div>';
709 433 $pformat = array('image', 'gallery', 'video', 'audio', 'aside', 'status', 'quote', 'link', 'chat' );
710 434 foreach ( $pformat as $type ) {
711 - $checked = (!empty(self::$filter['exclude'][$type]))? self::$filter['exclude'][$type] : false;
435 + $checked = (!empty($this->filter['exclude'][$type]))? $this->filter['exclude'][$type] : false;
712 436 $label = "<span>$type</span>";
713 437 $html .= self::checkbox("plf_option[exclude][$type]", $checked, $label);
714 438 }
715 439 $html .= '</div>';
716 440 echo $html;
717 - ?>
441 + ?>
718 442 </div>
719 - <p><strong>[ <?php _e('Post Language Locale', 'plf'); ?> ]</strong></p>
720 - <p><?php _e('A very simple multilingual feature that uses MO translation files for the selected locale per Post/Page editing screen.','plf'); ?></p>
721 - <?php
722 - $checked = (!empty(self::$filter['language']))? self::$filter['language'] : false;
723 - echo '<div class="language-option">' . self::checkbox("plf_option[language]", $checked, __('Language switching per post', 'plf') ) . '</div>';
724 - ?>
725 - </div>
726 - <div class="side-info">
727 - <?php if(! is_plugin_active('plugin-load-filter-addon/plugin-load-filter-addon.php')){ ?>
728 - <div style="background-color: #f0fff0; border:1px solid #70c370; padding:4px 20px; margin: 10px 0;" >
729 - <p><strong><?php _e('Introduction of Addon', 'plf'); ?></strong></p>
730 - <p><?php _e('Thank you for using Plugin Load Filter. We offer URL filtering as Addon. Please consider using Addon!', 'plf'); ?></p>
731 - <p><?php _e('See more information ', 'plf'); ?><a target="_blank" rel="noopener" href="https://celtislab.net/en/wp-plugin-load-filter-addon/"> Plugin Load Filter Addon</a></p>
732 - </div>
733 - <?php } ?>
734 - <?php if(! is_plugin_active('yasakani-cache/yasakani-cache.php')){ ?>
735 - <div style="background-color: #f0fff0; border:1px solid #70c370; padding:4px 20px; margin: 10px 0;" >
736 - <p><strong><?php _e('Introduction of YASAKANI Cache', 'plf'); ?></strong></p>
737 - <p><?php _e('We offer Free Cache Plugin that is very easy to use and very fast.', 'plf'); ?></p>
738 - <p><?php _e('See more information ', 'plf'); ?><a target="_blank" rel="noopener" href="https://celtislab.net/en/wp-yasakani-cache/"> YASAKANI Cache</a></p>
739 - <p><?php _e('We also sell Addon for Image Optimization, so please consider using them!', 'plf'); ?></p>
740 - <p><?php _e('See more information ', 'plf'); ?><a target="_blank" rel="noopener" href="https://celtislab.net/en/wp-yasakani-cache-img-optimizer-addon/"> YASAKANI Image Optimizer</a></p>
741 - </div>
742 - <?php } ?>
743 - </div>
744 443 </div>
444 + </div>
745 445 <?php
746 446 }
747 -
447 +
748 448 //Activate plugins select from Page Filter
749 449 public function _plfactive_checkbox_row($p_key, $select_cvplugins, $chklist, $filter) {
750 450
751 451 $selplugins = array_map("trim", explode(',', $select_cvplugins));
@@ -750,9 +450,9 @@
750 450
751 451 $selplugins = array_map("trim", explode(',', $select_cvplugins));
752 452 $devlist = array('desktop','mobile');
753 453 if(in_array( $p_key, $selplugins )){
754 - $p_name = self::pluginkey_to_name($p_key);
454 + $p_name = $this->pluginkey_to_name($p_key);
755 455 echo "<tr><td class='plugins-name'>$p_name</td>";
756 456 foreach($devlist as $devtype){
757 457 $checked = (empty($filter['group'][$devtype]['plugins']) || false === strpos($filter['group'][$devtype]['plugins'], $p_key))? false : true;
758 458 echo '<td class="device-type">' . self::altcheckbox("plfactive[$devtype][$p_key]", $checked, '<span class="dashicons dashicons-yes"></span>') . '</td>';
@@ -758,9 +458,9 @@
758 458 echo '<td class="device-type">' . self::altcheckbox("plfactive[$devtype][$p_key]", $checked, '<span class="dashicons dashicons-yes"></span>') . '</td>';
759 459 }
760 460 foreach($chklist as $pgtype){
761 461 $checked = (empty($filter['group'][$pgtype]['plugins']) || false === strpos($filter['group'][$pgtype]['plugins'], $p_key))? false : true;
762 - 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>';
763 463 }
764 464 echo "</tr>";
765 465 }
766 466 }
@@ -775,14 +475,14 @@
775 475 <thead>
776 476 <tr><th class="plugins-name"><?php _e('Plugins'); ?></th>
777 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>
778 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>
779 - <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>
780 - <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>
781 - <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>
782 - <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>
783 - <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>
784 - <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>
785 485 <?php
786 486 $pformat = array('image', 'gallery', 'video', 'audio', 'aside', 'status', 'quote', 'link', 'chat' );
787 487 $exclude = array();
788 488 if(!empty($filter['exclude'])){
@@ -795,20 +495,20 @@
795 495 foreach ( $pformat as $type) {
796 496 if(!in_array($type, $exclude)){
797 497 $title = __('Post : ', 'plf') . $type;
798 498 $icon = ($type === "link")? "dashicons-admin-links" : "dashicons-format-$type";
799 - 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>';
800 500 }
801 501 }
802 502 if(function_exists('is_embed')){
803 503 $title = __('WordPress Embed Content Card (API)', 'plf');
804 - 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>";
805 505 }
806 506 $post_types = get_post_types( array('public' => true, '_builtin' => false) );
807 507 foreach ( $post_types as $post_type ) {
808 508 if(!empty($post_type)){
809 509 $title = __('Custom Post : ', 'plf') . $post_type;
810 - 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>";
811 511 }
812 512 }
813 513 ?>
814 514 </tr>
@@ -816,9 +516,9 @@
816 516 <tbody class="plugins-table-body">
817 517 <?php
818 518 $nplugins = $jmodules = $cmodules = $allmodule = array();
819 519 foreach ( $plugins as $p_key => $p_data ) {
820 - $p_name = self::pluginkey_to_name($p_key);
520 + $p_name = $this->pluginkey_to_name($p_key);
821 521 if(empty($p_name))
822 522 continue;
823 523 if(strpos($p_key, 'jetpack_module/') !== false)
824 524 $jmodules[] = $p_key;
@@ -863,9 +563,8 @@
863 563 }
864 564
865 565 //Option Setting Form Display
866 566 public function plf_option_page() {
867 - $clear_dialog = __('Plugin Load Filter Settings\nClick OK to clear it.', 'plf');
868 567 ?>
869 568 <h2><?php _e('Plugin Load Filter Settings', 'plf'); ?></h2>
870 569 <p></p>
871 570 <div id="plf-setting-tabs">
@@ -870,46 +569,44 @@
870 569 <p></p>
871 570 <div id="plf-setting-tabs">
872 571 <ul>
873 572 <li><a href="#plf-registration-tab" ><?php _e('Filter Registration', 'plf'); ?></a></li>
874 - <li><a href="#plf-activation-tab" ><?php _e('Page Type Activation', 'plf'); ?></a></li>
573 + <li><a href="#plf-activation-tab" ><?php _e('Page Filter Activation', 'plf'); ?></a></li>
875 574 </ul>
876 - <div id="plf-registration-tab" style="display : none;">
877 - <form method="post" autocomplete="off">
878 - <?php wp_nonce_field( 'plugin_load_filter'); ?>
879 - <?php $this->plfregist_table(self::$plugins_inf, self::$filter); ?>
575 + <form method="post" >
576 + <?php wp_nonce_field( 'plugin_load_filter'); ?>
577 + <div id="plf-registration-tab" style="display : none;">
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>
880 594 <p class="submit">
881 - <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;
882 - <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'); ?>" />
883 597 </p>
884 - </form>
885 - </div>
886 - <div id="plf-activation-tab" style="display : none;">
887 - <form method="post" autocomplete="off">
888 - <?php wp_nonce_field( 'plugin_load_filter'); ?>
889 598 <?php
890 - $pgfilter = (!empty(self::$filter['_pagefilter']['plugins']))? self::$filter['_pagefilter']['plugins'] : array();
891 - if(!empty($pgfilter)){
892 - $this->plfactive_table(self::$plugins_inf, $pgfilter, self::$filter);
893 - ?>
894 - <br />
895 - <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 />
896 - <?php _e('You can also select plugins to activate from Post/Page content editing screen.', 'plf') ?>
897 - </p>
898 - <p class="submit">
899 - <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;
900 - <input type="submit" class="button-primary" name="edit_activate_page_filter" value="<?php _e('Activate Plugin Entry &raquo;', 'plf'); ?>" />
901 - </p>
902 - <?php
903 - } else {
904 - ?>
905 - <br />
906 - <p><span style="color: #ff0000;"><?php _e('Page Filter is not registered', 'plf') ?></span></p>
907 - <?php
908 - }
599 + }
600 + else {
909 601 ?>
910 - </form>
602 + <br />
603 + <p><span style="color: #ff0000;"><?php _e('Page Filter is not registered', 'plf') ?></span></p>
604 + <?php
605 + }
606 + ?>
911 607 </div>
608 + </form>
912 609 </div>
913 610 <?php
914 611 }
915 612
@@ -917,11 +614,11 @@
917 614 * Meta box
918 615 * Individual of the plug-in filter meta box for Post/Page/CustomPost
919 616 **************************************************************************/
920 617 function load_meta_boxes( $post_type, $post ) {
921 - if ( current_user_can('activate_plugins', $post->ID) ) {
922 - add_meta_box( 'pluginfilterdiv', __( 'Plugin Load Filter', 'plf' ), array(&$this, 'plf_meta_box'), null, 'side' );
923 - //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' ));
924 621 add_action( 'admin_footer', array(&$this, 'plf_meta_script' ));
925 622 }
926 623 }
927 624
@@ -936,9 +633,9 @@
936 633 $device['desktop'] = $checked_arcvplugins['desktop'];
937 634 $device['mobile'] = $checked_arcvplugins['mobile'];
938 635 $devlist = array('desktop','mobile');
939 636 if(in_array( $p_key, $selplugins )){
940 - $p_name = self::pluginkey_to_name($p_key);
637 + $p_name = $this->pluginkey_to_name($p_key);
941 638 $html .= "<tr><td class='plugins-name'>$p_name</td>";
942 639 foreach($devlist as $devtype){
943 640 $checked = (empty($device[$devtype]) || false === strpos($device[$devtype], $p_key))? false : true;
944 641 $html .= "<td class='device-type $devtype'>" . self::altcheckbox("plf_option[$devtype][$p_key]", $checked, '<span class="dashicons dashicons-yes"></span>') . '</td>';
@@ -966,9 +663,9 @@
966 663 $html .= '</thead>';
967 664 $html .= '<tbody class="plugins-table-body meta-boxes-plugins-table">';
968 665 $nplugins = $jmodules = $cmodules = array();
969 666 foreach ( $plugins as $p_key => $p_data ) {
970 - $p_name = self::pluginkey_to_name($p_key);
667 + $p_name = $this->pluginkey_to_name($p_key);
971 668 if(empty($p_name))
972 669 continue;
973 670 if(strpos($p_key, 'jetpack_module/') !== false)
974 671 $jmodules[] = $p_key;
@@ -997,23 +694,8 @@
997 694 $html .= '</table>';
998 695 return $html;
999 696 }
1000 697
1001 - //get_locale に加えたフィルターフックを外してサイトのロケールを取得
1002 - static function get_site_locale(){
1003 - global $locale;
1004 - if(class_exists('Plf_filter')){
1005 - remove_filter( 'locale', array('Plf_filter', 'post_locale') );
1006 - $locale = null;
1007 - $site_locale = get_locale();
1008 - add_filter( 'locale', array('Plf_filter', 'post_locale') );
1009 - } else {
1010 - $locale = null;
1011 - $site_locale = get_locale();
1012 - }
1013 - return $site_locale;
1014 - }
1015 -
1016 698 function plf_meta_box( $post, $box ) {
1017 699 if(is_object($post)){
1018 700 $myfilter = get_post_meta( $post->ID, '_plugin_load_filter', true );
1019 701 //ver2.2.0 for compatibility, set 'plugins' data to 'desktop' and 'mobile'
@@ -1024,87 +706,19 @@
1024 706 }
1025 707 $default = array( 'filter' => 'default', 'desktop' => '', 'mobile' => '');
1026 708 $option = (!empty($myfilter))? $myfilter : $default;
1027 709 $option = wp_parse_args( $option, $default);
1028 - $pgfilter = (!empty(self::$filter['_pagefilter']['plugins']))? self::$filter['_pagefilter']['plugins'] : array();
710 + $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
1029 711 $ajax_nonce = wp_create_nonce( 'plugin_load_filter-' . $post->ID );
1030 - $this->plf_css();
1031 712 ?>
1032 - <div id="plugin-filter-select">
1033 - <p><?php _e( 'Plugin filter for Single post', 'plf' ); ?></p>
1034 - <label><input type="radio" name="pagefilter" value="default" <?php checked('default', $option['filter']); ?>/><?php _e('Not Use', 'plf' ); ?></label>
1035 - <label><input type="radio" name="pagefilter" value="include" <?php checked('include', $option['filter']); ?>/><?php _e('Use', 'plf'); ?></label>
1036 - <div id="page-filter-stat">
1037 - <?php echo $this->pagefilter_plugins_checklist( self::$plugins_inf, $pgfilter, $option ); ?>
1038 - </div>
1039 - <div class="plf-option-info"><?php _e('Plugin Activate/Deactivate filter for this Post only', 'plf'); ?></div>
1040 - <?php
1041 - $c_locale = $o_post_id = '';
1042 - $languages = array();
1043 - $locale_mode = 'style="display:none;"';
1044 - if(!empty(self::$filter['language'])){
1045 - $languages = get_available_languages();
1046 - $site_locale = self::get_site_locale();
1047 - //bogo と同じ _locale ポストメタデータ採用
1048 - $c_locale = get_post_meta( $post->ID, '_locale', true );
1049 - if(empty($c_locale)){
1050 - $c_locale = $site_locale;
1051 - }
1052 - if ( ! in_array( $c_locale, $languages ) ) {
1053 - $c_locale = '';
1054 - }
1055 - $o_post_id = get_post_meta( $post->ID, '_original_post_id', true );
1056 - $o_post_id = (is_numeric($o_post_id))? $o_post_id : '';
1057 - $locale_mode = '';
1058 - }
1059 - 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>';
1060 - ?>
1061 - <hr>
1062 - <div id="plf-post-locale-select" <?php echo $locale_mode; ?>>
1063 - <p><?php _e( 'Language of this post', 'plf' ); ?> <span class="dashicons dashicons-translation" aria-hidden="true"></span></p>
1064 - <?php
1065 - wp_dropdown_languages(
1066 - array(
1067 - 'name' => 'plf_locale',
1068 - 'id' => 'plf_locale',
1069 - 'selected' => $c_locale,
1070 - 'languages' => $languages,
1071 - 'show_available_translations' => false,
1072 - )
1073 - );
1074 - ?>
1075 - <p><?php _e( 'Original post ID for hreflang', 'plf' ); ?></p>
1076 - <input type="text" id="plf_original_post_id" name="plf_original_post_id" size="8" value="<?php echo $o_post_id; ?>" />
1077 - <div class="hflang-group-edit-lonk">
1078 - <?php
1079 - $id = (is_numeric($o_post_id))? $o_post_id : $post->ID;
1080 - global $wpdb;
1081 - $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);
1082 - if(is_array($ids)){
1083 - if(!in_array((string)$id, $ids)){
1084 - $ids[] = (string)$id;
1085 - }
1086 - if(count($ids) > 1){
1087 - foreach ($ids as $v) {
1088 - if( $post->ID != $v){
1089 - $l = get_post_meta( $v, '_locale', true );
1090 - if(empty($l)){
1091 - $l = $site_locale;
1092 - }
1093 - $url = get_edit_post_link( $v );
1094 - if(!empty($url)){
1095 - 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>';
1096 - }
1097 - }
1098 - }
1099 - }
1100 - }
1101 - ?>
1102 - </div>
1103 - <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>
1104 - <?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>'; ?>
1105 - </div>
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 ); ?>
1106 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>
1107 721 <?php
1108 722 }
1109 723 }
1110 724
@@ -1111,58 +725,18 @@
1111 725 //wp_ajax_plugin_load_filter called function
1112 726 function plf_ajax_postidfilter() {
1113 727 if ( isset($_POST['post_id']) ) {
1114 728 $pid = (int) $_POST['post_id'];
1115 - if ( !current_user_can( 'activate_plugins', $pid ) )
729 + if ( !current_user_can( 'edit_plugins', $pid ) )
1116 730 wp_die( -1 );
1117 731 check_ajax_referer( "plugin_load_filter-$pid" );
1118 732
1119 - if(!empty(self::$filter['language'])){
1120 - if(isset($_POST['locale'])){
1121 - $s_locale = (!empty($_POST['locale']))? $_POST['locale'] : 'en_US';
1122 - $languages = get_available_languages();
1123 - $languages[] = 'en_US'; //add WP default locale
1124 - if ( in_array( $s_locale, $languages ) ) {
1125 - $g_locale = get_post_meta( $pid, '_locale', true );
1126 - global $locale;
1127 - if(class_exists('Plf_filter')){
1128 - remove_filter( 'locale', array('Plf_filter', 'post_locale') );
1129 - $locale = null;
1130 - $o_locale = get_locale();
1131 - add_filter( 'locale', array('Plf_filter', 'post_locale') );
1132 - } else {
1133 - $locale = null;
1134 - $o_locale = get_locale();
1135 - }
1136 - if($s_locale !== $g_locale){
1137 - if($s_locale === $o_locale){
1138 - delete_post_meta( $pid, '_locale');
1139 - } else {
1140 - update_post_meta( $pid, '_locale', $s_locale );
1141 - }
1142 - }
1143 - }
1144 - }
1145 - if(isset($_POST['original_post_id'])){
1146 - if(empty($_POST['original_post_id'])){
1147 - delete_post_meta( $pid, '_original_post_id');
1148 - } elseif(preg_match( '/([0-9]+)?/', $_POST['original_post_id'], $match )){
1149 - $o_id = (int)$match[1];
1150 - $post = get_post($o_id);
1151 - if(is_object($post)){
1152 - $g_id = get_post_meta( $pid, '_original_post_id', true );
1153 - if($o_id !== $g_id){
1154 - update_post_meta( $pid, '_original_post_id', $o_id );
1155 - }
1156 - }
1157 - }
1158 - }
1159 - }
1160 - $pgfilter = (!empty(self::$filter['_pagefilter']['plugins']))? self::$filter['_pagefilter']['plugins'] : array();
733 + $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
1161 734 $option["filter"] = (empty($_POST['filter']))? 'default' : $_POST['filter'];
1162 735 if('default' == $option["filter"]){
1163 736 delete_post_meta( $pid, '_plugin_load_filter');
1164 - } else {
737 + }
738 + else {
1165 739 $plugins = array();
1166 740 if( preg_match_all('/plf_option\[desktop\]\[(.+?)\]/u', $_POST['desktop'], $matches)){
1167 741 if(!empty($matches[1])){
1168 742 foreach ($matches[1] as $plugin){
@@ -1182,41 +756,14 @@
1182 756 }
1183 757 update_post_meta( $pid, '_plugin_load_filter', $option );
1184 758 }
1185 759
1186 - $html = $this->pagefilter_plugins_checklist( self::$plugins_inf, $pgfilter, $option );
760 + $html = $this->pagefilter_plugins_checklist( $this->plugins_inf, $pgfilter, $option );
1187 761 wp_send_json_success($html);
1188 762 }
1189 763 wp_die( 0 );
1190 764 }
1191 765
1192 - //alternate hreflang meta tag
1193 - static function altenate_hreflang() {
1194 - if ( is_singular() ) {
1195 - global $post, $wpdb;
1196 - $pid = $post->ID;
1197 - $oid = get_post_meta( $pid, '_original_post_id', true );
1198 - $oid = (is_numeric($oid))? $oid : $pid;
1199 - $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);
1200 - if(is_array($ids)){
1201 - if(!in_array((string)$oid, $ids)){
1202 - $ids[] = (string)$oid;
1203 - }
1204 - if(count($ids) > 1){
1205 - $site_locale = self::get_site_locale();
1206 - foreach ($ids as $id) {
1207 - $l = get_post_meta( $id, '_locale', true );
1208 - if(empty($l)){
1209 - $l = $site_locale;
1210 - }
1211 - $url = get_permalink( $id );
1212 - echo '<link rel="alternate" hreflang="' . esc_attr($l) . '" href="' . esc_url($url) .'" />' . PHP_EOL;
1213 - }
1214 - }
1215 - }
1216 - }
1217 - }
1218 -
1219 766 /***************************************************************************
1220 767 * Javascript
1221 768 **************************************************************************/
1222 769 function activetab_script() { ?>
@@ -1223,43 +770,14 @@
1223 770 <script type='text/javascript' >
1224 771 /* <![CDATA[ */
1225 772 var plf_activetab = <?php echo $this->tab_num; ?>
1226 773 /* ]]> */
1227 - jQuery(document).ready(function ($) {
1228 - plf_setting_tabs();
1229 - function plf_setting_tabs(){ $('#plf-setting-tabs').tabs({ active:plf_activetab, }); }
1230 - });
774 + jQuery(document).ready(function ($) { plf_setting_tabs(); function plf_setting_tabs(){ $('#plf-setting-tabs').tabs({ active:plf_activetab, }); }});
1231 775 </script>
1232 776 <?php }
1233 777
1234 - function plf_meta_script() {
1235 - $reload_dialog = __('Plugin Load Filter setting has been updated.\nClick OK to reload the page.', 'plf');
1236 - ?>
778 + function plf_meta_script() { ?>
1237 779 <script type='text/javascript' >
1238 - WPAddPagePluginLoadFilter = function(nonce){
1239 - jQuery.ajax({
1240 - type: 'POST',
1241 - url: ajaxurl,
1242 - data: {
1243 - action: "plugin_load_filter",
1244 - post_id : jQuery( '#post_ID' ).val(),
1245 - _ajax_nonce: nonce,
1246 - locale: jQuery("select[name='plf_locale']").val(),
1247 - original_post_id: jQuery("input[name='plf_original_post_id']").val(),
1248 - filter: jQuery("input[name='pagefilter']:checked").val(),
1249 - desktop: jQuery('.meta-boxes-plugins-table td.desktop input:checked').map(function(){ return jQuery(this).attr("name"); }).get().join(','),
1250 - mobile: jQuery('.meta-boxes-plugins-table td.mobile input:checked').map(function(){ return jQuery(this).attr("name"); }).get().join(','),
1251 - },
1252 - dataType: 'json',
1253 - }).then(
1254 - function (response, dataType) {
1255 - jQuery('#page-filter-stat').html(response.data);
1256 - if(window.confirm('<?php echo $reload_dialog; ?>')){
1257 - location.reload();
1258 - }
1259 - },
1260 - function () { /* alert("ajax error"); */ }
1261 - );
1262 - };
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; };
1263 781 </script>
1264 782 <?php }
1265 783 }