WP User Avatar - Version 1.1

Version Description

  • Add: Add filter for get_avatar
  • Add: CSS alignment classes
  • Add: Replace comment author avatar
  • Add: Shortcode
  • Update: readme.txt
Download this release

Release Info

Developer bangbay
Plugin Icon 128x128 WP User Avatar
Version 1.1
Comparing to
See all releases

Version 1.1

Files changed (5) hide show
  1. css/wp-user-avatar.css +2 -0
  2. index.html +1 -0
  3. js/wp-user-avatar.js +11 -0
  4. readme.txt +179 -0
  5. wp-user-avatar.php +312 -0
css/wp-user-avatar.css ADDED
@@ -0,0 +1,2 @@
1
+ #wp-user-avatar-message { color: #c00; display: none; }
2
+ #wp-user-avatar-preview img { max-width: 96px; }
index.html ADDED
@@ -0,0 +1 @@
1
+ <!-- Thanks for using WP User Avatar! -->
js/wp-user-avatar.js ADDED
@@ -0,0 +1,11 @@
1
+ function setWPUserAvatar(attachment, imageURL){
2
+ jQuery('#wp-user-avatar', window.parent.document).val(attachment);
3
+ jQuery('#wp-user-avatar-preview', window.parent.document).find('img').attr('src', imageURL).attr('width', '96').removeAttr('height', '');
4
+ jQuery('#wp-user-avatar-message', window.parent.document).show();
5
+ jQuery('#remove-wp-user-avatar', window.parent.document).show();
6
+ if(typeof(wp) != 'undefined'){
7
+ wp.media.wpUserAvatar.frame().close()
8
+ } else {
9
+ window.parent.tb_remove();
10
+ }
11
+ }
readme.txt ADDED
@@ -0,0 +1,179 @@
1
+ === WP User Avatar ===
2
+
3
+ Contributors: bangbay
4
+ Donate link: http://siboliban.org/donate
5
+ Tags: author image, author photo, author avatar, avatar, profile avatar, profile image, profile photo, user avatar, user image, user photo
6
+ Requires at least: 3.3
7
+ Tested up to: 3.5
8
+ Stable tag: 1.1
9
+ License: GPLv2 or later
10
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
+
12
+ Use any image from your WordPress Media Library as a custom user avatar.
13
+
14
+ == Description ==
15
+
16
+ WordPress currently only allows you to use custom avatars that are uploaded through gravatar.com. WP User Avatar enables you to use any photo uploaded into your Media Library as an avatar. This means you use the same uploader and library as your posts. No extra folders or image editing functions are necessary.
17
+
18
+ To use WP User Avatar in your theme, manually replace <code>get_avatar()</code> with <code>get_wp_user_avatar()</code> or leave <code>get_avatar()</code> as-is. <code>get_wp_user_avatar()</code> has functionality not available in <code>get_avatar()</code>. You can also use the shortcode <code>[avatar]</code> in your posts.
19
+
20
+ This plugin uses the new Media Uploader introduced in WordPress 3.5, but is also backwards-compatible to WordPress 3.3.
21
+
22
+ == Installation ==
23
+
24
+ 1. Download, install, and activate the WP User Avatar plugin.
25
+ 2. On your edit profile page, click "Edit WP User Avatar".
26
+ 3. Choose an image, then click "Set WP User Avatar".
27
+ 4. Click "Update Profile".
28
+ 5. In your theme, manually replace <code>get_avatar()</code> with <code>get_wp_user_avatar()</code> or leave <code>get_avatar()</code> as-is.
29
+ 6. You can also use the shortcode <code>[avatar]</code> in your posts.
30
+
31
+ **Example Usage**
32
+
33
+ Within The Loop, you may be using:
34
+
35
+ `<?php echo get_avatar(get_the_author_meta('ID'), 96); ?>`
36
+
37
+ Replace this function with:
38
+
39
+ `<?php echo get_wp_user_avatar(get_the_author_meta('ID'), 96); ?>`
40
+
41
+ You can also use the values "original", "large", "medium", or "thumbnail" for your avatar size:
42
+
43
+ `<?php echo get_wp_user_avatar(get_the_author_meta('ID'), 'medium'); ?>`
44
+
45
+ You can also add an alignment of "left", "right", or "center":
46
+
47
+ `<?php echo get_wp_user_avatar(get_the_author_meta('ID'), 96, 'left'); ?>`
48
+
49
+ On an author page outside of The Loop, you may be using:
50
+
51
+ `<?php
52
+ $user = get_user_by('slug', $author_name);
53
+ echo get_avatar($user->ID, 96);
54
+ ?>`
55
+
56
+ Replace this function with:
57
+
58
+ `<?php
59
+ $user = get_user_by('slug', $author_name);
60
+ echo get_wp_user_avatar($user->ID, 96);
61
+ ?>`
62
+
63
+ If you leave the options blank, WP User Avatar will detect whether you're inside The Loop or on an author page and return the correct avatar in the default 96x96 size:
64
+
65
+ `<?php echo get_wp_user_avatar(); ?>`
66
+
67
+ The function <code>get_wp_user_avatar()</code> will also fall back to <code>get_avatar()</code> if no WP User Avatar image is set. For this to work, "Show Avatars" must be checked in your Discussion settings.
68
+
69
+ **Other Available Functions**
70
+
71
+ = [avatar] shortcode =
72
+
73
+ You can use the shortcode <code>[avatar]</code> in your posts. It will detect the author of the post or you can specify an author by username. You can specify a size and alignment, but they are optional.
74
+
75
+ `[avatar user="admin" size="medium" align="left"]`
76
+
77
+ = get_wp_user_avatar_src() =
78
+
79
+ Works just like <code>get_wp_user_avatar()</code> but returns just the image src. This is useful if you would like to link a thumbnail-sized avatar to a larger version of the image:
80
+
81
+ `<a href="<?php echo get_wp_user_avatar_src($user_id, 'large'); ?>">
82
+ <?php echo get_wp_user_avatar($user_id, 'thumbnail'); ?>
83
+ </a>`
84
+
85
+ = has_wp_user_avatar() =
86
+
87
+ Returns true if the user has a WP User Avatar image. You can specify the user ID, or leave it blank to detect the author within The Loop or author page:
88
+
89
+ `<?php
90
+ if ( has_wp_user_avatar($user_id) ) {
91
+ echo get_wp_user_avatar($user_id, 96);
92
+ } else {
93
+ echo '<img src="my-alternate-image.jpg" />';
94
+ }
95
+ ?>`
96
+
97
+ == Frequently Asked Questions ==
98
+
99
+ = How do I use WP User Avatar? =
100
+
101
+ You have a choice of manually replacing <code>get_avatar()</code> with <code>get_wp_user_avatar()</code> in your theme, or leaving <code>get_avatar()</code> as-is. Here are the differences:
102
+
103
+ = get_wp_user_avatar() =
104
+
105
+ 1. Allows you to use the values "original", "large", "medium", or "thumbnail" for your avatar size.
106
+ 2. Doesn't add a fixed width and height to the image if you use the aforementioned values. This will give you more flexibility to resize the image with CSS.
107
+ 3. Optionally adds CSS classes "alignleft", "alignright", or "aligncenter" to position your avatar.
108
+ 4. Shows nothing if no WP User Avatar image is set.
109
+ 5. Shows the default avatar only if "Show Avatars" is enabled in your Discussion settings.
110
+
111
+ = get_avatar() =
112
+
113
+ 1. Requires you to enable "Show Avatars" in your Discussion settings to show any avatars.
114
+ 2. Accepts only numeric values for your avatar size.
115
+ 3. Always adds a fixed width and height to your image. This may cause problems if you use responsive CSS in your theme.
116
+ 4. Shows the default avatar if no WP User Avatar image is set. (Choosing "Blank" still generates a transparent image file.)
117
+ 5. Requires no changes to your theme files if you are currently using <code>get_avatar()</code>.
118
+
119
+ = How can I see which users have an avatar? =
120
+
121
+ For administrators, WP User Avatar adds a column with avatar thumbnails to your Users admin table. If "Show Avatars" is enabled in your Discussion settings, you will see avatars to the left of each username instead of in a new column.
122
+
123
+ = Will WP User Avatar work with comment author avatars? =
124
+
125
+ Yes, for registered users. Non-registered comment authors will show their gravatar.com avatars.
126
+
127
+ = Can I insert WP User Avatar directly into a post? =
128
+
129
+ You can use the shortcode <code>[avatar]</code> in your posts. It will detect the author of the post or you can specify an author by username. You can specify a size or alignment, but they are optional.
130
+
131
+ `[avatar user="admin" size="medium" align="left"]`
132
+
133
+ = What CSS can I use with WP User Avatar? =
134
+
135
+ WP User Avatar will add the CSS classes "wp-user-avatar" and "wp-user-avatar-{size}" to your image. If you add an alignment, the corresponding alignment class will be added:
136
+
137
+ `<?php echo get_wp_user_avatar($user_id, 96, 'left'); ?>`
138
+
139
+ Outputs:
140
+
141
+ `<img src="{imageURL}" width="96" height="96" class="wp-user-avatar wp-user-avatar-96 alignleft" />`
142
+
143
+ If you use the values "original", "large", "medium", or "thumbnail", no width or height will be added to the image. This will give you more flexibility to resize the image with CSS:
144
+
145
+ `<?php echo get_wp_user_avatar($user_id, 'medium'); ?>`
146
+
147
+ Outputs:
148
+
149
+ `<img src="{imageURL}" class="wp-user-avatar wp-user-avatar-medium" />`
150
+
151
+ **Note:** WordPress adds more CSS classes to the avater not listed here.
152
+
153
+ == Screenshots ==
154
+
155
+ 1. WP User Avatar adds a field to your profile in edit mode.
156
+
157
+ == Changelog ==
158
+
159
+ = 1.1 =
160
+ * Add: Add filter for get_avatar
161
+ * Add: CSS alignment classes
162
+ * Add: Replace comment author avatar
163
+ * Add: Shortcode
164
+ * Update: readme.txt
165
+
166
+ = 1.0.2 =
167
+ * Update: FAQ
168
+ * Remove: CSS that hides "Insert into Post"
169
+
170
+ = 1.0.1 =
171
+ * Add: CSS classes to image output
172
+
173
+ = 1.0 =
174
+ * Initial release
175
+
176
+ == Upgrade Notice ==
177
+
178
+ = 1.1 =
179
+ * New Features: [avatar] shortcode, direct replacement of get_avatar() and comment author avatar, more CSS classes
wp-user-avatar.php ADDED
@@ -0,0 +1,312 @@
1
+ <?php
2
+ /**
3
+ * @package WP User Avatar
4
+ * @version 1.1
5
+ */
6
+ /*
7
+ Plugin Name: WP User Avatar
8
+ Plugin URI: http://wordpress.org/extend/plugins/wp-user-avatar/
9
+ Description: Use any image from your WordPress Media Library as a custom user avatar.
10
+ Version: 1.1
11
+ Author: Bangbay Siboliban
12
+ Author URI: http://siboliban.org/
13
+ */
14
+
15
+ // Define paths and variables
16
+ define('WP_USER_AVATAR_FOLDER', basename(dirname(__FILE__)));
17
+ define('WP_USER_AVATAR_ABSPATH', trailingslashit(str_replace('\\','/', WP_PLUGIN_DIR.'/'.WP_USER_AVATAR_FOLDER)));
18
+ define('WP_USER_AVATAR_URLPATH', trailingslashit(plugins_url(WP_USER_AVATAR_FOLDER)));
19
+
20
+ // Remove user metadata on plugin delete
21
+ register_uninstall_hook(__FILE__, 'wp_user_avatar_delete_setup');
22
+
23
+ // Remove user metadata
24
+ function wp_user_avatar_delete_setup(){
25
+ $users = get_users();
26
+ foreach($users as $user){
27
+ delete_user_meta($user->ID, 'wp_user_avatar');
28
+ }
29
+ }
30
+
31
+ // WP User Avatar
32
+ if(!class_exists('wp_user_avatar')){
33
+ class wp_user_avatar{
34
+ function wp_user_avatar(){
35
+ add_action('show_user_profile', array('wp_user_avatar','action_show_user_profile'));
36
+ add_action('edit_user_profile', array($this,'action_show_user_profile'));
37
+ add_action('personal_options_update', array($this,'action_process_option_update'));
38
+ add_action('edit_user_profile_update', array($this,'action_process_option_update'));
39
+ if(!function_exists('wp_enqueue_media')){
40
+ add_filter('attachment_fields_to_edit', array($this, 'add_wp_user_avatar_attachment_field_to_edit'), 10, 2);
41
+ }
42
+ if(get_option('show_avatars') != '1'){
43
+ add_filter('manage_users_columns', array($this, 'add_wp_user_avatar_column'), 10, 1);
44
+ add_filter('manage_users_custom_column', array($this, 'show_wp_user_avatar_column'), 10, 3);
45
+ }
46
+ add_action('admin_enqueue_scripts', array($this, 'media_upload_scripts'));
47
+ }
48
+
49
+ // Add to user profile edit
50
+ function action_show_user_profile($user){
51
+ $wp_user_avatar = get_user_meta($user->ID, 'wp_user_avatar', true);
52
+ $hide = !has_wp_user_avatar($user->ID) ? ' style="display:none;"' : '';
53
+ ?>
54
+ <h3><?php _e('WP User Avatar') ?></h3>
55
+ <table class="form-table">
56
+ <tbody>
57
+ <tr>
58
+ <th><label for="wp_user_avatar"><?php _e('WP User Avatar'); ?></label></th>
59
+ <td>
60
+ <input type="hidden" name="wp-user-avatar" id="wp-user-avatar" value="<?php echo $wp_user_avatar; ?>" />
61
+ <p><button type="button" class="button" id="add-wp-user-avatar"><?php _e('Edit WP User Avatar'); ?></button></p>
62
+ <div id="wp-user-avatar-preview">
63
+ <p>
64
+ <?php
65
+ if(has_wp_user_avatar($user->ID)){
66
+ echo get_wp_user_avatar($user->ID, 'medium');
67
+ } else {
68
+ if(get_option('show_avatars') == '1'){
69
+ echo get_avatar($user->ID, 96);
70
+ } else {
71
+ echo '<img src="'.includes_url().'images/blank.gif" alt="" />';
72
+ }
73
+ }
74
+ ?>
75
+ </p>
76
+ </div>
77
+ <p><button type="button" class="button" id="remove-wp-user-avatar"<?php echo $hide; ?>><?php _e('Remove'); ?></button></p>
78
+ <p id="wp-user-avatar-message"><?php _e('Press "Update Profile" to save your changes.'); ?></p>
79
+ </td>
80
+ </tr>
81
+ </tbody>
82
+ </table>
83
+ <script type="text/javascript">
84
+ jQuery(function($){
85
+ <?php if(function_exists('wp_enqueue_media')) : // Use Backbone uploader for WP 3.5+ ?>
86
+ wp.media.wpUserAvatar = {
87
+ get: function() {
88
+ return wp.media.view.settings.post.wpUserAvatarId;
89
+ },
90
+ set: function(id) {
91
+ var settings = wp.media.view.settings;
92
+ settings.post.wpUserAvatarId = id;
93
+ settings.post.wpUserAvatarSrc = $('div.attachment-info').find('img').attr('src');
94
+ if(settings.post.wpUserAvatarId)
95
+ setWPUserAvatar(settings.post.wpUserAvatarId, settings.post.wpUserAvatarSrc);
96
+ },
97
+ frame: function(){
98
+ if(this._frame)
99
+ return this._frame;
100
+ this._frame = wp.media({
101
+ state: 'library',
102
+ states: [ new wp.media.controller.Library({ title: "Edit WP User Avatar: <?php echo $user->display_name; ?>" }) ]
103
+ });
104
+ this._frame.on('open', function(){
105
+ var selection = this.state().get('selection');
106
+ id = jQuery('#wp-user-avatar').val();
107
+ attachment = wp.media.attachment(id);
108
+ attachment.fetch();
109
+ selection.add(attachment ? [ attachment ] : []);
110
+ }, this._frame);
111
+ this._frame.on('toolbar:create:select', function(toolbar){
112
+ this.createSelectToolbar(toolbar, {
113
+ text: 'Set WP User Avatar'
114
+ });
115
+ }, this._frame);
116
+ this._frame.state('library').on('select', this.select);
117
+ return this._frame;
118
+ },
119
+ select: function(id) {
120
+ var settings = wp.media.view.settings,
121
+ selection = this.get('selection').single();
122
+ wp.media.wpUserAvatar.set(selection ? selection.id : -1);
123
+ },
124
+ init: function() {
125
+ $('body').on('click', '#add-wp-user-avatar', function(e){
126
+ e.preventDefault();
127
+ e.stopPropagation();
128
+ wp.media.wpUserAvatar.frame().open();
129
+ });
130
+ }
131
+ };
132
+ $(wp.media.wpUserAvatar.init);
133
+ <?php else : // Fall back to Thickbox uploader ?>
134
+ $('#add-wp-user-avatar').click(function(e){
135
+ e.preventDefault();
136
+ tb_show('Edit WP User Avatar: <?php echo $user->display_name; ?>', 'media-upload.php?type=image&post_type=user&tab=library&TB_iframe=1');
137
+ });
138
+ <?php endif; ?>
139
+ });
140
+ jQuery(function($){
141
+ $('#remove-wp-user-avatar').click(function(e){
142
+ var gravatar = '<img src="<?php echo includes_url().'images/blank.gif'; ?>" alt="" />';
143
+ e.preventDefault();
144
+ $(this).hide();
145
+ $('#wp-user-avatar-preview').find('img').replaceWith(gravatar);
146
+ $('#wp-user-avatar').val('');
147
+ $('#wp-user-avatar-message').show();
148
+ });
149
+ });
150
+ </script>
151
+ <?php
152
+ }
153
+ // Update user meta
154
+ function action_process_option_update($user_id){
155
+ update_user_meta($user_id, 'wp_user_avatar', (isset($_POST['wp-user-avatar']) ? $_POST['wp-user-avatar'] : ''));
156
+ }
157
+
158
+ // Add button to attach image
159
+ function add_wp_user_avatar_attachment_field_to_edit($fields, $post){
160
+ $image = wp_get_attachment_image_src($post->ID, "medium");
161
+ $button .= '<button type="button" class="button" id="set-wp-user-avatar-image" onclick="setWPUserAvatar(\''.$post->ID.'\', \''.$image[0].'\')">Set WP User Avatar</button>';
162
+ $fields['wp-user-avatar'] = array(
163
+ 'label' => __('WP User Avatar'),
164
+ 'input' => 'html',
165
+ 'html' => $button
166
+ );
167
+ return $fields;
168
+ }
169
+
170
+ // Add column to Users page
171
+ function add_wp_user_avatar_column($columns){
172
+ return $columns + array('wp-user-avatar' => __('WP User Avatar'));;
173
+ }
174
+
175
+ // Show thumbnail of wp_user_avatar
176
+ function show_wp_user_avatar_column($value, $column_name, $user_id){
177
+ $wp_user_avatar = get_user_meta($user_id, 'wp_user_avatar', true);
178
+ $wp_user_avatar_image = wp_get_attachment_image($wp_user_avatar, array(32,32));
179
+ if($column_name == 'wp-user-avatar'){
180
+ return $wp_user_avatar_image;
181
+ }
182
+ }
183
+
184
+ // Media uploader
185
+ function media_upload_scripts(){
186
+ wp_enqueue_script('media-upload');
187
+ wp_enqueue_script('thickbox');
188
+ if(function_exists('wp_enqueue_media')){
189
+ wp_enqueue_media();
190
+ }
191
+ wp_enqueue_script('wp-user-avatar', WP_USER_AVATAR_URLPATH.'js/wp-user-avatar.js');
192
+ wp_enqueue_style('thickbox');
193
+ wp_enqueue_style('wp-user-avatar', WP_USER_AVATAR_URLPATH.'css/wp-user-avatar.css');
194
+ }
195
+ }
196
+ // Initialize wp_user_avatar
197
+ global $wp_user_avatar_instance;
198
+ $wp_user_avatar_instance = new wp_user_avatar();
199
+ }
200
+
201
+ // Returns true if user has wp_user_avatar
202
+ function has_wp_user_avatar($user_id = ''){
203
+ global $post;
204
+ if(empty($user_id)){
205
+ $author_name = get_query_var('author_name');
206
+ $user = is_author() ? get_user_by('slug', $author_name) : get_the_author_meta('id');
207
+ $user_id = $user->ID;
208
+ }
209
+ $wp_user_avatar = get_user_meta($user_id, 'wp_user_avatar', true);
210
+ if(!empty($wp_user_avatar)){
211
+ return true;
212
+ }
213
+ }
214
+
215
+ // Find wp_user_avatar, show get_avatar if empty
216
+ function get_wp_user_avatar($id_or_email = '', $size = '96', $align = ''){
217
+ global $post, $comment;
218
+ $author_name = get_query_var('author_name');
219
+ $user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
220
+ // Find user ID on comment, author page, or post
221
+ if(is_object($id_or_email)){
222
+ $id_or_email = $comment->user_id != '0' ? $comment->user_id : $comment->comment_author_email;
223
+ $alt = $comment->comment_author;
224
+ } else {
225
+ if(!empty($id_or_email)){
226
+ $user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
227
+ } else {
228
+ $user = is_author() ? get_user_by('slug', $author_name) : get_the_author_meta('id');
229
+ }
230
+ $id_or_email = $user->ID;
231
+ $alt = $user->display_name;
232
+ }
233
+ $wp_user_avatar_meta = get_the_author_meta('wp_user_avatar', $id_or_email);
234
+ $alignclass = !empty($align) ? ' align'.$align : '';
235
+ if(!empty($wp_user_avatar_meta)){
236
+ $get_size = is_numeric($size) ? array($size,$size) : $size;
237
+ $wp_user_avatar_image = wp_get_attachment_image_src($wp_user_avatar_meta, $get_size);
238
+ $dimensions = is_numeric($size) ? ' width="'.$wp_user_avatar_image[1].'" height="'.$wp_user_avatar_image[2].'"' : '';
239
+ $wp_user_avatar = '<img src="'.$wp_user_avatar_image[0].'"'.$dimensions.' alt="'.$alt.'" class="wp-user-avatar wp-user-avatar-'.$size.$alignclass.' avatar avatar-'.$size.' photo" />';
240
+ } else {
241
+ $default = '';
242
+ $alt = '';
243
+ if($size == 'original' || $size == 'large'){
244
+ $get_size = get_option('large_size_w');
245
+ } elseif($size == 'medium'){
246
+ $get_size = get_option('medium_size_w');
247
+ } elseif($size == 'thumbnail'){
248
+ $get_size = get_option('thumbnail_size_w');
249
+ } else {
250
+ $get_size = $size;
251
+ }
252
+ $avatar = get_avatar($id_or_email, $get_size, $default, $alt);
253
+ $gravatar = str_replace("class='", "class='wp-user-avatar wp-user-avatar-".$get_size.$alignclass." ", $avatar);
254
+ $wp_user_avatar = $gravatar;
255
+ }
256
+ return $wp_user_avatar;
257
+ }
258
+
259
+ // Return just the image src
260
+ function get_wp_user_avatar_src($id_or_email, $size = '', $align = ''){
261
+ $wp_user_avatar_image = get_wp_user_avatar($id_or_email, $size, $align);
262
+ $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $wp_user_avatar_image, $matches, PREG_SET_ORDER);
263
+ $wp_user_avatar_image_src = $matches [0] [1];
264
+ return $wp_user_avatar_image_src;
265
+ }
266
+
267
+ // Replace get_avatar()
268
+ function get_wp_user_avatar_alt($avatar, $id_or_email, $size = '', $default = '', $alt = false){
269
+ global $post, $pagenow, $comment;
270
+ $author_name = get_query_var('author_name');
271
+ $user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
272
+ // Find user ID on comment, author page, or post
273
+ if(is_object($id_or_email)){
274
+ $id_or_email = $comment->user_id != '0' ? $comment->user_id : $comment->comment_author_email;
275
+ $alt = $comment->comment_author;
276
+ } else {
277
+ if(!empty($id_or_email)){
278
+ $user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
279
+ } else {
280
+ $user = is_author() ? get_user_by('slug', $author_name) : get_the_author_meta('id');
281
+ }
282
+ $id_or_email = $user->ID;
283
+ $alt = $user->display_name;
284
+ }
285
+ $wp_user_avatar_meta = get_the_author_meta('wp_user_avatar', $id_or_email);
286
+ if(!empty($wp_user_avatar_meta) && $pagenow != 'options-discussion.php'){
287
+ $wp_user_avatar_image = wp_get_attachment_image_src($wp_user_avatar_meta, array($size,$size));
288
+ $dimensions = is_numeric($size) ? ' width="'.$wp_user_avatar_image[1].'" height="'.$wp_user_avatar_image[2].'"' : '';
289
+ $wp_user_avatar = '<img src="'.$wp_user_avatar_image[0].'"'.$dimensions.' alt="'.$alt.'" class="wp-user-avatar wp-user-avatar-'.$size.' avatar avatar-'.$size.' photo" />';
290
+ } else {
291
+ $gravatar = str_replace("class='", "class='wp-user-avatar wp-user-avatar-".$size." ", $avatar);
292
+ $wp_user_avatar = $gravatar;
293
+ }
294
+ return $wp_user_avatar;
295
+ }
296
+ add_filter('get_avatar', 'get_wp_user_avatar_alt', 10, 6);
297
+
298
+ // Shortcode
299
+ function wp_user_avatar_shortcode($atts, $content){
300
+ // EXAMPLE USAGE:
301
+ // [avatar size="medium"]
302
+
303
+ // Set shortcode attributes
304
+ extract(shortcode_atts(array('user' => '', 'size' => '96', 'align' => ''), $atts));
305
+ $get_user = get_user_by('slug', $user);
306
+ $id_or_email = !empty($get_user) ? $get_user->ID : '';
307
+ $wp_user_avatar = get_wp_user_avatar($id_or_email, $size, $align);
308
+ return $wp_user_avatar;
309
+ }
310
+ add_shortcode('avatar','wp_user_avatar_shortcode');
311
+
312
+ ?>