Changeset 3186851
- Timestamp:
- 11/13/2024 01:35:42 AM (14 months ago)
- Location:
- plugin-load-filter/trunk
- Files:
-
- 3 edited
-
mu-plugins/plf-filter.php (modified) (11 diffs)
-
plugin-load-filter.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
plugin-load-filter/trunk/mu-plugins/plf-filter.php
r3066500 r3186851 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. 1.15 Version: 4.2.0 6 6 Plugin URI: http://celtislab.net/en/wp-plugin-load-filter 7 7 Author: enomoto@celtislab … … 43 43 */ 44 44 function wp_get_current_user() { 45 if ( ! function_exists( 'wp_set_current_user' ) ){ 45 static $_current_user = null; 46 if ( did_action( 'setup_theme' ) === 0 ){ 46 47 if ( defined( 'LOGGED_IN_COOKIE' ) && !empty( $_COOKIE[ LOGGED_IN_COOKIE ] ) ) { 47 48 $cookie_elements = explode( '|', $_COOKIE[ LOGGED_IN_COOKIE ] ); … … 49 50 list( $username, $expiration, $token, $hmac ) = $cookie_elements; 50 51 if ( $expiration > time() ) { 52 if (!empty($_current_user) && $_current_user->user_login === $username){ 53 return $_current_user; 54 } 51 55 $user = get_user_by( 'login', $username ); 52 if ( $user ) { 56 if ( $user ) { 53 57 $pass_frag = substr( $user->user_pass, 8, 4 ); 54 55 58 $key = plf_logged_in_hash( $username . '|' . $pass_frag . '|' . $expiration . '|' . $token ); 56 59 … … 62 65 $manager = WP_Session_Tokens::get_instance( $user->ID ); 63 66 if ( $manager->verify( $token ) ) { 67 //この時点のユーザーは仮ユーザーデータであり $current_user は未設定とする 68 $_current_user = $user; 64 69 return $user; 65 70 } … … 75 80 76 81 } else { 82 //$GLOBALS['wp_roles'] セット後の setup_theme アクション後に $current_user を設定する 83 //※使用プラグインの組み合わせにもよるが、想定外に早い $current_user 設定は bbpress 等の一部プラグインにおいて capability 動的追加が反映されないことがあるため 77 84 return _wp_get_current_user(); 78 85 } … … 190 197 add_filter('pre_option_jetpack_active_modules', array('Plf_filter', 'active_jetmodules')); 191 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); 192 201 193 202 add_action('update_option_active_plugins', array($this, 'update_active_plugins'), 99999, 3); … … 506 515 } 507 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 508 565 //プラグインロード前は bbPress等 カスタムポストタイプのデバッグモードでのエラー表示抑制 509 566 static function exclude_trigger_error( $trigger, $function, $message, $version) { … … 787 844 } 788 845 } 846 $post_id = apply_filters('plf_singler_custom_url_to_postid', $post_id, $parse_url['path'], self::$base_plugins); 847 if(!empty($post_id)){ 848 if(empty($wp_query->post)){ 849 $r = new WP_Query( array( 'p' => $post_id, 'post_type' => 'any' ) ); 850 if ($r->have_posts()) { 851 if(!empty($r->post)){ 852 $wp_query->posts = $r->posts; 853 $wp_query->post = $r->post; 854 } 855 } 856 } 857 self::$url2id[$req_url] = (int)$post_id; 858 } 789 859 } 790 860 if(!empty($post_id)){ … … 1016 1086 1017 1087 //Equal treatment for when the wp_is_mobile is not yet available(wp-include/vars.php wp_is_mobile) 1018 if ( empty($_SERVER['HTTP_USER_AGENT']) ) { 1088 if ( isset( $_SERVER['HTTP_SEC_CH_UA_MOBILE'] ) ) { 1089 // This is the `Sec-CH-UA-Mobile` user agent client hint HTTP request header. 1090 // See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-UA-Mobile>. 1091 $is_mobile = ( '?1' === $_SERVER['HTTP_SEC_CH_UA_MOBILE'] ); 1092 } elseif ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { 1019 1093 $is_mobile = false; 1020 } elseif ( str pos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.)1021 || str pos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false1022 || str pos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false1023 || str pos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false1024 || str pos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false1025 || str pos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false1026 || str pos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false) {1094 } elseif ( str_contains( $_SERVER['HTTP_USER_AGENT'], 'Mobile' ) // Many mobile devices (all iPhone, iPad, etc.) 1095 || str_contains( $_SERVER['HTTP_USER_AGENT'], 'Android' ) 1096 || str_contains( $_SERVER['HTTP_USER_AGENT'], 'Silk/' ) 1097 || str_contains( $_SERVER['HTTP_USER_AGENT'], 'Kindle' ) 1098 || str_contains( $_SERVER['HTTP_USER_AGENT'], 'BlackBerry' ) 1099 || str_contains( $_SERVER['HTTP_USER_AGENT'], 'Opera Mini' ) 1100 || str_contains( $_SERVER['HTTP_USER_AGENT'], 'Opera Mobi' ) ) { 1027 1101 $is_mobile = true; 1028 1102 } else { … … 1182 1256 } 1183 1257 if(empty($wp_query->post)){ 1258 //パーマリンクをカスタムするプラグイン等により URL から post ID が所得できない場合用のフィルターフック 1259 $post_id = apply_filters('plf_singler_custom_url_to_postid', 0, $parse_url['path'], self::$base_plugins); 1260 if(!empty($post_id)){ 1261 $r = new WP_Query( array( 'p' => $post_id, 'post_type' => 'any' ) ); 1262 if ($r->have_posts()) { 1263 if(!empty($r->post)){ 1264 $wp_query->posts = $r->posts; 1265 $wp_query->post = $r->post; 1266 } 1267 } 1268 } 1269 } 1270 if(empty($wp_query->post)){ 1184 1271 $unknown = true; 1185 1272 } … … 1188 1275 1189 1276 $single_opt = array(); 1190 if(is_singular() && is_object($wp_query->post)){ 1191 self::$pre_post_id = $wp_query->post->ID; //for post_locale() 1192 $myfilter = get_post_meta( $wp_query->post->ID, '_plugin_load_filter', true ); 1193 $default = array( 'filter' => 'default', 'desktop' => '', 'mobile' => ''); 1194 $single_opt = (!empty($myfilter))? $myfilter : $default; 1195 $single_opt = wp_parse_args( $single_opt, $default); 1277 if(is_singular()){ 1278 if(is_object($wp_query->post)){ 1279 self::$pre_post_id = $wp_query->post->ID; //for post_locale() 1280 $myfilter = get_post_meta( $wp_query->post->ID, '_plugin_load_filter', true ); 1281 $default = array( 'filter' => 'default', 'desktop' => '', 'mobile' => ''); 1282 $single_opt = (!empty($myfilter))? $myfilter : $default; 1283 $single_opt = wp_parse_args( $single_opt, $default); 1284 } 1196 1285 } 1197 1286 if(!empty(self::$s_url_filter)){ -
plugin-load-filter/trunk/plugin-load-filter.php
r3066500 r3186851 3 3 Plugin Name: plugin load filter 4 4 Description: Dynamically activate the selected plugins for each page. Response will be faster by filtering plugins. 5 Version: 4. 1.15 Version: 4.2.0 6 6 Plugin URI: https://celtislab.net/en/wp-plugin-load-filter 7 7 Author: enomoto@celtislab 8 8 Author URI: https://celtislab.net/ 9 9 Requires at least: 5.3 10 Tested up to: 6. 510 Tested up to: 6.7 11 11 Requires PHP: 7.2 12 12 License: GPLv2 … … 183 183 public function __construct() { 184 184 185 load_plugin_textdomain('plf', false, basename( dirname( __FILE__ ) ).'/languages');186 185 add_action('init', function(){ load_plugin_textdomain('plf', false, basename( dirname( __FILE__ ) ).'/languages' ); }, 1); 186 187 187 self::$filter = get_option('plf_option', array()); 188 188 if(empty(self::$filter['optver']) || self::$filter['optver'] < '2'){ -
plugin-load-filter/trunk/readme.txt
r3066500 r3186851 3 3 Tags: dynamic deactivate plugins, disable plugins, performance, Locale switching 4 4 Requires at least: 5.3 5 Tested up to: 6. 55 Tested up to: 6.7 6 6 Requires PHP: 7.2 7 Stable tag: 4. 1.17 Stable tag: 4.2.0 8 8 Donate link: https://celtislab.net/en/wp-plugin-load-filter-addon/ 9 9 License: GPLv2 … … 82 82 == Changelog == 83 83 84 = 4.2.0 = 85 * 2024-11-12 86 * tested WP6.7 87 * Adjusted timing $current_user setting when calling wp_get_current_user is after setup_theme action. 88 * Added filter hook plf_singler_custom_url_to_postid for when post ID cannot be detected from the singler URL due to using a permalink change plugin etc. 89 * plf_singler_custom_url_to_postid filter hook has been used to get Post ID from custom URL of Permalink Manger or Custom Permalinks plugins. 90 * Fixed the call to load_plugin_textdomain to init hook. 91 92 84 93 = 4.1.1 = 85 94 * 2024-4-8
Note: See TracChangeset
for help on using the changeset viewer.