Created
December 14, 2020 04:16
-
-
Save permanart/05e911e6349ac9d519591cbf2311f03c to your computer and use it in GitHub Desktop.
Create Verified Author WordPress with user Role
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function add_verification_bagdge_to_authors($display_name) { | |
global $authordata; | |
if (!is_object($authordata)) | |
return $display_name; | |
$icon_roles = array( | |
'administrator', | |
'editor', | |
'your-custom-role', | |
); | |
$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="fa fa-check-circle"></i>', | |
$display_name, | |
__('This is a Verified Author', 'text-domain-here') | |
); | |
return $result; | |
} | |
add_filter( 'the_author', 'add_verification_bagdge_to_authors' ); | |
function my_comment_author( $author = '' ) { | |
// Get the comment ID from WP_Query | |
$comment = get_comment( $comment_ID ); | |
if ( ! empty($comment->comment_author) ) { | |
if (!empty($comment->user_id)){ | |
$user=get_userdata($comment->user_id); | |
$author=$user->display_name.' '. do_shortcode('[this_is_verified-sc]'); // This is where i used the shortcode | |
} else { | |
$author = $comment->comment_author; | |
} | |
} else { | |
$author = $comment->comment_author; | |
} | |
return $author; | |
} | |
add_filter('get_comment_author', 'my_comment_author', 10, 1); | |
function add_verification_bagdge_to_authors_sc($display_name) { | |
global $authordata; | |
if (!is_object($authordata)) | |
return $display_name; | |
$icon_roles = array( | |
'administrator', | |
'editor', | |
'um_verified-user' | |
); | |
$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="fa fa-check-circle"></i>', $display_name, __('This is a Verified Author', 'text-domain-here') ); | |
return $result; | |
} | |
add_shortcode( 'this_is_verified-sc', 'add_verification_bagdge_to_authors_sc' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for very useful code.
Sir,
Will you little modify for me . because i iam new on wordpress,
I want to display different icon based on Role,
for Administrator = Blue Color Icon
for Author = Yellow Color icon
for Contributer = green icon.
Specially For Cooment.
Please you only modify Php Code. and i will add self Custom font awesome icon.
Sorry for my bad English.
Thanks!