A simple way to achieve this is to do a conditional redirect on template_redirect
action. In the action callback, check that the request is for an author archive of the specified role and if it is, then do the redirect.
function my_disabled_author_archive_role() {
return 'buyer';
}
add_action(
'template_redirect',
function() {
// Is this an author archive?
if ( ! is_author() ) {
return;
}
// Does the author have the specified role?
$author = get_queried_object();
if ( ! in_array( my_disabled_author_archive_role(), (array) $author->roles ) ) {
return;
}
// Redirect to somewhere
if ( wp_safe_redirect( home_url() ) ) {
exit;
}
}
);
If you want to exclude the role also from the default WP sitemap, then filter the users sitemap query args.
add_filter(
'wp_sitemaps_users_query_args',
function($args) {
$args['role__not_in'] = my_disabled_author_archive_role();
return $args;
}
);