5

Hi guys :) I know there is the wpmu_new_blog action hook which enables us to perform an action when a new WPMU blog is created. Is there something similar to this which enables us to perform an action when a WPMU blog is deleted? Something which looks like this:

add_action('blog_deletion_hook', 'function_to_perform')

4

Yes, inside /wp-admin/includes/ms.php there is the action hook delete_blog.

This test prevents a blog deletion:

add_action( 'delete_blog', 'prevent_blog_delete_wpse_82961', 10, 2 );

/**
* @param int $blog_id Blog ID
* @param bool $drop True if blog's table should be dropped. Default is false.
*/
function prevent_blog_delete_wpse_82961( $blog_id, $drop ) 
{
    wp_die( 'aborting delete_blog' );
}
| improve this answer | |
  • This did the trick, thanks! Although I ran into the problem that the action I wanted to perform on deletion didn't work with WPMU. I solved this by 'Network Enabling' the plugin. :) – Steef Jan 25 '13 at 0:10
1

WordPress use since version 5.1 a new hook.

do_action( 'wp_delete_site', $old_site );

The var $old_site is the deleted site object.

If you need a hook before the blog will delete, use the hook below.

 * Fires before a site should be deleted from the database.
 *
 * Plugins should amend the `$errors` object via its `WP_Error::add()` method. If any errors
 * are present, the site will not be deleted.
 *
 * @since 5.1.0
 *
 * @param WP_Error $errors   Error object to add validation errors to.
 * @param WP_Site  $old_site The site object to be deleted.
 */
do_action( 'wp_validate_site_deletion', $errors, $old_site );

You should use a hook from this two options because the hook delete_blog is deprecated.

| improve this answer | |
0

FYI this is now deprecated. I haven't found a substitute yet, unfortunately :( https://developer.wordpress.org/reference/hooks/delete_blog/

| improve this answer | |

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.