PluginProbe
Plugin Load Filter / 2.4.0
Plugin Load Filter v2.4.0
trunk 2.0.0 2.0.1 2.1.0 2.2.0 2.2.1 2.3.0 2.3.1 2.4.0 2.4.1 2.5.1 3.3.0 4.0.6 4.1.1 4.2.0 4.3.0 4.3.1 4.4.0
← All changes | mu-plugins/plf-filter.php +147 -771 4.0.62.4.0 View file →
@@ -1,10 +1,10 @@
1 1 <?php
2 2 /*
3 3 Plugin Name: plugin load filter [plf-filter]
4 4 Description: Dynamically activated only plugins that you have selected in each page. [Note] plf-filter has been automatically installed / deleted by Activate / Deactivate of "load filter plugin".
5 - Version: 4.0.6
6 - Plugin URI: http://celtislab.net/en/wp-plugin-load-filter
5 + Version: 2.4.0
6 + Plugin URI: http://celtislab.net/wp_plugin_load_filter
7 7 Author: enomoto@celtislab
8 8 Author URI: http://celtislab.net/
9 9 License: GPLv2
10 10 */
@@ -19,11 +19,17 @@
19 19 * Retrieve the current user object.
20 20 * @return WP_User Current user WP_User object
21 21 */
22 22 function wp_get_current_user() {
23 - if ( ! function_exists( 'wp_set_current_user' ) ){
23 + if ( ! function_exists( 'wp_set_current_user' ) )
24 24 return 0;
25 - } else {
25 + //get_currentuserinfo is deprecated since version 4.5
26 + if ( version_compare( $GLOBALS['wp_version'], '4.5', '<' ) ){
27 + global $current_user;
28 + get_currentuserinfo();
29 + return $current_user;
30 + }
31 + else {
26 32 return _wp_get_current_user();
27 33 }
28 34 }
29 35 endif;
@@ -77,14 +83,15 @@
77 83 }
78 84 endif;
79 85
80 86 /***************************************************************************
81 - * Plugin Load Filter
87 + * Plugin Load Filter( Admin, Desktop, Mobile, Page 4types filter)
82 88 **************************************************************************/
83 89
84 90 if(in_array( 'plugin-load-filter/plugin-load-filter.php', (array) get_option( 'active_plugins', array() ) )){
85 91 $plugin_load_filter = new Plf_filter();
86 -} elseif ( is_multisite() ) {
92 +}
93 +elseif ( is_multisite() ) {
87 94 $plugins = get_site_option( 'active_sitewide_plugins');
88 95 if ( isset($plugins['plugin-load-filter/plugin-load-filter.php']) ){
89 96 $plugin_load_filter = new Plf_filter();
90 97 }
@@ -89,350 +96,94 @@
89 96 $plugin_load_filter = new Plf_filter();
90 97 }
91 98 }
92 99
93 -class Plf_filter {
94 - static private $filter; //Plugin Load Filter Setting option data
95 - static private $rlocale;
96 - static private $url_filter;
97 - static private $s_url_filter;
98 - static private $is_filterkey;
99 - static private $base_plugins;
100 - static private $filtered_plugins;
101 - static private $cache;
102 - static private $url2id;
100 +class Plf_filter {
101 +
102 + private $filter = array(); //Plugin Load Filter Setting option data
103 + private $cache;
103 104
104 105 function __construct() {
105 - self::$cache = null;
106 - self::$url2id = null;
107 - self::$rlocale = null;
108 - self::$url_filter = null;
109 - self::$s_url_filter = null;
110 - self::$is_filterkey = false;
111 - self::$base_plugins = array();
112 - self::$filtered_plugins = array();
113 - self::$filter = get_option('plf_option');
114 - if(!empty(self::$filter)){
115 - //Addon option get
116 - $plugins = get_option( 'active_plugins', array() );
117 - if ( ! is_array( $plugins ) ) {
118 - $plugins = array();
106 + $this->filter = get_option('plf_option');
107 + //v2.3.0 option change
108 + if(empty($this->filter['optver']) || $this->filter['optver'] < '2'){
109 + //For ver2.2.0 compatibility, set '_pagefilter' data to 'desktop' and 'mobile'
110 + if(empty($this->filter['group']['desktop']) && empty($this->filter['group']['mobile'])){
111 + if(!empty($this->filter['_pagefilter'])){
112 + $this->filter['group']['desktop'] = $this->filter['_pagefilter'];
113 + $this->filter['group']['mobile'] = $this->filter['_pagefilter'];
114 + }
119 115 }
116 + }
117 +
118 + $this->cache = null;
119 + if(!empty($this->filter)){
120 120 if ( is_multisite() ) {
121 - $network_plugins = (array) get_site_option( 'active_sitewide_plugins', array() );
122 - $plugins = array_merge( $plugins, array_keys( $network_plugins ) );
121 + add_filter('pre_site_option_active_sitewide_plugins', array(&$this, 'active_sitewide_plugins'));
123 122 }
124 - if(in_array( 'plugin-load-filter-addon/plugin-load-filter-addon.php', $plugins)){
125 - self::$url_filter = get_option('plf_addon_options');
126 - }
127 -
128 - //active_plugins filter
129 - if ( is_multisite() ) {
130 - add_filter('pre_site_option_active_sitewide_plugins', array('Plf_filter', 'active_sitewide_plugins'));
131 - add_action('update_site_option_active_sitewide_plugins', array(&$this, 'update_active_sitewide_plugins'), 99999, 4);
132 - }
133 - add_filter('pre_option_active_plugins', array('Plf_filter', 'active_plugins'));
134 - add_filter('pre_option_jetpack_active_modules', array('Plf_filter', 'active_jetmodules'));
135 - add_filter('pre_option_celtispack_active_modules', array('Plf_filter', 'active_celtismodules'));
136 -
137 - add_action('update_option_active_plugins', array(&$this, 'update_active_plugins'), 99999, 3);
138 - add_action('update_option_jetpack_active_modules', array(&$this, 'update_jetmodules'), 99999, 3);
139 - add_action('update_option_celtispack_active_modules', array(&$this, 'update_celtismodules'), 99999, 3);
140 - add_action('switch_theme', array(&$this, 'switch_theme'));
141 -
142 - add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
123 + add_filter('pre_option_active_plugins', array(&$this, 'active_plugins'));
124 + add_filter('pre_option_jetpack_active_modules', array(&$this, 'active_jetmodules'));
125 + add_filter('pre_option_celtispack_active_modules', array(&$this, 'active_celtismodules'));
143 126 add_action('wp_loaded', array(&$this, 'cache_post_type'), 1);
144 - //admin-bar filtered status
145 - if(!empty(self::$filter['admin_bar'])){
146 - add_action('admin_bar_menu', array(&$this,'custom_bar_menus'), 201);
147 - }
148 - //language locale filter
149 - if(!empty(self::$filter['language'])){
150 - add_filter( 'locale', array('Plf_filter', 'post_locale') );
151 - add_filter( 'determine_locale', array('Plf_filter', 'post_determine_locale') );
152 - }
153 127 }
154 128 }
155 -
156 - //Notice: scriptを使うと AMP でエラーとなるので target でオープン/クローズを行う
157 - static function plf_filtered_result_dialog( $text ) {
158 - ?>
159 - <style>
160 - #wpadminbar #wp-admin-bar-plf-statlink .ab-icon:before { content: '\f106'; top: 2px;}
161 - #plf-status { display:none;}
162 - #plf-status:target { display:block;}
163 - #plf-status .dialog-overlay{ position:fixed; left:0px; top:0px; width:100%; height:100%; background-color:rgba(0,0,0,.5); z-index:999999999;}
164 - #plf-status div.dialog { position:fixed; top:50%; left:50%; transform:translate(-50%, -50%); width:66%; max-width:420px; height:auto; padding:1.5em; color:#222; background:#fff; z-index:999999999;}
165 - #plf-status .dialog-title { margin: 0 0 1em; font-size: 16px;}
166 - #plf-status textarea { font-size: 13px;}
167 - #plf-status .button-group { display:block; margin-top:2em; text-align:right; font-size:1em;}
168 - #plf-status a.button { display:inline-block; text-decoration:none; margin: 0 0 0 1em; padding: .5em 1em; color: #0071a1; background: #f5f5f5; border:solid 1px #0071a1; border-radius:3px; cursor:pointer;}
169 - #plf-status a.button:hover { background: #e8ffff; border-color: #016087; color: #016087;}
170 - </style>
171 - <div id="plf-status">
172 - <div class="dialog-overlay"></div>
173 - <div class="dialog">
174 - <p class="dialog-title"><strong><?php echo 'Plugin Load Filter status'; ?></strong></p>
175 - <div><textarea id="plf-filtered-result" style="width:100%; height:320px; margin:5px 0;"><?php echo $text; ?></textarea></div>
176 - <div class="button-group">
177 - <a href="#" id="plf-status-close" class="button" aria-label="Close modal"><?php _e('Close'); ?></a>
178 - </div>
179 - </div>
180 - </div>
181 - <?php
182 - }
183 -
184 - //filtered plugins list print
185 - static function result_plugin_print( $e_plugins, $d_plugins ) {
186 - $text = PHP_EOL . "[Activate Plugins]" . PHP_EOL;
187 - $idx = 1;
188 - foreach ($e_plugins as $key) {
189 - $key = preg_replace('|/.+?\.php|', '', $key);
190 - $text .= "$idx. $key" . PHP_EOL;
191 - $idx++;
192 - }
193 - $text .= PHP_EOL . "[Deactivate Plugins]" . PHP_EOL;
194 - $idx = 1;
195 - foreach ($d_plugins as $key) {
196 - $key = preg_replace('|/.+?\.php|', '', $key);
197 - $text .= "$idx. $key" . PHP_EOL;
198 - $idx++;
199 - }
200 - return $text;
201 - }
202 -
203 - public function custom_bar_menus($wp_admin_bar) {
204 - if (current_user_can( 'activate_plugins' )) {
205 - $base_plugins = self::get_base_plugins();
206 - if(!empty($base_plugins)){
207 - $text = '==== Plugin Load Filter status ====' . PHP_EOL;
208 - $is_filterkey = self::is_filterkey();
209 - if($is_filterkey !== false){
210 - $text .= '[Filter] ' . $is_filterkey . PHP_EOL;
211 - $e_plugins = self::get_filtered_plugins();
212 - $d_plugins = array_diff( $base_plugins, $e_plugins );
213 - } else {
214 - $text .= '[Filter] Not Used' . PHP_EOL;
215 - $e_plugins = $base_plugins;
216 - $d_plugins = array();
217 - }
218 - ksort($e_plugins, SORT_STRING);
219 - ksort($d_plugins, SORT_STRING);
220 -
221 - $text .= self::result_plugin_print( $e_plugins, $d_plugins );
222 - self::plf_filtered_result_dialog( $text );
223 - $wp_admin_bar->add_menu( array(
224 - 'id' => 'plf-statlink',
225 - 'title' => '<span class="ab-icon"></span>PLF',
226 - 'href' => '#plf-status',
227 - ));
228 - }
229 - }
230 - }
231 -
129 +
232 130 //active_sitewide plugins Filter add ver2.4.0
233 - static function active_sitewide_plugins( $default = false) {
234 - return self::plf_filter( 'active_sitewide_plugins', $default);
131 + function active_sitewide_plugins( $default = false) {
132 + create_initial_taxonomies();
133 + create_initial_post_types();
134 + return $this->plf_filter( 'active_sitewide_plugins', $default);
235 135 }
236 136
237 137 //active plugins Filter
238 - static function active_plugins( $default = false) {
239 - return self::plf_filter( 'active_plugins', $default);
138 + function active_plugins( $default = false) {
139 + return $this->plf_filter( 'active_plugins', $default);
240 140 }
241 141
242 142 //Jetpack module Filter
243 - static function active_jetmodules( $default = false) {
244 - return self::plf_filter( 'jetpack_active_modules', $default);
143 + function active_jetmodules( $default = false) {
144 + return $this->plf_filter( 'jetpack_active_modules', $default);
245 145 }
246 146
247 147 //Celtispack module Filter
248 - static function active_celtismodules( $default = false) {
249 - return self::plf_filter( 'celtispack_active_modules', $default);
148 + function active_celtismodules( $default = false) {
149 + return $this->plf_filter( 'celtispack_active_modules', $default);
250 150 }
251 151
252 - function updated_plf_stat() {
253 - $default = array(
254 - 'post_type_query_vars' => array(),
255 - 'queryable_post_types' => array(),
256 - 'wp_post_statuses' => array(),
257 - 'wp_post_types' => array(),
258 - 'wp_taxonomies' => array(),
259 - 'stat_change' => false,
260 - );
261 - $data = get_option('plf_queryvars');
262 - $data = wp_parse_args( (array) $data, $default);
263 - //plugin bulk action repeated call
264 - if(empty($data['stat_change'])){
265 - $data['stat_change'] = true;
266 - update_option('plf_queryvars', $data);
267 - }
268 - }
269 -
270 - //Plugin/Module activate or deactivate stat change
271 - function update_active_sitewide_plugins( $option, $value, $old_value, $network_id ) {
272 - $this->updated_plf_stat();
273 - }
274 - function update_active_plugins( $old_value, $value, $option ) {
275 - $this->updated_plf_stat();
276 - }
277 - function update_active_jetmodules( $old_value, $value, $option ) {
278 - $this->updated_plf_stat();
279 - }
280 - function update_active_celtismodules( $old_value, $value, $option ) {
281 - $this->updated_plf_stat();
282 - }
283 - function switch_theme() {
284 - $this->updated_plf_stat();
285 - }
286 -
287 - //Make taxonomies and posts available to 'plugin load filter'.
288 - //force register_taxonomy (category, post_tag, post_format)
289 - static function force_initial_taxonomies(){
290 - global $wp_actions;
291 - $wp_actions[ 'init' ] = 1;
292 - create_initial_taxonomies();
293 - create_initial_post_types();
294 - unset($wp_actions[ 'init' ]);
295 - }
296 -
297 - //all plugins loaded
298 - function plugins_loaded() {
299 - //ver4.0.5 カスタムポストタイプのキャッシュデータを $wp_post_types グローバル変数には反映しないよう変更したのでこの処理は不要となるが、なんらかの影響があると嫌なのでとりあえず残しておく
300 - // woocommerce が init 後に register_post_type, register_taxonomy が実行されたか判定しているので該当データを一旦クリアして init で再登録させる
301 - if(post_type_exists( 'product' )){
302 - if(method_exists('WC_Post_Types', 'register_post_types')){
303 - unregister_post_type( 'product' );
304 - //ver4.0.2 wc_register_order_type で登録されるタイプも一旦クリアする
305 - if(post_type_exists( 'shop_order' )){
306 - unregister_post_type( 'shop_order' );
307 - }
308 - if(post_type_exists( 'shop_order_refund' )){
309 - unregister_post_type( 'shop_order_refund' );
310 - }
311 - }
312 - }
313 - if ( taxonomy_exists( 'product_type' ) ) {
314 - if(method_exists('WC_Post_Types', 'register_taxonomies')){
315 - unregister_taxonomy( 'product_type' );
316 - }
317 - }
318 - }
319 -
320 152 //Post Format Type, Custom Post Type Data Cache for parse request
321 153 function cache_post_type() {
322 - if (!is_admin() || self::$is_filterkey !== false || ( defined('DOING_AJAX') && DOING_AJAX ))
323 - return;
324 -
325 - $default = array(
326 - 'post_type_query_vars' => array(),
327 - 'queryable_post_types' => array(),
328 - 'wp_post_statuses' => array(),
329 - 'wp_post_types' => array(),
330 - 'wp_taxonomies' => array(),
331 - 'stat_change' => false,
332 - );
154 + if (!is_admin() || ( defined('DOING_AJAX') && DOING_AJAX ) || (defined('DOING_CRON') && DOING_CRON))
155 + return;
156 +
157 + global $wp;
158 + $public_query_vars = (!empty($wp->public_query_vars))? $wp->public_query_vars : array();;
159 + $post_type_query_vars = array();
160 + foreach ( get_post_types( array(), 'objects' ) as $post_type => $t ){
161 + if ( $t->query_var )
162 + $post_type_query_vars[$t->query_var] = $post_type;
163 + }
164 + $queryable_post_types = get_post_types( array('publicly_queryable' => true) );
165 +
333 166 $data = get_option('plf_queryvars');
334 - $data = wp_parse_args( (array) $data, $default);
335 -
336 - //init or plugin activate or deactivate stat change
337 - if(empty($data['wp_post_types']) || !empty($data['stat_change'])){
338 - global $wp;
339 - global $wp_post_types;
340 - global $wp_post_statuses;
341 - global $wp_taxonomies;
342 - $public_query_vars = (!empty($wp->public_query_vars))? $wp->public_query_vars : array();;
343 - $post_type_query_vars = array();
344 - foreach ( get_post_types( array(), 'objects' ) as $post_type => $t ){
345 - if ( $t->query_var )
346 - $post_type_query_vars[$t->query_var] = $post_type;
347 - }
348 - $queryable_post_types = get_post_types( array('publicly_queryable' => true) );
349 -
167 + if(!empty($post_type_query_vars) && !empty($queryable_post_types)){
350 168 $data['public_query_vars'] = $public_query_vars;
351 169 $data['post_type_query_vars'] = $post_type_query_vars;
352 170 $data['queryable_post_types'] = $queryable_post_types;
353 - $data['wp_post_statuses'] = $wp_post_statuses;
354 - $data['wp_post_types'] = $wp_post_types;
355 - $data['wp_taxonomies'] = $wp_taxonomies;
356 - $data['stat_change'] = false;
357 171 update_option('plf_queryvars', $data);
358 172 }
173 + else if(!empty($data['post_type_query_vars']) || !empty($data['queryable_post_types'])){
174 + delete_option('plf_queryvars');
175 + }
359 176 }
360 177
361 - /**
362 - * Filters the locale for the current request.
363 - *
364 - * @param string $locale The locale.
365 - */
366 - static function post_locale( $locale ) {
367 - if(empty(self::$rlocale)) {
368 - $pid = 0;
369 - if ( strpos( $_SERVER['REQUEST_URI'], 'wp-json' ) !== false || preg_match( '/(admin|wc)-ajax/', $_SERVER['REQUEST_URI'])) {
370 - $refurl = wp_get_raw_referer();
371 - if(!empty( $refurl )){
372 - if(preg_match( '/post=([0-9]+)?/', $refurl, $match )){
373 - $pid = (int)$match[1];
374 - } elseif(preg_match( '/post_ID=([0-9]+)?/', $refurl, $match )){
375 - $pid = (int)$match[1];
376 - } else {
377 - $pid = (isset(self::$url2id[$refurl]))? self::$url2id[$refurl] : url_to_postid( $refurl );
378 - self::$url2id[$refurl] = (int)$pid;
379 - }
380 - }
381 - } elseif ( strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) !== false) {
382 - if ( isset( $_GET['post'] ) ) {
383 - $pid = (int) $_GET['post'];
384 - } elseif ( isset( $_POST['post_ID'] ) ) {
385 - $pid = (int) $_POST['post_ID'];
386 - }
387 - } else {
388 - global $wp_query;
389 - if(is_singular() && is_object($wp_query->post) && !empty($wp_query->post->ID)){
390 - $pid = $wp_query->post->ID;
391 - } else {
392 - $refurl = wp_get_raw_referer();
393 - if (!empty( $refurl )) {
394 - $pid = (isset(self::$url2id[$refurl]))? self::$url2id[$refurl] : url_to_postid( $refurl );
395 - self::$url2id[$refurl] = (int)$pid;
396 - }
397 - }
398 - }
399 - if(!empty($pid)){
400 - $c_locale = get_post_meta( $pid, '_locale', true );
401 - if(!empty($c_locale)){
402 - self::$rlocale = $c_locale;
403 - }
404 - }
405 - }
406 - if(!empty(self::$rlocale)) {
407 - $locale = self::$rlocale;
408 - }
409 - return $locale;
410 - }
411 -
412 - static function post_determine_locale( $locale ) {
413 - if(!empty(self::$rlocale)) {
414 - $locale = self::$rlocale;
415 - }
416 - return $locale;
417 - }
418 -
419 - //parse_request Action Hook for Custom Post Type query add
420 - static function parse_request( &$args ) {
421 - if (did_action( 'plugins_loaded' ) === 0) {
178 + //parse_request Action Hook for Custom Post Type query add
179 + function parse_request( &$args ) {
180 + if (did_action( 'plugins_loaded' ) === 0 ) {
422 181 $data = get_option('plf_queryvars');
423 - if(!empty($data['post_type_query_vars']) && !empty($data['queryable_post_types']) && empty($data['stat_change'])){
424 - //ver4.0.5 グローバルのカスタムポストタイプに事前設定するとプラグイン内での登録済みチェック処理とコンフリクトするので止める
425 - //global $wp_post_statuses;
426 - //global $wp_post_types;
427 - //global $wp_taxonomies;
428 - //$wp_post_statuses = $data['wp_post_statuses'];
429 - //$wp_post_types = $data['wp_post_types'];
430 - //$wp_taxonomies = $data['wp_taxonomies'];
182 + if(!empty($data['post_type_query_vars']) && !empty($data['queryable_post_types'])){
431 183 $post_type_query_vars = $data['post_type_query_vars'];
432 184 $queryable_post_types = $data['queryable_post_types'];
433 185
434 - //query_vars に query_posts() で実行するSQL用のポストタイプデータをセット
435 186 $args->public_query_vars = $data['public_query_vars'];
436 187 if ( isset( $args->matched_query ) ) {
437 188 parse_str($args->matched_query, $perma_query_vars);
438 189 }
@@ -470,275 +221,26 @@
470 221 unset( $args->query_vars['post_type'] );
471 222 } else {
472 223 $args->query_vars['post_type'] = array_intersect( $args->query_vars['post_type'], $queryable_post_types );
473 224 }
474 - }
475 - }
476 - }
477 - }
478 -
479 - //get filter name
480 - static function is_filterkey() {
481 - return self::$is_filterkey;
482 - }
483 - //base plugins (initial activated plugins & module)
484 - static function get_base_plugins() {
485 - return self::$base_plugins;
486 - }
487 - //filtered plugins (plugins & module)
488 - static function get_filtered_plugins() {
489 - return self::$filtered_plugins;
490 - }
491 -
492 - /**
493 - * Get URL Filter (for addon optional)
494 - * @param $stat : 'active' / 'deactive' / '' = all
495 - * @param $urltype : 'front' / 'admin' / '' = all
496 - * @param $device : 'desktop' / 'mobile' / '' = all
497 - * @return url filter data array.
498 - */
499 - static function get_url_filter( $stat='', $urltype='', $device='' ) {
500 - $frontlist = array();
501 - $adminlist = array();
502 - if(!empty(self::$url_filter)){
503 - foreach (self::$url_filter['filter'] as $slug => $v) {
504 - if(empty($stat) || (!empty($v['stat']) && $stat === 'active') || (empty($v['stat']) && $stat === 'deactive')){
505 - if(empty($device) || (!empty($v['desktop']) && $device === 'desktop') || (!empty($v['mobile']) && $device === 'mobile')){
506 - if(!empty($v['type'])){
507 - $item = "{$v['group']}-{$v['slug']}";
508 - if($v['type'] == 'front'){
509 - $frontlist[$item] = $v;
510 - } elseif($v['type'] == 'admin'){
511 - $adminlist[$item] = $v;
512 - }
513 - }
514 - }
515 225 }
516 226 }
517 - //group 毎に slug をソート A-Za-z 順となる
518 - ksort($frontlist, SORT_STRING);
519 - ksort($adminlist, SORT_STRING);
520 227 }
521 - $list = array();
522 - if(empty($urltype) || $urltype === 'front'){
523 - foreach ($frontlist as $item => $v) {
524 - $list[] = $v;
525 - }
526 - }
527 - if(empty($urltype) || $urltype === 'admin'){
528 - foreach ($adminlist as $item => $v) {
529 - $list[] = $v;
530 - }
531 - }
532 - return $list;
533 228 }
534 - //active group list
535 - static function get_active_group() {
536 - $grouplist = array();
537 - $sluglist = self::get_url_filter( 'active' );
538 - foreach ($sluglist as $v) {
539 - if(!in_array($v['group'], $grouplist)){
540 - $grouplist[] = $v['group'];
541 - }
542 - }
543 - return $grouplist;
544 - }
545 - //active slug filter data in group
546 - static function get_slug_filter( $group ) {
547 - $list = array();
548 - $sluglist = self::get_url_filter( 'active' );
549 - foreach ($sluglist as $v) {
550 - if($v['group'] == $group){
551 - $list[] = $v;
552 - }
553 - }
554 - return $list;
555 - }
556 229
557 - //Is there a term in taxonomies
558 - static function is_term_in_taxonomy( $post_id, $term, $taxonomies) {
559 - $ret = false;
560 - $txs = explode(',', $taxonomies);
561 - foreach ( $txs as $slug ) {
562 - $names = '';
563 - $terms = get_the_terms( $post_id, $slug );
564 - if (!empty($terms) ) {
565 - foreach ( $terms as $tobj ) {
566 - $names .= $tobj->name . ',';
567 - }
568 - if(strpos($names, $term ) !== false){
569 - $ret = true;
570 - break;
571 - }
572 - }
573 - }
574 - return $ret;
575 - }
576 230
577 - // url path, query parameter match check
578 - static function is_url_match( $req_url, $parse_url, $filter ) {
579 - if(empty($parse_url['path']))
231 + //Plugin Load Filter Main (active plugins/modules filtering)
232 + function plf_filter( $option, $default = false) {
233 + if ( defined( 'WP_SETUP_CONFIG' ) )
580 234 return false;
581 - $_url['url_path'] = $parse_url['path'];
582 - $_url['url_q_and'] = $_url['url_q_not'] = (!empty($parse_url['query']))? $parse_url['query'] : '';
583 -
584 - $match = array();
585 - $keynum = array();
586 - foreach (array('url_path', 'url_q_and', 'url_q_not') as $item) {
587 - $match[$item] = 0;
588 - $keynum[$item] = 0;
589 - if($item === 'url_path'){
590 - $reg_before = "(/?)";
591 - $reg_after = "(/?$)";
592 - } else {
593 - $reg_before = "(^|&)";
594 - $reg_after = "(=|&|$)";
595 - }
596 235
597 - $keylist = (!empty($filter[$item])) ? $filter[$item] : '';
598 - $keylist = str_replace( "*", ".+?", $keylist);
599 - $ar_key = (!empty($keylist))? array_filter( array_map("trim", explode(PHP_EOL, $keylist))) : array();
600 - $keynum[$item] = count($ar_key);
601 - if(empty($ar_key)) {
602 - if($item === 'url_path')
603 - $match[$item] += 1;
604 - } else {
605 - $ar_new = array();
606 - foreach ($ar_key as $key) {
607 - //v4.0.6 home (/) のみの指定は別判定しないとトレイルスラッシュで終わる全てのURLにマッチしてしまう
608 - if($item === 'url_path' && $key === '/'){
609 - if($_url['url_path'] === '/'){
610 - $match[$item] += 1;
611 - }
612 - } elseif(preg_match("#{$reg_before}{$key}{$reg_after}#ui", $_url[$item])){
613 - $match[$item] += 1;
614 - }
615 - }
616 - }
617 - }
618 - $group = false;
619 - $hit = ($match['url_path'] > 0 && $match['url_q_and'] === $keynum['url_q_and'] && $match['url_q_not'] === 0)? true : false;
620 - if($hit){
621 - if((strpos($_url['url_path'], 'admin-ajax.php' ) !== false || strpos($_url['url_q_and'], 'wc-ajax' ) !== false) && (int)$filter['targetpage'] === 2){
622 - $action = '';
623 - if(isset($_REQUEST['action'])){
624 - $action = esc_attr($_REQUEST['action']);
625 - } elseif(!empty( $_GET['wc-ajax'] )) {
626 - $action = sanitize_text_field( wp_unslash( $_GET['wc-ajax'] ) );
627 - }
628 - if(!empty($filter['ajax_action'])){
629 - if( $action == $filter['ajax_action'] ){
630 - $group = $filter['group'];
631 - }
632 - } else {
633 - //exclude special action : plugin_load_filter, plf_urlfilter_test
634 - if (! in_array( $action, array('plugin_load_filter', 'plf_urlfilter_test')) ){
635 - $group = $filter['group'];
636 - }
637 - }
638 - } elseif(strpos($_url['url_path'], 'post-new.php' ) === false && (int)$filter['targetpage'] === 1){
639 - $post_id = 0;
640 - if ( isset( $_GET['post'] ) && isset( $_POST['post_ID'] ) && (int) $_GET['post'] !== (int) $_POST['post_ID'] ) {
641 - } elseif ( isset( $_GET['post'] ) ) {
642 - $post_id = (int) $_GET['post'];
643 - } elseif ( isset( $_POST['post_ID'] ) ) {
644 - $post_id = (int) $_POST['post_ID'];
645 - }
646 - if(empty($post_id)){
647 - //クエリーパラメータ形式だとポストIDが取得できないようなので、シュミレータ以外なら $wp_query->post->ID を使う
648 - if (isset($_REQUEST['action']) && isset($_POST['test_url']) ) {
649 - $post_id = (isset(self::$url2id[$req_url]))? self::$url2id[$req_url] : url_to_postid( $req_url );
650 - self::$url2id[$req_url] = (int)$post_id;
651 - } else {
652 - global $wp_query;
653 - if(is_object($wp_query->post) && !empty($wp_query->post->ID)) {
654 - $post_id = $wp_query->post->ID;
655 - } else {
656 - $post_id = (isset(self::$url2id[$req_url]))? self::$url2id[$req_url] : url_to_postid( $req_url );
657 - self::$url2id[$req_url] = (int)$post_id;
658 - }
659 - }
660 - }
661 - if(!empty($post_id)){
662 - $post = get_post( $post_id );
663 - if ( is_object($post) && !empty($post->post_type)) {
664 - if(!empty($filter['post_type'])){
665 - if(preg_match("#{$post->post_type}#", $filter['post_type'])){
666 - if(!empty($filter['taxonomies']) && !empty($filter['term'])){
667 - if(self::is_term_in_taxonomy( $post_id, $filter['term'], $filter['taxonomies'])){
668 - $group = $filter['group'];
669 - }
670 - } else {
671 - $group = $filter['group'];
672 - }
673 - }
674 - } else {
675 - if(!empty($filter['taxonomies']) && !empty($filter['term'])){
676 - if(self::is_term_in_taxonomy( $post_id, $filter['term'], $filter['taxonomies'])){
677 - $group = $filter['group'];
678 - }
679 - } else {
680 - $group = $filter['group'];
681 - }
682 - }
683 - }
684 - }
685 - } else {
686 - $group = $filter['group'];
687 - }
688 - }
689 - return($group);
690 - }
691 -
692 - static function plugin_keygen( $fname, $option ) {
693 - $key = false;
694 - if($option === 'jetpack_active_modules'){
695 - $key = 'jetpack_module/' . $fname;
696 - } elseif($option === 'celtispack_active_modules'){
697 - $key = 'celtispack_module/' . str_replace( '.php', '', basename( $fname ) );
698 - } else {
699 - $key = $fname;
700 - }
701 - return $key;
702 - }
703 -
704 - /**
705 - * Get valid plugins list for groupkey (for addon optional)
706 - * @param $groupkey : url filter group name
707 - * @param $filter : plf filtering setting data
708 - * @param $option : option data eg. 'active_plugins', 'active_sitewide_plugins', 'jetpack_active_modules' ...
709 - * @param $plugins : active plugins values before filtering
710 - * @return data values after filtering
711 - */
712 - static function filter_to_active_plugins( $groupkey, $filter, $option, $plugins ){
713 - $new_plugins = array();
714 - foreach ( $plugins as $item ) {
715 - $unload = false;
716 - $p_key = self::plugin_keygen( $item, $option );
717 - if(!empty($filter['plfurlkey'][$groupkey]['plugins'])){
718 - if(false !== strpos($filter['plfurlkey'][$groupkey]['plugins'], $p_key))
719 - $unload = true;
720 - }
721 - if(!$unload) {
722 - if($option === 'active_sitewide_plugins'){
723 - // v4.0.6 $new_plugins[$item] = $plugins[$item];
724 - $new_plugins[$item] = $item;
725 - } else {
726 - $new_plugins[] = $item;
727 - }
728 - }
729 - }
730 - return $new_plugins;
731 - }
732 -
733 - //Plugin Load Filter Main (active plugins/modules filtering)
734 - static function plf_filter( $option, $default = false) {
735 - // v4.0.6 if ( defined( 'WP_SETUP_CONFIG' ) || did_action( 'muplugins_loaded' ) === 0)
736 - if ( defined( 'WP_SETUP_CONFIG' ) || did_action( 'mu_plugin_loaded' ) === 0)
236 + //Admin mode exclude
237 + if(is_admin())
737 238 return false;
738 239
739 240 if ( ! defined( 'WP_INSTALLING' ) ) {
740 241 global $wpdb, $current_site;
242 + // if ( ! wp_installing() ) { // WP4.4
741 243 if ( is_multisite() && $option === 'active_sitewide_plugins' ) {
742 244 //get_network_option() current site ID
743 245 $network_id = $current_site->id;
744 246
@@ -749,18 +251,18 @@
749 251 return apply_filters( 'default_site_option_' . $option, $default, $option );
750 252 }
751 253
752 254 $cache_key = "$network_id:$option";
753 - $opt_value = wp_cache_get( $cache_key, 'site-options' );
255 + $value = wp_cache_get( $cache_key, 'site-options' );
754 256
755 - if ( ! isset( $opt_value ) || false === $opt_value ) {
257 + if ( ! isset( $value ) || false === $value ) {
756 258 $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $network_id ) );
757 259
758 260 // Has to be get_row instead of get_var because of funkiness with 0, false, null values
759 261 if ( is_object( $row ) ) {
760 - $opt_value = $row->meta_value;
761 - $opt_value = maybe_unserialize( $opt_value );
762 - wp_cache_set( $cache_key, $opt_value, 'site-options' );
262 + $value = $row->meta_value;
263 + $value = maybe_unserialize( $value );
264 + wp_cache_set( $cache_key, $value, 'site-options' );
763 265 } else {
764 266 if ( ! is_array( $notoptions ) ) {
765 267 $notoptions = array();
766 268 }
@@ -767,12 +269,13 @@
767 269 $notoptions[ $option ] = true;
768 270 wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
769 271
770 272 /** This filter is documented in wp-includes/option.php */
771 - $opt_value = apply_filters( 'default_site_option_' . $option, $default, $option );
273 + $value = apply_filters( 'default_site_option_' . $option, $default, $option );
772 274 }
773 275 }
774 - } else {
276 + }
277 + else {
775 278 // prevent non-existent options from triggering multiple queries
776 279 $notoptions = wp_cache_get( 'notoptions', 'options' );
777 280 if ( isset( $notoptions[$option] ) )
778 281 return apply_filters( 'default_option_' . $option, $default );
@@ -778,19 +281,19 @@
778 281 return apply_filters( 'default_option_' . $option, $default );
779 282
780 283 $alloptions = wp_load_alloptions();
781 284 if ( isset( $alloptions[$option] ) ) {
782 - $opt_value = $alloptions[$option];
285 + $value = $alloptions[$option];
783 286 } else {
784 - $opt_value = wp_cache_get( $option, 'options' );
287 + $value = wp_cache_get( $option, 'options' );
785 288
786 - if ( false === $opt_value ) {
289 + if ( false === $value ) {
787 290 $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
788 291
789 292 // Has to be get_row instead of get_var because of funkiness with 0, false, null values
790 293 if ( is_object( $row ) ) {
791 - $opt_value = $row->option_value;
792 - wp_cache_add( $option, $opt_value, 'options' );
294 + $value = $row->option_value;
295 + wp_cache_add( $option, $value, 'options' );
793 296 } else { // option does not exist, so we must cache its non-existence
794 297 if ( ! is_array( $notoptions ) ) {
795 298 $notoptions = array();
796 299 }
@@ -805,31 +308,9 @@
805 308 }
806 309 } else {
807 310 return false;
808 311 }
809 -
810 - $req_url = $_SERVER['REQUEST_URI'];
811 - $req_url = str_replace( "\\", "/", $req_url);
812 - $parse_url = parse_url($req_url);
813 - $action = (strpos($parse_url['path'], 'admin-ajax.php' ) !== false && isset($_REQUEST['action']))? esc_attr($_REQUEST['action']) : '';
814 -
815 - $act_plugins = ($option === 'active_sitewide_plugins')? array_keys( (array)$opt_value ) : maybe_unserialize( $opt_value );
816 - if($option === 'celtispack_active_modules'){
817 - if(empty(self::$base_plugins['celtispack-addon/celtispack-addon.php'])){
818 - $opt = get_option( 'celtis_addon_options' );
819 - if(!empty($opt['active_modules'])){
820 - $nact_plugins = array();
821 - foreach ($act_plugins as $pkey) {
822 - $key = str_replace( '.php', '', basename( $pkey ));
823 - if(!empty($opt['active_modules'][$key]))
824 - continue;
825 - $nact_plugins[] = $pkey;
826 - }
827 - $act_plugins = $nact_plugins;
828 - }
829 - }
830 - }
831 -
312 +
832 313 //Equal treatment for when the wp_is_mobile is not yet available(wp-include/vars.php wp_is_mobile)
833 314 if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
834 315 $is_mobile = false;
835 316 } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.)
@@ -844,159 +325,55 @@
844 325 $is_mobile = false;
845 326 }
846 327 $is_mobile = apply_filters( 'custom_is_mobile' , $is_mobile );
847 328
329 + $filter = $this->filter;
848 330 //get_option is called many times, intermediate processing data to cache
849 - $keyid = md5('plf_'. (string)$is_mobile . $req_url . $action);
850 - if(!empty(self::$cache[$keyid][$option])){
851 - return self::$cache[$keyid][$option];
331 + $keyid = md5('plf_'. (string)$is_mobile . $_SERVER['REQUEST_URI']);
332 + if(!empty($this->cache[$keyid][$option])){
333 + return $this->cache[$keyid][$option];
852 334 }
853 335
854 336 //Before plugins loaded, it does not use conditional branch such as is_home, to set wp_query, wp in temporary query
855 337 if(empty($GLOBALS['wp_the_query'])){
856 - // プラグイン無効化時等で rewrite_rule がクリアされると rewrite_rule が更新されるまでカスタムポストタイプを判定できずにカスタムポストタイプのページはホームへ飛ばされる
857 - // 但し、permlink structure が plain(基本) の場合は除く
858 - if(!empty(get_option( 'permalink_structure' ))){
859 - $rewrite_rules = get_option('rewrite_rules');
860 - // rewrite_rule を監視して変更された場合はプラグインのフィルタリングをスキップさせていたが、
861 - // plugin activate / deactivate を監視するように変更したのでここでは空の場合のみチェック
862 - if(empty($rewrite_rules)){
863 - return false;
864 - }
865 - // Welcart usces_itemnew 新規商品追加時のエラー (A variable mismatch has been detected.) parse_request で発生してるので特別に回避
866 - if ( isset( $_GET[ 'page' ] ) && isset( $_POST[ 'page' ] ) && $_GET[ 'page' ] !== $_POST[ 'page' ] ) {
867 - return false;
868 - }
869 - }
870 -
871 338 $GLOBALS['wp_the_query'] = new WP_Query();
872 339 $GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];
873 340 $GLOBALS['wp_rewrite'] = new WP_Rewrite();
874 341 $GLOBALS['wp'] = new WP();
875 - //register_taxonomy(category, post_tag, post_format) support for is_archive
876 - self::force_initial_taxonomies();
877 342 //Post Format, Custom Post Type support
878 - add_action('parse_request', array('Plf_filter', 'parse_request'));
343 + add_action('parse_request', array(&$this, 'parse_request'));
879 344 $GLOBALS['wp']->parse_request('');
880 - $GLOBALS['wp']->query_posts();
345 + $GLOBALS['wp']->query_posts();
881 346 }
882 -
883 - //active plugin data
884 - foreach ($act_plugins as $key) {
885 - $key = self::plugin_keygen( $key, $option );
886 - self::$base_plugins[$key] = $key;
887 - }
888 -
889 - $filter = self::$filter;
890 -
891 - //plf Addon Extract only target data
892 - $devtype = ($is_mobile)? 'mobile' : 'desktop';
893 - $urltype = (strpos($parse_url['path'], '/wp-admin' ) !== false)? 'admin' : 'front';
894 - if(!empty(self::$url_filter) && empty(self::$s_url_filter)){
895 - self::$s_url_filter = self::get_url_filter( 'active', $urltype, $devtype );
347 + //Only available display pages (login, cron, ajax request ... excluded)
348 + //downloadmanager plugin downloadlink request [home]/?wpdmact=XXXXXX exclude home GET query
349 + global $wp_query;
350 + if(!(function_exists('is_embed') && is_embed())){
351 + if((is_home() || is_front_page() || is_archive() || is_search() || is_singular()) == false
352 + || (is_home() && !empty($_GET))
353 + || (is_singular() && empty($wp_query->post))){
354 + return false;
355 + }
896 356 }
897 357
898 -
899 - //======== The following are Admin backend page processes ========
900 -
901 - if($urltype === 'admin'){
902 - if(!empty(self::$s_url_filter)){
903 - //plf Addon Admin Backend URL filtering
904 - foreach (self::$s_url_filter as $key => $v) {
905 - $groupkey = self::is_url_match( $req_url, $parse_url, $v );
906 - if($groupkey !== false) {
907 - self::$is_filterkey = 'url-group-filter : ' . $groupkey;
908 - $new_plugins = self::filter_to_active_plugins( $groupkey, $filter, $option, $act_plugins );
909 - self::$cache[$keyid][$option] = $new_plugins;
910 - foreach ($new_plugins as $key) {
911 - $key = self::plugin_keygen( $key, $option );
912 - self::$filtered_plugins[$key] = $key;
913 - }
914 - return $new_plugins;
915 - }
916 - }
358 + $us_value = ($option === 'active_sitewide_plugins')? array_keys( (array)$value ) : maybe_unserialize( $value );
359 + $new_value = array();
360 + foreach ( $us_value as $item ) {
361 + $unload = false;
362 + //Jetpack module slug / Celtiapack module slug / Plugin php file name
363 + if($option === 'jetpack_active_modules'){
364 + $p_key = 'jetpack_module/' . $item;
917 365 }
918 - return false;
919 - }
920 -
921 -
922 - //======== The following are frontend page processes ========
923 -
924 - global $wp_query;
925 - $unknown = false;
926 - if( ! is_embed() ){
927 - if((is_home() || is_front_page() || is_archive() || is_search() || is_singular()) == false || (is_home() && !empty($_GET))) {
928 - //bbPress users page requests are treated the same as is_home
929 - //downloadmanager plugin downloadlink request [home]/?wpdmact=XXXXXX exclude home GET query
930 - $unknown = true;
931 -
932 - } elseif(is_singular() && empty($wp_query->post)){
933 - //documentroot special php file (wp-login.php, wp-cron.php, etc) これらはこの時点では singular とみなされるが post が設定されていないことで判別
934 - //フィルタリングしたい場合は urlfilter Addon を使用すること
935 - //但し、private (非公開)ページ時は post がこの時点ではまだ設定されていないので private でクエリー発行して再確認
936 - if(!empty($wp_query->query)) {
937 - //get post for private
938 - $query = $wp_query->query;
939 - $query['post_status'] = 'private';
940 - $r = new WP_Query( $query );
941 - if ($r->have_posts()) {
942 - if(!empty($r->post)){
943 - $wp_query->posts = $r->posts;
944 - $wp_query->post = $r->post;
945 - }
946 - }
947 - }
948 - if(empty($wp_query->post)){
949 - $unknown = true;
950 - }
366 + elseif($option === 'celtispack_active_modules'){
367 + $p_key = 'celtispack_module/' . str_replace( '.php', '', basename( $item) );
951 368 }
952 - }
953 -
954 - $single_opt = false;
955 - if(is_singular() && is_object($wp_query->post)){
956 - $myfilter = get_post_meta( $wp_query->post->ID, '_plugin_load_filter', true );
957 - $default = array( 'filter' => 'default', 'desktop' => '', 'mobile' => '');
958 - $single_opt = (!empty($myfilter))? $myfilter : $default;
959 - $single_opt = wp_parse_args( $single_opt, $default);
960 - }
961 - if(!empty(self::$s_url_filter)){
962 - //Addon frontend URL filtering
963 - //個別フィルター有効なシングラーは URL filtering 無効(個別フィルター優先)
964 - if(empty($single_opt) || $single_opt['filter'] === 'default'){
965 - foreach (self::$s_url_filter as $key => $v) {
966 - $groupkey = self::is_url_match( $req_url, $parse_url, $v );
967 - if($groupkey !== false) {
968 - self::$is_filterkey = 'url-group-filter : ' . $groupkey;
969 - $new_plugins = self::filter_to_active_plugins( $groupkey, $filter, $option, $act_plugins );
970 - self::$cache[$keyid][$option] = $new_plugins;
971 - foreach ($new_plugins as $key) {
972 - $key = self::plugin_keygen( $key, $option );
973 - self::$filtered_plugins[$key] = $key;
974 - }
975 - return $new_plugins;
976 - }
977 - }
369 + else {
370 + $p_key = $item;
978 371 }
979 - }
980 - if($unknown || strpos($parse_url['path'], '/wp-cron' ) !== false || strpos($parse_url['path'], '/wp-json' ) !== false || (!empty($parse_url['query']) && strpos($parse_url['query'], 'rest_route=' ) !== false )){
981 - //url filter 処理後、REST api, cron, フィルター対象外の不明なリクエストはフィルタリング処理を行わない
982 - return false;
983 - }
984 -
985 - //plf standard filtering
986 - $new_plugins = array();
987 - foreach ( $act_plugins as $item ) {
988 - $unload = false;
989 - $p_key = self::plugin_keygen( $item, $option );
990 372 //admin mode filter
991 373 if(!empty($filter['_admin']['plugins'])){
992 - if(in_array($p_key, array_map("trim", explode(',', $filter['_admin']['plugins'])))){
374 + if(in_array($p_key, array_map("trim", explode(',', $filter['_admin']['plugins']))))
993 375 $unload = true;
994 - if(self::$is_filterkey === false){
995 - //Page Type admin filter のみ適用の場合用
996 - self::$is_filterkey = 'page-type-filter : admin filter';
997 - }
998 - }
999 376 }
1000 377 //page filter
1001 378 if(!$unload){
1002 379 if(!empty($filter['_pagefilter']['plugins'])){
@@ -1001,19 +378,30 @@
1001 378 if(!$unload){
1002 379 if(!empty($filter['_pagefilter']['plugins'])){
1003 380 if(in_array($p_key, array_map("trim", explode(',', $filter['_pagefilter']['plugins'])))){
1004 381 $unload = true;
1005 - $type = false;
1006 382
1007 383 //desktop/mobile device disable filter
384 + $single_opt = false;
1008 385 $dis_dev = true;
386 + $devtype = ($is_mobile)? 'mobile' : 'desktop';
1009 387 if(is_singular() && is_object($wp_query->post)){
388 + $myfilter = get_post_meta( $wp_query->post->ID, '_plugin_load_filter', true );
389 + //For ver2.2.0 compatibility, set 'plugins' data to 'desktop' and 'mobile'
390 + if(!empty($myfilter['plugins'])){
391 + $myfilter['desktop'] = $myfilter['plugins'];
392 + $myfilter['mobile'] = $myfilter['plugins'];
393 + unset($myfilter['plugins']);
394 + }
395 + $default = array( 'filter' => 'default', 'desktop' => '', 'mobile' => '');
396 + $single_opt = (!empty($myfilter))? $myfilter : $default;
397 + $single_opt = wp_parse_args( $single_opt, $default);
1010 398 if($single_opt['filter'] === 'include'){
1011 399 if(false !== strpos($single_opt[$devtype], $p_key))
1012 400 $dis_dev = false;
1013 - elseif(strpos($p_key, 'jetpack/') !== false && strpos($single_opt[$devtype], 'jetpack_module/') !== false)
401 + else if(strpos($p_key, 'jetpack/') !== false && strpos($single_opt[$devtype], 'jetpack_module/') !== false)
1014 402 $dis_dev = false;
1015 - elseif(strpos($p_key, 'celtispack/') !== false && strpos($single_opt[$devtype], 'celtispack_module/') !== false)
403 + else if(strpos($p_key, 'celtispack/') !== false && strpos($single_opt[$devtype], 'celtispack_module/') !== false)
1016 404 $dis_dev = false;
1017 405 }
1018 406 }
1019 407 if(empty($single_opt) || $single_opt['filter'] === 'default'){
@@ -1019,44 +407,47 @@
1019 407 if(empty($single_opt) || $single_opt['filter'] === 'default'){
1020 408 if(!empty($filter['group'][$devtype]['plugins'])){
1021 409 if(false !== strpos($filter['group'][$devtype]['plugins'], $p_key))
1022 410 $dis_dev = false;
1023 - elseif(strpos($p_key, 'jetpack/') !== false && strpos($filter['group'][$devtype]['plugins'], 'jetpack_module/') !== false)
411 + else if(strpos($p_key, 'jetpack/') !== false && strpos($filter['group'][$type]['plugins'], 'jetpack_module/') !== false)
1024 412 $dis_dev = false;
1025 - elseif(strpos($p_key, 'celtispack/') !== false && strpos($filter['group'][$devtype]['plugins'], 'celtispack_module/') !== false)
413 + else if(strpos($p_key, 'celtispack/') !== false && strpos($filter['group'][$type]['plugins'], 'celtispack_module/') !== false)
1026 414 $dis_dev = false;
1027 415 }
1028 416 }
1029 417 if(!$dis_dev){
1030 418 //oEmbed Content API
1031 - if(is_embed()){
419 + if(function_exists('is_embed') && is_embed()){
1032 420 $type = 'content-card';
1033 421 if(!empty($filter['group'][$type]['plugins'])){
1034 422 if(false !== strpos($filter['group'][$type]['plugins'], $p_key))
1035 423 $unload = false;
1036 - elseif(strpos($p_key, 'jetpack/') !== false && strpos($filter['group'][$type]['plugins'], 'jetpack_module/') !== false)
424 + else if(strpos($p_key, 'jetpack/') !== false && strpos($filter['group'][$type]['plugins'], 'jetpack_module/') !== false)
1037 425 $unload = false;
1038 - elseif(strpos($p_key, 'celtispack/') !== false && strpos($filter['group'][$type]['plugins'], 'celtispack_module/') !== false)
426 + else if(strpos($p_key, 'celtispack/') !== false && strpos($filter['group'][$type]['plugins'], 'celtispack_module/') !== false)
1039 427 $unload = false;
1040 428 }
1041 - } else {
429 + }
430 + else {
1042 431 $pgfopt = false;
1043 432 if(is_singular()){
1044 433 if(!empty($single_opt) && $single_opt['filter'] === 'include'){
1045 - $type = 'Single page option';
1046 434 $pgfopt = true;
1047 435 if(false !== strpos($single_opt[$devtype], $p_key)){
1048 436 $unload = false;
1049 - } else {
437 + }
438 + else {
1050 439 //Enable plugin because plugin module is selected
1051 440 if(strpos($p_key, 'jetpack/') !== false && strpos($single_opt[$devtype], 'jetpack_module/') !== false)
1052 441 $unload = false;
1053 - elseif(strpos($p_key, 'celtispack/') !== false && strpos($single_opt[$devtype], 'celtispack_module/') !== false)
442 + else if(strpos($p_key, 'celtispack/') !== false && strpos($single_opt[$devtype], 'celtispack_module/') !== false)
1054 443 $unload = false;
444 +
1055 445 }
1056 446 }
1057 447 }
1058 448 if($pgfopt === false){
449 + $type = false;
1059 450 if(is_home() || is_front_page())
1060 451 $type = 'home';
1061 452 elseif(is_archive())
1062 453 $type = 'archive';
@@ -1067,23 +458,17 @@
1067 458 elseif(is_page())
1068 459 $type = 'page';
1069 460 elseif(is_single()){ //Post & Custom Post
1070 461 $type = get_post_type( $wp_query->post);
1071 - //bbPress private (非公開)ページ時のポストタイプ取得
1072 - if($type === false && isset($wp_query->query_vars['post_type'])){
1073 - $type = $wp_query->query_vars['post_type'];
1074 - }
1075 462 if($type === 'post'){
1076 463 $fmt = get_post_format( $wp_query->post);
1077 464 $type = ($fmt === 'standard' || $fmt == false)? 'post' : "post-$fmt";
1078 465 }
1079 - } else {
1080 - $type = 'unknown';
1081 466 }
1082 - if(!empty($type) && !empty($filter['group'][$type]['plugins'])){
1083 - if(in_array($p_key, array_map("trim", explode(',', $filter['group'][$type]['plugins'])))){
467 + if($type !== false && !empty($filter['group'][$type]['plugins'])){
468 + if(in_array($p_key, array_map("trim", explode(',', $filter['group'][$type]['plugins']))))
1084 469 $unload = false;
1085 - } else {
470 + else {
1086 471 if(strpos($p_key, 'jetpack/') !== false && strpos($filter['group'][$type]['plugins'], 'jetpack_module/') !== false)
1087 472 $unload = false;
1088 473 else if(strpos($p_key, 'celtispack/') !== false && strpos($filter['group'][$type]['plugins'], 'celtispack_module/') !== false)
1089 474 $unload = false;
@@ -1091,27 +476,18 @@
1091 476 }
1092 477 }
1093 478 }
1094 479 }
1095 - if($type !== false){
1096 - self::$is_filterkey = 'page-type-filter : ' . $type;
1097 - }
1098 480 }
1099 481 }
1100 482 }
1101 483 if(!$unload) {
1102 - if($option === 'active_sitewide_plugins') {
1103 - // v4.0.6 $new_plugins[$item] = $opt_value[$item];
1104 - $new_plugins[$item] = $item;
1105 - } else {
1106 - $new_plugins[] = $item;
1107 - }
484 + if($option === 'active_sitewide_plugins')
485 + $new_value[$item] = $value[$item];
486 + else
487 + $new_value[] = $item;
1108 488 }
1109 - }
1110 - self::$cache[$keyid][$option] = $new_plugins;
1111 - foreach ($new_plugins as $key) {
1112 - $key = self::plugin_keygen( $key, $option );
1113 - self::$filtered_plugins[$key] = $key;
1114 489 }
1115 - return $new_plugins;
490 + $this->cache[$keyid][$option] = $new_value;
491 + return $new_value;
1116 492 }
1117 493 }