I’m trying to prevent the deletion of blogs in a WordPress Multisite installation. There is already a plugin that does this, but it uses wp_die()
as the solution, which in my scenario does not work.
When selecting multiple blogs for deletion in wp-admin/network, I want WordPress to continue working and not die in the attempt to delete the first in the loop.
I have tried solving it like this as an mu-plugin:
if(!$argv[1]) {
add_action( 'delete_blog', 'prevent_blog_delete_wpse', 1, 2 );
function prevent_blog_delete_wpse($blog_id, $drop = FALSE)
{
global $wpdb;
$wpdb->query("update wp_blogs set deleted = 1 where blog_id = '".$blog_id."'");
return FALSE;
}
}
So if deletion if called via browser and not CLI, it will just mark the blog as deleted. Sadly this does not work. I have also tried to change the priority from 1 to 99, it still does not work.
The reason for this solution is that i have a separate cronjob that does the actual deletion, but first makes a tarball of the sql tables and blogs.dir files in case I need to restore.
This can of course be fixed by hacking wpmu_delete_blog()
core code function, but I’d rather not do that, as it will break on next update of WordPress.