Skip to content

Commit b0a8da6

Browse files
committed
get_avatar(). see WordPress#5775
git-svn-id: https://develop.svn.wordpress.org/trunk@6748 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 147843f commit b0a8da6

9 files changed

Lines changed: 97 additions & 2 deletions

File tree

wp-admin/includes/schema.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ function populate_options() {
235235
// 2.2
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');
240244
foreach ($unusedoptions as $option) :

wp-admin/options-reading.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,41 @@
7575
</tr>
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'));
102+
foreach ($ratings as $key => $rating) :
103+
$selected = (get_option('avatar_rating') == $key) ? 'selected="selected"' : '';
104+
echo "\n\t<option value='$key' $selected>$rating</option>";
105+
endforeach;
106+
?>
107+
</select>
108+
</td>
109+
</tr>
110+
</table>
111+
</fieldset>
112+
78113
<table class="niceblue">
79114
<tr valign="top">
80115
<th width="33%" scope="row"><?php _e('Encoding for pages and feeds:') ?></th>
@@ -88,7 +123,7 @@
88123
</p>
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>
94129
</form>
1.72 KB
Loading
787 Bytes
Loading
920 Bytes
Loading
1015 Bytes
Loading
1.41 KB
Loading

wp-includes/pluggable.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,62 @@ function wp_set_password( $password, $user_id ) {
11621162
}
11631163
endif;
11641164

1165+
if ( !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+
*/
1177+
function 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+
}
1219+
endif;
1220+
11651221
if ( !function_exists('wp_setcookie') ) :
11661222
/**
11671223
* wp_setcookie() - Sets a cookie for a user who just logged in

wp-includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
*
1717
* @global int $wp_db_version
1818
*/
19-
$wp_db_version = 6736;
19+
$wp_db_version = 6748;
2020

2121
?>

0 commit comments

Comments
 (0)