humanmade / Mercator

WordPress multisite domain mapping for the modern era.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

delete_blog hook is delete_blog - Suggested hook wp_uninitialize_site mercator.php

jerrickhakim opened this issue · comments

add_action('wp_uninitialize_site', NAMESPACE . '\clear_mappings_on_delete');

/**

  • Clear mappings for a site when it's deleted

  • @param obj $site Site object that is being deleted
    */
    function clear_mappings_on_delete($site)
    {
    $mappings = Mapping::get_by_site($site->blog_id);

    if (empty($mappings)) {
    return;
    }

    foreach ($mappings as $mapping) {
    $error = $mapping->delete();

     if (is_wp_error($error)) {
         $message = sprintf(
             __('Unable to delete mapping %1$d for site %2$d', 'mercator'),
             $mapping->get_id(),
             $site_id
         );
         trigger_error($message, E_USER_WARNING);
     }
    

    }
    }