I was able to figure this out. Here’s the code, explanation follows.
$subscribers = get_users('role=subscriber');
foreach ($subscribers as $subscriber) {
$subscriber_id = esc_html($subscriber->user_login);
add_action('init', function() use($subscriber_id) {
add_feed($subscriber_id, function() {
get_template_part('feed', 'subscribers');
});
});
$wp_rewrite->flush_rules($hard);
}
First, I stopped nesting functions, per Tom J Newell’s critique in the comments under the original question.
Second, I found that after adding a new feed the WP rewrite rules needed to be updated. This can be done manually in the settings be re-saving the permalink settings, or using $wp_rewrite as shown above.
Third, to use the variable $subscriber_id I needed to include it in the anonymous function with “use()”.
Finally, rather than trying to separate things out into functions and calling those functions, I just wrapped all the old functions into anonymous functions.
It’s all working perfectly now.