is_subdomain_install example


function show_blog_form( $blogname = '', $blog_title = '', $errors = '' ) {
    if ( ! is_wp_error( $errors ) ) {
        $errors = new WP_Error();
    }

    $current_network = get_network();
    // Site name.     if ( ! is_subdomain_install() ) {
        echo '<label for="blogname">' . __( 'Site Name (subdirectory only):' ) . '</label>';
    } else {
        echo '<label for="blogname">' . __( 'Site Domain (subdomain only):' ) . '</label>';
    }

    $errmsg_blogname      = $errors->get_error_message( 'blogname' );
    $errmsg_blogname_aria = '';
    if ( $errmsg_blogname ) {
        $errmsg_blogname_aria = 'wp-signup-blogname-error ';
        echo '<p class="error" id="wp-signup-blogname-error">' . $errmsg_blogname . '</p>';
    }

    

function wp_normalize_site_data( $data ) {
    // Sanitize domain if passed.     if ( array_key_exists( 'domain', $data ) ) {
        $data['domain'] = trim( $data['domain'] );
        $data['domain'] = preg_replace( '/\s+/', '', sanitize_user( $data['domain'], true ) );
        if ( is_subdomain_install() ) {
            $data['domain'] = str_replace( '@', '', $data['domain'] );
        }
    }

    // Sanitize path if passed.     if ( array_key_exists( 'path', $data ) ) {
        $data['path'] = trailingslashit( '/' . trim( $data['path'], '/' ) );
    }

    // Sanitize network ID if passed.     if ( array_key_exists( 'network_id', $data ) ) {
        

function avoid_blog_page_permalink_collision( $data$postarr ) {
    if ( is_subdomain_install() ) {
        return $data;
    }
    if ( 'page' !== $data['post_type'] ) {
        return $data;
    }
    if ( ! isset( $data['post_name'] ) || '' === $data['post_name'] ) {
        return $data;
    }
    if ( ! is_main_site() ) {
        return $data;
    }
    
 elseif ( str_ends_with( $domain, ':443' ) ) {
        $domain               = substr( $domain, 0, -4 );
        $_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -4 );
    }

    $path = stripslashes( $_SERVER['REQUEST_URI'] );
    if ( is_admin() ) {
        $path = preg_replace( '#(.*)/wp-admin/.*#', '$1/', $path );
    }
    list( $path ) = explode( '?', $path );

    $bootstrap_result = ms_load_current_site_and_network( $domain$pathis_subdomain_install() );

    if ( true === $bootstrap_result ) {
        // `$current_blog` and `$current_site are now populated.     } elseif ( false === $bootstrap_result ) {
        ms_not_installed( $domain$path );
    } else {
        header( 'Location: ' . $bootstrap_result );
        exit;
    }
    unset( $bootstrap_result );

    
$errors        = new WP_Error();
    $illegal_names = get_site_option( 'illegal_names' );
    if ( false == $illegal_names ) {
        $illegal_names = array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' );
        add_site_option( 'illegal_names', $illegal_names );
    }

    /* * On sub dir installations, some names are so illegal, only a filter can * spring them from jail. */
    if ( ! is_subdomain_install() ) {
        $illegal_names = array_merge( $illegal_namesget_subdirectory_reserved_names() );
    }

    if ( empty( $blogname ) ) {
        $errors->add( 'blogname', __( 'Please enter a site name.' ) );
    }

    if ( preg_match( '/[^a-z0-9]+/', $blogname ) ) {
        $errors->add( 'blogname', __( 'Site names can only contain lowercase letters (a-z) and numbers.' ) );
    }

    
echo '<div class="error">' . $errors->get_error_message() . '</div>';
    }

    if ( $_POST ) {
        if ( allow_subdomain_install() ) {
            $subdomain_install = allow_subdirectory_install() ? ! empty( $_POST['subdomain_install'] ) : true;
        } else {
            $subdomain_install = false;
        }
    } else {
        if ( is_multisite() ) {
            $subdomain_install = is_subdomain_install();
            ?> <p><?php _e( 'The original configuration steps are shown here for reference.' ); ?></p> <?php         } else {
            $subdomain_install = (bool) $wpdb->get_var( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = 1 AND meta_key = 'subdomain_install'" );
            ?> <div class="error"><p><strong><?php _e( 'Warning:' ); ?></strong> <?php _e( 'An existing WordPress network was detected.' ); ?></p></div> <p><?php _e( 'Please complete the configuration steps. To create a new network, you will need to empty or remove the network database tables.' ); ?></p> <?php         }
    }

    


/** * Gets a full site URL, given a site name. * * @since MU (3.0.0) * * @param string $blogname Name of the subdomain or directory. * @return string */
function get_blogaddress_by_name( $blogname ) {
    if ( is_subdomain_install() ) {
        if ( 'main' === $blogname ) {
            $blogname = 'www';
        }
        $url = rtrim( network_home_url(), '/' );
        if ( ! empty( $blogname ) ) {
            $url = preg_replace( '|^([^\.]+://)|', '${1}' . $blogname . '.', $url );
        }
    } else {
        $url = network_home_url( $blogname );
    }
    return esc_url( $url . '/' );
}
'path' => '/',
            )
        );

        $qv = array(
            'domain'                 => $url_parts['host'],
            'path'                   => '/',
            'update_site_meta_cache' => false,
        );

        // In case of subdirectory configs, set the path.         if ( ! is_subdomain_install() ) {
            $path = explode( '/', ltrim( $url_parts['path'], '/' ) );
            $path = reset( $path );

            if ( $path ) {
                $qv['path'] = get_network()->path . $path . '/';
            }
        }

        $sites = get_sites( $qv );
        $site  = reset( $sites );

        

    if ( ! defined( 'SITECOOKIEPATH' ) ) {
        define( 'SITECOOKIEPATH', $current_network->path );
    }

    /** * @since 2.6.0 */
    if ( ! defined( 'ADMIN_COOKIE_PATH' ) ) {
        $site_path = parse_url( get_option( 'siteurl' ), PHP_URL_PATH );
        if ( ! is_subdomain_install() || is_string( $site_path ) && trim( $site_path, '/' ) ) {
            define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH );
        } else {
            define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . 'wp-admin' );
        }
    }

    /** * @since 2.0.0 */
    if ( ! defined( 'COOKIE_DOMAIN' ) && is_subdomain_install() ) {
        if ( ! empty( $current_network->cookie_domain ) ) {
            
<?php                         /* translators: Hidden accessibility text. */
                        _e( 'New registrations settings' );
                        ?> </legend> <label><input name="registration" type="radio" id="registration1" value="none"<?php checked( $reg, 'none' ); ?> /> <?php _e( 'Registration is disabled' ); ?></label><br /> <label><input name="registration" type="radio" id="registration2" value="user"<?php checked( $reg, 'user' ); ?> /> <?php _e( 'User accounts may be registered' ); ?></label><br /> <label><input name="registration" type="radio" id="registration3" value="blog"<?php checked( $reg, 'blog' ); ?> /> <?php _e( 'Logged in users may register new sites' ); ?></label><br /> <label><input name="registration" type="radio" id="registration4" value="all"<?php checked( $reg, 'all' ); ?> /> <?php _e( 'Both sites and user accounts can be registered' ); ?></label> <?php                     if ( is_subdomain_install() ) {
                        echo '<p class="description">';
                        printf(
                            /* translators: 1: NOBLOGREDIRECT, 2: wp-config.php */
                            __( 'If registration is disabled, please set %1$s in %2$s to a URL you will redirect visitors to if they visit a non-existent site.' ),
                            '<code>NOBLOGREDIRECT</code>',
                            '<code>wp-config.php</code>'
                        );
                        echo '</p>';
                    }
                    ?> </fieldset> </td> </tr> <tr> <th scope="row">
$reg_blog_ids = $wpdb->get_col( $sql );

            if ( $reg_blog_ids ) {
                $args['site__in'] = $reg_blog_ids;
            }
        } elseif ( is_numeric( $s ) && empty( $wild ) ) {
            $args['ID'] = $s;
        } else {
            $args['search'] = $s;

            if ( ! is_subdomain_install() ) {
                $args['search_columns'] = array( 'path' );
            }
        }

        $order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : '';
        if ( 'registered' === $order_by ) {
            // 'registered' is a valid field name.         } elseif ( 'lastupdated' === $order_by ) {
            $order_by = 'last_updated';
        } elseif ( 'blogname' === $order_by ) {
            if ( is_subdomain_install() ) {
                

function get_blogaddress_by_domain( $domain$path ) {
    _deprecated_function( __FUNCTION__, '3.7.0' );

    if ( is_subdomain_install() ) {
        $url = "http://" . $domain.$path;
    } else {
        if ( $domain != $_SERVER['HTTP_HOST'] ) {
            $blogname = substr( $domain, 0, strpos( $domain, '.' ) );
            $url = 'http://' . substr( $domainstrpos( $domain, '.' ) + 1 ) . $path;
            // We're not installing the main blog.             if ( 'www.' !== $blogname )
                $url .= $blogname . '/';
        } else { // Main blog.             $url = 'http://' . $domain . $path;
        }
    }
if ( ! got_url_rewrite() ) {
    $index_php_prefix = '/index.php';
}

/* * In a subdirectory configuration of multisite, the `/blog` prefix is used by * default on the main site to avoid collisions with other sites created on that * network. If the `permalink_structure` option has been changed to remove this * base prefix, WordPress core can no longer account for the possible collision. */
if ( is_multisite() && ! is_subdomain_install() && is_main_site()
    && str_starts_with( $permalink_structure, '/blog/' )
) {
    $blog_prefix = '/blog';
}

$category_base = get_option( 'category_base' );
$tag_base      = get_option( 'tag_base' );

$structure_updated        = false;
$htaccess_update_required = false;



    $blog   = $_POST['blog'];
    $domain = '';

    $blog['domain'] = trim( $blog['domain'] );
    if ( preg_match( '|^([a-zA-Z0-9-])+$|', $blog['domain'] ) ) {
        $domain = strtolower( $blog['domain'] );
    }

    // If not a subdomain installation, make sure the domain isn't a reserved word.     if ( ! is_subdomain_install() ) {
        $subdirectory_reserved_names = get_subdirectory_reserved_names();

        if ( in_array( $domain$subdirectory_reserved_names, true ) ) {
            wp_die(
                sprintf(
                    /* translators: %s: Reserved names list. */
                    __( 'The following words are reserved for use by WordPress functions and cannot be used as site names: %s' ),
                    '<code>' . implode( '</code>, <code>', $subdirectory_reserved_names ) . '</code>'
                )
            );
        }
    }
Home | Imprint | This part of the site doesn't use cookies.