How to Trigger Cloning from Custom Code or Another Plugin
$array_of_post_types = array(
'attachment',
'page',
'post',
'product',
'revision',
'wp_global_styles',
);
$array_of_tables = array(
'wp_commentmeta',
'wp_comments',
'wp_links',
'wp_options',
'wp_postmeta',
'wp_posts',
'wp_term_relationships',
'wp_term_taxonomy',
'wp_termmeta',
'wp_terms',
);
/**
* Set up the cloning request.
* These are the same fields that get submitted via an AJAX request when cloning via the
* admin interface, so you can inspect that request to determine other ways to configure
* the parameters, particularly if you're using NS Cloner Pro and want to use another
* clone mode (like clone-over or teleport / remote cloning)
*/
$request = array(
'clone_mode' => 'core',
'source_id' => 1, // any blog/site id on network
'target_name' => 'subdomain-or-subdir',
'target_title' => 'New Site Title',
'tables_to_clone' => $array_of_tables,
'do_copy_posts' => 1,
'post_types_to_clone' => $array_of_post_types, // can customize post types . . .
'debug' => 1,
'clone_nonce' => wp_create_nonce( 'ns_cloner' ),
);
// Load WordPress (ONLY if invoking this from outside WordPress).
// Other plugins and themes do NOT need to do this.
require_once( 'wp-load.php' );
// This is required to bootstrap the required plugin classes.
ns_cloner()->init();
foreach ( $request as $key => $value ) {
ns_cloner_request()->set( $key, $value );
}
ns_cloner_request()->set_up_vars();
ns_cloner_request()->save();
// Run init to begin. This will run in the background
ns_cloner()->process_manager->init();