I would start by looking into the set_user_role
action hook. You would be passed 3 arguments to your callback function - the User ID, the new user role, and an array of the old user roles(that seems strange to me, that you can't pass an array of roles, but oh well).
So here's an example code - I'm not certain for how you would get the sites that the user owns, but it should give you a general idea:
function my_set_user_role_callback( $user_id, $new_role, $old_roles ) {
// Get the user sites here - not sure how you'd do that, but there should be a way
$user_sites = array();
if ( $user_sites ) {
if ( in_array( 'administrator', $old_roles ) && $new_role == 'subscriber' ) {
foreach ( $user_sites as $site ) {
// Archive the site
$site->archived = true;
update_blog_details( $site->userblog_id, (array) $site );
}
} elseif ( in_array( 'subscriber', $old_roles ) && $new_role == 'administrator' ) {
foreach ( $user_sites as $site ) {
// Un-archive the site
$site->archived = false;
update_blog_details( $site->userblog_id, (array) $site );
}
}
}
}
add_action( 'set_user_role', 'my_set_user_role_callback', 10, 3 );
Once you figure-out how to get the user sites, fix the properties of the $site
object with the proper ones(there's the chance that these would be correct, but still).
PS: You can put all of your code in a plugin and network activate it, or put it in the wp-content/mu-plugins/ directory so that it will always be enabled for all sites.