Skip to content

Commit 43b7ac1

Browse files
committed
Users: Add support for Initials and Color Gravatar images in default user profile pics.
Gravatar includes support for Initials and Color auto-generated images. This changeset adds them to the built-in feature for user profile images. Props haozi, audrasjb, getsyash, valentingrenier. Fixes #63087. See #57493. git-svn-id: https://develop.svn.wordpress.org/trunk@60269 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 064682f commit 43b7ac1

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

src/wp-admin/options-discussion.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@
309309
'monsterid' => __( 'MonsterID (Generated)' ),
310310
'retro' => __( 'Retro (Generated)' ),
311311
'robohash' => __( 'RoboHash (Generated)' ),
312+
'initials' => __( 'Initials (Generated)' ),
313+
'color' => __( 'Color (Generated)' ),
312314
);
313315
/**
314316
* Filters the default avatars.

src/wp-includes/link-template.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4298,6 +4298,8 @@ function the_shortlink( $text = '', $title = '', $before = '', $after = '' ) {
42984298
* - 'monsterid' (a monster)
42994299
* - 'wavatar' (a cartoon face)
43004300
* - 'identicon' (the "quilt", a geometric pattern)
4301+
* - 'initials' (initials based avatar with background color)
4302+
* - 'color' (generated background color)
43014303
* - 'mystery', 'mm', or 'mysteryman' (The Oyster Man)
43024304
* - 'blank' (transparent GIF)
43034305
* - 'gravatar_default' (the Gravatar logo)
@@ -4366,6 +4368,8 @@ function is_avatar_comment_type( $comment_type ) {
43664368
* - 'monsterid' (a monster)
43674369
* - 'wavatar' (a cartoon face)
43684370
* - 'identicon' (the "quilt", a geometric pattern)
4371+
* - 'initials' (initials based avatar with background color)
4372+
* - 'color' (generated background color)
43694373
* - 'mystery', 'mm', or 'mysteryman' (The Oyster Man)
43704374
* - 'blank' (transparent GIF)
43714375
* - 'gravatar_default' (the Gravatar logo)
@@ -4545,6 +4549,33 @@ function get_avatar_data( $id_or_email, $args = null ) {
45454549
'r' => $args['rating'],
45464550
);
45474551

4552+
// Handle additional parameters for the 'initials' avatar type
4553+
if ( 'initials' === $args['default'] ) {
4554+
$name = '';
4555+
4556+
if ( $user ) {
4557+
$name = ! empty( $user->display_name ) ? $user->display_name :
4558+
( ! empty( $user->first_name ) && ! empty( $user->last_name ) ?
4559+
$user->first_name . ' ' . $user->last_name : $user->user_login );
4560+
} elseif ( is_object( $id_or_email ) && isset( $id_or_email->comment_author ) ) {
4561+
$name = $id_or_email->comment_author;
4562+
} elseif ( is_string( $id_or_email ) && false !== strpos( $id_or_email, '@' ) ) {
4563+
$name = str_replace( array( '.', '_', '-' ), ' ', substr( $id_or_email, 0, strpos( $id_or_email, '@' ) ) );
4564+
}
4565+
4566+
if ( ! empty( $name ) ) {
4567+
if ( preg_match( '/\p{Han}|\p{Hiragana}|\p{Katakana}|\p{Hangul}/u', $name ) || false === strpos( $name, ' ' ) ) {
4568+
$initials = mb_substr( $name, 0, min( 2, mb_strlen( $name, 'UTF-8' ) ), 'UTF-8' );
4569+
} else {
4570+
$first = mb_substr( $name, 0, 1, 'UTF-8' );
4571+
$last = mb_substr( $name, strrpos( $name, ' ' ) + 1, 1, 'UTF-8' );
4572+
$initials = $first . $last;
4573+
}
4574+
4575+
$url_args['initials'] = $initials;
4576+
}
4577+
}
4578+
45484579
/*
45494580
* Gravatars are always served over HTTPS.
45504581
*

src/wp-includes/pluggable.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3048,6 +3048,8 @@ function wp_set_password(
30483048
* - 'monsterid' (a monster)
30493049
* - 'wavatar' (a cartoon face)
30503050
* - 'identicon' (the "quilt", a geometric pattern)
3051+
* - 'initials' (initials based avatar with background color)
3052+
* - 'color' (generated background color)
30513053
* - 'mystery', 'mm', or 'mysteryman' (The Oyster Man)
30523054
* - 'blank' (transparent GIF)
30533055
* - 'gravatar_default' (the Gravatar logo)

0 commit comments

Comments
 (0)