我正在使用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>
如果我做错了,请建议我!
答案 0 :(得分:0)
我找到了这个问题的解决方案,wpmu_create_blog函数在本地主机上不起作用。此函数适用于实时服务器。代码完美地从前端创建新站点。这是url问题,localhost有localhost / wordpress格式,这个函数只采用www.example.com格式来创建新网站。