WP-Mobile-Pack在Multisite模式下的修正
WordPress Mobile Pack插件为Wordpress站点提供适合移动设备浏览的页面. WPMP支持3种检测模式:
1. 根据浏览器User-Agent决定博客输出,
2. 为博客单独设置一个Mobile域名, 根据用户访问的域名决定输出,
3. 上述基于浏览器和基于域名的结合.
从3.0版本开始, WordPress支持Multisite模模式, 也就是原先的Wordpress-MU的延续. 在Multisite模式下, 可以用同一套Wordpress软件和数据库同时管理多个Blog. 通过domain_mapping插件, 还可以为每个Blog设置多个域名. domain_mapping插件可以为每个Blog设置一个主域名, 并且将其他域名的访问请求通过”Permanent Redirect”的方法重定向到主域名上, 据说这样可以提高站点的Pagerank. Anyway, 这个功能一般推荐选上, 如下图所示:

不过, domain_mapping插件的Permanent Redirect功能和WPMP的Mobile域名功能冲突, 当用户访问WPMP给站点设置的Mobile域名的时候, 会被domain_mapping插件重定向到主域名.
解决WPMP插件和domain_mapping插件之间的冲突, 需要首先修改domain_mapping.php中redirect_to_mapped_domain函数的实现, 或者下载我已经改好的文件:
domain_mapping.php (34.9 KiB, 1,039 hits)
function redirect_to_mapped_domain() { global $current_blog, $wpdb; if ( !isset( $_SERVER[ 'HTTPS' ] ) ) $_SERVER[ 'HTTPS' ] = "off"; $protocol = ( 'on' == strtolower($_SERVER['HTTPS']) ) ? 'https://' : 'http://'; $url = domain_mapping_siteurl( false ); $urltmp = untrailingslashit( $protocol . $current_blog->domain . $current_blog->path ); $is_alias = false; if (function_exists('wpmp_switcher_domains')) { $is_alias = ( $current_blog->domain == wpmp_switcher_domains('mobile', true) || $current_blog->domain == wpmp_switcher_domains('desktop', true) ); } if ( $url && $url != $urltmp && !$is_alias ) { $redirect = get_site_option( 'dm_301_redirect' ) ? '301' : '302'; if ( ( defined( 'VHOST' ) && constant( "VHOST" ) != 'yes' ) || ( defined( 'SUBDOMAIN_INSTALL' ) && constant( 'SUBDOMAIN_INSTALL' ) == false ) ) { $_SERVER[ 'REQUEST_URI' ] = str_replace( $current_blog->path, '/', $_SERVER[ 'REQUEST_URI' ] ); } header( "Location: {$url}{$_SERVER[ 'REQUEST_URI' ]}", true, $redirect ); exit; } }
除此之外, WPMP插件自身在Mobile域名模式下也有一些bug, 导致用户不能在Mobile站点和普通站点之间进行正确的切换. 下载下面的文件, 替换wordpress-mobile-pack插件子目录plugins/wpmp_switcher/下的wpmp_switcher.php文件, 可以解决上述bug. 具体修改参见如下patch:
wpmp_switcher.php (25.9 KiB, 442 hits)
diff --git a/wp-content/plugins/wordpress-mobile-pack/plugins/wpmp_switcher/wpmp_switcher.php b/wp-content/plugins/wordpress-mobile-pack/plugins/wpmp_switcher/wpmp_switcher.php index ed46c88..2949ebb 100755 --- a/wp-content/plugins/wordpress-mobile-pack/plugins/wpmp_switcher/wpmp_switcher.php +++ b/wp-content/plugins/wordpress-mobile-pack/plugins/wpmp_switcher/wpmp_switcher.php @@ -92,12 +92,10 @@ function wpmp_switcher_init() { wpmp_switcher_mobile_interstitial(); break; case WPMP_SWITCHER_REDIRECT_TO_MOBILE: - wpmp_switcher_set_cookie('mobile'); $target_url = "http://" . wpmp_switcher_domains('mobile', true) . wpmp_switcher_current_path_plus_cgi(); header("Location: $target_url"); exit; case WPMP_SWITCHER_REDIRECT_TO_DESKTOP: - wpmp_switcher_set_cookie('desktop'); $target_url = "http://" . wpmp_switcher_domains('desktop', true) . wpmp_switcher_current_path_plus_cgi(); header("Location: $target_url"); exit; @@ -373,13 +371,13 @@ function wpmp_switcher_outcome_process($switcher_mode, $desktop_domain, $mobile_ case 'browserdomain': if ($desktop_domain) { if ($desktop_browser) { - if (($mobile_cookie && !$cgi) || $cgi == 'mobile') { + if ($mobile_cookie && !$cgi) { return WPMP_SWITCHER_REDIRECT_TO_MOBILE; } else { return WPMP_SWITCHER_DESKTOP_PAGE; } } else { - if (($desktop_cookie && !$cgi) || $cgi == 'desktop') { + if ($cgi || $desktop_cookie) { return WPMP_SWITCHER_DESKTOP_PAGE; } else { if ($mobile_cookie) { @@ -474,7 +472,7 @@ function wpmp_switcher_is_cgi_parameter_present() { function wpmp_switcher_link($type, $label) { $cookie = WPMP_SWITCHER_COOKIE_VAR . "=$type;path=/;expires=Tue, 01-01-2030 00:00:00 GMT"; - $target_url = "http://" . wpmp_switcher_domains('desktop', true) . wpmp_switcher_current_path_plus_cgi('', $type); + $target_url = "http://" . wpmp_switcher_domains($type, true) . wpmp_switcher_current_path_plus_cgi('', $type); if ($target_url) { return "<a onclick='document.cookie=\"$cookie\";' href='$target_url'>$label</a>"; }
Recent Comments