Use guest commenter names instead of emails

This commit is contained in:
Jeremy Dormitzer 2018-10-30 16:04:17 -04:00
parent a3fa00640d
commit 21479922b7
2 changed files with 9 additions and 6 deletions

View File

@ -62,7 +62,7 @@ function get_comment_actor_slug( $comment ) {
if ( $comment->user_id !== '0' ) {
return get_comment_user_actor_slug( $comment->user_id );
} else {
return get_comment_email_actor_slug( $comment );
return get_comment_guest_actor_slug( $comment );
}
}
@ -75,7 +75,7 @@ function get_comment_user_actor_slug( $user_id ) {
}
}
function get_comment_email_actor_slug( $comment ) {
function get_comment_guest_actor_slug( $comment ) {
$email_address = $comment->comment_author_email;
$url = $comment->comment_author_url;
if ( empty( $url ) ) {

View File

@ -258,7 +258,7 @@ function get_create_actor_query( $slug, $type, $email = null, $url = null, $name
function upsert_commenter_actor( $email_address, $url = null, $name = null, $icon = null ) {
global $wpdb;
$slug = email_address_to_slug( $email_address );
$slug = name_to_slug( $name );
$existing = $wpdb->get_row( $wpdb->prepare(
"SELECT * FROM {$wpdb->prefix}pterotype_actors WHERE slug = %s",
$slug
@ -284,8 +284,11 @@ function upsert_commenter_actor( $email_address, $url = null, $name = null, $ico
return $slug;
}
function email_address_to_slug( $email_address ) {
$slug = str_replace( array( '@', '.'), '_', $email_address );
return preg_replace( '/[^a-zA-Z0-9-_]/', '', $slug );
function name_to_slug( $name ) {
if ( ! $name ) {
return 'anonymous';
}
$slug = str_replace( array( '@', '.', ' '), '_', $name );
return strtolower( preg_replace( '/[^a-zA-Z0-9-_]/', '', $slug ) );
}
?>