I think I figured it out.
I had multiple things wrong with the code:
function category_to_all( $term_id ){
remove_action( 'create_category', __FUNCTION__ );
$currentcatdata = get_term_by('id', $term_id, 'category');
$allsiteids = get_sites(array('fields' => 'ids'));
$currentsiteid = get_current_blog_id();
if (($key = array_search($currentsiteid, $allsiteids)) !== false) {
unset($allsiteids[$key]);
}
$blog_ids = array_values($allsiteids);
foreach( $blog_ids as $blog_id ) {
switch_to_blog( $blog_id );
$cid = wp_insert_term($currentcatdata->name, 'category',
array(
'description' => $currentcatdata->description,
'slug' => $currentcatdata->slug,
'parent'=> $currentcatdata->parent,
)
);
restore_current_blog();
}
}
add_action( 'create_category', 'category_to_all', 10, 1 );
That seems to work, sort of – whatever blog/site your in on the multisite,
if you create a new category, it gets created on the others as well.
What’s missing is handling of “parent” – if the IDs don’t match,
it will fail to add a new category due to mismatch.