Skip to content

Instantly share code, notes, and snippets.

@cryptexvinci
Last active October 12, 2020 04:50
Show Gist options
  • Select an option

  • Save cryptexvinci/2bd2ef2d35fda172bb360a010e4386b0 to your computer and use it in GitHub Desktop.

Select an option

Save cryptexvinci/2bd2ef2d35fda172bb360a010e4386b0 to your computer and use it in GitHub Desktop.
Displaying "First initial of first name & last name" for my buying customers that gave a review for privacy purpose.
<?php
add_filter( 'comment_author', 'custom_comment_author', 10, 2 );
function custom_comment_author( $author, $commentID ) {
$comment = get_comment( $commentID );
$user = get_user_by( 'email', $comment->comment_author_email );
if( ! $user ) {
return $author;
} else {
$firstname = (string) get_user_meta( $user->id, 'first_name', true );
$lastname = (string) get_user_meta( $user->id, 'last_name', true );
if( empty( $firstname ) OR empty( $lastname ) ){
return $author;
} else{
return esc_attr( $firstname[0] . " ". $lastname );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment