How to update author display name on blog posts based on user role
I'm trying to add a verify author badge to my blog and i have been able to use this code
function add_verification_bagdge_to_authors($current_user) {
global $post;
$current_user = wp_get_current_user();
$admin_role = in_array( 'administrator', (array) $current_user-roles );
$verifed_author = in_array( 'verified_author', (array) $current_user-roles );
$tnt_first_name = $current_user-first_name;
$display_name = $current_user-display_name;
$tnt_last_name = $current_user-last_name;
$combine_names = $tnt_first_name.' '.$tnt_last_name;
if ( $admin_role $current_user-ID == $post-post_author ) {
$verify_ico = $combine_names .' '. 'i title="This is a Verified Author" class="userfnt-accept"/i';
} elseif ( $verifed_author $current_user-ID == $post-post_author ) {
$verify_ico = $combine_names .' '. 'i title="This is a Verified Author" class="userfnt-accept"/i';
}else {
$verify_ico = $display_name;
}
return $verify_ico;
}
add_filter( 'the_author', 'add_verification_bagdge_to_authors' );
add_filter( 'get_the_author_display_name', 'add_verification_bagdge_to_authors' );
The idea is, all Administrator are automatically Verified and users with role (Verified Author) which i have created using the add_role() function is as well verified.
But with the above code, the name updates with the badge but if i'm logged in as the admin, all posts will have the author name as the admin name with the verified badge and when logged in as the verified author, all post then has the author name as the verified author and if logged out the else statement is used and no author name will show on all post.
What i want to achieve is;
if it is the admin (logged in or not logged in), all post by admin should have the author name with a verified badge/icon.
if user has a verified author role (logged in or not logged in), all post by such author should have their name with the verified badge/icon.
ELSE (1 2) it should just display the name of the user without verification badge (logged in or not).
Please help or guide me in the right direction.
Thanks
Topic verification author Wordpress
Category Web