How to call NS Cloner to Copy Sites from Other Plugins

Have you ever wondered if there an API to clone a site with PHP instead of using the NS Cloner interface? Well, there is!
/**
 * Before doing anything: setup clone $_POST data.
 * [] {
 *     @type  string  'action'         => 'process',
 *     @type  string  'clone_mode'     => 'core',
 *     @type  int     'source_id'      => $blog_id,
 *     @type  string  'target_name'    => $target_name,
 *     @type  string  'target_title'   => $target_title,
 *     @type  bool    'disable_addons' => true,
 *     @type  string  'clone_nonce'    => wp_create_nonce('ns_cloner')
 * }
 */

// Load WordPress.
require( wp-load.php );

// Setup clone process and run it.
$ns_site_cloner = new ns_cloner();
$ns_site_cloner->process();

$site_id = $ns_site_cloner->target_id;
$site_info = get_blog_details( $site_id );
if ( $site_info ) {
	// Clone successful!
}
Note: The function below assumes that WordPress is already loaded and that the NS Cloner is network activated. Use the code below in other plugins and themes as long as NS Cloner has loaded first.

Feedback and Knowledge Base