There’s a filter you can use for that, autologin_urls_for_users
, see class-wp-mail.php#L89-L100
I haven’t tested this, but I think it should work, add it to your functions.php:
/**
* Check does the recipient user have the subscriber role, if not do not add autologin code in emails.
*
* @param bool $should_add_autologin Variable to set to true/false to control the plugin behaviour.
* @param \WP_User $user The WordPress user the email is being sent to.
* @param array{to:string|array<string>, subject:string, message:string, headers?:string|array<string>, attachments:string|array<string>} $wp_mail_args The array of values wp_mail() functions uses: subject, message etc.
*/
$only_add_autologin_urls_for_subscribers = function( bool $should_add_autologin, \WP_User $user, array $wp_mail_args ): bool {
return in_array( 'subscriber', $user->roles, true );
};
add_filter( 'autologin_urls_for_users', $only_add_autologin_urls_for_subscribers, 10, 3 );