Taxonomies: Only broadcast terms without parents

This code snippet will only broadcast terms that do not have parents in the taxonomy hierarchy. So:

  • terms without parents are broadcasted
  • terms that have parents in the hierarchy, are not broadcasted
add_action( 'threewp_broadcast_broadcasting_started', function( $action )
{
	$bcd = $action->broadcasting_data;

	foreach( $bcd->parent_post_taxonomies as $taxonomy => $terms )
	{
		foreach( $terms as $term_index => $term )
		{
			if ( $term->parent < 1 ) continue; ThreeWP_Broadcast()->debug( 'Term %s %s has a parent. Forgetting.',
				$term->term_id,
				$term->name
			);
			$bcd->taxonomies()->forget_term_id( $term->term_id );
			unset( $bcd->parent_post_taxonomies[ $taxonomy ][ $term_index ] );
		}
	}
} );