Filters and Actions

The NS Cloner is built to be extended – it includes a lot of custom filters and actions so that it can easily be customized or added on to. Here is a non-exhaustive of some of the most commonly used hooks, which we’ll be documenting further over time:

Filters

Limit list of sites available to clone from: ns_cloner_sites_list

add_filter( 'ns_cloner_sites_list', function( $sites ){
	// Replace list of all sites with custom manual selection - useful for very large networks.
	$sites = get_sites( [ 
		'site__in' => [ 1, 2, 5, 8 ],
	] );
	return $sites;
});

Skip copying a directory in wp-content/uploads: ns_cloner_dir_copy_ignore

add_filter( 'ns_cloner_dir_copy_ignore', function( $blacklist ){
   $blacklist[] = 'some_plugin_directory_not_to_copy';
   return $blacklist;
});

Actions

Before a site is cloned: ns_cloner_process_init

add_action( 'ns_cloner_process_init', function(){

   // Get array of all submitted cloner options and calculated variables.
   // Note that some values like target site id won't yet be available at this point.
   $request = ns_cloner_request()->get_request();

   // Or you can get individual request values like this:
   $source_id = ns_cloner_request()->get( 'source_id' );

   // Do something here.

});

After a site is cloned: ns_cloner_process_finish

add_action( 'ns_cloner_process_finish', function(){

   // Get array of all submitted cloner options and calculated variables.
   $request = ns_cloner_request()->get_request();

   // Or you can get individual request values like this:
   $target_id = ns_cloner_request()->get( 'target_id' );
   $source_id = ns_cloner_request()->get( 'source_id' );

   // Do something here.

});

Still need help? Contact Us Contact Us