我自动化了https://wordpress.org/plugins/blog-copier/ 来解决这个问题。如果您只想手动执行,请使用此插件,否则,这是我的自动版本:
include "BlogCopierExtended.php";
add_action("wpmu_activate_blog", "blog_copy",15,3);
function blog_copy($blog_id)
{
// first I save the options I want to preserve
$customer_name = get_blog_option($blog_id, "customer_name");
// get the customized class
$blog_copier = new BlogCopierExtended();
// the default blog, from where to copy the data from
$default_blog = get_id_from_blogname( "default" );
// copy this
$copy_now = $blog_copier->copy_blog_to_existing($blog_id, "", "", $default_blog, true);
// now we save the values back
update_blog_option($blog_id, "customer_name", $customer_name);
}
博客复制器扩展类是这样的
if (class_exists(\'BlogCopier\')) {
class BlogCopierExtended extends BlogCopier
{
public function copy_blog_to_existing($blog_id, $domain, $title, $from_blog_id = 0, $copy_files = true)
{
global $wpdb, $current_site, $base;
$email = get_blog_option($from_blog_id, \'admin_email\');
$user_id = email_exists(sanitize_email($email));
if (!$user_id) {
// Use current user instead
$user_id = get_current_user_id();
}
// The user id of the user that will become the blog admin of the new blog.
$user_id = apply_filters(\'copy_blog_user_id\', $user_id, $from_blog_id);
if (is_subdomain_install()) {
$newdomain = $domain . "." . $current_site->domain;
$path = $base;
}
else {
$newdomain = $current_site->domain;
$path = trailingslashit($base) . trailingslashit($domain);
}
// The new domain that will be created for the destination blog.
$newdomain = apply_filters(\'copy_blog_domain\', $newdomain, $domain);
// The new path that will be created for the destination blog.
$path = apply_filters(\'copy_blog_path\', $path, $domain);
$wpdb->hide_errors();
// $to_blog_id = get_current_blog_id();
$to_blog_id = $blog_id;
$wpdb->show_errors();
if (!is_wp_error($to_blog_id)) {
$dashboard_blog = get_dashboard_blog();
if (!is_super_admin() && get_user_option(\'primary_blog\', $user_id) == $dashboard_blog->blog_id) update_user_option($user_id, \'primary_blog\', $to_blog_id, true);
// now copy
if ($from_blog_id) {
$this->copy_blog_data($from_blog_id, $to_blog_id);
if ($copy_files) {
$this->copy_blog_files($from_blog_id, $to_blog_id);
$this->replace_content_urls($from_blog_id, $to_blog_id);
}
$msg = sprintf(__(\'Copied: %s in %s seconds\', $this->_domain) , \'<a href="http://\' . $newdomain . \'" target="_blank">\' . $title . \'</a>\', number_format_i18n(timer_stop()));
// do_action( \'log\', __( \'Copy Complete!\', $this->_domain ), $this->_domain, $msg );
// do_action( \'copy_blog_complete\', $from_blog_id, $to_blog_id );
}
}
else {
$msg = $to_blog_id->get_error_message();
}
return $msg;
}
}
}
应该这样做