Created
March 23, 2019 02:16
-
-
Save KaineLabs/b7ea19ed224bd73cc01955cb4d6ab5fc to your computer and use it in GitHub Desktop.
Add Username Tag
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
<?php | |
/** | |
* Add Tagname to profile username. | |
*/ | |
function yzc_add_username_tag( $username ) { | |
// Get Current User Data. | |
$user = get_userdata( bp_displayed_user_id() ); | |
if ( ! in_array( 'administrator', (array) $user->roles ) ) { | |
return $username; | |
} | |
// Tag. | |
$tag = yzc_tagname_format(); | |
return $username . $tag; | |
} | |
add_filter( 'yz_user_profile_username', 'yzc_add_username_tag', 99 ); | |
/** | |
* Add Tagname after username link. | |
*/ | |
function yzc_add_user_link_tagname( $html, $user_id ) { | |
// Get Current User Data. | |
$user = get_userdata( $user_id ); | |
if ( ! in_array( 'administrator', (array) $user->roles ) ) { | |
return $html; | |
} | |
// Tag. | |
$tag = yzc_tagname_format(); | |
// Return; | |
return $html . $tag; | |
} | |
add_filter( 'bp_core_get_userlink', 'yzc_add_user_link_tagname', 99, 2 ); | |
/** | |
* Add tagname after member name | |
*/ | |
function yzc_add_member_name_tagname( $member_name ) { | |
global $members_template, $activities_template; | |
// Get User Id. | |
if ( isset( $members_template->member->id ) ) { | |
$user_id = $members_template->member->id; | |
} elseif ( isset( $activities_template->activity->current_comment->user_id ) ) { | |
$user_id = $activities_template->activity->current_comment->user_id; | |
} else { | |
$user_id = false; | |
} | |
// Get Current User Data. | |
$user = get_userdata( $user_id ); | |
if ( ! in_array( 'administrator', (array) $user->roles ) ) { | |
return $member_name; | |
} | |
// Tag | |
$tag = yzc_tagname_format(); | |
// Return Name With Icon; | |
return $member_name . $tag; | |
} | |
add_filter( 'bp_member_name', 'yzc_add_member_name_tagname', 100 ); | |
add_filter( 'bp_activity_comment_name', 'yzc_add_member_name_tagname', 100 ); | |
/** | |
* Get Custom Tagname format | |
*/ | |
function yzc_tagname_format() { | |
return '<span class="yzc-tag"><i class="fas fa-user-secret"></i><span class="yzc-tagname">' . __( 'Moderator', 'youzer' ) . '</span></span>'; | |
} | |
/** | |
* Add Tag CSS . | |
*/ | |
function yzc_user_tag_css() { | |
?> | |
<style type="text/css"> | |
.yzc-tag i { | |
width: 23px; | |
height: 23px; | |
font-size: 12px; | |
margin-left: 8px; | |
line-height: 22px; | |
border-radius: 100%; | |
color: #fff; | |
text-align: center; | |
display: inline-block; | |
background-color: #FFC107; | |
vertical-align: text-bottom; | |
} | |
.yzc-tag .yzc-tagname { | |
color: #fff; | |
font-size: 10px; | |
font-weight: 600; | |
margin-left: 9px; | |
line-height: 10px; | |
border-radius: 50px; | |
padding: 3px 6px 5px; | |
display: inline-block; | |
vertical-align: middle; | |
text-transform: uppercase; | |
background-color: #FFC107; | |
} | |
.acomment-meta .yzc-tag i, | |
.activity-header .yzc-tag i { | |
width: 20px; | |
height: 20px; | |
font-size: 11px; | |
margin-left: 6px; | |
line-height: 18px; | |
vertical-align: middle; | |
} | |
.acomment-meta .yzc-tag .yzc-tagname, | |
.activity-header .yzc-tag .yzc-tagname { | |
margin-left: 5px; | |
} | |
</style> | |
<?php | |
} | |
add_action( 'wp_head', 'yzc_user_tag_css' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment