Hi Dave,
It looks like you’re on the right track with the ns_cloner_process_finish action. That definitely should fire every time, so I suspect there’s something unexpected happening with the code inside your action. Have you tried calling ns_cloner()->log->log() to debug values inside your action? That will add entries to the cloner debug log if you have the debugging option enabled, and you should be able to search in the log file for ns_cloner_process_finish and see your custom entries after that.
Hi Thanks for the info, and probably a stupid question but how should that line read in the action and does it need to be in the loop I’m running? I’ve tried a couple things and got nothing but errors. Tried stuff like: $getstuff = ns_cloner()->log->log();
Also tried running a manual clone (not using the templates) and chose debug there but don’t really see anything in the log. Thanks in advance,
No problem, should’ve been more clear in my example. You can pass whatever value you want to debug to the log method, and it can accept a single value or a label and then value so you could do like this (using the labeled option) to check the value of the $user_id variable and make sure it’s being set correctly:
ns_cloner()->log->log('Admin user id:', $user_id)
Awesome – thanks for the update on this!
Ok got one more issue, my finish process must have something that caused the process to never finish and the log shows it just keeps looping on 4 things ‘CHECKING for running ns_cloner_tables_process – none found’ (and users, rows, files).
So since the clone does not show as ‘active’ in status, which makes sense since this is an ‘after finish hook’ I guess I need to kill the running process somehow.
Tried deactivating the plugin but no luck.
Is there a way to to stop the clone process? (other than restoring an earlier site backup)
thanks
Actually never mind, if I go to the backend Nscloner screen it does show it running there so I was able to cancel it. (started the clone from a frontend template)
Not sure why is does not show as running on the status/log screen but it does show it as running on the nscloner screen.
Have never gotten the finish hook to work, so finally looked at the request array and see that it does not have a ‘target_id’ there, but it does have ‘clone_over_target_ids’.
So I guess problem solved. I was trying to use ‘target_id’ based on some posts here such as: https://ww.wp.xz.cn/support/topic/ns_cloner_after_everything-hook/
So my function here is wrong:
add_action( 'ns_cloner_process_finish', function(){
$target_id = ns_cloner_request()->get( 'target_id' );
// Do something here.
});
It should be this:
add_action( 'ns_cloner_process_finish', function(){
$target_id = ns_cloner_request()->get( 'clone_over_target_ids' );
// Do something here.
});
*Have not had time to test yet, but if I’m wrong or need to do this differently please let me know. Thanks again, – Dave
Hi Dave,
Yes, target_id is used for standard new cloning operations, but clone_over_target_ids would be the correct key for when the Cloner is in ‘clone_over’ mode to overwrite an existing site, which is the case with frontend registration template cloning (should’ve noticed that you mentioned that and pointed out the key difference, sorry for the oversight).
The only difference I see from what you have above is that cloner_over_target_ids will actually be an array (with just one item in the case of frontend cloning), so just take that typing into account when using the $target_id variable — you’d want to use $target_id[0] to get the raw site ID itself.
Hi and thanks for the help and clarification.
$request = ns_cloner_request()->get_request();
$target_ids = ns_cloner_request()->get( 'clone_over_target_ids' );
$target_id = $target_ids[0];
Yes, ran into that ‘array of 1’ thing right away and that above is what I ended up with.
Great, nice work. Marking this resolved since it sounds like you’ve got it sorted.