How do I programmatically set default role for new users?

This allows plugins to easily hijack the default role while they’re active.

// Hijack the option, the role will follow!
add_filter('pre_option_default_role', function($default_role){
    // You can also add conditional tags here and return whatever
    return 'subscriber'; // This is changed
    return $default_role; // This allows default
});

I use it to make sure some plugins that need subscriber roles get it regardless of Administrator attempts to change 🙂

Regards.

Leave a Comment