How to Set Parent Theme for Each Site in a WordPress Multisite Network

In a multisite with multiple subsites, three different themes (custom-made) are used. They all have something in common, so it is necessary to extract this commonality (shared styles, scripts, etc.) into one theme and make each current theme of each site a child theme.

I created a parent theme, moved the common elements there, and specified the title for the child themes to indicate their relationship to the parent theme. In general, I did everything that was needed.

Now, the last step is to specify in the settings of each site that the current theme is a child theme of the theme "hb-base-theme". This is done with the following code:

// Set the parent theme for all themes (needs to be run once on the main site).
if( isset($_GET['set_parent_theme_for_all_themes']) ){

	foreach( get_sites() as $site ){
		switch_to_blog( $site->blog_id );
		update_option( 'template', 'hb-base-theme' );
		restore_current_blog();
	}

	die( 'Done!' );
}