我正在使用 wpmu_create_blog() 从前端创建一个子站点。整个代码工作正常,但主要问题发生在我们访问它获得的新站点前端时
404页面不存在
但是当我从 wp-admin 创建新的子站点时,新站点可以完美运行,没有错误。
我在页面模板中用于创建新子站点的代码是 -
<?php
# Load WordPress barebones
define( 'WP_USE_THEMES', false );
require( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );
# Multisite domain
$main_site = get_site_url();
# Type of Multisite
$subdomain_install = false;
# URL param activated
if( isset( $_POST['new-site'] ) )
{
# Create a new user
$rand_number = rand( 1, 2000 );
$username = $_POST['username'];
$password = $_POST['password'];
// $password = wp_generate_password( 12, false );
$email = $_POST['emailaddr'];
$user_id = wpmu_create_user( $username, $password, $email );
// wp_new_user_notification( $user_id, $password );
# Create site
$newdomain = str_replace(array('http://','https://'),'',$main_site);
$path = "/{$_POST['site_title']}/";
$title = $_POST['site_title'];
$blog_id = wpmu_create_blog( $newdomain, $path, $title, $user_id, array( 'public' => 1 ) );
if ( is_wp_error($return) ) {
die($blog_id->get_error_message());
}
else {
echo "success";
}
}
?>
<form action="" method="POST">
<label>User Name</label>
<input type="text" name="username" value="" />
<label>Password</label>
<input type="password" name="password" value="" />
<label>Email</label>
<input type="email" name="emailaddr" value="" />
<label>Site Address</label>
<input type="text" name="siteaddress" value="" />
<label>Site Title</label>
<input type="text" name="site_title" value="" />
<input type="submit" name="new-site" value="new-site" />
</form>
如果我做错了什么,请建议我!