php 端口切换以获得使用WordPress Multisite的解决方法,也没有默认端口80。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 端口切换以获得使用WordPress Multisite的解决方法,也没有默认端口80。相关的知识,希望对你有一定的参考价值。

<?php # -*- coding: utf-8 -*-
declare( strict_types = 1 ); 
/**
 * Plugin Name: Port Switch
 * Plugin URI:  https://gist.github.com/bueltge/51013ab809f5f0f5e305c70c2d393fff
 * Description: Port switch to get an workaround to use WordPress Multisite also without the default port 80.
 * Version:     dev
 * Author:      Frank Bültge
 * Author URI:  https://bueltge.de
 * License:     MIT
 * License URI: LICENSE
 *
 * Kudos to https://benohead.com/wordpress-running-multisite-different-port/
 * Kudos to https://wordpress.stackexchange.com/questions/212978/multisite-network-port-num-issues
 */

namespace Bueltge\PortSwitch;

defined( 'ABSPATH' ) || die();

const PORT = 81;

/**
 * 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 ) {

	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 );

	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 ) {

			// 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;
	} );
} );

add_filter( 'gettext', function( $text, $original, $domain) {

	add_action( 'current_screen', function() {

		if ( 'network' !== get_current_screen()->id ) {
			return;
		}
	} );

	switch( $original ) {
		
		case 'The internet address of your network will be %s.':
			$text = sprintf(
				__( 'The internet address of your network will be: %s', 'portswitch' ),
				'<code>' . get_clean_basedomain() . '</code>'
			);
			break;
	}
	
	return $text;
}, 99, 3 );

以上是关于php 端口切换以获得使用WordPress Multisite的解决方法,也没有默认端口80。的主要内容,如果未能解决你的问题,请参考以下文章

php WordPress mu-plugin,添加管理栏集成,以指示dev / staging网站是干净还是脏。 https://cloudup.com/cip1BZXH8kC

php WordPress mu-plugin,添加管理栏集成,以指示dev / staging网站是干净还是脏。 https://cloudup.com/cip1BZXH8kC

PHP Wordpress MU timthumb修复

PHP 在Wordpress MU和Buddypress上的地图上显示用户

php [WordPress] [WP Rocket]自定义功能(MU)插件的Boilerplate。

php WordPress mu-plugin概念证明可自动禁用开始抛出错误的插件。