1 回答
TA贡献1847条经验 获得超7个赞
调整是:
显示名字
詹姆斯成为J***s
在代码中添加了注释和解释
function my_comment_author( $author, $comment_id, $comment ) {
// NOT empty
if ( $comment ) {
// Get user id
$user_id = $comment->user_id;
// User id exists
if( $user_id > 0 ) {
// Get user data
$user = get_userdata( $user_id );
// User first name
$user_first_name = $user->first_name;
// Call function
$author = replace_with_stars( $user_first_name );
} else {
$author = __('Anonymous', 'woocommerce');
}
}
return $author;
}
add_filter('get_comment_author', 'my_comment_author', 10, 3 );
function replace_with_stars( $str ) {
// Returns the length of the given string.
$len = strlen( $str );
return substr( $str, 0, 1 ).str_repeat('*', $len - 2).substr( $str, $len - 1, 1 );
}
- 1 回答
- 0 关注
- 157 浏览
添加回答
举报