警告:这仅是针对开发人员安装而非生产站点的测试
我很想知道是否有一种解决方法,对于那些想要在开发人员安装中但不在与:80
and的不同端口上开发多站点的人:443
,例如:8080
。
我只找到Henri Benoit的这篇博客文章。他在那里举例说明如何修改3.9.1核心,以避开核心限制。
这是一个必须使用的插件/wp-content/mu-plugins/wpse-ms-on-different-port.php
,在其中我们尝试避免进行核心修改:
<?php
/**
* Test for multisite support on a different port than :80 and :443 (e.g. :8080)
*
* Here we assume that the 'siteurl' and 'home' options contain the :8080 port
*
* WARNING: Not suited for production sites!
*/
/**
* Get around the problem with wpmu_create_blog() where sanitize_user()
* strips out the semicolon (:) in the $domain string
* This means created sites with hostnames of
* e.g. example.tld8080 instead of example.tld:8080
*/
add_filter( 'sanitize_user', function( $username, $raw_username, $strict )
{
// Edit the port to your needs
$port = 8080;
if( $strict // wpmu_create_blog uses strict mode
&& is_multisite() // multisite check
&& $port == parse_url( $raw_username, PHP_URL_PORT ) // raw domain has port
&& false === strpos( $username, ':' . $port ) // stripped domain is without correct port
)
$username = str_replace( $port, ':' . $port, $username ); // replace e.g. example.tld8080 to example.tld:8080
return $username;
}, 1, 3 );
/**
* Temporarly change the port (e.g. :8080 ) to :80 to get around
* the core restriction in the network.php page.
*/
add_action( 'load-network.php', function()
{
add_filter( 'option_active_plugins', function( $value )
{
add_filter( 'option_siteurl', function( $value )
{
// Edit the port to your needs
$port = 8080;
// Network step 2
if( is_multisite() || network_domain_check() )
return $value;
// Network step 1
static $count = 0;
if( 0 === $count++ )
$value = str_replace( ':' . $port, ':80', $value );
return $value;
} );
return $value;
} );
} );
我只是在我的开发人员安装上测试过,但是当然这可能需要更多检查;-)
echo get_clean_basedomain();
什么?支持的端口似乎是:80
和:443
。