The main culprit is this line
$current_user = wp_get_current_user();
As the name “get current user” suggests, it gets you the currently logged in user. That is not what you want.
Being in the the_author
filter, you can use the global $authordata
variable, as the function calling the filter relies on it as well.
function add_verification_bagdge_to_authors($display_name) {
global $authordata;
if (!is_object($authordata))
return $display_name;
$icon_roles = [
'administrator',
'verified_author',
];
$found_role = false;
foreach ($authordata->roles as $role) {
if (in_array(strtolower($role), $icon_roles)) {
$found_role = true;
break;
}
}
if (!$found_role)
return $display_name;
$result = sprintf('%s <i title="%s" class="userfnt-accept"></i>',
$display_name,
__('This is a Verified Author', 'plugin_or_theme_lang_slug')
);
return $result;
}
add_filter( 'the_author', 'add_verification_bagdge_to_authors' );
get_the_author_display_name
is not a core filter, so you might need to use other code for it, depending on how this filter works and where it is from.