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