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 | mu-plugins/plf-filter.php +140 -844 4.0.62.3.1 View file →
@@ -1,15 +1,14 @@
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.3.1
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 */
11 -defined( 'ABSPATH' ) || exit;
12 11
13 12 /***************************************************************************
14 13 * pluggable.php defined function overwrite
15 14 * pluggable.php read before the query_posts () is processed by the current user undetermined
@@ -19,11 +18,17 @@
19 18 * Retrieve the current user object.
20 19 * @return WP_User Current user WP_User object
21 20 */
22 21 function wp_get_current_user() {
23 - if ( ! function_exists( 'wp_set_current_user' ) ){
22 + if ( ! function_exists( 'wp_set_current_user' ) )
24 23 return 0;
25 - } else {
24 + //get_currentuserinfo is deprecated since version 4.5
25 + if ( version_compare( $GLOBALS['wp_version'], '4.5', '<' ) ){
26 + global $current_user;
27 + get_currentuserinfo();
28 + return $current_user;
29 + }
30 + else {
26 31 return _wp_get_current_user();
27 32 }
28 33 }
29 34 endif;
@@ -77,362 +82,89 @@
77 82 }
78 83 endif;
79 84
80 85 /***************************************************************************
81 - * Plugin Load Filter
86 + * Plugin Load Filter( Admin, Desktop, Mobile, Page 4types filter)
82 87 **************************************************************************/
83 88
84 -if(in_array( 'plugin-load-filter/plugin-load-filter.php', (array) get_option( 'active_plugins', array() ) )){
85 - $plugin_load_filter = new Plf_filter();
86 -} elseif ( is_multisite() ) {
87 - $plugins = get_site_option( 'active_sitewide_plugins');
88 - if ( isset($plugins['plugin-load-filter/plugin-load-filter.php']) ){
89 - $plugin_load_filter = new Plf_filter();
90 - }
91 -}
89 +$plugin_load_filter = new Plf_filter();
92 90
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;
91 +class Plf_filter {
92 +
93 + private $filter = array(); //Plugin Load Filter Setting option data
94 + private $cache;
103 95
104 96 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();
119 - }
120 - if ( is_multisite() ) {
121 - $network_plugins = (array) get_site_option( 'active_sitewide_plugins', array() );
122 - $plugins = array_merge( $plugins, array_keys( $network_plugins ) );
123 - }
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'));
143 - 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 - }
154 - }
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();
97 + $this->filter = get_option('plf_option');
98 + //v2.3.0 option change
99 + if(empty($this->filter['optver']) || $this->filter['optver'] < '2'){
100 + //For ver2.2.0 compatibility, set '_pagefilter' data to 'desktop' and 'mobile'
101 + if(empty($this->filter['group']['desktop']) && empty($this->filter['group']['mobile'])){
102 + if(!empty($this->filter['_pagefilter'])){
103 + $this->filter['group']['desktop'] = $this->filter['_pagefilter'];
104 + $this->filter['group']['mobile'] = $this->filter['_pagefilter'];
217 105 }
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 106 }
229 107 }
230 - }
231 108
232 - //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);
109 + $this->cache = null;
110 + if(!empty($this->filter)){
111 + add_filter('pre_option_active_plugins', array(&$this, 'active_plugins'));
112 + add_filter('pre_option_jetpack_active_modules', array(&$this, 'active_jetmodules'));
113 + add_filter('pre_option_celtispack_active_modules', array(&$this, 'active_celtismodules'));
114 + add_action('wp_loaded', array(&$this, 'cache_post_type'), 1);
115 + }
235 116 }
236 -
237 - //active plugins Filter
238 - static function active_plugins( $default = false) {
239 - return self::plf_filter( 'active_plugins', $default);
117 +
118 + //Active plugins Filter
119 + function active_plugins( $default = false) {
120 + return $this->plf_filter( 'active_plugins', $default);
240 121 }
241 122
242 123 //Jetpack module Filter
243 - static function active_jetmodules( $default = false) {
244 - return self::plf_filter( 'jetpack_active_modules', $default);
124 + function active_jetmodules( $default = false) {
125 + return $this->plf_filter( 'jetpack_active_modules', $default);
245 126 }
246 127
247 128 //Celtispack module Filter
248 - static function active_celtismodules( $default = false) {
249 - return self::plf_filter( 'celtispack_active_modules', $default);
129 + function active_celtismodules( $default = false) {
130 + return $this->plf_filter( 'celtispack_active_modules', $default);
250 131 }
251 132
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 133 //Post Format Type, Custom Post Type Data Cache for parse request
321 134 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 - );
135 + if (!is_admin() || ( defined('DOING_AJAX') && DOING_AJAX ) || (defined('DOING_CRON') && DOING_CRON))
136 + return;
137 +
138 + global $wp;
139 + $public_query_vars = (!empty($wp->public_query_vars))? $wp->public_query_vars : array();;
140 + $post_type_query_vars = array();
141 + foreach ( get_post_types( array(), 'objects' ) as $post_type => $t ){
142 + if ( $t->query_var )
143 + $post_type_query_vars[$t->query_var] = $post_type;
144 + }
145 + $queryable_post_types = get_post_types( array('publicly_queryable' => true) );
146 +
333 147 $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 -
148 + if(!empty($post_type_query_vars) && !empty($queryable_post_types)){
350 149 $data['public_query_vars'] = $public_query_vars;
351 150 $data['post_type_query_vars'] = $post_type_query_vars;
352 151 $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 152 update_option('plf_queryvars', $data);
358 153 }
154 + else if(!empty($data['post_type_query_vars']) || !empty($data['queryable_post_types'])){
155 + delete_option('plf_queryvars');
156 + }
359 157 }
360 158
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) {
159 + //parse_request Action Hook for Custom Post Type query add
160 + function parse_request( &$args ) {
161 + if (did_action( 'plugins_loaded' ) === 0 ) {
422 162 $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'];
163 + if(!empty($data['post_type_query_vars']) && !empty($data['queryable_post_types'])){
431 164 $post_type_query_vars = $data['post_type_query_vars'];
432 165 $queryable_post_types = $data['queryable_post_types'];
433 166
434 - //query_vars に query_posts() で実行するSQL用のポストタイプデータをセット
435 167 $args->public_query_vars = $data['public_query_vars'];
436 168 if ( isset( $args->matched_query ) ) {
437 169 parse_str($args->matched_query, $perma_query_vars);
438 170 }
@@ -470,533 +202,101 @@
470 202 unset( $args->query_vars['post_type'] );
471 203 } else {
472 204 $args->query_vars['post_type'] = array_intersect( $args->query_vars['post_type'], $queryable_post_types );
473 205 }
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 206 }
516 207 }
517 - //group 毎に slug をソート A-Za-z 順となる
518 - ksort($frontlist, SORT_STRING);
519 - ksort($adminlist, SORT_STRING);
520 208 }
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 209 }
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 210
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 -
577 - // url path, query parameter match check
578 - static function is_url_match( $req_url, $parse_url, $filter ) {
579 - if(empty($parse_url['path']))
211 + //Plugin Load Filter Main (active plugins/modules filtering)
212 + function plf_filter( $option, $default = false) {
213 + if ( defined( 'WP_SETUP_CONFIG' ) )
580 214 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 215
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)
216 + //Admin mode exclude
217 + if(is_admin())
737 218 return false;
738 219
739 220 if ( ! defined( 'WP_INSTALLING' ) ) {
740 - global $wpdb, $current_site;
741 - if ( is_multisite() && $option === 'active_sitewide_plugins' ) {
742 - //get_network_option() current site ID
743 - $network_id = $current_site->id;
221 + // prevent non-existent options from triggering multiple queries
222 + $notoptions = wp_cache_get( 'notoptions', 'options' );
223 + if ( isset( $notoptions[$option] ) )
224 + return apply_filters( 'default_option_' . $option, $default );
744 225
745 - // prevent non-existent options from triggering multiple queries
746 - $notoptions_key = "$network_id:notoptions";
747 - $notoptions = wp_cache_get( $notoptions_key, 'site-options' );
748 - if ( isset( $notoptions[ $option ] ) ) {
749 - return apply_filters( 'default_site_option_' . $option, $default, $option );
750 - }
226 + $alloptions = wp_load_alloptions();
227 + if ( isset( $alloptions[$option] ) ) {
228 + $value = $alloptions[$option];
229 + } else {
230 + $value = wp_cache_get( $option, 'options' );
751 231
752 - $cache_key = "$network_id:$option";
753 - $opt_value = wp_cache_get( $cache_key, 'site-options' );
232 + if ( false === $value ) {
233 + $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
754 234
755 - if ( ! isset( $opt_value ) || false === $opt_value ) {
756 - $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $network_id ) );
757 -
758 235 // Has to be get_row instead of get_var because of funkiness with 0, false, null values
759 236 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' );
763 - } else {
764 - if ( ! is_array( $notoptions ) ) {
765 - $notoptions = array();
766 - }
767 - $notoptions[ $option ] = true;
768 - wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
237 + $value = $row->option_value;
238 + wp_cache_add( $option, $value, 'options' );
239 + } else { // option does not exist, so we must cache its non-existence
240 + $notoptions[$option] = true;
241 + wp_cache_set( 'notoptions', $notoptions, 'options' );
769 242
770 243 /** This filter is documented in wp-includes/option.php */
771 - $opt_value = apply_filters( 'default_site_option_' . $option, $default, $option );
244 + return apply_filters( 'default_option_' . $option, $default );
772 245 }
773 246 }
774 - } else {
775 - // prevent non-existent options from triggering multiple queries
776 - $notoptions = wp_cache_get( 'notoptions', 'options' );
777 - if ( isset( $notoptions[$option] ) )
778 - return apply_filters( 'default_option_' . $option, $default );
779 -
780 - $alloptions = wp_load_alloptions();
781 - if ( isset( $alloptions[$option] ) ) {
782 - $opt_value = $alloptions[$option];
783 - } else {
784 - $opt_value = wp_cache_get( $option, 'options' );
785 -
786 - if ( false === $opt_value ) {
787 - $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
788 -
789 - // Has to be get_row instead of get_var because of funkiness with 0, false, null values
790 - if ( is_object( $row ) ) {
791 - $opt_value = $row->option_value;
792 - wp_cache_add( $option, $opt_value, 'options' );
793 - } else { // option does not exist, so we must cache its non-existence
794 - if ( ! is_array( $notoptions ) ) {
795 - $notoptions = array();
796 - }
797 - $notoptions[$option] = true;
798 - wp_cache_set( 'notoptions', $notoptions, 'options' );
799 -
800 - /** This filter is documented in wp-includes/option.php */
801 - return apply_filters( 'default_option_' . $option, $default, $option );
802 - }
803 - }
804 - }
805 247 }
806 248 } else {
807 249 return false;
808 250 }
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 -
832 - //Equal treatment for when the wp_is_mobile is not yet available(wp-include/vars.php wp_is_mobile)
833 - if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
834 - $is_mobile = false;
835 - } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.)
836 - || strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false
837 - || strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false
838 - || strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false
839 - || strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false
840 - || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false
841 - || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false ) {
842 - $is_mobile = true;
843 - } else {
844 - $is_mobile = false;
845 - }
846 - $is_mobile = apply_filters( 'custom_is_mobile' , $is_mobile );
847 251
252 + $filter = $this->filter;
848 253 //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];
254 + $keyid = md5('plf_'. (string)wp_is_mobile(). $_SERVER['REQUEST_URI']);
255 + if(!empty($this->cache[$keyid][$option])){
256 + return apply_filters( 'option_' . $option, $this->cache[$keyid][$option]);
852 257 }
853 258
854 259 //Before plugins loaded, it does not use conditional branch such as is_home, to set wp_query, wp in temporary query
855 260 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 261 $GLOBALS['wp_the_query'] = new WP_Query();
872 262 $GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];
873 263 $GLOBALS['wp_rewrite'] = new WP_Rewrite();
874 264 $GLOBALS['wp'] = new WP();
875 - //register_taxonomy(category, post_tag, post_format) support for is_archive
876 - self::force_initial_taxonomies();
877 265 //Post Format, Custom Post Type support
878 - add_action('parse_request', array('Plf_filter', 'parse_request'));
266 + add_action('parse_request', array(&$this, 'parse_request'));
879 267 $GLOBALS['wp']->parse_request('');
880 - $GLOBALS['wp']->query_posts();
268 + $GLOBALS['wp']->query_posts();
881 269 }
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 );
270 + //Only available display pages (login, cron, ajax request ... excluded)
271 + //downloadmanager plugin downloadlink request [home]/?wpdmact=XXXXXX exclude home GET query
272 + global $wp_query;
273 + if(!(function_exists('is_embed') && is_embed())){
274 + if((is_home() || is_front_page() || is_archive() || is_search() || is_singular()) == false
275 + || (is_home() && !empty($_GET))
276 + || (is_singular() && empty($wp_query->post))){
277 + return false;
278 + }
896 279 }
897 280
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 - }
281 + $us_value = maybe_unserialize( $value );
282 + $new_value = array();
283 + foreach ( $us_value as $item ) {
284 + $unload = false;
285 + //Jetpack module slug / Celtiapack module slug / Plugin php file name
286 + if($option === 'jetpack_active_modules'){
287 + $p_key = 'jetpack_module/' . $item;
917 288 }
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 - }
289 + elseif($option === 'celtispack_active_modules'){
290 + $p_key = 'celtispack_module/' . str_replace( '.php', '', basename( $item) );
951 291 }
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 - }
292 + else {
293 + $p_key = $item;
978 294 }
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 295 //admin mode filter
991 296 if(!empty($filter['_admin']['plugins'])){
992 - if(in_array($p_key, array_map("trim", explode(',', $filter['_admin']['plugins'])))){
297 + if(in_array($p_key, array_map("trim", explode(',', $filter['_admin']['plugins']))))
993 298 $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 299 }
1000 300 //page filter
1001 301 if(!$unload){
1002 302 if(!empty($filter['_pagefilter']['plugins'])){
@@ -1001,19 +301,30 @@
1001 301 if(!$unload){
1002 302 if(!empty($filter['_pagefilter']['plugins'])){
1003 303 if(in_array($p_key, array_map("trim", explode(',', $filter['_pagefilter']['plugins'])))){
1004 304 $unload = true;
1005 - $type = false;
1006 305
1007 306 //desktop/mobile device disable filter
307 + $single_opt = false;
1008 308 $dis_dev = true;
309 + $devtype = (wp_is_mobile())? 'mobile' : 'desktop';
1009 310 if(is_singular() && is_object($wp_query->post)){
311 + $myfilter = get_post_meta( $wp_query->post->ID, '_plugin_load_filter', true );
312 + //For ver2.2.0 compatibility, set 'plugins' data to 'desktop' and 'mobile'
313 + if(!empty($myfilter['plugins'])){
314 + $myfilter['desktop'] = $myfilter['plugins'];
315 + $myfilter['mobile'] = $myfilter['plugins'];
316 + unset($myfilter['plugins']);
317 + }
318 + $default = array( 'filter' => 'default', 'desktop' => '', 'mobile' => '');
319 + $single_opt = (!empty($myfilter))? $myfilter : $default;
320 + $single_opt = wp_parse_args( $single_opt, $default);
1010 321 if($single_opt['filter'] === 'include'){
1011 322 if(false !== strpos($single_opt[$devtype], $p_key))
1012 323 $dis_dev = false;
1013 - elseif(strpos($p_key, 'jetpack/') !== false && strpos($single_opt[$devtype], 'jetpack_module/') !== false)
324 + else if(strpos($p_key, 'jetpack/') !== false && strpos($single_opt[$devtype], 'jetpack_module/') !== false)
1014 325 $dis_dev = false;
1015 - elseif(strpos($p_key, 'celtispack/') !== false && strpos($single_opt[$devtype], 'celtispack_module/') !== false)
326 + else if(strpos($p_key, 'celtispack/') !== false && strpos($single_opt[$devtype], 'celtispack_module/') !== false)
1016 327 $dis_dev = false;
1017 328 }
1018 329 }
1019 330 if(empty($single_opt) || $single_opt['filter'] === 'default'){
@@ -1019,44 +330,47 @@
1019 330 if(empty($single_opt) || $single_opt['filter'] === 'default'){
1020 331 if(!empty($filter['group'][$devtype]['plugins'])){
1021 332 if(false !== strpos($filter['group'][$devtype]['plugins'], $p_key))
1022 333 $dis_dev = false;
1023 - elseif(strpos($p_key, 'jetpack/') !== false && strpos($filter['group'][$devtype]['plugins'], 'jetpack_module/') !== false)
334 + else if(strpos($p_key, 'jetpack/') !== false && strpos($filter['group'][$type]['plugins'], 'jetpack_module/') !== false)
1024 335 $dis_dev = false;
1025 - elseif(strpos($p_key, 'celtispack/') !== false && strpos($filter['group'][$devtype]['plugins'], 'celtispack_module/') !== false)
336 + else if(strpos($p_key, 'celtispack/') !== false && strpos($filter['group'][$type]['plugins'], 'celtispack_module/') !== false)
1026 337 $dis_dev = false;
1027 338 }
1028 339 }
1029 340 if(!$dis_dev){
1030 341 //oEmbed Content API
1031 - if(is_embed()){
342 + if(function_exists('is_embed') && is_embed()){
1032 343 $type = 'content-card';
1033 344 if(!empty($filter['group'][$type]['plugins'])){
1034 345 if(false !== strpos($filter['group'][$type]['plugins'], $p_key))
1035 346 $unload = false;
1036 - elseif(strpos($p_key, 'jetpack/') !== false && strpos($filter['group'][$type]['plugins'], 'jetpack_module/') !== false)
347 + else if(strpos($p_key, 'jetpack/') !== false && strpos($filter['group'][$type]['plugins'], 'jetpack_module/') !== false)
1037 348 $unload = false;
1038 - elseif(strpos($p_key, 'celtispack/') !== false && strpos($filter['group'][$type]['plugins'], 'celtispack_module/') !== false)
349 + else if(strpos($p_key, 'celtispack/') !== false && strpos($filter['group'][$type]['plugins'], 'celtispack_module/') !== false)
1039 350 $unload = false;
1040 351 }
1041 - } else {
352 + }
353 + else {
1042 354 $pgfopt = false;
1043 355 if(is_singular()){
1044 356 if(!empty($single_opt) && $single_opt['filter'] === 'include'){
1045 - $type = 'Single page option';
1046 357 $pgfopt = true;
1047 358 if(false !== strpos($single_opt[$devtype], $p_key)){
1048 359 $unload = false;
1049 - } else {
360 + }
361 + else {
1050 362 //Enable plugin because plugin module is selected
1051 363 if(strpos($p_key, 'jetpack/') !== false && strpos($single_opt[$devtype], 'jetpack_module/') !== false)
1052 364 $unload = false;
1053 - elseif(strpos($p_key, 'celtispack/') !== false && strpos($single_opt[$devtype], 'celtispack_module/') !== false)
365 + else if(strpos($p_key, 'celtispack/') !== false && strpos($single_opt[$devtype], 'celtispack_module/') !== false)
1054 366 $unload = false;
367 +
1055 368 }
1056 369 }
1057 370 }
1058 371 if($pgfopt === false){
372 + $type = false;
1059 373 if(is_home() || is_front_page())
1060 374 $type = 'home';
1061 375 elseif(is_archive())
1062 376 $type = 'archive';
@@ -1067,23 +381,17 @@
1067 381 elseif(is_page())
1068 382 $type = 'page';
1069 383 elseif(is_single()){ //Post & Custom Post
1070 384 $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 385 if($type === 'post'){
1076 386 $fmt = get_post_format( $wp_query->post);
1077 387 $type = ($fmt === 'standard' || $fmt == false)? 'post' : "post-$fmt";
1078 388 }
1079 - } else {
1080 - $type = 'unknown';
1081 389 }
1082 - if(!empty($type) && !empty($filter['group'][$type]['plugins'])){
1083 - if(in_array($p_key, array_map("trim", explode(',', $filter['group'][$type]['plugins'])))){
390 + if($type !== false && !empty($filter['group'][$type]['plugins'])){
391 + if(in_array($p_key, array_map("trim", explode(',', $filter['group'][$type]['plugins']))))
1084 392 $unload = false;
1085 - } else {
393 + else {
1086 394 if(strpos($p_key, 'jetpack/') !== false && strpos($filter['group'][$type]['plugins'], 'jetpack_module/') !== false)
1087 395 $unload = false;
1088 396 else if(strpos($p_key, 'celtispack/') !== false && strpos($filter['group'][$type]['plugins'], 'celtispack_module/') !== false)
1089 397 $unload = false;
@@ -1091,27 +399,15 @@
1091 399 }
1092 400 }
1093 401 }
1094 402 }
1095 - if($type !== false){
1096 - self::$is_filterkey = 'page-type-filter : ' . $type;
1097 - }
1098 403 }
1099 404 }
1100 405 }
1101 406 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 - }
407 + $new_value[] = $item;
1108 408 }
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 409 }
1115 - return $new_plugins;
410 + $this->cache[$keyid][$option] = $new_value;
411 + return apply_filters( 'option_' . $option, $new_value );
1116 412 }
1117 413 }