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