| @@ -1,15 +1,14 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /* |
| 3 | 3 | Plugin Name: plugin load filter [plf-filter] |
| 4 | 4 | Description: Dynamically activated only plugins that you have selected in each page. [Note] plf-filter has been automatically installed / deleted by Activate / Deactivate of "load filter plugin". |
| 5 | - Version: 2.4.1 | |
| 5 | + Version: 2.3.1 | |
| 6 | 6 | Plugin URI: http://celtislab.net/wp_plugin_load_filter |
| 7 | 7 | Author: enomoto@celtislab |
| 8 | 8 | Author URI: http://celtislab.net/ |
| 9 | 9 | License: GPLv2 |
| 10 | 10 | */ |
| 11 | -defined( 'ABSPATH' ) || exit; | |
| 12 | 11 | |
| 13 | 12 | /*************************************************************************** |
| 14 | 13 | * pluggable.php defined function overwrite |
| 15 | 14 | * pluggable.php read before the query_posts () is processed by the current user undetermined |
| @@ -86,17 +85,9 @@ | ||
| 86 | 85 | /*************************************************************************** |
| 87 | 86 | * Plugin Load Filter( Admin, Desktop, Mobile, Page 4types filter) |
| 88 | 87 | **************************************************************************/ |
| 89 | 88 | |
| 90 | -if(in_array( 'plugin-load-filter/plugin-load-filter.php', (array) get_option( 'active_plugins', array() ) )){ | |
| 91 | - $plugin_load_filter = new Plf_filter(); | |
| 92 | -} | |
| 93 | -elseif ( is_multisite() ) { | |
| 94 | - $plugins = get_site_option( 'active_sitewide_plugins'); | |
| 95 | - if ( isset($plugins['plugin-load-filter/plugin-load-filter.php']) ){ | |
| 96 | - $plugin_load_filter = new Plf_filter(); | |
| 97 | - } | |
| 98 | -} | |
| 89 | +$plugin_load_filter = new Plf_filter(); | |
| 99 | 90 | |
| 100 | 91 | class Plf_filter { |
| 101 | 92 | |
| 102 | 93 | private $filter = array(); //Plugin Load Filter Setting option data |
| @@ -116,11 +107,8 @@ | ||
| 116 | 107 | } |
| 117 | 108 | |
| 118 | 109 | $this->cache = null; |
| 119 | 110 | if(!empty($this->filter)){ |
| 120 | - if ( is_multisite() ) { | |
| 121 | - add_filter('pre_site_option_active_sitewide_plugins', array(&$this, 'active_sitewide_plugins')); | |
| 122 | - } | |
| 123 | 111 | add_filter('pre_option_active_plugins', array(&$this, 'active_plugins')); |
| 124 | 112 | add_filter('pre_option_jetpack_active_modules', array(&$this, 'active_jetmodules')); |
| 125 | 113 | add_filter('pre_option_celtispack_active_modules', array(&$this, 'active_celtismodules')); |
| 126 | 114 | add_action('wp_loaded', array(&$this, 'cache_post_type'), 1); |
| @@ -126,14 +114,9 @@ | ||
| 126 | 114 | add_action('wp_loaded', array(&$this, 'cache_post_type'), 1); |
| 127 | 115 | } |
| 128 | 116 | } |
| 129 | 117 | |
| 130 | - //active_sitewide plugins Filter add ver2.4.0 | |
| 131 | - function active_sitewide_plugins( $default = false) { | |
| 132 | - return $this->plf_filter( 'active_sitewide_plugins', $default); | |
| 133 | - } | |
| 134 | - | |
| 135 | - //active plugins Filter | |
| 118 | + //Active plugins Filter | |
| 136 | 119 | function active_plugins( $default = false) { |
| 137 | 120 | return $this->plf_filter( 'active_plugins', $default); |
| 138 | 121 | } |
| 139 | 122 | |
| @@ -146,18 +129,8 @@ | ||
| 146 | 129 | function active_celtismodules( $default = false) { |
| 147 | 130 | return $this->plf_filter( 'celtispack_active_modules', $default); |
| 148 | 131 | } |
| 149 | 132 | |
| 150 | - //Make taxonomies and posts available to 'plugin load filter'. | |
| 151 | - //force register_taxonomy (category, post_tag, post_format) | |
| 152 | - function force_initial_taxonomies(){ | |
| 153 | - global $wp_actions; | |
| 154 | - $wp_actions[ 'init' ] = 1; | |
| 155 | - create_initial_taxonomies(); | |
| 156 | - create_initial_post_types(); | |
| 157 | - unset($wp_actions[ 'init' ]); | |
| 158 | - } | |
| 159 | - | |
| 160 | 133 | //Post Format Type, Custom Post Type Data Cache for parse request |
| 161 | 134 | function cache_post_type() { |
| 162 | 135 | if (!is_admin() || ( defined('DOING_AJAX') && DOING_AJAX ) || (defined('DOING_CRON') && DOING_CRON)) |
| 163 | 136 | return; |
| @@ -162,9 +135,8 @@ | ||
| 162 | 135 | if (!is_admin() || ( defined('DOING_AJAX') && DOING_AJAX ) || (defined('DOING_CRON') && DOING_CRON)) |
| 163 | 136 | return; |
| 164 | 137 | |
| 165 | 138 | global $wp; |
| 166 | - global $wp_post_statuses; | |
| 167 | 139 | $public_query_vars = (!empty($wp->public_query_vars))? $wp->public_query_vars : array();; |
| 168 | 140 | $post_type_query_vars = array(); |
| 169 | 141 | foreach ( get_post_types( array(), 'objects' ) as $post_type => $t ){ |
| 170 | 142 | if ( $t->query_var ) |
| @@ -176,15 +148,13 @@ | ||
| 176 | 148 | if(!empty($post_type_query_vars) && !empty($queryable_post_types)){ |
| 177 | 149 | $data['public_query_vars'] = $public_query_vars; |
| 178 | 150 | $data['post_type_query_vars'] = $post_type_query_vars; |
| 179 | 151 | $data['queryable_post_types'] = $queryable_post_types; |
| 180 | - $data['wp_post_statuses'] = $wp_post_statuses; | |
| 181 | 152 | update_option('plf_queryvars', $data); |
| 182 | 153 | } |
| 183 | 154 | else if(!empty($data['post_type_query_vars']) || !empty($data['queryable_post_types'])){ |
| 184 | 155 | delete_option('plf_queryvars'); |
| 185 | 156 | } |
| 186 | - | |
| 187 | 157 | } |
| 188 | 158 | |
| 189 | 159 | //parse_request Action Hook for Custom Post Type query add |
| 190 | 160 | function parse_request( &$args ) { |
| @@ -190,12 +160,10 @@ | ||
| 190 | 160 | function parse_request( &$args ) { |
| 191 | 161 | if (did_action( 'plugins_loaded' ) === 0 ) { |
| 192 | 162 | $data = get_option('plf_queryvars'); |
| 193 | 163 | if(!empty($data['post_type_query_vars']) && !empty($data['queryable_post_types'])){ |
| 194 | - global $wp_post_statuses; | |
| 195 | 164 | $post_type_query_vars = $data['post_type_query_vars']; |
| 196 | 165 | $queryable_post_types = $data['queryable_post_types']; |
| 197 | - $wp_post_statuses = $data['wp_post_statuses']; | |
| 198 | 166 | |
| 199 | 167 | $args->public_query_vars = $data['public_query_vars']; |
| 200 | 168 | if ( isset( $args->matched_query ) ) { |
| 201 | 169 | parse_str($args->matched_query, $perma_query_vars); |
| @@ -239,9 +207,8 @@ | ||
| 239 | 207 | } |
| 240 | 208 | } |
| 241 | 209 | } |
| 242 | 210 | |
| 243 | - | |
| 244 | 211 | //Plugin Load Filter Main (active plugins/modules filtering) |
| 245 | 212 | function plf_filter( $option, $default = false) { |
| 246 | 213 | if ( defined( 'WP_SETUP_CONFIG' ) ) |
| 247 | 214 | return false; |
| @@ -250,133 +217,61 @@ | ||
| 250 | 217 | if(is_admin()) |
| 251 | 218 | return false; |
| 252 | 219 | |
| 253 | 220 | if ( ! defined( 'WP_INSTALLING' ) ) { |
| 254 | - global $wpdb, $current_site; | |
| 255 | - // if ( ! wp_installing() ) { // WP4.4 | |
| 256 | - if ( is_multisite() && $option === 'active_sitewide_plugins' ) { | |
| 257 | - //get_network_option() current site ID | |
| 258 | - $network_id = $current_site->id; | |
| 221 | + // prevent non-existent options from triggering multiple queries | |
| 222 | + $notoptions = wp_cache_get( 'notoptions', 'options' ); | |
| 223 | + if ( isset( $notoptions[$option] ) ) | |
| 224 | + return apply_filters( 'default_option_' . $option, $default ); | |
| 259 | 225 | |
| 260 | - // prevent non-existent options from triggering multiple queries | |
| 261 | - $notoptions_key = "$network_id:notoptions"; | |
| 262 | - $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); | |
| 263 | - if ( isset( $notoptions[ $option ] ) ) { | |
| 264 | - return apply_filters( 'default_site_option_' . $option, $default, $option ); | |
| 265 | - } | |
| 226 | + $alloptions = wp_load_alloptions(); | |
| 227 | + if ( isset( $alloptions[$option] ) ) { | |
| 228 | + $value = $alloptions[$option]; | |
| 229 | + } else { | |
| 230 | + $value = wp_cache_get( $option, 'options' ); | |
| 266 | 231 | |
| 267 | - $cache_key = "$network_id:$option"; | |
| 268 | - $value = wp_cache_get( $cache_key, 'site-options' ); | |
| 232 | + if ( false === $value ) { | |
| 233 | + $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) ); | |
| 269 | 234 | |
| 270 | - if ( ! isset( $value ) || false === $value ) { | |
| 271 | - $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $network_id ) ); | |
| 272 | - | |
| 273 | 235 | // Has to be get_row instead of get_var because of funkiness with 0, false, null values |
| 274 | 236 | if ( is_object( $row ) ) { |
| 275 | - $value = $row->meta_value; | |
| 276 | - $value = maybe_unserialize( $value ); | |
| 277 | - wp_cache_set( $cache_key, $value, 'site-options' ); | |
| 278 | - } else { | |
| 279 | - if ( ! is_array( $notoptions ) ) { | |
| 280 | - $notoptions = array(); | |
| 281 | - } | |
| 282 | - $notoptions[ $option ] = true; | |
| 283 | - wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); | |
| 237 | + $value = $row->option_value; | |
| 238 | + wp_cache_add( $option, $value, 'options' ); | |
| 239 | + } else { // option does not exist, so we must cache its non-existence | |
| 240 | + $notoptions[$option] = true; | |
| 241 | + wp_cache_set( 'notoptions', $notoptions, 'options' ); | |
| 284 | 242 | |
| 285 | 243 | /** This filter is documented in wp-includes/option.php */ |
| 286 | - $value = apply_filters( 'default_site_option_' . $option, $default, $option ); | |
| 244 | + return apply_filters( 'default_option_' . $option, $default ); | |
| 287 | 245 | } |
| 288 | 246 | } |
| 289 | 247 | } |
| 290 | - else { | |
| 291 | - // prevent non-existent options from triggering multiple queries | |
| 292 | - $notoptions = wp_cache_get( 'notoptions', 'options' ); | |
| 293 | - if ( isset( $notoptions[$option] ) ) | |
| 294 | - return apply_filters( 'default_option_' . $option, $default ); | |
| 295 | - | |
| 296 | - $alloptions = wp_load_alloptions(); | |
| 297 | - if ( isset( $alloptions[$option] ) ) { | |
| 298 | - $value = $alloptions[$option]; | |
| 299 | - } else { | |
| 300 | - $value = wp_cache_get( $option, 'options' ); | |
| 301 | - | |
| 302 | - if ( false === $value ) { | |
| 303 | - $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) ); | |
| 304 | - | |
| 305 | - // Has to be get_row instead of get_var because of funkiness with 0, false, null values | |
| 306 | - if ( is_object( $row ) ) { | |
| 307 | - $value = $row->option_value; | |
| 308 | - wp_cache_add( $option, $value, 'options' ); | |
| 309 | - } else { // option does not exist, so we must cache its non-existence | |
| 310 | - if ( ! is_array( $notoptions ) ) { | |
| 311 | - $notoptions = array(); | |
| 312 | - } | |
| 313 | - $notoptions[$option] = true; | |
| 314 | - wp_cache_set( 'notoptions', $notoptions, 'options' ); | |
| 315 | - | |
| 316 | - /** This filter is documented in wp-includes/option.php */ | |
| 317 | - return apply_filters( 'default_option_' . $option, $default, $option ); | |
| 318 | - } | |
| 319 | - } | |
| 320 | - } | |
| 321 | - } | |
| 322 | 248 | } else { |
| 323 | 249 | return false; |
| 324 | 250 | } |
| 325 | 251 | |
| 326 | - //Equal treatment for when the wp_is_mobile is not yet available(wp-include/vars.php wp_is_mobile) | |
| 327 | - if ( empty($_SERVER['HTTP_USER_AGENT']) ) { | |
| 328 | - $is_mobile = false; | |
| 329 | - } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.) | |
| 330 | - || strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false | |
| 331 | - || strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false | |
| 332 | - || strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false | |
| 333 | - || strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false | |
| 334 | - || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false | |
| 335 | - || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false ) { | |
| 336 | - $is_mobile = true; | |
| 337 | - } else { | |
| 338 | - $is_mobile = false; | |
| 339 | - } | |
| 340 | - $is_mobile = apply_filters( 'custom_is_mobile' , $is_mobile ); | |
| 341 | - | |
| 342 | 252 | $filter = $this->filter; |
| 343 | 253 | //get_option is called many times, intermediate processing data to cache |
| 344 | - $keyid = md5('plf_'. (string)$is_mobile . $_SERVER['REQUEST_URI']); | |
| 254 | + $keyid = md5('plf_'. (string)wp_is_mobile(). $_SERVER['REQUEST_URI']); | |
| 345 | 255 | if(!empty($this->cache[$keyid][$option])){ |
| 346 | - return $this->cache[$keyid][$option]; | |
| 256 | + return apply_filters( 'option_' . $option, $this->cache[$keyid][$option]); | |
| 347 | 257 | } |
| 348 | 258 | |
| 349 | 259 | //Before plugins loaded, it does not use conditional branch such as is_home, to set wp_query, wp in temporary query |
| 350 | 260 | if(empty($GLOBALS['wp_the_query'])){ |
| 351 | - $rewrite_rules = get_option('rewrite_rules'); //save rewrite_rules | |
| 352 | - | |
| 353 | 261 | $GLOBALS['wp_the_query'] = new WP_Query(); |
| 354 | 262 | $GLOBALS['wp_query'] = $GLOBALS['wp_the_query']; |
| 355 | 263 | $GLOBALS['wp_rewrite'] = new WP_Rewrite(); |
| 356 | 264 | $GLOBALS['wp'] = new WP(); |
| 357 | - //register_taxonomy(category, post_tag, post_format) support for is_archive | |
| 358 | - $this->force_initial_taxonomies(); | |
| 359 | 265 | //Post Format, Custom Post Type support |
| 360 | 266 | add_action('parse_request', array(&$this, 'parse_request')); |
| 361 | 267 | $GLOBALS['wp']->parse_request(''); |
| 362 | 268 | $GLOBALS['wp']->query_posts(); |
| 363 | - | |
| 364 | - //Discard the temporarily generated 'rewrite_rules' | |
| 365 | - update_option('rewrite_rules', $rewrite_rules); //return rewrite_rules | |
| 366 | 269 | } |
| 367 | 270 | //Only available display pages (login, cron, ajax request ... excluded) |
| 368 | 271 | //downloadmanager plugin downloadlink request [home]/?wpdmact=XXXXXX exclude home GET query |
| 369 | - //bbPress users page requests are treated the same as is_home | |
| 370 | 272 | global $wp_query; |
| 371 | 273 | if(!(function_exists('is_embed') && is_embed())){ |
| 372 | - | |
| 373 | - | |
| 374 | - //ToDo Next Version AMP page judgment (is_amp similer is_embed) by enomoto | |
| 375 | - //ToDo is_sinbular() and URL "/amp(/(.*))?/?$" check ? | |
| 376 | - | |
| 377 | - | |
| 378 | - | |
| 379 | 274 | if((is_home() || is_front_page() || is_archive() || is_search() || is_singular()) == false |
| 380 | 275 | || (is_home() && !empty($_GET)) |
| 381 | 276 | || (is_singular() && empty($wp_query->post))){ |
| 382 | 277 | return false; |
| @@ -381,10 +276,10 @@ | ||
| 381 | 276 | || (is_singular() && empty($wp_query->post))){ |
| 382 | 277 | return false; |
| 383 | 278 | } |
| 384 | 279 | } |
| 385 | - | |
| 386 | - $us_value = ($option === 'active_sitewide_plugins')? array_keys( (array)$value ) : maybe_unserialize( $value ); | |
| 280 | + | |
| 281 | + $us_value = maybe_unserialize( $value ); | |
| 387 | 282 | $new_value = array(); |
| 388 | 283 | foreach ( $us_value as $item ) { |
| 389 | 284 | $unload = false; |
| 390 | 285 | //Jetpack module slug / Celtiapack module slug / Plugin php file name |
| @@ -410,9 +305,9 @@ | ||
| 410 | 305 | |
| 411 | 306 | //desktop/mobile device disable filter |
| 412 | 307 | $single_opt = false; |
| 413 | 308 | $dis_dev = true; |
| 414 | - $devtype = ($is_mobile)? 'mobile' : 'desktop'; | |
| 309 | + $devtype = (wp_is_mobile())? 'mobile' : 'desktop'; | |
| 415 | 310 | if(is_singular() && is_object($wp_query->post)){ |
| 416 | 311 | $myfilter = get_post_meta( $wp_query->post->ID, '_plugin_load_filter', true ); |
| 417 | 312 | //For ver2.2.0 compatibility, set 'plugins' data to 'desktop' and 'mobile' |
| 418 | 313 | if(!empty($myfilter['plugins'])){ |
| @@ -454,10 +349,8 @@ | ||
| 454 | 349 | else if(strpos($p_key, 'celtispack/') !== false && strpos($filter['group'][$type]['plugins'], 'celtispack_module/') !== false) |
| 455 | 350 | $unload = false; |
| 456 | 351 | } |
| 457 | 352 | } |
| 458 | - //ToDo elseif($this->is_amp()){ | |
| 459 | - //ToDo } | |
| 460 | 353 | else { |
| 461 | 354 | $pgfopt = false; |
| 462 | 355 | if(is_singular()){ |
| 463 | 356 | if(!empty($single_opt) && $single_opt['filter'] === 'include'){ |
| @@ -510,14 +403,11 @@ | ||
| 510 | 403 | } |
| 511 | 404 | } |
| 512 | 405 | } |
| 513 | 406 | if(!$unload) { |
| 514 | - if($option === 'active_sitewide_plugins') | |
| 515 | - $new_value[$item] = $value[$item]; | |
| 516 | - else | |
| 517 | - $new_value[] = $item; | |
| 407 | + $new_value[] = $item; | |
| 518 | 408 | } |
| 519 | 409 | } |
| 520 | 410 | $this->cache[$keyid][$option] = $new_value; |
| 521 | - return $new_value; | |
| 411 | + return apply_filters( 'option_' . $option, $new_value ); | |
| 522 | 412 | } |
| 523 | 413 | } |