Hello @sroskylo1,
Yes, you can hide some characters of the user email from the leaderboard. Add the below code snippets in your active theme’s functions.php file.
Here is the code:
add_filter( 'mycred_ranking_row', 'mycredpro_add_masked_email_to_leaderboard', 10, 4 );
function mycredpro_add_masked_email_to_leaderboard( $layout, $template, $user, $position ) {
if ( isset( $user->ID ) )
$user_id = $user->ID;
elseif ( isset( $user['ID'] ) )
$user_id = $user['ID'];
else return $layout;
// Get the user's email
$user_info = get_userdata( $user_id );
$email = $user_info->user_email;
// Mask the email
$masked_email = mask_email( $email );
// Replace %email% placeholder with the masked email
return str_replace( '%email%', esc_html( $masked_email ), $layout );
}
// Function to mask email (e.g., [email protected] to user***@exa***.com)
function mask_email( $email ) {
list( $username, $domain ) = explode( '@', $email );
// Mask part of the username (first 3 characters shown, rest masked)
$masked_username = substr( $username, 0, 3 ) . str_repeat( '*', strlen( $username ) - 3 );
// Mask part of the domain (first 3 characters of domain shown, rest masked except TLD)
$domain_parts = explode( '.', $domain );
$masked_domain = substr( $domain_parts[0], 0, 3 ) . str_repeat( '*', strlen( $domain_parts[0] ) - 3 ) . '.' . $domain_parts[1];
return $masked_username . '@' . $masked_domain;
}
Place the below shortcode on any page.
<table>
<thead>
<tr>
<th>Position</th>
<th>Name</th>
<th>Points</th>
<th>Email</th>
</tr>
</thead>
<tbody>
[mycred_leaderboard wrap=""]
<tr>
<td>%position%</td>
<td>%display_name%</td>
<td>%cred_f%</td>
<td>%email%</td>
</tr>
[/mycred_leaderboard]
</tbody>
</table>
If you have any questions, feel free to reach out. We’re here to assist you.
Thank you