WordPress.org

Make WordPress Core

Changeset 6748


Ignore:
Timestamp:
02/07/2008 06:07:12 AM (14 years ago)
Author:
ryan
Message:

get_avatar(). see #5775

Location:
trunk
Files:
6 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/schema.php

    r6736 r6748  
    236236    add_option('tag_base');
    237237
     238    // 2.5
     239    add_option('show_avatars', '1');
     240    add_option('avatar_rating', 'G');
     241
    238242    // Delete unused options
    239243    $unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat', 'default_geourl_lon', 'use_default_geourl', 'weblogs_xml_url', 'new_users_can_blog', '_wpnonce', '_wp_http_referer', 'Update', 'action', 'rich_editing');
  • trunk/wp-admin/options-reading.php

    r6475 r6748  
    7676</table>
    7777</fieldset>
     78
     79<fieldset class="options">
     80<legend><?php _e('Avatars') ?></legend>
     81<table class="niceblue">
     82<tr valign="top">
     83<th width="33%" scope="row"><?php _e('Show Avatars?') ?></th>
     84<td>
     85<select name="show_avatars" id="show_avatars">
     86<?php
     87    $yesorno = array(0 => __("Don't show Avatars"), 1 => __('Show Avatars'));
     88    foreach ( $yesorno as $key => $value) {
     89        $selected = (get_option('show_avatars') == $key) ? 'selected="selected"' : '';
     90        echo "\n\t<option value='$key' $selected>$value</option>";
     91    }
     92?>
     93</select>
     94</td>
     95</tr>
     96<tr valign="top">
     97<th width="33%" scope="row"><?php _e('Show Avatars with Rating:') ?></th>
     98<td>
     99<select name="avatar_rating" id="avatar_rating">
     100<?php
     101$ratings = array( 'G' => _c('G|rating'), 'PG' => _c('PG|Rating'), 'R' => _c('R|Rating'), 'X' => _c('X|Rating'));
     102foreach ($ratings as $key => $rating) :
     103    $selected = (get_option('avatar_rating') == $key) ? 'selected="selected"' : '';
     104    echo "\n\t<option value='$key' $selected>$rating</option>";
     105endforeach;
     106?>
     107</select>
     108</td>
     109</tr>
     110</table>
     111</fieldset>
     112
    78113<table class="niceblue">
    79114<tr valign="top">
     
    89124<p class="submit">
    90125<input type="hidden" name="action" value="update" />
    91 <input type="hidden" name="page_options" value="posts_per_page,posts_per_rss,rss_use_excerpt,blog_charset,gzipcompression,show_on_front,page_on_front,page_for_posts" />
     126<input type="hidden" name="page_options" value="posts_per_page,posts_per_rss,rss_use_excerpt,blog_charset,gzipcompression,show_on_front,page_on_front,page_for_posts,show_avatars,avatar_rating" />
    92127<input type="submit" name="Submit" value="<?php _e('Update Options &raquo;') ?>" />
    93128</p>
  • trunk/wp-includes/pluggable.php

    r6739 r6748  
    11631163endif;
    11641164
     1165if ( !function_exists( 'get_avatar' ) ) :
     1166/**
     1167 * get_avatar() - Get avatar for a user
     1168 *
     1169 * Retrieve the avatar for a user provided a user ID or email address
     1170 *
     1171 * @since 2.5
     1172 * @param int|string $id_or_email A user ID or email address
     1173 * @param int $size Size of the avatar image
     1174 * @param string $default URL to a default image to use if no avatar is available
     1175 * @return string <img> tag for the user's avatar
     1176*/
     1177function get_avatar( $id_or_email, $size = '96', $default = '' ) {
     1178    if ( ! get_option('show_avatars') )
     1179        return false;
     1180
     1181    if ( is_numeric($id_or_email) ) {
     1182        $id = (int) $id_or_email;
     1183        $user = get_userdata($id);
     1184        if ( !$user)
     1185            $email = '';
     1186        else
     1187            $email = $user->user_email;
     1188    } else {
     1189        $email = $id_or_email;
     1190    }
     1191
     1192    $default_sizes = array(16, 32, 48, 96, 128);
     1193    if ( empty($default) ) {
     1194        if ( in_array($size, $default_sizes) )
     1195            $default = trailingslashit(get_bloginfo('wpurl')) . "wp-includes/images/avatar/unknown-$size.jpg";
     1196        else
     1197            $default = trailingslashit(get_bloginfo('wpurl')) . "wp-includes/images/avatar/unknown-96.jpg";
     1198    }
     1199
     1200    if ( !empty($email) ) {
     1201        $default = urlencode( $default );
     1202
     1203        $out = 'http://www.gravatar.com/avatar.php?gravatar_id=';
     1204        $out .= md5( $email );
     1205        $out .= "&amp;size={$size}";
     1206        $out .= "&amp;default={$default}";
     1207
     1208        $rating = get_option('avatar_rating');
     1209        if ( !empty( $rating ) )
     1210            $out .= "&amp;rating={$rating}";
     1211
     1212        $avatar = "<img alt='' src='{$out}' class='avatar avatar-{$size}' height='{$size}' width='{$size}' />";
     1213    } else {
     1214        $avatar = "<img alt='' src='{$default}' />";
     1215    }
     1216
     1217    return apply_filters('get_avatar', $avatar, $id_or_email, $size, $default);
     1218}
     1219endif;
     1220
    11651221if ( !function_exists('wp_setcookie') ) :
    11661222/**
  • trunk/wp-includes/version.php

    r6736 r6748  
    1717 * @global int $wp_db_version
    1818 */
    19 $wp_db_version = 6736;
     19$wp_db_version = 6748;
    2020
    2121?>
Note: See TracChangeset for help on using the changeset viewer.