4

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.

0

You can not stop anything which do not have an explicit option to be stopped. In this case, actions are a mean to execute some additional code in the context of a specific execution path, and not to alter it. If there is no way to signal to the process to stop, than the only way is to die().

If you think about it from a more distant logical perception, it does not make any sense that a blog delete API will not delete the blog. If you need something like "queue for deletion" you just need to write your own function and replace the relevant delete links in the admin with links to your operation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.