PluginProbe
Plugin Load Filter / 4.1.1
Plugin Load Filter v4.1.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
plugin-load-filter / mu-plugins / plf-filter.php

plf-filter.php in Plugin Load Filter 4.1.1, at mu-plugins/plf-filter.php

1,385 lines 67.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: plugin load filter [plf-filter]
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.1.1
6 Plugin URI: http://celtislab.net/en/wp-plugin-load-filter
7 Author: enomoto@celtislab
8 Author URI: http://celtislab.net/
9 License: GPLv2
10 */
11 defined( 'ABSPATH' ) || exit;
12
13 /***************************************************************************
14 * pluggable.php defined function overwrite
15 * pluggable.php read before the query_posts () is processed by the current user undetermined
16 **************************************************************************/
17 /**
18 * Gets hash of given string.
19 *
20 * @param string $data Plain text to hash.
21 * @return string Hash of $data.
22 */
23 //wp_salt( $scheme ) を簡略化して logged_in cookie 限定
24 function plf_logged_in_hash( $data ) {
25 $values = array(
26 'key' => '',
27 'salt' => '',
28 );
29 foreach ( array( 'key', 'salt' ) as $type ) {
30 $const = strtoupper( "logged_in_{$type}" );
31 if ( defined( $const ) && constant( $const ) ) {
32 $values[ $type ] = constant( $const );
33 }
34 }
35 $salt = $values['key'] . $values['salt'];
36 return hash_hmac( 'md5', $data, $salt );
37 }
38
39 if ( !function_exists('wp_get_current_user') ) :
40 /**
41 * Retrieve the current user object.
42 * @return WP_User Current user WP_User object
43 */
44 function wp_get_current_user() {
45 if ( ! function_exists( 'wp_set_current_user' ) ){
46 if ( defined( 'LOGGED_IN_COOKIE' ) && !empty( $_COOKIE[ LOGGED_IN_COOKIE ] ) ) {
47 $cookie_elements = explode( '|', $_COOKIE[ LOGGED_IN_COOKIE ] );
48 if ( count( $cookie_elements ) === 4 ) {
49 list( $username, $expiration, $token, $hmac ) = $cookie_elements;
50 if ( $expiration > time() ) {
51 $user = get_user_by( 'login', $username );
52 if ( $user ) {
53 $pass_frag = substr( $user->user_pass, 8, 4 );
54
55 $key = plf_logged_in_hash( $username . '|' . $pass_frag . '|' . $expiration . '|' . $token );
56
57 // If ext/hash is not present, compat.php's hash_hmac() does not support sha256.
58 $algo = function_exists( 'hash' ) ? 'sha256' : 'sha1';
59 $hash = hash_hmac( $algo, $username . '|' . $expiration . '|' . $token, $key );
60
61 if ( hash_equals( $hash, $hmac ) ) {
62 $manager = WP_Session_Tokens::get_instance( $user->ID );
63 if ( $manager->verify( $token ) ) {
64 return $user;
65 }
66 }
67 }
68 }
69 }
70 }
71 //ver4.0.17 fixed https://wordpress.org/support/topic/wp_get_current_user-is-overridden/
72 //return 0;
73 $user = new WP_User( 0 );
74 return $user;
75
76 } else {
77 return _wp_get_current_user();
78 }
79 }
80 endif;
81
82 if ( !function_exists('get_userdata') ) :
83 /**
84 * Retrieve user info by user ID.
85 * @param int $user_id User ID
86 * @return WP_User|bool WP_User object on success, false on failure.
87 */
88 function get_userdata( $user_id ) {
89 return get_user_by( 'id', $user_id );
90 }
91 endif;
92
93 if ( !function_exists('get_user_by') ) :
94 /**
95 * Retrieve user info by a given field
96 * @param string $field The field to retrieve the user with. id | slug | email | login
97 * @param int|string $value A value for $field. A user ID, slug, email address, or login name.
98 * @return WP_User|bool WP_User object on success, false on failure.
99 */
100 function get_user_by( $field, $value ) {
101 $userdata = WP_User::get_data_by( $field, $value );
102
103 if ( !$userdata )
104 return false;
105
106 $user = new WP_User;
107 $user->init( $userdata );
108
109 return $user;
110 }
111 endif;
112
113 if ( !function_exists('is_user_logged_in') ) :
114 /**
115 * Checks if the current visitor is a logged in user.
116 * @return bool True if user is logged in, false if not logged in.
117 */
118 function is_user_logged_in() {
119 if ( ! function_exists( 'wp_set_current_user' ) )
120 return false;
121
122 $user = wp_get_current_user();
123
124 if ( ! $user->exists() )
125 return false;
126
127 return true;
128 }
129 endif;
130
131 /***************************************************************************
132 * Plugin Load Filter
133 **************************************************************************/
134
135 if(in_array( 'plugin-load-filter/plugin-load-filter.php', (array) get_option( 'active_plugins', array() ) )){
136 $plugin_load_filter = new Plf_filter();
137 } elseif ( is_multisite() ) {
138 $plugins = get_site_option( 'active_sitewide_plugins');
139 if ( isset($plugins['plugin-load-filter/plugin-load-filter.php']) ){
140 $plugin_load_filter = new Plf_filter();
141 }
142 }
143
144 class Plf_filter {
145 static private $filter; //Plugin Load Filter Setting option data
146 static private $rlocale;
147 static private $url_filter;
148 static private $s_url_filter;
149 static private $is_filterkey;
150 static private $iniget_active_plugins;
151 static private $iniget_active_sitewide_plugins;
152 static private $base_plugins;
153 static private $filtered_plugins;
154 static private $cache;
155 static private $url2id;
156 static private $pre_post_id;
157 static private $base_public_query_vars;
158
159 function __construct() {
160 self::$rlocale = null;
161 self::$cache = array();
162 self::$url2id = array();
163 self::$pre_post_id = 0;
164 self::$base_public_query_vars = array();
165 self::$url_filter = array();
166 self::$s_url_filter = array();
167 self::$is_filterkey = false;
168 self::$iniget_active_plugins = array();
169 self::$iniget_active_sitewide_plugins = array();
170 self::$base_plugins = array();
171 self::$filtered_plugins = array();
172 self::$filter = get_option('plf_option', array());
173 if(!empty(self::$filter)){
174 //Addon option get
175 self::$iniget_active_plugins = $plugins = get_option( 'active_plugins', array() );
176 if ( is_multisite() ) {
177 self::$iniget_active_sitewide_plugins = (array) get_site_option( 'active_sitewide_plugins', array() );
178 $plugins = array_merge( $plugins, array_keys( self::$iniget_active_sitewide_plugins ) );
179 }
180 if(!empty($plugins) && in_array( 'plugin-load-filter-addon/plugin-load-filter-addon.php', $plugins)){
181 self::$url_filter = get_option('plf_addon_options', array());
182 }
183
184 //active_plugins filter
185 if ( is_multisite() ) {
186 add_filter('pre_site_option_active_sitewide_plugins', array('Plf_filter', 'active_sitewide_plugins'));
187 add_action('update_site_option_active_sitewide_plugins', array($this, 'update_active_sitewide_plugins'), 99999, 4);
188 }
189 add_filter('pre_option_active_plugins', array('Plf_filter', 'active_plugins'));
190 add_filter('pre_option_jetpack_active_modules', array('Plf_filter', 'active_jetmodules'));
191 add_filter('pre_option_celtispack_active_modules', array('Plf_filter', 'active_celtismodules'));
192
193 add_action('update_option_active_plugins', array($this, 'update_active_plugins'), 99999, 3);
194 add_action('update_option_jetpack_active_modules', array($this, 'update_active_jetmodules'), 99999, 3);
195 add_action('update_option_celtispack_active_modules', array($this, 'update_active_celtismodules'), 99999, 3);
196 add_action('switch_theme', array($this, 'switch_theme'));
197
198 add_action('plugins_loaded', array($this, 'plugins_loaded'));
199 add_action('admin_init', array($this, 'cache_post_type'));
200 //admin-bar filtered status
201 if(!empty(self::$filter['admin_bar'])){
202 add_action('admin_bar_menu', array($this,'custom_bar_menus'), 201);
203 }
204 //language locale filter
205 if(!empty(self::$filter['language'])){
206 add_filter( 'locale', array('Plf_filter', 'post_locale') );
207 add_filter( 'determine_locale', array('Plf_filter', 'post_determine_locale') );
208 }
209 }
210 }
211
212 //Notice: scriptを使うと AMP でエラーとなるので target でオープン/クローズを行う
213 static function plf_filtered_result_dialog( $text ) {
214 ?>
215 <style>
216 #wpadminbar #wp-admin-bar-plf-statlink .ab-icon:before { content: '\f106'; top: 2px;}
217 #plf-status { display:none;}
218 #plf-status:target { display:block;}
219 #plf-status .dialog-overlay{ position:fixed; left:0px; top:0px; width:100%; height:100%; background-color:rgba(0,0,0,.5); z-index:999999999;}
220 #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;}
221 #plf-status .dialog-title { margin: 0 0 1em; font-size: 16px;}
222 #plf-status textarea { font-size: 13px;}
223 #plf-status .button-group { display:block; margin-top:2em; text-align:right; font-size:1em;}
224 #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;}
225 #plf-status a.button:hover { background: #e8ffff; border-color: #016087; color: #016087;}
226 </style>
227 <div id="plf-status">
228 <div class="dialog-overlay"></div>
229 <div class="dialog">
230 <p class="dialog-title"><strong><?php echo 'Plugin Load Filter status'; ?></strong></p>
231 <div><textarea id="plf-filtered-result" style="width:100%; height:320px; margin:5px 0;"><?php echo $text; ?></textarea></div>
232 <div class="button-group">
233 <a href="#" id="plf-status-close" class="button" aria-label="Close modal">Close</a>
234 </div>
235 </div>
236 </div>
237 <?php
238 }
239
240 //filtered plugins list print
241 static function result_plugin_print( $e_plugins, $d_plugins ) {
242 $text = PHP_EOL . "[Activate Plugins]" . PHP_EOL;
243 $idx = 1;
244 foreach ($e_plugins as $key) {
245 if(!empty($key)){
246 $key = preg_replace('|/.+?\.php|', '', $key);
247 $text .= "$idx. $key" . PHP_EOL;
248 $idx++;
249 }
250 }
251 $text .= PHP_EOL . "[Deactivate Plugins]" . PHP_EOL;
252 $idx = 1;
253 foreach ($d_plugins as $key) {
254 if(!empty($key)){
255 $key = preg_replace('|/.+?\.php|', '', $key);
256 $text .= "$idx. $key" . PHP_EOL;
257 $idx++;
258 }
259 }
260 return $text;
261 }
262
263 public function custom_bar_menus($wp_admin_bar) {
264 if (current_user_can( 'activate_plugins' )) {
265 $base_plugins = self::get_base_plugins();
266 if(!empty($base_plugins)){
267 $text = '==== Plugin Load Filter status ====' . PHP_EOL;
268 $is_filterkey = self::is_filterkey();
269 if($is_filterkey !== false){
270 $text .= '[Filter] ' . $is_filterkey . PHP_EOL;
271 $e_plugins = self::get_filtered_plugins();
272 $d_plugins = array_diff( $base_plugins, $e_plugins );
273 } else {
274 $text .= '[Filter] Not Used' . PHP_EOL;
275 $e_plugins = $base_plugins;
276 $d_plugins = array();
277 }
278 ksort($e_plugins, SORT_STRING);
279 ksort($d_plugins, SORT_STRING);
280
281 $text .= self::result_plugin_print( $e_plugins, $d_plugins );
282 self::plf_filtered_result_dialog( $text );
283 $wp_admin_bar->add_menu( array(
284 'id' => 'plf-statlink',
285 'title' => '<span class="ab-icon"></span>PLF',
286 'href' => '#plf-status',
287 ));
288 }
289 }
290 }
291
292 //active_sitewide plugins Filter add ver2.4.0
293 static function active_sitewide_plugins( $default = false) {
294 return self::plf_filter( 'active_sitewide_plugins', $default);
295 }
296
297 //active plugins Filter
298 static function active_plugins( $default = false) {
299 return self::plf_filter( 'active_plugins', $default);
300 }
301
302 //Jetpack module Filter
303 static function active_jetmodules( $default = false) {
304 return self::plf_filter( 'jetpack_active_modules', $default);
305 }
306
307 //Celtispack module Filter
308 static function active_celtismodules( $default = false) {
309 return self::plf_filter( 'celtispack_active_modules', $default);
310 }
311
312 function updated_plf_stat() {
313 $default = array(
314 'post_type_query_vars' => array(),
315 'queryable_post_types' => array(),
316 //'wp_post_statuses' => array(),
317 //'wp_post_types' => array(),
318 //'wp_taxonomies' => array(),
319 'stat_change' => false,
320 );
321 $data = get_option('plf_queryvars', array());
322 $data = wp_parse_args( (array) $data, $default);
323 //plugin bulk action repeated call
324 if(empty($data['stat_change'])){
325 $data['stat_change'] = true;
326 update_option('plf_queryvars', $data);
327 }
328 }
329
330 //Plugin/Module activate or deactivate stat change
331 function update_active_sitewide_plugins( $option, $value, $old_value, $network_id ) {
332 $this->updated_plf_stat();
333 }
334 function update_active_plugins( $old_value, $value, $option ) {
335 $this->updated_plf_stat();
336 }
337 function update_active_jetmodules( $old_value, $value, $option ) {
338 $this->updated_plf_stat();
339 }
340 function update_active_celtismodules( $old_value, $value, $option ) {
341 $this->updated_plf_stat();
342 }
343 function switch_theme() {
344 $this->updated_plf_stat();
345 }
346
347 //Make taxonomies and posts available to 'plugin load filter'.
348 //force register_taxonomy (category, post_tag, post_format)
349 static function force_initial_taxonomies(){
350 global $wp_actions;
351 $wp_actions[ 'init' ] = 1;
352 create_initial_taxonomies();
353 create_initial_post_types();
354 unset($wp_actions[ 'init' ]);
355 }
356
357 //all plugins loaded
358 function plugins_loaded() {
359 //ver4.0.5 カスタムポストタイプのキャッシュデータを $wp_post_types グローバル変数には反映しないよう変更したのでこの処理は不要となるが、なんらかの影響があると嫌なのでとりあえず残しておく
360 // woocommerce が init 後に register_post_type, register_taxonomy が実行されたか判定しているので該当データを一旦クリアして init で再登録させる
361 if(post_type_exists( 'product' )){
362 if(method_exists('WC_Post_Types', 'register_post_types')){
363 unregister_post_type( 'product' );
364 //ver4.0.2 wc_register_order_type で登録されるタイプも一旦クリアする
365 if(post_type_exists( 'shop_order' )){
366 unregister_post_type( 'shop_order' );
367 }
368 if(post_type_exists( 'shop_order_refund' )){
369 unregister_post_type( 'shop_order_refund' );
370 }
371 }
372 }
373 if ( taxonomy_exists( 'product_type' ) ) {
374 if(method_exists('WC_Post_Types', 'register_taxonomies')){
375 unregister_taxonomy( 'product_type' );
376 }
377 }
378 }
379
380 //Post Format Type, Custom Post Type Data Cache for parse request
381 function cache_post_type() {
382 if (!is_admin() || self::$is_filterkey !== false || ( defined('DOING_AJAX') && DOING_AJAX ))
383 return;
384
385 $default = array(
386 'post_type_query_vars' => array(),
387 'queryable_post_types' => array(),
388 //'wp_post_statuses' => array(),
389 //'wp_post_types' => array(),
390 //'wp_taxonomies' => array(),
391 'stat_change' => false,
392 );
393 $data = get_option('plf_queryvars', array());
394 $data = wp_parse_args( (array) $data, $default);
395
396 global $plugin_page;
397 if(isset($plugin_page) && $plugin_page === 'plugin_load_filter_admin_manage_page'){
398 $data['stat_change'] = true;
399 }
400
401 //init or plugin activate or deactivate stat change
402 if(!empty($data['stat_change'])){
403 global $wp;
404 $public_query_vars = (!empty($wp->public_query_vars))? $wp->public_query_vars : array();;
405 $post_type_query_vars = array();
406 foreach ( get_post_types( array(), 'objects' ) as $post_type => $t ){
407 if (!empty($t) && $t->query_var )
408 $post_type_query_vars[$t->query_var] = $post_type;
409 }
410 $queryable_post_types = get_post_types( array('publicly_queryable' => true) );
411
412 //global $wp_post_types;
413 //global $wp_post_statuses;
414 //global $wp_taxonomies;
415 //$data['wp_post_types'] = $wp_post_types;
416 //$data['wp_post_statuses'] = $wp_post_statuses;
417 //$data['wp_taxonomies'] = $wp_taxonomies;
418 //$data['public_query_vars'] = $public_query_vars;
419 //ver4.0.11 使わないデータを取り除きオプションデータを縮小化
420 if(!empty($data['rewrite_rules'])){
421 unset($data['rewrite_rules']); //データの残骸があれば使わないので取り除く
422 }
423 if(!empty($data['wp_post_types'])){
424 unset($data['wp_post_types']);
425 }
426 if(!empty($data['wp_post_statuses'])){
427 unset($data['wp_post_statuses']);
428 }
429 if(!empty($data['wp_taxonomies'])){
430 unset($data['wp_taxonomies']);
431 }
432 if(!empty($data['public_query_vars'])){
433 unset($data['public_query_vars']);
434 }
435 $add_query_vars = array_diff( $public_query_vars, self::$base_public_query_vars );
436 $data['add_public_query_vars']= $add_query_vars;
437 $data['post_type_query_vars'] = $post_type_query_vars;
438 $data['queryable_post_types'] = $queryable_post_types;
439 $data['stat_change'] = false;
440 update_option('plf_queryvars', $data);
441 }
442 }
443
444 /**
445 * Filters the locale for the current request.
446 *
447 * @param string $locale The locale.
448 */
449 static function post_locale( $locale ) {
450 if(empty(self::$rlocale)) {
451 $pid = 0;
452 if(isset($_SERVER['REQUEST_URI'])){
453 if ( strpos( $_SERVER['REQUEST_URI'], 'wp-json' ) !== false || preg_match( '/(admin|wc)-ajax/', $_SERVER['REQUEST_URI'])) {
454 $refurl = wp_get_raw_referer();
455 if(!empty( $refurl )){
456 if(preg_match( '/post=([0-9]+)?/', $refurl, $match )){
457 $pid = (int)$match[1];
458 } elseif(preg_match( '/post_ID=([0-9]+)?/', $refurl, $match )){
459 $pid = (int)$match[1];
460 } else {
461 $pid = (isset(self::$url2id[$refurl]))? self::$url2id[$refurl] : url_to_postid( $refurl );
462 self::$url2id[$refurl] = (int)$pid;
463 }
464 }
465 } elseif ( strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) !== false) {
466 if ( isset( $_GET['post'] ) ) {
467 $pid = (int) $_GET['post'];
468 } elseif ( isset( $_POST['post_ID'] ) ) {
469 $pid = (int) $_POST['post_ID'];
470 }
471 } else {
472 global $wp_query;
473 if(!empty(self::$pre_post_id)){
474 $pid = self::$pre_post_id;
475 } elseif(!empty($wp_query)){
476 if(!empty($wp_query->post) && !empty($wp_query->post->ID)){
477 $pid = $wp_query->post->ID;
478 } else {
479 $refurl = wp_get_raw_referer();
480 if (!empty( $refurl )) {
481 $pid = (isset(self::$url2id[$refurl]))? self::$url2id[$refurl] : url_to_postid( $refurl );
482 self::$url2id[$refurl] = (int)$pid;
483 }
484 }
485 }
486 }
487 }
488 if(!empty($pid)){
489 $c_locale = get_post_meta( $pid, '_locale', true );
490 if(!empty($c_locale)){
491 self::$rlocale = $c_locale;
492 }
493 }
494 }
495 if(!empty(self::$rlocale)) {
496 $locale = self::$rlocale;
497 }
498 return $locale;
499 }
500
501 static function post_determine_locale( $locale ) {
502 if(!empty(self::$rlocale)) {
503 $locale = self::$rlocale;
504 }
505 return $locale;
506 }
507
508 //プラグインロード前は bbPress等 カスタムポストタイプのデバッグモードでのエラー表示抑制
509 static function exclude_trigger_error( $trigger, $function, $message, $version) {
510 if (did_action( 'plugins_loaded' ) === 0) {
511 if($function === 'map_meta_cap'){
512 $trigger = false;
513 }
514 }
515 return $trigger;
516 }
517 //プラグインロード前は closed 等のカスタムステータスがまだ登録されてない状�
518 �でも取得 posts �
519 報がクリアされないよう抑制
520 static function exclude_map_meta_cap( $caps, $cap, $user_id, $args) {
521 if (did_action( 'plugins_loaded' ) === 0) {
522 if(!empty($caps) && $caps[0] === 'edit_others_posts'){
523 $caps = array();
524 }
525 }
526 return $caps;
527 }
528
529 //parse_request Action Hook for Custom Post Type query add
530 static function parse_request( &$args ) {
531 if (did_action( 'plugins_loaded' ) === 0) {
532 $data = get_option('plf_queryvars', array());
533 if(!empty($data['post_type_query_vars']) && !empty($data['queryable_post_types']) && empty($data['stat_change'])){
534 //ver4.0.5 グローバルのカスタムポストタイプに事前設定するとプラグイン�
535 での登録済みチェック処理とコンフリクトするので止める
536 //global $wp_post_statuses;
537 //global $wp_post_types;
538 //global $wp_taxonomies;
539 //$wp_post_statuses = $data['wp_post_statuses'];
540 //$wp_post_types = $data['wp_post_types'];
541 //$wp_taxonomies = $data['wp_taxonomies'];
542
543 $post_type_query_vars = $data['post_type_query_vars'];
544 $queryable_post_types = $data['queryable_post_types'];
545
546 //query_vars に query_posts() で実行するSQL用のポストタイプデータをセット
547 if(isset($data['add_public_query_vars'])){
548 //ver4.0.11 差分データにしたのでここでマージするが更新時にエラーとならないよう旧処理も残しておく
549 $args->public_query_vars = array_merge(self::$base_public_query_vars, $data['add_public_query_vars']);
550 } else {
551 $args->public_query_vars = $data['public_query_vars'];
552 }
553 if ( isset( $args->matched_query ) ) {
554 parse_str($args->matched_query, $perma_query_vars);
555 }
556
557 foreach ( $args->public_query_vars as $wpvar ) {
558 if ( isset( $args->extra_query_vars[$wpvar] ) ){
559 $args->query_vars[$wpvar] = $args->extra_query_vars[$wpvar];
560 } elseif ( isset( $_GET[ $wpvar ] ) && isset( $_POST[ $wpvar ] ) && $_GET[ $wpvar ] !== $_POST[ $wpvar ] ) {
561 wp_die( 'A variable mismatch has been detected.', 'Sorry, you are not allowed to view this item.', 400 );
562 } elseif ( isset( $_POST[$wpvar] ) ){
563 $args->query_vars[$wpvar] = $_POST[$wpvar];
564 } elseif ( isset( $_GET[$wpvar] ) ){
565 $args->query_vars[$wpvar] = $_GET[$wpvar];
566 } elseif ( isset( $perma_query_vars[$wpvar] ) ){
567 $args->query_vars[$wpvar] = $perma_query_vars[$wpvar];
568 }
569 if ( !empty( $args->query_vars[$wpvar] ) ) {
570 if ( ! is_array( $args->query_vars[$wpvar] ) ) {
571 $args->query_vars[$wpvar] = (string) $args->query_vars[$wpvar];
572 } else {
573 foreach ( $args->query_vars[$wpvar] as $vkey => $v ) {
574 if ( is_scalar( $v ) ) {
575 $args->query_vars[$wpvar][$vkey] = (string) $v;
576 }
577 }
578 }
579
580 if ( isset($post_type_query_vars[$wpvar] ) ) {
581 $args->query_vars['post_type'] = $post_type_query_vars[$wpvar];
582 $args->query_vars['name'] = $args->query_vars[$wpvar];
583 }
584 }
585 }
586
587 // Limit publicly queried post_types to those that are 'publicly_queryable'.
588 if ( isset( $args->query_vars['post_type']) ) {
589 if ( ! is_array( $args->query_vars['post_type'] ) ) {
590 if ( ! in_array( $args->query_vars['post_type'], $queryable_post_types, true ) ) {
591 unset( $args->query_vars['post_type'] );
592 }
593 } else {
594 $args->query_vars['post_type'] = array_intersect( $args->query_vars['post_type'], $queryable_post_types );
595 }
596 }
597 }
598 }
599 }
600
601 //get filter name
602 static function is_filterkey() {
603 return self::$is_filterkey;
604 }
605 //base plugins (initial activated plugins & module)
606 static function get_base_plugins() {
607 return self::$base_plugins;
608 }
609 //filtered plugins (plugins & module)
610 static function get_filtered_plugins() {
611 return self::$filtered_plugins;
612 }
613
614 /**
615 * Get URL Filter (for addon optional)
616 * @param $stat : 'active' / 'deactive' / '' = all
617 * @param $urltype : 'front' / 'admin' / '' = all
618 * @param $device : 'desktop' / 'mobile' / '' = all
619 * @return url filter data array.
620 */
621 static function get_url_filter( $stat='', $urltype='', $device='' ) {
622 $frontlist = array();
623 $adminlist = array();
624 if(!empty(self::$url_filter)){
625 foreach (self::$url_filter['filter'] as $slug => $v) {
626 if(empty($stat) || (!empty($v['stat']) && $stat === 'active') || (empty($v['stat']) && $stat === 'deactive')){
627 if(empty($device) || (!empty($v['desktop']) && $device === 'desktop') || (!empty($v['mobile']) && $device === 'mobile')){
628 if(!empty($v['type'])){
629 $item = "{$v['group']}-{$v['slug']}";
630 if($v['type'] == 'front'){
631 $frontlist[$item] = $v;
632 } elseif($v['type'] == 'admin'){
633 $adminlist[$item] = $v;
634 }
635 }
636 }
637 }
638 }
639 //group 毎に slug をソート A-Za-z 順となる
640 ksort($frontlist, SORT_STRING);
641 ksort($adminlist, SORT_STRING);
642 }
643 $list = array();
644 if(empty($urltype) || $urltype === 'front'){
645 foreach ($frontlist as $item => $v) {
646 if(!empty($v)){
647 $list[] = $v;
648 }
649 }
650 }
651 if(empty($urltype) || $urltype === 'admin'){
652 foreach ($adminlist as $item => $v) {
653 if(!empty($v)){
654 $list[] = $v;
655 }
656 }
657 }
658 return $list;
659 }
660 //active group list
661 static function get_active_group() {
662 $grouplist = array();
663 $sluglist = self::get_url_filter( 'active' );
664 foreach ($sluglist as $v) {
665 if(!empty($v['group']) && !in_array($v['group'], $grouplist)){
666 $grouplist[] = $v['group'];
667 }
668 }
669 return $grouplist;
670 }
671 //active slug filter data in group
672 static function get_slug_filter( $group ) {
673 $list = array();
674 $sluglist = self::get_url_filter( 'active' );
675 foreach ($sluglist as $v) {
676 if(!empty($v['group']) && $v['group'] == $group){
677 $list[] = $v;
678 }
679 }
680 return $list;
681 }
682
683 //Is there a term in taxonomies
684 static function is_term_in_taxonomy( $post_id, $term, $taxonomies) {
685 $ret = false;
686 $txs = explode(',', $taxonomies);
687 foreach ( $txs as $slug ) {
688 if(!empty($slug)){
689 $names = '';
690 $terms = get_the_terms( $post_id, $slug );
691 if (!empty($terms) ) {
692 foreach ( $terms as $tobj ) {
693 if(!empty($tobj)){
694 $names .= $tobj->name . ',';
695 }
696 }
697 if(strpos($names, $term ) !== false){
698 $ret = true;
699 break;
700 }
701 }
702 }
703 }
704 return $ret;
705 }
706
707 // url path, query parameter match check
708 static function is_url_match( $req_url, $parse_url, $filter ) {
709 if(empty($req_url) || empty($parse_url['path']))
710 return false;
711 $_url['url_path'] = $parse_url['path'];
712 $_url['url_q_and'] = $_url['url_q_not'] = (!empty($parse_url['query']))? $parse_url['query'] : '';
713
714 $match = array();
715 $keynum = array();
716 foreach (array('url_path', 'url_q_and', 'url_q_not') as $item) {
717 $match[$item] = 0;
718 $keynum[$item] = 0;
719 if($item === 'url_path'){
720 $reg_before = "(/?)";
721 $reg_after = "(/?$)";
722 } else {
723 $reg_before = "(^|&)";
724 $reg_after = "(=|&|$)";
725 }
726
727 $keylist = (!empty($filter[$item])) ? $filter[$item] : '';
728 $keylist = str_replace( "*", ".+?", $keylist);
729 $ar_key = (!empty($keylist))? array_filter( array_map("trim", explode(PHP_EOL, $keylist))) : array();
730 $keynum[$item] = count($ar_key);
731 if(empty($ar_key)) {
732 if($item === 'url_path')
733 $match[$item] += 1;
734 } else {
735 $ar_new = array();
736 foreach ($ar_key as $key) {
737 //v4.0.6 home (/) のみの指定は別判定しないとトレイルスラッシュで終わる�
738 �てのURLにマッチしてしまう
739 if($item === 'url_path' && $key === '/'){
740 if($_url['url_path'] === '/'){
741 $match[$item] += 1;
742 }
743 } elseif(preg_match("#{$reg_before}{$key}{$reg_after}#ui", $_url[$item])){
744 $match[$item] += 1;
745 }
746 }
747 }
748 }
749 $group = false;
750 $hit = ($match['url_path'] > 0 && $match['url_q_and'] === $keynum['url_q_and'] && $match['url_q_not'] === 0)? true : false;
751 if($hit){
752 if((strpos($_url['url_path'], 'admin-ajax.php' ) !== false || strpos($_url['url_q_and'], 'wc-ajax' ) !== false) && (int)$filter['targetpage'] === 2){
753 $action = '';
754 if(isset($_REQUEST['action'])){
755 $action = esc_attr($_REQUEST['action']);
756 } elseif(!empty( $_GET['wc-ajax'] )) {
757 $action = sanitize_text_field( wp_unslash( $_GET['wc-ajax'] ) );
758 }
759 if(!empty($filter['ajax_action'])){
760 if( $action == $filter['ajax_action'] ){
761 $group = $filter['group'];
762 }
763 } else {
764 //exclude special action : plugin_load_filter, plf_urlfilter_test
765 if (! in_array( $action, array('plugin_load_filter', 'plf_urlfilter_test')) ){
766 $group = $filter['group'];
767 }
768 }
769 } elseif(strpos($_url['url_path'], 'post-new.php' ) === false && (int)$filter['targetpage'] === 1){
770 $post_id = 0;
771 if ( isset( $_GET['post'] ) && isset( $_POST['post_ID'] ) && (int) $_GET['post'] !== (int) $_POST['post_ID'] ) {
772 } elseif ( isset( $_GET['post'] ) ) {
773 $post_id = (int) $_GET['post'];
774 } elseif ( isset( $_POST['post_ID'] ) ) {
775 $post_id = (int) $_POST['post_ID'];
776 }
777 if(empty($post_id)){
778 //クエリーパラメータ形式だとポストIDが取得できないようなので、シュミレータ以外なら $wp_query->post->ID を使う
779 global $wp_query;
780 if(!empty($wp_query)){
781 if (isset($_REQUEST['action']) && isset($_POST['test_url']) ) {
782 $post_id = (isset(self::$url2id[$req_url]))? self::$url2id[$req_url] : url_to_postid( $req_url );
783 self::$url2id[$req_url] = (int)$post_id;
784 } else {
785 if(!empty($wp_query->post) && !empty($wp_query->post->ID)){
786 $post_id = $wp_query->post->ID;
787 } else {
788 $post_id = (isset(self::$url2id[$req_url]))? self::$url2id[$req_url] : url_to_postid( $req_url );
789 self::$url2id[$req_url] = (int)$post_id;
790 }
791 }
792 }
793 }
794 if(!empty($post_id)){
795 $post = get_post( $post_id );
796 if ( is_object($post) && !empty($post->post_type)) {
797 if(!empty($filter['post_type'])){
798 if(preg_match("#{$post->post_type}#", $filter['post_type'])){
799 if(!empty($filter['taxonomies']) && !empty($filter['term'])){
800 if(self::is_term_in_taxonomy( $post_id, $filter['term'], $filter['taxonomies'])){
801 $group = $filter['group'];
802 }
803 } else {
804 $group = $filter['group'];
805 }
806 }
807 } else {
808 if(!empty($filter['taxonomies']) && !empty($filter['term'])){
809 if(self::is_term_in_taxonomy( $post_id, $filter['term'], $filter['taxonomies'])){
810 $group = $filter['group'];
811 }
812 } else {
813 $group = $filter['group'];
814 }
815 }
816 }
817 }
818 } else {
819 $group = $filter['group'];
820 }
821 }
822 return($group);
823 }
824
825 static function plugin_keygen( $fname, $option ) {
826 $key = false;
827 if($option === 'jetpack_active_modules'){
828 $key = 'jetpack_module/' . $fname;
829 } elseif($option === 'celtispack_active_modules'){
830 $key = 'celtispack_module/' . str_replace( '.php', '', basename( $fname ) );
831 } else {
832 $key = $fname;
833 }
834 return $key;
835 }
836
837 /**
838 * Get valid plugins list for groupkey (for addon optional)
839 * @param $groupkey : url filter group name
840 * @param $filter : plf filtering setting data
841 * @param $option : option data eg. 'active_plugins', 'active_sitewide_plugins', 'jetpack_active_modules' ...
842 * @param $plugins : active plugins values before filtering
843 * @return data values after filtering
844 */
845 static function filter_to_active_plugins( $groupkey, $filter, $option, $plugins ){
846 $new_plugins = array();
847 foreach ( $plugins as $item ) {
848 if(!empty($item)){
849 $unload = false;
850 $p_key = self::plugin_keygen( $item, $option );
851 if(!empty($filter['plfurlkey'][$groupkey]['plugins'])){
852 if(false !== strpos($filter['plfurlkey'][$groupkey]['plugins'], $p_key))
853 $unload = true;
854 }
855 if(!$unload) {
856 if($option === 'active_sitewide_plugins'){
857 // v4.0.6 $new_plugins[$item] = $plugins[$item];
858 $new_plugins[$item] = $item;
859 } else {
860 $new_plugins[] = $item;
861 }
862 }
863 }
864 }
865
866 $new_plugins = apply_filters('plf_custom_changes_to_active_plugins', $new_plugins);
867 return $new_plugins;
868 }
869
870 /**
871 * Get valid plugins list for ajax acceleration filter
872 * @param $p_slugs : ajax _ajax_plf activate plugins slug data (Separate multiple with commas)
873 * @param $option : option data eg. 'active_plugins', 'active_sitewide_plugins', 'jetpack_active_modules' ...
874 * @param $plugins : active plugins values before filtering
875 * @return data values after filtering
876 */
877 static function ajaxfilter_to_active_plugins( $p_slugs, $option, $plugins ){
878 //�
879 �合用にカンマ区切りをスラッシュ区切りへ変換
880 $arslugs = array_filter( array_map("trim", explode(',', $p_slugs)));
881 $slugs = '/' . implode('/', $arslugs) . '/';
882
883 $new_plugins = array();
884 foreach ( $plugins as $item ) {
885 if(!empty($item)){
886 $unload = false;
887 $p_key = self::plugin_keygen( $item, $option );
888 $sep = strpos($p_key, '/' );
889 $p_slug = ($sep !== false)? substr($p_key, 0, $sep) : $p_key;
890 if(false === strpos($slugs, "/$p_slug/")){
891 $unload = true;
892 }
893 if(!$unload) {
894 if($option === 'active_sitewide_plugins'){
895 $new_plugins[$item] = $item;
896 } else {
897 $new_plugins[] = $item;
898 }
899 }
900 }
901 }
902 return $new_plugins;
903 }
904
905 //Plugin Load Filter Main (active plugins/modules filtering)
906 static function plf_filter( $option, $default = false) {
907 if ( defined( 'WP_SETUP_CONFIG' ) || did_action( 'mu_plugin_loaded' ) === 0)
908 return false;
909
910 //Check if the caller is wp-settings.php wp_get_active_network_plugins() / wp_get_active_and_valid_plugins()
911 if( in_array($option, array('active_plugins', 'active_sitewide_plugins' ))){
912 $is_caller_target = false;
913 $trace = debug_backtrace();
914 foreach ($trace as $stp) {
915 if(isset($stp['file']) && strpos($stp['file'], 'wp-settings.php') !== false){
916 if(isset($stp['function']) && in_array($stp['function'], array('wp_get_active_network_plugins', 'wp_get_active_and_valid_plugins'))){
917 $is_caller_target = true;
918 break;
919 }
920 }
921 }
922 if( !$is_caller_target ) {
923 return false;
924 }
925 }
926
927 if ( ! defined( 'WP_INSTALLING' ) ) {
928 global $wpdb, $current_site;
929 if ( is_multisite() && $option === 'active_sitewide_plugins' ) {
930 //get_network_option() current site ID
931 $network_id = $current_site->id;
932
933 // prevent non-existent options from triggering multiple queries
934 $notoptions_key = "$network_id:notoptions";
935 $notoptions = wp_cache_get( $notoptions_key, 'site-options' );
936 if ( isset( $notoptions[ $option ] ) ) {
937 return apply_filters( 'default_site_option_' . $option, $default, $option );
938 }
939
940 $cache_key = "$network_id:$option";
941 $opt_value = wp_cache_get( $cache_key, 'site-options' );
942
943 if ( ! isset( $opt_value ) || false === $opt_value ) {
944 $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $network_id ) );
945
946 // Has to be get_row instead of get_var because of funkiness with 0, false, null values
947 if ( is_object( $row ) ) {
948 $opt_value = $row->meta_value;
949 $opt_value = maybe_unserialize( $opt_value );
950 wp_cache_set( $cache_key, $opt_value, 'site-options' );
951 } else {
952 if ( ! is_array( $notoptions ) ) {
953 $notoptions = array();
954 }
955 $notoptions[ $option ] = true;
956 wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
957
958 /** This filter is documented in wp-includes/option.php */
959 $opt_value = apply_filters( 'default_site_option_' . $option, $default, $option );
960 }
961 }
962 } else {
963 // prevent non-existent options from triggering multiple queries
964 $notoptions = wp_cache_get( 'notoptions', 'options' );
965 if ( isset( $notoptions[$option] ) )
966 return apply_filters( 'default_option_' . $option, $default );
967
968 $alloptions = wp_load_alloptions();
969 if ( isset( $alloptions[$option] ) ) {
970 $opt_value = $alloptions[$option];
971 } else {
972 $opt_value = wp_cache_get( $option, 'options' );
973
974 if ( false === $opt_value ) {
975 $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
976
977 // Has to be get_row instead of get_var because of funkiness with 0, false, null values
978 if ( is_object( $row ) ) {
979 $opt_value = $row->option_value;
980 wp_cache_add( $option, $opt_value, 'options' );
981 } else { // option does not exist, so we must cache its non-existence
982 if ( ! is_array( $notoptions ) ) {
983 $notoptions = array();
984 }
985 $notoptions[$option] = true;
986 wp_cache_set( 'notoptions', $notoptions, 'options' );
987
988 /** This filter is documented in wp-includes/option.php */
989 return apply_filters( 'default_option_' . $option, $default, $option );
990 }
991 }
992 }
993 }
994 } else {
995 return false;
996 }
997
998 $req_url = (isset($_SERVER['REQUEST_URI']))? $_SERVER['REQUEST_URI'] : '';
999 $req_url = str_replace( "\\", "/", $req_url);
1000 $parse_url = parse_url($req_url);
1001 $action = (!empty($parse_url['path']) && strpos($parse_url['path'], 'admin-ajax.php' ) !== false && isset($_REQUEST['action']))? esc_attr($_REQUEST['action']) : '';
1002
1003 $act_plugins = ($option === 'active_sitewide_plugins')? array_keys( (array)$opt_value ) : maybe_unserialize( $opt_value );
1004 if($option === 'celtispack_active_modules'){
1005 if(empty(self::$base_plugins['celtispack-addon/celtispack-addon.php'])){
1006 $opt = get_option( 'celtis_addon_options', array() );
1007 if(!empty($opt['active_modules'])){
1008 $nact_plugins = array();
1009 foreach ($act_plugins as $pkey) {
1010 if(!empty($pkey)){
1011 $key = str_replace( '.php', '', basename( $pkey ));
1012 if(!empty($opt['active_modules'][$key]))
1013 continue;
1014 $nact_plugins[] = $pkey;
1015 }
1016 }
1017 $act_plugins = $nact_plugins;
1018 }
1019 }
1020 }
1021
1022 //Equal treatment for when the wp_is_mobile is not yet available(wp-include/vars.php wp_is_mobile)
1023 if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
1024 $is_mobile = false;
1025 } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.)
1026 || strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false
1027 || strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false
1028 || strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false
1029 || strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false
1030 || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false
1031 || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false ) {
1032 $is_mobile = true;
1033 } else {
1034 $is_mobile = false;
1035 }
1036 $is_mobile = apply_filters( 'custom_is_mobile' , $is_mobile );
1037
1038 //get_option is called many times, intermediate processing data to cache
1039 $keyid = md5('plf_'. (string)$is_mobile . $req_url . $action);
1040 if(!empty(self::$cache[$keyid][$option])){
1041 return self::$cache[$keyid][$option];
1042 }
1043
1044 //Before plugins loaded, it does not use conditional branch such as is_home, to set wp_query, wp in temporary query
1045 if(empty($GLOBALS['wp_the_query'])){
1046 // プラグイン無効化時等で rewrite_rule がクリアされると rewrite_rule が更新されるまでカスタムポストタイプを判定できずにカスタムポストタイプのページはホームへ飛ばされる
1047 // 但し、permlink structure が plain(基本) の場合は除く
1048 if(!empty(get_option( 'permalink_structure' ))){
1049 $rewrite_rules = get_option('rewrite_rules');
1050 // rewrite_rule を監視して変更された場合はプラグインのフィルタリングをスキップさせていたが、
1051 // plugin activate / deactivate を監視するように変更したのでここでは空の場合のみチェック
1052 if(empty($rewrite_rules)){
1053 return false;
1054 }
1055 // Welcart usces_itemnew 新規商品追加時のエラー (A variable mismatch has been detected.) parse_request で発生してるので特別に回避
1056 if ( isset( $_GET[ 'page' ] ) && isset( $_POST[ 'page' ] ) && $_GET[ 'page' ] !== $_POST[ 'page' ] ) {
1057 return false;
1058 }
1059 }
1060 $GLOBALS['wp_the_query'] = new WP_Query();
1061 $GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];
1062 $GLOBALS['wp_rewrite'] = new WP_Rewrite();
1063 $GLOBALS['wp'] = new WP();
1064 self::$base_public_query_vars = $GLOBALS['wp']->public_query_vars;
1065 //register_taxonomy(category, post_tag, post_format) support for is_archive
1066 self::force_initial_taxonomies();
1067
1068 if((!empty($parse_url['path']) && (strpos($parse_url['path'], 'admin-ajax.php' ) !== false || 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 )){
1069 //ver4.0.15 admin-ajax action:send-attachment-to-editor リクエストが query_posts() 呼び出し時にエラーとなるので ajax, rest api, cron では呼び出さず url filter 処理へ
1070 //https://wordpress.org/support/topic/amin-ajax-php-cant-add-images-in-posts/#post-16938082
1071 } else {
1072 //Post Format, Custom Post Type support
1073 add_action('parse_request', array('Plf_filter', 'parse_request'));
1074 add_filter('doing_it_wrong_trigger_error', array('Plf_filter', 'exclude_trigger_error'), 10, 4 );
1075 //custom parse request filter (for experimental development)
1076 $custom = apply_filters( 'plf_experimental_custom_parse_request', false );
1077 if ( false === $custom) {
1078 $GLOBALS['wp']->parse_request('');
1079 }
1080 $GLOBALS['wp']->query_posts();
1081 }
1082 }
1083
1084 //active plugin data
1085 foreach ($act_plugins as $key) {
1086 if(!empty($key)){
1087 $key = self::plugin_keygen( $key, $option );
1088 self::$base_plugins[$key] = $key;
1089 }
1090 }
1091
1092 $filter = self::$filter;
1093
1094 //plf Addon Extract only target data
1095 $devtype = ($is_mobile)? 'mobile' : 'desktop';
1096 $urltype = (!empty($parse_url['path']) && strpos($parse_url['path'], '/wp-admin' ) !== false)? 'admin' : 'front';
1097 if(!empty(self::$url_filter) && empty(self::$s_url_filter)){
1098 self::$s_url_filter = self::get_url_filter( 'active', $urltype, $devtype );
1099 }
1100
1101
1102 //======== The following are Admin backend page processes ========
1103
1104 if($urltype === 'admin'){
1105 //wp-admin/plugins.php or wp-admin/update-core.php request : Do not filter this request URL
1106 if(strpos($parse_url['path'], '/plugins.php' ) !== false || strpos($parse_url['path'], '/update-core.php' ) !== false){
1107 return false;
1108 }
1109 //Ajax acceleration plugin filter (for plugin developers)
1110 if(!empty($action) && !empty(self::$filter['ajax_accelfilter'])){
1111 $slugs = (isset($_REQUEST['_ajax_plf']))? wp_kses( stripslashes($_REQUEST['_ajax_plf']), 'strip' ) : '';
1112 if(!empty($slugs)){
1113 $referer = (!empty( $_SERVER['HTTP_REFERER'] )) ? wp_kses( stripslashes($_SERVER['HTTP_REFERER']), 'strip' ) : '';
1114 $parse_ref = parse_url($referer);
1115 if(!empty($parse_ref['host']) && strpos( home_url(), $parse_ref['host'] ) !== false){
1116 $new_plugins = self::ajaxfilter_to_active_plugins( $slugs, $option, $act_plugins );
1117 foreach ($new_plugins as $key) {
1118 if(!empty($key)){
1119 $key = self::plugin_keygen( $key, $option );
1120 self::$filtered_plugins[$key] = $key;
1121 }
1122 }
1123 return $new_plugins;
1124 }
1125 }
1126 }
1127 if(!empty(self::$s_url_filter)){
1128 //plf Addon Admin Backend URL filtering
1129 foreach (self::$s_url_filter as $key => $v) {
1130 if(!empty($v)){
1131 $groupkey = self::is_url_match( $req_url, $parse_url, $v );
1132 if($groupkey !== false) {
1133 self::$is_filterkey = 'url-group-filter : ' . $groupkey;
1134 $new_plugins = self::filter_to_active_plugins( $groupkey, $filter, $option, $act_plugins );
1135 self::$cache[$keyid][$option] = $new_plugins;
1136 foreach ($new_plugins as $key) {
1137 if(!empty($key)){
1138 $key = self::plugin_keygen( $key, $option );
1139 self::$filtered_plugins[$key] = $key;
1140 }
1141 }
1142 return $new_plugins;
1143 }
1144 }
1145 }
1146 }
1147 return false;
1148 }
1149
1150
1151 //======== The following are frontend page processes ========
1152
1153 global $wp_query;
1154 $unknown = false;
1155 if( ! is_embed() ){
1156 if((is_home() || is_front_page() || is_archive() || is_search() || is_singular()) == false || (is_home() && !empty($_GET))) {
1157 //bbPress users page requests are treated the same as is_home
1158 //downloadmanager plugin downloadlink request [home]/?wpdmact=XXXXXX exclude home GET query
1159 $unknown = true;
1160
1161 } elseif(is_singular() && empty($wp_query->post)){
1162 //documentroot special php file (wp-login.php, wp-cron.php, etc) これらはこの時点では singular とみなされるが post が設定されていないことで判別
1163 //フィルタリングしたい場合は urlfilter Addon を使用すること
1164 //但し、private (非�
1165 �開)ページ時は post がこの時点ではまだ設定されていないので private でクエリー発行して再確認
1166 if(!empty($parse_url['path']) && strpos( $parse_url['path'], '.php' ) === false && !empty($wp_query->query)) {
1167 //get post for private
1168 $query = $wp_query->query;
1169 $query['post_status'] = 'private';
1170 $r = new WP_Query( $query );
1171 if ($r->have_posts()) {
1172 if(!empty($r->post)){
1173 $wp_query->posts = $r->posts;
1174 $wp_query->post = $r->post;
1175 }
1176 } else {
1177 //カスタムステータスがまだ登録されてない状�
1178 �でも取得 posts �
1179 報がクリアされないよう抑制
1180 add_filter( 'map_meta_cap', array('Plf_filter', 'exclude_map_meta_cap'), 10, 4 );
1181 $query['post_status'] = 'any';
1182 $r = new WP_Query( $query );
1183 if ($r->have_posts()) {
1184 if(!empty($r->post)){
1185 $wp_query->posts = $r->posts;
1186 $wp_query->post = $r->post;
1187 }
1188 }
1189 }
1190 }
1191 if(empty($wp_query->post)){
1192 $unknown = true;
1193 }
1194 }
1195 }
1196
1197 $single_opt = array();
1198 if(is_singular() && is_object($wp_query->post)){
1199 self::$pre_post_id = $wp_query->post->ID; //for post_locale()
1200 $myfilter = get_post_meta( $wp_query->post->ID, '_plugin_load_filter', true );
1201 $default = array( 'filter' => 'default', 'desktop' => '', 'mobile' => '');
1202 $single_opt = (!empty($myfilter))? $myfilter : $default;
1203 $single_opt = wp_parse_args( $single_opt, $default);
1204 }
1205 if(!empty(self::$s_url_filter)){
1206 //Addon frontend URL filtering
1207 //個別フィルター有効なシングラーは URL filtering 無効(個別フィルター優�
1208 �)
1209 if(empty($single_opt) || $single_opt['filter'] === 'default'){
1210 foreach (self::$s_url_filter as $key => $v) {
1211 if(!empty($v)){
1212 $groupkey = self::is_url_match( $req_url, $parse_url, $v );
1213 if($groupkey !== false) {
1214 self::$is_filterkey = 'url-group-filter : ' . $groupkey;
1215 $new_plugins = self::filter_to_active_plugins( $groupkey, $filter, $option, $act_plugins );
1216 self::$cache[$keyid][$option] = $new_plugins;
1217 foreach ($new_plugins as $key) {
1218 if(!empty($key)){
1219 $key = self::plugin_keygen( $key, $option );
1220 self::$filtered_plugins[$key] = $key;
1221 }
1222 }
1223 return $new_plugins;
1224 }
1225 }
1226 }
1227 }
1228 }
1229 if($unknown || empty($parse_url['path']) || 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 )){
1230 //url filter 処理後、REST api, cron, フィルター対象外の不明なリクエストはフィルタリング処理を行わない
1231 return false;
1232 }
1233
1234 //plf standard filtering
1235 $type = false;
1236 if(!empty($filter['_pagefilter']['plugins'])){
1237 if(is_embed()){
1238 $type = 'content-card';
1239 } elseif(is_home() || is_front_page()){
1240 $type = 'home';
1241 } elseif(is_archive()) {
1242 $type = 'archive';
1243 } elseif(is_search()) {
1244 $type = 'search';
1245 } elseif(is_attachment()) {
1246 $type = 'attachment';
1247 } elseif(is_page()) {
1248 $type = 'page';
1249 } elseif(is_single()){ //Post & Custom Post
1250 $type = get_post_type( $wp_query->post);
1251 //bbPress private (非�
1252 �開)ページ時のポストタイプ取得
1253 if($type === false && isset($wp_query->query_vars['post_type'])){
1254 $type = $wp_query->query_vars['post_type'];
1255 }
1256 if($type === 'post'){
1257 $fmt = get_post_format( $wp_query->post);
1258 $type = ($fmt === 'standard' || $fmt == false)? 'post' : "post-$fmt";
1259 }
1260 } else {
1261 $type = 'unknown';
1262 }
1263 self::$is_filterkey = 'page-type-filter : ' . $type;
1264 if(is_singular()){
1265 if(!empty($single_opt) && $single_opt['filter'] === 'include'){
1266 self::$is_filterkey = 'page-type-filter : Single page option';
1267 }
1268 }
1269 } elseif(!empty($filter['_admin']['plugins'])){
1270 //Page Type 未指定時は admin type 除外フィルターのみ
1271 self::$is_filterkey = 'page-type-filter : admin filter';
1272 }
1273
1274 $new_plugins = array();
1275 foreach ( $act_plugins as $item ) {
1276 if(!empty($item)){
1277 $unload = false;
1278 $p_key = self::plugin_keygen( $item, $option );
1279 //admin filter
1280 if(!empty($filter['_admin']['plugins'])){
1281 if(in_array($p_key, array_map("trim", explode(',', $filter['_admin']['plugins'])))){
1282 $unload = true;
1283 }
1284 }
1285 //page filter
1286 if(!$unload){
1287 if(!empty($filter['_pagefilter']['plugins'])){
1288 if(in_array($p_key, array_map("trim", explode(',', $filter['_pagefilter']['plugins'])))){
1289 $unload = true;
1290
1291 //desktop/mobile device disable filter
1292 $dis_dev = true;
1293 if(is_singular() && is_object($wp_query->post)){
1294 if(!empty($single_opt) && $single_opt['filter'] === 'include'){
1295 if(!empty($single_opt[$devtype])){
1296 if(false !== strpos($single_opt[$devtype], $p_key))
1297 $dis_dev = false;
1298 elseif(strpos($p_key, 'jetpack/') !== false && strpos($single_opt[$devtype], 'jetpack_module/') !== false)
1299 $dis_dev = false;
1300 elseif(strpos($p_key, 'celtispack/') !== false && strpos($single_opt[$devtype], 'celtispack_module/') !== false)
1301 $dis_dev = false;
1302 }
1303 }
1304 }
1305 if(empty($single_opt) || $single_opt['filter'] === 'default'){
1306 if(!empty($filter['group'][$devtype]['plugins'])){
1307 if(false !== strpos($filter['group'][$devtype]['plugins'], $p_key))
1308 $dis_dev = false;
1309 elseif(strpos($p_key, 'jetpack/') !== false && strpos($filter['group'][$devtype]['plugins'], 'jetpack_module/') !== false)
1310 $dis_dev = false;
1311 elseif(strpos($p_key, 'celtispack/') !== false && strpos($filter['group'][$devtype]['plugins'], 'celtispack_module/') !== false)
1312 $dis_dev = false;
1313 }
1314 }
1315 if(!$dis_dev){
1316 //oEmbed Content API
1317 if(is_embed()){
1318 if(!empty($type) && !empty($filter['group'][$type]['plugins'])){
1319 if(false !== strpos($filter['group'][$type]['plugins'], $p_key))
1320 $unload = false;
1321 elseif(strpos($p_key, 'jetpack/') !== false && strpos($filter['group'][$type]['plugins'], 'jetpack_module/') !== false)
1322 $unload = false;
1323 elseif(strpos($p_key, 'celtispack/') !== false && strpos($filter['group'][$type]['plugins'], 'celtispack_module/') !== false)
1324 $unload = false;
1325 }
1326 } else {
1327 $pgfopt = false;
1328 if(is_singular()){
1329 if(!empty($single_opt) && $single_opt['filter'] === 'include'){
1330 $pgfopt = true;
1331 if(!empty($single_opt[$devtype])){
1332 if(false !== strpos($single_opt[$devtype], $p_key)){
1333 $unload = false;
1334 } else {
1335 //Enable plugin because plugin module is selected
1336 if(strpos($p_key, 'jetpack/') !== false && strpos($single_opt[$devtype], 'jetpack_module/') !== false)
1337 $unload = false;
1338 elseif(strpos($p_key, 'celtispack/') !== false && strpos($single_opt[$devtype], 'celtispack_module/') !== false)
1339 $unload = false;
1340 }
1341 }
1342 }
1343 }
1344 if($pgfopt === false){
1345 if(!empty($type) && !empty($filter['group'][$type]['plugins'])){
1346 if(in_array($p_key, array_map("trim", explode(',', $filter['group'][$type]['plugins'])))){
1347 $unload = false;
1348 } else {
1349 if(strpos($p_key, 'jetpack/') !== false && strpos($filter['group'][$type]['plugins'], 'jetpack_module/') !== false)
1350 $unload = false;
1351 else if(strpos($p_key, 'celtispack/') !== false && strpos($filter['group'][$type]['plugins'], 'celtispack_module/') !== false)
1352 $unload = false;
1353 }
1354 }
1355 }
1356 }
1357 }
1358 }
1359 }
1360 }
1361 if(!$unload) {
1362 if($option === 'active_sitewide_plugins') {
1363 // v4.0.6 $new_plugins[$item] = $opt_value[$item];
1364 $new_plugins[$item] = $item;
1365 } else {
1366 $new_plugins[] = $item;
1367 }
1368 }
1369 }
1370 }
1371
1372 //https://wordpress.org/support/topic/function-to-retriev-user-before-init-hook-is-fired/
1373 $new_plugins = apply_filters('plf_custom_changes_to_active_plugins', $new_plugins);
1374
1375 self::$cache[$keyid][$option] = $new_plugins;
1376 foreach ($new_plugins as $key) {
1377 if(!empty($key)){
1378 $key = self::plugin_keygen( $key, $option );
1379 self::$filtered_plugins[$key] = $key;
1380 }
1381 }
1382 return $new_plugins;
1383 }
1384 }
1385