Skip to main content
added 132 characters in body
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251

Update: Finally supported in WP 6.6. The core ticket here was recently merged in and closed.

Update: Finally supported in WP 6.6. The core ticket here was recently merged and closed.

Update: Finally supported in WP 6.6. The core ticket here was recently merged in and closed.

added 132 characters in body
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251

Update: Finally supported in WP 6.6. The core ticket here was recently merged and closed.

Older answer:

Warning: This is just a test for dev installs and not production sites

Warning: This is just a test for dev installs and not production sites

Update: Finally supported in WP 6.6. The core ticket here was recently merged and closed.

Older answer:

Warning: This is just a test for dev installs and not production sites

added 716 characters in body
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251

I was curious to see if there was a workaround, for those who want to develope multisites on their dev installs but on different ports than :80:80 and :443:443, e.g. 8080:8080.

<?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 containscontain the :8080 port
 *
 * WARNING: Not suited for production sites!
 */

/**
 * Get around the problem with wpmu_createblogwpmu_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( false !  $strict                                                // wpmu_create_blog uses strict mode
        && is_multisite()                                         // multisite check
        && $port == strposparse_url( $raw_username, ':8080'PHP_URL_PORT )      // raw domain has port 
        && false === strpos( $username, ':8080'' . $port )             // stripped domain is without correct port
    )
        $username = str_replace( '8080'$port, ':8080'' . $port, $username ); // replace e.g. example.tld8080 to example.tld:8080

    return $username;
}, 1, 3 );

/**
 * Temporarly change the port from(e.g. :8080 ) to :80 to get around 
 * the core restriction onin 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( ':8080'' . $port, ':80', $value );
            return $value;
        } );
        return $value;
    } );
} );

I was curious to see if there was a workaround, for those who want to develope multisites on their dev installs but on different ports than :80 and :443, e.g. 8080.

<?php 
/**
 * Test for multisite support on a different port than :80 and :443 (e.g. :8080)
 *
 * Here we assume that 'siteurl' and 'home' options contains the :8080 port
 *
 * WARNING: Not suited for production sites!
 */

/**
 * Get around the problem with wpmu_createblog where sanitize_user()  
 * strips out the semicolon (:) in the $domain string
 */
add_filter( 'sanitize_user', function( $username, $raw_username, $strict )
{
    if( false !== strpos( $raw_username, ':8080' ) && false === strpos( $username, ':8080' ) )
        $username = str_replace( '8080', ':8080', $username );

    return $username;
}, 1, 3 );

/**
 * Temporarly change the port from :8080 to :80 to get around 
 * the core restriction on the network.php page.
 */
add_action( 'load-network.php', function()
{
    add_filter( 'option_active_plugins', function( $value )
    {
        add_filter( 'option_siteurl', function( $value )
        {
            static $count = 0;
            if( 0 === $count++ )
                $value = str_replace( ':8080', ':80', $value );
            return $value;
        } );
        return $value;
    } );
} );

I was curious to see if there was a workaround, for those who want to develope multisites on their dev installs but on different ports than :80 and :443, e.g. :8080.

<?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;
    } );
} );
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251
Loading