WordPress.org

Make WordPress Core

Ticket #38896: 38896.patch

File 38896.patch, 3.5 KB (added by johnjamesjacoby, 4 years ago)

Add filters for avatar types, plus 1 for the avatar help text (since several old plugins with many active installations modify this area)

  • src/wp-admin/options-discussion.php

    diff --git src/wp-admin/options-discussion.php src/wp-admin/options-discussion.php
    index fefc0d8..1c715a8 100644
     
    217217<th scope="row"><?php _e('Default Avatar'); ?></th>
    218218<td class="defaultavatarpicker"><fieldset><legend class="screen-reader-text"><span><?php _e('Default Avatar'); ?></span></legend>
    219219
    220 <?php _e('For users without a custom avatar of their own, you can either display a generic logo or a generated one based on their email address.'); ?><br />
    221 
    222220<?php
    223 $avatar_defaults = array(
     221
     222$static_avatars = array(
    224223        'mystery' => __('Mystery Person'),
    225224        'blank' => __('Blank'),
    226         'gravatar_default' => __('Gravatar Logo'),
     225        'gravatar_default' => __('Gravatar Logo')
     226);
     227
     228$avatar_generated =     array(
    227229        'identicon' => __('Identicon (Generated)'),
    228230        'wavatar' => __('Wavatar (Generated)'),
    229231        'monsterid' => __('MonsterID (Generated)'),
    230232        'retro' => __('Retro (Generated)')
    231233);
     234
     235/**
     236 * Filters the generated avatars.
     237 *
     238 * Avatars are stored in key/value pairs, where the key is option value,
     239 * and the name is the displayed avatar name.
     240 *
     241 * @since 4.8.0
     242 *
     243 * @param array $avatar_generated Array of default avatars.
     244 */
     245$static_avatars = apply_filters( 'default_static_avatars', $static_avatars );
     246
     247/**
     248 * Filters the generated avatars.
     249 *
     250 * Avatars are stored in key/value pairs, where the key is option value,
     251 * and the name is the displayed avatar name.
     252 *
     253 * @since 4.8.0
     254 *
     255 * @param array $avatar_generated Array of default avatars.
     256 */
     257$avatar_generated = apply_filters( 'default_generated_avatars', $avatar_generated );
     258
     259// Merge the two avatar types together
     260$avatar_defaults = array_merge( $static_avatars, $avatar_generated );
     261
    232262/**
    233263 * Filters the default avatars.
    234264 *
     
    239269 *
    240270 * @param array $avatar_defaults Array of default avatars.
    241271 */
    242 $avatar_defaults = apply_filters( 'avatar_defaults', $avatar_defaults );
     272$new_avatar_defaults = apply_filters( 'avatar_defaults', $avatar_defaults );
     273
     274if ( array_intersect_key( $new_avatar_defaults, $avatar_generated ) ) {
     275        $default_avatar_help = __( 'For users without a custom avatar of their own, you can either display a generic logo or a generated one based on their email address.');
     276} else {
     277        $default_avatar_help = __( 'For users without a custom avatar of their own, you can display a generic logo instead.');
     278}
     279
     280/**
     281 * Filters the help text used for default avatars.
     282 *
     283 * Avatars are stored in key/value pairs, where the key is option value,
     284 * and the name is the displayed avatar name.
     285 *
     286 * @since 4.8.0
     287 *
     288 * @param array $default_avatar_help Array of default avatars.
     289 */
     290$default_avatar_help = apply_filters( 'default_avatar_help', $default_avatar_help );
     291
     292// Maybe output default avatar help text
     293if ( ! empty( $default_avatar_help ) ) {
     294        echo '<p><label for="avatar_default">'. $default_avatar_help . '</label></p>';
     295}
     296
    243297$default = get_option( 'avatar_default', 'mystery' );
    244298$avatar_list = '';
    245299
    246300// Force avatars on to display these choices
    247301add_filter( 'pre_option_show_avatars', '__return_true', 100 );
    248302
    249 foreach ( $avatar_defaults as $default_key => $default_name ) {
     303foreach ( $new_avatar_defaults as $default_key => $default_name ) {
    250304        $selected = ($default == $default_key) ? 'checked="checked" ' : '';
    251305        $avatar_list .= "\n\t<label><input type='radio' name='avatar_default' id='avatar_{$default_key}' value='" . esc_attr($default_key) . "' {$selected}/> ";
    252306        $avatar_list .= get_avatar( $user_email, 32, $default_key, '', array( 'force_default' => true ) );