[DEV] Response only when Duplication is Complete 0

[ad_1]

Hi there,
I am developing a feature for my multisite where a user submits a gravity form and all a new is generated for them.
Later on some changes are done on the newly duplicated site (User details are replaced there).
But these changes are undone as the nscloner duplication function runs in background.
Is there a way we can get the response from the function only when the Site is Completely Duplicated.
Also we should get the newly created site ID as return.
here’s the code i am using for reference.

            $response = ns_cloner_perform_clone( array(
'source_id' => 9,
'target_name' => $target_name,
'target_title' => $target_title,
'user_id' => $user_id
) );

if($response)
{
print_r("<br>Site Created Successfully");
$site_url = get_site_url(); // Get the main site URL
$blog_url = $site_url . '/' . $target_name;

$template_vars = array(
'username' => $username,
'blog_url' => $blog_url,
'password' => $password
);

ob_start();
include 'email_sitegenerated.php';
$template = ob_get_clean();

$to = $user_email;
$subject="Your Site is Ready";
$headers = array('Content-Type: text/html; charset=UTF-8');

wp_mail($to, $subject, $template, $headers);

$site_after_id = get_blog_id('/'.$target_name);

print_r("<br>Target of Generated Site is ".$target_name);
print_r("<br> ID of generated site is ".$site_after_id);

clear_elementor_cache();
switch_to_blog($site_after_id);

// wp_cache_flush(); // Ensure no stale cache
update_site_contact_info($contact_info);
attach_wordpress_logo($site_logo);
update_colors($site_after_id,$selected_demo,$main_color,$accent_color);

restore_current_blog();

}

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer