Commit 6a7b277ecc for wordpress.org
commit 6a7b277ecc700857eda3ddb201d9d3de115a97a3
Author: audrasjb <audrasjb@git.wordpress.org>
Date: Fri May 30 17:02:27 2025 +0000
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.
Built from https://develop.svn.wordpress.org/trunk@60269
git-svn-id: http://core.svn.wordpress.org/trunk@59605 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-admin/options-discussion.php b/wp-admin/options-discussion.php
index 6bb8ce2f54..e0e12dc21f 100644
--- a/wp-admin/options-discussion.php
+++ b/wp-admin/options-discussion.php
@@ -309,6 +309,8 @@ $avatar_defaults = array(
'monsterid' => __( 'MonsterID (Generated)' ),
'retro' => __( 'Retro (Generated)' ),
'robohash' => __( 'RoboHash (Generated)' ),
+ 'initials' => __( 'Initials (Generated)' ),
+ 'color' => __( 'Color (Generated)' ),
);
/**
* Filters the default avatars.
diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php
index 3e02c17853..cf41630c4a 100644
--- a/wp-includes/link-template.php
+++ b/wp-includes/link-template.php
@@ -4298,6 +4298,8 @@ function the_shortlink( $text = '', $title = '', $before = '', $after = '' ) {
* - 'monsterid' (a monster)
* - 'wavatar' (a cartoon face)
* - 'identicon' (the "quilt", a geometric pattern)
+ * - 'initials' (initials based avatar with background color)
+ * - 'color' (generated background color)
* - 'mystery', 'mm', or 'mysteryman' (The Oyster Man)
* - 'blank' (transparent GIF)
* - 'gravatar_default' (the Gravatar logo)
@@ -4366,6 +4368,8 @@ function is_avatar_comment_type( $comment_type ) {
* - 'monsterid' (a monster)
* - 'wavatar' (a cartoon face)
* - 'identicon' (the "quilt", a geometric pattern)
+ * - 'initials' (initials based avatar with background color)
+ * - 'color' (generated background color)
* - 'mystery', 'mm', or 'mysteryman' (The Oyster Man)
* - 'blank' (transparent GIF)
* - 'gravatar_default' (the Gravatar logo)
@@ -4545,6 +4549,33 @@ function get_avatar_data( $id_or_email, $args = null ) {
'r' => $args['rating'],
);
+ // Handle additional parameters for the 'initials' avatar type
+ if ( 'initials' === $args['default'] ) {
+ $name = '';
+
+ if ( $user ) {
+ $name = ! empty( $user->display_name ) ? $user->display_name :
+ ( ! empty( $user->first_name ) && ! empty( $user->last_name ) ?
+ $user->first_name . ' ' . $user->last_name : $user->user_login );
+ } elseif ( is_object( $id_or_email ) && isset( $id_or_email->comment_author ) ) {
+ $name = $id_or_email->comment_author;
+ } elseif ( is_string( $id_or_email ) && false !== strpos( $id_or_email, '@' ) ) {
+ $name = str_replace( array( '.', '_', '-' ), ' ', substr( $id_or_email, 0, strpos( $id_or_email, '@' ) ) );
+ }
+
+ if ( ! empty( $name ) ) {
+ if ( preg_match( '/\p{Han}|\p{Hiragana}|\p{Katakana}|\p{Hangul}/u', $name ) || false === strpos( $name, ' ' ) ) {
+ $initials = mb_substr( $name, 0, min( 2, mb_strlen( $name, 'UTF-8' ) ), 'UTF-8' );
+ } else {
+ $first = mb_substr( $name, 0, 1, 'UTF-8' );
+ $last = mb_substr( $name, strrpos( $name, ' ' ) + 1, 1, 'UTF-8' );
+ $initials = $first . $last;
+ }
+
+ $url_args['initials'] = $initials;
+ }
+ }
+
/*
* Gravatars are always served over HTTPS.
*
diff --git a/wp-includes/pluggable.php b/wp-includes/pluggable.php
index e7ce2edb41..c6a0c6e24e 100644
--- a/wp-includes/pluggable.php
+++ b/wp-includes/pluggable.php
@@ -3048,6 +3048,8 @@ if ( ! function_exists( 'get_avatar' ) ) :
* - 'monsterid' (a monster)
* - 'wavatar' (a cartoon face)
* - 'identicon' (the "quilt", a geometric pattern)
+ * - 'initials' (initials based avatar with background color)
+ * - 'color' (generated background color)
* - 'mystery', 'mm', or 'mysteryman' (The Oyster Man)
* - 'blank' (transparent GIF)
* - 'gravatar_default' (the Gravatar logo)
diff --git a/wp-includes/version.php b/wp-includes/version.php
index ae80547f5d..b9ca249807 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '6.9-alpha-60268';
+$wp_version = '6.9-alpha-60269';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.