Make WordPress Core

Changeset 60269


Ignore:
Timestamp:
05/30/2025 05:00:17 PM (7 weeks ago)
Author:
audrasjb
Message:

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.

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/options-discussion.php

    r59600 r60269  
    310310    'retro'            => __( 'Retro (Generated)' ),
    311311    'robohash'         => __( 'RoboHash (Generated)' ),
     312    'initials'         => __( 'Initials (Generated)' ),
     313    'color'            => __( 'Color (Generated)' ),
    312314);
    313315/**
  • trunk/src/wp-includes/link-template.php

    r60152 r60269  
    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)
     
    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)
     
    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.
  • trunk/src/wp-includes/pluggable.php

    r59893 r60269  
    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)
Note: See TracChangeset for help on using the changeset viewer.