WP User Avatar - Version 1.2.1

Version Description

  • Add: TinyMCE button
  • Update: Clean up redundant code
  • Update: Compatibility only back to WordPress 3.3
Download this release

Release Info

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

Version 1.2.1

css/wp-user-avatar.css ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ #wp-user-avatar-message { color: #c00; display: none; }
2
+ #wp-user-avatar-preview img { max-width: 96px; }
3
+ .defaultavatarpicker #wp-user-avatar-preview { width: 32px; height: 32px; display: inline-block; overflow: hidden; vertical-align: middle; }
4
+ .defaultavatarpicker #wp-user-avatar-preview img { width: 32px; }
images/wp-user-avatar-32x32.png ADDED
Binary file
images/wp-user-avatar.png ADDED
Binary file
includes/tinymce.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package WP User Avatar
4
+ * @version 1.2.1
5
+ */
6
+
7
+ function myplugin_addbuttons() {
8
+ // Don't bother doing this stuff if the current user lacks permissions
9
+ if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') )
10
+ return;
11
+
12
+ // Add only in Rich Editor mode
13
+ if(get_user_option('rich_editing') == 'true'){
14
+ add_filter('mce_external_plugins', 'add_myplugin_tinymce_plugin');
15
+ add_filter('mce_buttons', 'register_myplugin_button');
16
+ }
17
+ }
18
+
19
+ function register_myplugin_button($buttons) {
20
+ array_push($buttons, 'separator', 'wpUserAvatar');
21
+ return $buttons;
22
+ }
23
+
24
+ // Load the TinyMCE plugin : editor_plugin.js (wp2.5)
25
+ function add_myplugin_tinymce_plugin($plugin_array) {
26
+ $plugin_array['wpUserAvatar'] = WP_USER_AVATAR_URLPATH.'includes/tinymce/editor_plugin.js';
27
+ return $plugin_array;
28
+ }
29
+
30
+ // init process for button control
31
+ add_action('init', 'myplugin_addbuttons');
32
+
33
+ // Call TinyMCE window content via admin-ajax
34
+ function wp_user_avatar_ajax_tinymce(){
35
+ if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') )
36
+ die('You are not allowed to call this page directly.');
37
+ include_once(WP_USER_AVATAR_ABSPATH.'includes/tinymce/window.php');
38
+ die();
39
+ }
40
+ add_action('wp_ajax_wp_user_avatar_tinymce', 'wp_user_avatar_ajax_tinymce');
41
+
42
+ ?>
includes/tinymce/editor_plugin.js ADDED
@@ -0,0 +1 @@
 
1
+ (function(){tinymce.PluginManager.requireLangPack('wpUserAvatar');tinymce.create('tinymce.plugins.wpUserAvatar',{init:function(ed,url){ed.addCommand('mceWpUserAvatar',function(){ed.windowManager.open({file:ajaxurl+'?action=wp_user_avatar_tinymce',width:300,height:175,inline:1},{plugin_url:url})});ed.addButton('wpUserAvatar',{title:'Insert WP User Avatar',cmd:'mceWpUserAvatar',image:url+'/../../images/wp-user-avatar.png'});ed.onNodeChange.add(function(ed,cm,n){cm.setActive('wpUserAvatar',n.nodeName=='IMG')})},createControl:function(n,cm){return null},getInfo:function(){return{longname:'WP User Avatar',author:'Bangbay Siboliban',authorurl:'http://siboliban.org/',infourl:'http://wordpress.org/extend/plugins/wp-user-avatar/',version:"1.2.1"}}});tinymce.PluginManager.add('wpUserAvatar',tinymce.plugins.wpUserAvatar)})();
includes/tinymce/editor_plugin.src.js ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Docu : http://wiki.moxiecode.com/index.php/TinyMCE:Create_plugin/3.x#Creating_your_own_plugins
2
+
3
+ (function() {
4
+ // Load plugin specific language pack
5
+ tinymce.PluginManager.requireLangPack('wpUserAvatar');
6
+
7
+ tinymce.create('tinymce.plugins.wpUserAvatar', {
8
+ /**
9
+ * Initializes the plugin, this will be executed after the plugin has been created.
10
+ * This call is done before the editor instance has finished it's initialization so use the onInit event
11
+ * of the editor instance to intercept that event.
12
+ *
13
+ * @param {tinymce.Editor} ed Editor instance that the plugin is initialized in.
14
+ * @param {string} url Absolute URL to where the plugin is located.
15
+ */
16
+ init : function(ed, url) {
17
+ // Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('mceExample');
18
+
19
+ ed.addCommand('mceWpUserAvatar', function() {
20
+ ed.windowManager.open({
21
+ // call content via admin-ajax, no need to know the full plugin path
22
+ file : ajaxurl + '?action=wp_user_avatar_tinymce',
23
+ width : 300,
24
+ height : 175,
25
+ inline : 1
26
+ }, {
27
+ plugin_url : url // Plugin absolute URL
28
+ });
29
+ });
30
+
31
+ // Register example button
32
+ ed.addButton('wpUserAvatar', {
33
+ title : 'Insert WP User Avatar',
34
+ cmd : 'mceWpUserAvatar',
35
+ image : url + '/../../images/wp-user-avatar.png'
36
+ });
37
+
38
+ // Add a node change handler, selects the button in the UI when a image is selected
39
+ ed.onNodeChange.add(function(ed, cm, n) {
40
+ cm.setActive('wpUserAvatar', n.nodeName == 'IMG');
41
+ });
42
+ },
43
+
44
+ /**
45
+ * Creates control instances based in the incomming name. This method is normally not
46
+ * needed since the addButton method of the tinymce.Editor class is a more easy way of adding buttons
47
+ * but you sometimes need to create more complex controls like listboxes, split buttons etc then this
48
+ * method can be used to create those.
49
+ *
50
+ * @param {String} n Name of the control to create.
51
+ * @param {tinymce.ControlManager} cm Control manager to use inorder to create new control.
52
+ * @return {tinymce.ui.Control} New control instance or null if no control was created.
53
+ */
54
+ createControl : function(n, cm) {
55
+ return null;
56
+ },
57
+
58
+ /**
59
+ * Returns information about the plugin as a name/value array.
60
+ * The current keys are longname, author, authorurl, infourl and version.
61
+ *
62
+ * @return {Object} Name/value array containing information about the plugin.
63
+ */
64
+ getInfo : function() {
65
+ return {
66
+ longname : 'WP User Avatar',
67
+ author : 'Bangbay Siboliban',
68
+ authorurl : 'http://siboliban.org/',
69
+ infourl : 'http://wordpress.org/extend/plugins/wp-user-avatar/',
70
+ version : "1.2.1"
71
+ };
72
+ }
73
+ });
74
+
75
+ // Register plugin
76
+ tinymce.PluginManager.add('wpUserAvatar', tinymce.plugins.muluBox);
77
+ })();
includes/tinymce/window.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package WP User Avatar
4
+ * @version 1.2.1
5
+ */
6
+
7
+ if ( !defined('ABSPATH') )
8
+ die('You are not allowed to call this page directly.');
9
+ @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
10
+ ?>
11
+ <html xmlns="http://www.w3.org/1999/xhtml">
12
+ <head>
13
+ <title>WP User Avatar</title>
14
+ <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
15
+ <base target="_self" />
16
+ <script type="text/javascript" src="<?php echo site_url(); ?>/wp-includes/js/tinymce/tiny_mce_popup.js"></script>
17
+ <script type="text/javascript" src="<?php echo site_url(); ?>/wp-includes/js/tinymce/utils/form_utils.js"></script>
18
+ <script type="text/javascript" src="<?php echo site_url(); ?>/wp-includes/js/jquery/jquery.js"></script>
19
+ <script type="text/javascript">
20
+ function insert_wp_user_avatar(){
21
+ // Custom shortcode values
22
+ var shortcode;
23
+ var user = document.getElementById('wp_user_avatar_user').value;
24
+ var size = document.getElementById('wp_user_avatar_size').value;
25
+ var size_number = document.getElementById('wp_user_avatar_size_number').value;
26
+ var align = document.getElementById('wp_user_avatar_align').value;
27
+
28
+ // Add tag to shortcode only if not blank
29
+ var user_tag = (user != '') ? ' user="' + user + '"' : '';
30
+ var size_tag = (size != '' && size_number == '') ? ' size="' + size + '"' : '';
31
+ size_tag = (size_number != '') ? ' size="' + size_number + '"' : size_tag;
32
+ var align_tag = (align != '') ? ' align="' + align + '"' : '';
33
+
34
+ shortcode = "<p>[avatar" + user_tag + size_tag + align_tag + "]</p>";
35
+
36
+ if(window.tinyMCE) {
37
+ window.tinyMCE.execInstanceCommand(window.tinyMCE.activeEditor.id, 'mceInsertContent', false, shortcode);
38
+ tinyMCEPopup.editor.execCommand('mceRepaint');
39
+ tinyMCEPopup.close();
40
+ }
41
+ return;
42
+ }
43
+ </script>
44
+ <style type="text/css">
45
+ form { background: #fff; border: 1px solid #eee; }
46
+ p { margin: 0; padding: 12px 0 0; }
47
+ label { width: 90px; display: inline-block; text-align: right; }
48
+ .mceActionPanel { padding: 7px 0 12px; text-align: center; }
49
+ .mceActionPanel #insert { float: none; width: 150px; margin: 0 auto; }
50
+ </style>
51
+ </head>
52
+ <body id="link" class="wp-core-ui" onload="document.body.style.display='';" style="display:none;">
53
+ <form name="wpUserAvatar" action="#">
54
+ <p><label for="<?php esc_attr_e('wp_user_avatar_user'); ?>"><?php _e("User:"); ?></label>
55
+ <select id="<?php esc_attr_e('wp_user_avatar_user'); ?>" name="<?php esc_attr_e('wp_user_avatar_user'); ?>">
56
+ <option value=""></option>
57
+ <?php $users = get_users(); foreach($users as $user) : ?>
58
+ <option value="<?php echo $user->user_login; ?>"><?php echo $user->display_name; ?></option>
59
+ <?php endforeach; ?>
60
+ </select></p>
61
+
62
+ <p style="text-align:center;">Choose a preset size or enter a number value.</p>
63
+
64
+ <p>
65
+ <label for="<?php esc_attr_e('wp_user_avatar_size'); ?>"><?php _e("Size:"); ?></label>
66
+ <select id="<?php esc_attr_e('wp_user_avatar_size'); ?>" name="<?php esc_attr_e('wp_user_avatar_size'); ?>">
67
+ <option value=""></option>
68
+ <option value="original"><?php _e("Original"); ?></option>
69
+ <option value="large"><?php _e("Large"); ?></option>
70
+ <option value="medium"><?php _e("Medium"); ?></option>
71
+ <option value="thumbnail"><?php _e("Thumbnail"); ?></option>
72
+ </select>
73
+ or
74
+ <input type="text" size="8" id="<?php esc_attr_e('wp_user_avatar_size_number'); ?>" name="<?php esc_attr_e('wp_user_avatar_size'); ?>" value="" />
75
+ </p>
76
+
77
+ <p><label for="<?php esc_attr_e('wp_user_avatar_align'); ?>"><?php _e("Alignment:"); ?></label>
78
+ <select id="<?php esc_attr_e('wp_user_avatar_align'); ?>" name="<?php esc_attr_e('wp_user_avatar_align'); ?>">
79
+ <option value=""></option>
80
+ <option value="center"><?php _e("Center"); ?></option>
81
+ <option value="left"><?php _e("Left"); ?></option>
82
+ <option value="right"><?php _e("Right"); ?></option>
83
+ </select></p>
84
+ <div class="mceActionPanel">
85
+ <input type="submit" id="insert" class="button-primary" name="insert" value="<?php _e("Insert WP User Avatar"); ?>" onclick="insert_wp_user_avatar();" />
86
+ </div>
87
+ </form>
88
+ </body>
89
+ </html>
index.html ADDED
@@ -0,0 +1 @@
 
1
+ <!-- Thanks for using WP User Avatar! -->
js/wp-user-avatar.js ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Backbone uploader for WP 3.5
2
+ function openMediaUploader(section){
3
+ wp.media.wpUserAvatar = {
4
+ get: function(){
5
+ return wp.media.view.settings.post.wpUserAvatarId;
6
+ },
7
+ set: function(id){
8
+ var settings = wp.media.view.settings;
9
+ settings.post.wpUserAvatarId = id;
10
+ settings.post.wpUserAvatarSrc = jQuery('div.attachment-info').find('img').attr('src');
11
+ if(settings.post.wpUserAvatarId){
12
+ setWPUserAvatar(settings.post.wpUserAvatarId, settings.post.wpUserAvatarSrc);
13
+ jQuery('#wp_user_avatar_radio').val(settings.post.wpUserAvatarSrc).trigger('click');
14
+ }
15
+ },
16
+ frame: function(){
17
+ if(this._frame){
18
+ return this._frame;
19
+ }
20
+ this._frame = wp.media({
21
+ state: 'library',
22
+ states: [ new wp.media.controller.Library({ title: "Edit WP User Avatar: " + section }) ]
23
+ });
24
+ this._frame.on('open', function(){
25
+ var selection = this.state().get('selection');
26
+ id = jQuery('#wp-user-avatar').val();
27
+ attachment = wp.media.attachment(id);
28
+ attachment.fetch();
29
+ selection.add(attachment ? [ attachment ] : []);
30
+ }, this._frame);
31
+ this._frame.on('toolbar:create:select', function(toolbar){
32
+ this.createSelectToolbar(toolbar, {
33
+ text: 'Set WP User Avatar'
34
+ });
35
+ }, this._frame);
36
+ this._frame.state('library').on('select', this.select);
37
+ return this._frame;
38
+ },
39
+ select: function(id){
40
+ var settings = wp.media.view.settings,
41
+ selection = this.get('selection').single();
42
+ wp.media.wpUserAvatar.set(selection ? selection.id : -1);
43
+ },
44
+ init: function(){
45
+ jQuery('body').on('click', '#add-wp-user-avatar', function(e){
46
+ e.preventDefault();
47
+ e.stopPropagation();
48
+ wp.media.wpUserAvatar.frame().open();
49
+ });
50
+ }
51
+ };
52
+ jQuery(wp.media.wpUserAvatar.init);
53
+ }
54
+
55
+ // Thickbox uploader
56
+ function openThickboxUploader(section, iframe){
57
+ jQuery('body').on('click', '#add-wp-user-avatar', function(e){
58
+ e.preventDefault();
59
+ tb_show('Edit WP User Avatar: ' + section, iframe);
60
+ });
61
+ }
62
+
63
+ // Set WP User Avatar
64
+ function setWPUserAvatar(attachment, imageURL){
65
+ jQuery('#wp-user-avatar', window.parent.document).val(attachment);
66
+ jQuery('#wp-user-avatar-preview', window.parent.document).find('img').attr('src', imageURL).removeAttr('width', '').removeAttr('height', '');
67
+ jQuery('#wp-user-avatar-message', window.parent.document).show();
68
+ jQuery('#remove-wp-user-avatar', window.parent.document).show();
69
+ jQuery('#gravatar-notice', window.parent.document).hide();
70
+ jQuery('#wp_user_avatar_radio', window.parent.document).val(imageURL).trigger('click');
71
+ // Check if WP 3.5
72
+ if(typeof(wp) != 'undefined'){
73
+ wp.media.wpUserAvatar.frame().close()
74
+ } else {
75
+ window.parent.tb_remove();
76
+ }
77
+ }
78
+
79
+ // Remove WP User Avatar
80
+ function removeWPUserAvatar(avatar_full, avatar_thumb){
81
+ jQuery('body').on('click', '#remove-wp-user-avatar', function(e){
82
+ e.preventDefault();
83
+ jQuery(this).hide();
84
+ jQuery('#wp-user-avatar-preview').find('img').attr('src', avatar_thumb).removeAttr('width', '').removeAttr('height', '');
85
+ jQuery('#wp-user-avatar').val('');
86
+ jQuery('#wp-user-avatar-message').show();
87
+ jQuery('#wp_user_avatar_radio').val(avatar_full).trigger('click');
88
+ });
89
+ }
readme.txt ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.1
8
+ Stable tag: 1.2.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. Add your own Default Avatar.
13
+
14
+ == Description ==
15
+
16
+ WordPress currently only allows you to use custom avatars that are uploaded through [gravatar.com](http://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
+ WP User Avatar also lets you:
19
+
20
+ * Upload your own Default Avatar in your Discussion settings.
21
+ * Show the user's gravatar.com avatar or Default Avatar if the user doesn't have a WP User Avatar image.
22
+ * Use the shortcode <code>[avatar]</code> in your posts. The shortcode will work with any theme, whether it has avatar support or not.
23
+
24
+ To use WP User Avatar, choose a theme that has avatar support. 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>. [Read about the differences here](http://wordpress.org/extend/plugins/wp-user-avatar/faq/).
25
+
26
+ [Read more about get_avatar in the WordPress Function Reference](http://codex.wordpress.org/Function_Reference/get_avatar).
27
+
28
+ This plugin uses the Media uploader introduced in WordPress 3.5, but is also backwards-compatible to WordPress 3.3.
29
+
30
+ == Installation ==
31
+
32
+ 1. Download, install, and activate the WP User Avatar plugin.
33
+ 2. On your edit profile page, click "Edit WP User Avatar".
34
+ 3. Choose an image, then click "Set WP User Avatar".
35
+ 4. Click "Update Profile".
36
+ 5. Upload your own Default Avatar in your Discussion settings (optional).
37
+ 6. Choose a theme that has avatar support. In your theme, manually replace <code>get_avatar</code> with <code>get_wp_user_avatar</code> or leave <code>get_avatar</code> as-is. [Read about the differences here](http://wordpress.org/extend/plugins/wp-user-avatar/faq/).
38
+ 7. You can also use the shortcode <code>[avatar]</code> in your posts. The shortcode will work with any theme, whether it has avatar support or not.
39
+
40
+ **Example Usage**
41
+
42
+ Within The Loop, you may be using:
43
+
44
+ `<?php echo get_avatar(get_the_author_meta('ID'), 96); ?>`
45
+
46
+ Replace this function with:
47
+
48
+ `<?php echo get_wp_user_avatar(get_the_author_meta('ID'), 96); ?>`
49
+
50
+ You can also use the values "original", "large", "medium", or "thumbnail" for your avatar size:
51
+
52
+ `<?php echo get_wp_user_avatar(get_the_author_meta('ID'), 'medium'); ?>`
53
+
54
+ You can also add an alignment of "left", "right", or "center":
55
+
56
+ `<?php echo get_wp_user_avatar(get_the_author_meta('ID'), 96, 'left'); ?>`
57
+
58
+ On an author page outside of The Loop, you may be using:
59
+
60
+ `<?php
61
+ $user = get_user_by('slug', $author_name);
62
+ echo get_avatar($user->ID, 96);
63
+ ?>`
64
+
65
+ Replace this function with:
66
+
67
+ `<?php
68
+ $user = get_user_by('slug', $author_name);
69
+ echo get_wp_user_avatar($user->ID, 96);
70
+ ?>`
71
+
72
+ 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:
73
+
74
+ `<?php echo get_wp_user_avatar(); ?>`
75
+
76
+ The function <code>get_wp_user_avatar</code> will also fall back to <code>get_avatar</code> if the user has no WP User Avatar image. For this to work, "Show Avatars" must be checked in your Discussion settings. When this setting is enabled, you will see the user's gravatar.com avatar or Default Avatar.
77
+
78
+ **Other Available Functions**
79
+
80
+ = [avatar] shortcode =
81
+
82
+ 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.
83
+
84
+ `[avatar user="admin" size="medium" align="left"]`
85
+
86
+ = get_wp_user_avatar_src =
87
+
88
+ 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:
89
+
90
+ `<a href="<?php echo get_wp_user_avatar_src($user_id, 'large'); ?>">
91
+ <?php echo get_wp_user_avatar($user_id, 'thumbnail'); ?>
92
+ </a>`
93
+
94
+ = has_wp_user_avatar =
95
+
96
+ 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:
97
+
98
+ `<?php
99
+ if ( has_wp_user_avatar($user_id) ) {
100
+ echo get_wp_user_avatar($user_id, 96);
101
+ } else {
102
+ echo '<img src="my-alternate-image.jpg" />';
103
+ }
104
+ ?>`
105
+
106
+ == Frequently Asked Questions ==
107
+
108
+ = How do I use WP User Avatar? =
109
+
110
+ First, choose a theme that has avatar support. In your theme, you have a choice of manually replacing <code>get_avatar</code> with <code>get_wp_user_avatar</code>, or leaving <code>get_avatar</code> as-is. Here are the differences:
111
+
112
+ = get_wp_user_avatar =
113
+
114
+ 1. Allows you to use the values "original", "large", "medium", or "thumbnail" for your avatar size.
115
+ 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.
116
+ 3. Optionally adds CSS classes "alignleft", "alignright", or "aligncenter" to position your avatar.
117
+ 4. Shows nothing if the user has no WP User Avatar image.
118
+ 5. Shows the user's gravatar.com avatar or Default Avatar only if "Show Avatars" is enabled in your Discussion settings.
119
+
120
+ = get_avatar =
121
+
122
+ 1. Requires you to enable "Show Avatars" in your Discussion settings to show any avatars.
123
+ 2. Accepts only numeric values for your avatar size.
124
+ 3. Always adds a fixed width and height to your image. This may cause problems if you use responsive CSS in your theme.
125
+ 4. Shows the user's gravatar.com avatar or Default Avatar if the user doesn't have a WP User Avatar image. (Choosing "Blank" as your Default Avatar still generates a transparent image file.)
126
+ 5. Requires no changes to your theme files if you are currently using <code>get_avatar</code>.
127
+
128
+ = Can I create a custom Default Avatar? =
129
+ In your Discussion settings, you can upload your own Default Avatar.
130
+
131
+ = Can I insert WP User Avatar directly into a post? =
132
+
133
+ You can use the shortcode <code>[avatar]</code> in your posts. The shortcode will work with any theme, whether it has avatar support or not. 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.
134
+
135
+ `[avatar user="admin" size="medium" align="left"]`
136
+
137
+ = Will WP User Avatar work with comment author avatars? =
138
+
139
+ Yes, for registered users. Non-registered comment authors will show their gravatar.com avatars or Default Avatar.
140
+
141
+ = How can I see which users have an avatar? =
142
+
143
+ For administrators, WP User Avatar adds a column with avatar thumbnails to your Users list 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.
144
+
145
+ = What CSS can I use with WP User Avatar? =
146
+
147
+ 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:
148
+
149
+ `<?php echo get_wp_user_avatar($user_id, 96, 'left'); ?>`
150
+
151
+ Outputs:
152
+
153
+ `<img src="{imageURL}" width="96" height="96" class="wp-user-avatar wp-user-avatar-96 alignleft" />`
154
+
155
+ **Note:** "alignleft", "alignright", and aligncenter" are common WordPress CSS classes, but not every theme supports them. Contact the theme author to add those CSS classes if they are missing.
156
+
157
+ 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:
158
+
159
+ `<?php echo get_wp_user_avatar($user_id, 'medium'); ?>`
160
+
161
+ Outputs:
162
+
163
+ `<img src="{imageURL}" class="wp-user-avatar wp-user-avatar-medium" />`
164
+
165
+ **Note:** WordPress adds more CSS classes to the avatar not listed here.
166
+
167
+ = What other functions are available for WP User Avatar? =
168
+ * <code>get_wp_user_avatar_src</code>: retrieves just the image URL
169
+ * <code>has_wp_user_avatar</code>: checks if the user has a WP User Avatar image
170
+ * [See example usage here](http://wordpress.org/extend/plugins/wp-user-avatar/installation/)
171
+
172
+ == Screenshots ==
173
+
174
+ 1. WP User Avatar lets you upload your own Default Avatar.
175
+ 2. WP User Avatar adds a field to your edit profile page.
176
+ 3. After you've set a WP User Avatar image, you will see the option to remove it.
177
+
178
+ == Changelog ==
179
+
180
+ = 1.2.1 =
181
+ * Add: TinyMCE button
182
+ * Update: Clean up redundant code
183
+ * Update: Compatibility only back to WordPress 3.3
184
+
185
+ = 1.2 =
186
+ * Add: Default Avatar setting
187
+
188
+ = 1.1.7 =
189
+ * Bug Fix: Change update_usermeta to update_user_meta
190
+
191
+ = 1.1.6 =
192
+ * Bug Fix: Image not showing in user profile edit
193
+
194
+ = 1.1.5a =
195
+ * Update: readme.txt
196
+
197
+ = 1.1.5 =
198
+ * Bug Fix: Remove stray curly bracket
199
+
200
+ = 1.1.4 =
201
+ * Bug Fix: Change get_usermeta to get_user_meta
202
+ * Bug Fix: Non-object warning when retrieving user ID
203
+
204
+ = 1.1.3 =
205
+ * Bug Fix: Comment author with no e-mail address
206
+
207
+ = 1.1.2 =
208
+ * Remove: Unused variables
209
+
210
+ = 1.1.1 =
211
+ * Bug Fix: Capabilities error in comment avatar
212
+
213
+ = 1.1 =
214
+ * Add: Add filter for get_avatar
215
+ * Add: CSS alignment classes
216
+ * Add: Replace comment author avatar
217
+ * Add: Shortcode
218
+ * Update: readme.txt
219
+
220
+ = 1.0.2 =
221
+ * Update: FAQ
222
+ * Remove: CSS that hides "Insert into Post"
223
+
224
+ = 1.0.1 =
225
+ * Add: CSS classes to image output
226
+
227
+ = 1.0 =
228
+ * Initial release
229
+
230
+ == Upgrade Notice ==
231
+
232
+ = 1.2.1 =
233
+ * New Feature: Shortcode insertion button for Visual Editor
234
+
235
+ = 1.2 =
236
+ * New Feature: Default Avatar customization
237
+
238
+ = 1.1 =
239
+ * New Features: [avatar] shortcode, direct replacement of get_avatar() and comment author avatar, more CSS classes
wp-user-avatar.php ADDED
@@ -0,0 +1,325 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package WP User Avatar
4
+ * @version 1.2.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. Add your own Default Avatar.
10
+ Version: 1.2.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
+ // Load add-ons
21
+ include_once(WP_USER_AVATAR_ABSPATH.'includes/tinymce.php');
22
+
23
+ // Initialize default settings
24
+ register_activation_hook(__FILE__, 'wp_user_avatar_options');
25
+
26
+ // Remove user metadata on plugin delete
27
+ register_uninstall_hook(__FILE__, 'wp_user_avatar_delete_setup');
28
+
29
+ // Settings saved to wp_options
30
+ function wp_user_avatar_options(){
31
+ add_option('avatar_default_wp_user_avatar','');
32
+ }
33
+ add_action('init', 'wp_user_avatar_options');
34
+
35
+ // Remove user metadata
36
+ function wp_user_avatar_delete_setup(){
37
+ $users = get_users();
38
+ foreach($users as $user){
39
+ delete_user_meta($user->ID, 'wp_user_avatar');
40
+ }
41
+ delete_option('avatar_default_wp_user_avatar');
42
+ }
43
+
44
+ // WP User Avatar
45
+ if(!class_exists('wp_user_avatar')){
46
+ class wp_user_avatar{
47
+ function wp_user_avatar(){
48
+ add_action('show_user_profile', array('wp_user_avatar','action_show_user_profile'));
49
+ add_action('edit_user_profile', array($this,'action_show_user_profile'));
50
+ add_action('personal_options_update', array($this,'action_process_option_update'));
51
+ add_action('edit_user_profile_update', array($this,'action_process_option_update'));
52
+ add_action('discussion_update', array($this,'action_process_option_update'));
53
+ // Only add attachment field for WP 3.4 and older
54
+ if(!function_exists('wp_enqueue_media')){
55
+ add_filter('attachment_fields_to_edit', array($this, 'add_wp_user_avatar_attachment_field_to_edit'), 10, 2);
56
+ }
57
+ // Hide column in Users table if avatars are shown
58
+ if(get_option('show_avatars') != '1'){
59
+ add_filter('manage_users_columns', array($this, 'add_wp_user_avatar_column'), 10, 1);
60
+ add_filter('manage_users_custom_column', array($this, 'show_wp_user_avatar_column'), 10, 3);
61
+ }
62
+ add_action('admin_enqueue_scripts', array($this, 'media_upload_scripts'));
63
+ }
64
+
65
+ // Add to edit user profile
66
+ function action_show_user_profile($user){
67
+ $wp_user_avatar = get_user_meta($user->ID, 'wp_user_avatar', true);
68
+ $hide_notice = has_wp_user_avatar($user->ID) ? ' style="display:none;"' : '';
69
+ $hide_remove = !has_wp_user_avatar($user->ID) ? ' style="display:none;"' : '';
70
+ $avatar_full_src = get_option('show_avatars') == '1' ? get_avatar_original($user->ID, 96) : includes_url().'images/blank.gif';
71
+ $avatar_full = has_wp_user_avatar($user->ID) ? get_wp_user_avatar_src($user->ID, 'medium') : $avatar_full_src;
72
+ ?>
73
+ <h3><?php _e('WP User Avatar') ?></h3>
74
+ <table class="form-table">
75
+ <tbody>
76
+ <tr>
77
+ <th><label for="wp_user_avatar"><?php _e('WP User Avatar'); ?></label></th>
78
+ <td>
79
+ <input type="hidden" name="wp-user-avatar" id="wp-user-avatar" value="<?php echo $wp_user_avatar; ?>" />
80
+ <p><button type="button" class="button" id="add-wp-user-avatar"><?php _e('Edit WP User Avatar'); ?></button></p>
81
+ <div id="wp-user-avatar-preview">
82
+ <p><?php echo '<img src="'.$avatar_full.'" alt="" />'; ?></p>
83
+ </div>
84
+ <?php if(get_option('show_avatars') == '1') : ?>
85
+ <p id="gravatar-notice"<?php echo $hide_notice; ?>>This is your default avatar.</p>
86
+ <?php endif; ?>
87
+ <p><button type="button" class="button" id="remove-wp-user-avatar"<?php echo $hide_remove; ?>><?php _e('Remove'); ?></button></p>
88
+ <p id="wp-user-avatar-message"><?php _e('Press "Update Profile" to save your changes.'); ?></p>
89
+ </td>
90
+ </tr>
91
+ </tbody>
92
+ </table>
93
+ <?php
94
+ echo edit_default_wp_user_avatar($user->display_name, $avatar_full_src, $avatar_full_src);
95
+ }
96
+
97
+ // Update user meta
98
+ function action_process_option_update($user_id){
99
+ update_user_meta($user_id, 'wp_user_avatar', (isset($_POST['wp-user-avatar']) ? $_POST['wp-user-avatar'] : ''));
100
+ }
101
+
102
+ // Add button to attach image
103
+ function add_wp_user_avatar_attachment_field_to_edit($fields, $post){
104
+ $image = wp_get_attachment_image_src($post->ID, "medium");
105
+ $button = '<button type="button" class="button" id="set-wp-user-avatar-image" onclick="setWPUserAvatar(\''.$post->ID.'\', \''.$image[0].'\')">Set WP User Avatar</button>';
106
+ $fields['wp-user-avatar'] = array(
107
+ 'label' => __('WP User Avatar'),
108
+ 'input' => 'html',
109
+ 'html' => $button
110
+ );
111
+ return $fields;
112
+ }
113
+
114
+ // Add column to Users page
115
+ function add_wp_user_avatar_column($columns){
116
+ return $columns + array('wp-user-avatar' => __('WP User Avatar'));;
117
+ }
118
+
119
+ // Show thumbnail of wp_user_avatar
120
+ function show_wp_user_avatar_column($value, $column_name, $user_id){
121
+ $wp_user_avatar = get_user_meta($user_id, 'wp_user_avatar', true);
122
+ $wp_user_avatar_image = wp_get_attachment_image($wp_user_avatar, array(32,32));
123
+ if($column_name == 'wp-user-avatar'){
124
+ return $wp_user_avatar_image;
125
+ }
126
+ }
127
+
128
+ // Media uploader
129
+ function media_upload_scripts(){
130
+ if(!function_exists('wp_enqueue_media')){
131
+ wp_enqueue_script('media-upload');
132
+ wp_enqueue_script('thickbox');
133
+ wp_enqueue_style('thickbox');
134
+ } else {
135
+ wp_enqueue_media();
136
+ }
137
+ wp_enqueue_script('wp-user-avatar', WP_USER_AVATAR_URLPATH.'js/wp-user-avatar.js');
138
+ wp_enqueue_style('wp-user-avatar', WP_USER_AVATAR_URLPATH.'css/wp-user-avatar.css');
139
+ }
140
+ }
141
+
142
+ // Uploader scripts
143
+ function edit_default_wp_user_avatar($section, $avatar_full, $avatar_thumb){ ?>
144
+ <script type="text/javascript">
145
+ jQuery(function(){
146
+ <?php if(function_exists('wp_enqueue_media')) : // Backbone uploader for WP 3.5+ ?>
147
+ openMediaUploader("<?php echo $section; ?>");
148
+ <?php else : // Fall back to Thickbox uploader ?>
149
+ openThickboxUploader("<?php echo $section; ?>", "<?php echo get_upload_iframe_src('image', '0', 'library'); ?>");
150
+ <?php endif; ?>
151
+ removeWPUserAvatar("<?php echo $avatar_full; ?>", "<?php echo $avatar_thumb; ?>");
152
+ });
153
+ </script>
154
+ <?php
155
+ }
156
+
157
+ // Add default avatar
158
+ function add_default_wp_user_avatar($avatar_list){
159
+ $avatar_default = get_option('avatar_default');
160
+ $avatar_default_wp_user_avatar = get_option('avatar_default_wp_user_avatar');
161
+ if(!empty($avatar_default_wp_user_avatar)){
162
+ $avatar_full_src = wp_get_attachment_image_src($avatar_default_wp_user_avatar, 'medium');
163
+ $avatar_thumb_src = wp_get_attachment_image_src($avatar_default_wp_user_avatar, array(32,32));
164
+ $avatar_full = $avatar_full_src[0];
165
+ $avatar_thumb = $avatar_thumb_src[0];
166
+ $hide_remove = '';
167
+ } else {
168
+ $avatar_full = WP_USER_AVATAR_URLPATH.'images/wp-user-avatar.png';
169
+ $avatar_thumb = WP_USER_AVATAR_URLPATH.'images/wp-user-avatar-32x32.png';
170
+ $hide_remove = ' style="display:none;"';
171
+ }
172
+ $selected_avatar = ($avatar_default == $avatar_full) ? ' checked="checked" ' : '';
173
+ $avatar_thumb_img = '<div id="wp-user-avatar-preview"><img src="'.$avatar_thumb.'" width="32" /></div>';
174
+ $wp_user_avatar_list = "\n\t<label><input type='radio' name='avatar_default' id='wp_user_avatar_radio' value='$avatar_full'$selected_avatar /> ";
175
+ $wp_user_avatar_list .= preg_replace("/src='(.+?)'/", "src='\$1&amp;forcedefault=1'", $avatar_thumb_img);
176
+ $wp_user_avatar_list .= ' WP User Avatar</label>';
177
+ $wp_user_avatar_list .= '<p style="padding-left:15px;"><button type="button" class="button" id="add-wp-user-avatar">Edit WP User Avatar</button>';
178
+ $wp_user_avatar_list .= '&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" id="remove-wp-user-avatar"'.$hide_remove.'>Remove</a></p>';
179
+ $wp_user_avatar_list .= '<input type="hidden" id="wp-user-avatar" name="avatar_default_wp_user_avatar" value="'.$avatar_default_wp_user_avatar.'">';
180
+ $wp_user_avatar_list .= '<p id="wp-user-avatar-message">Press "Save Changes" to save your changes.</p>';
181
+ $wp_user_avatar_list .= edit_default_wp_user_avatar('Default Avatar', $avatar_full, $avatar_thumb);
182
+ return $wp_user_avatar_list.$avatar_list;
183
+ }
184
+ add_filter('default_avatar_select', 'add_default_wp_user_avatar');
185
+
186
+ // Add default avatar field to whitelist
187
+ function wp_user_avatar_whitelist_options($whitelist_options){
188
+ $whitelist_options['discussion'] = array( 'default_pingback_flag', 'default_ping_status', 'default_comment_status', 'comments_notify', 'moderation_notify', 'comment_moderation', 'require_name_email', 'comment_whitelist', 'comment_max_links', 'moderation_keys', 'blacklist_keys', 'show_avatars', 'avatar_rating', 'avatar_default', 'close_comments_for_old_posts', 'close_comments_days_old', 'thread_comments', 'thread_comments_depth', 'page_comments', 'comments_per_page', 'default_comments_page', 'comment_order', 'comment_registration', 'avatar_default_wp_user_avatar' );
189
+ return $whitelist_options;
190
+ }
191
+ add_filter('whitelist_options', 'wp_user_avatar_whitelist_options');
192
+
193
+ // Returns true if user has wp_user_avatar
194
+ function has_wp_user_avatar($user_id = ''){
195
+ global $post;
196
+ if(empty($user_id)){
197
+ $author_name = get_query_var('author_name');
198
+ $user = is_author() ? get_user_by('slug', $author_name) : get_the_author_meta('ID');
199
+ $user_id = $user->ID;
200
+ }
201
+ $wp_user_avatar = get_user_meta($user_id, 'wp_user_avatar', true);
202
+ if(!empty($wp_user_avatar)){
203
+ return true;
204
+ }
205
+ }
206
+
207
+ // Find wp_user_avatar, show get_avatar if empty
208
+ function get_wp_user_avatar($id_or_email = '', $size = '96', $align = ''){
209
+ global $post, $comment;
210
+ // Find user ID on comment, author page, or post
211
+ if(is_object($id_or_email)){
212
+ $id_or_email = $comment->user_id != '0' ? $comment->user_id : $comment->comment_author_email;
213
+ $alt = $comment->comment_author;
214
+ } else {
215
+ if(!empty($id_or_email)){
216
+ $user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
217
+ } else {
218
+ $author_name = get_query_var('author_name');
219
+ if(is_author()){
220
+ $user = get_user_by('slug', $author_name);
221
+ } else {
222
+ $user_id = get_the_author_meta('ID');
223
+ $user = get_user_by('id', $user_id);
224
+ }
225
+ }
226
+ $id_or_email = !empty($user) ? $user->ID: '';
227
+ $alt = $user->display_name;
228
+ }
229
+ $wp_user_avatar_meta = !empty($id_or_email) ? get_the_author_meta('wp_user_avatar', $id_or_email) : '';
230
+ $alignclass = !empty($align) ? ' align'.$align : '';
231
+ if(!empty($wp_user_avatar_meta)){
232
+ $get_size = is_numeric($size) ? array($size,$size) : $size;
233
+ $wp_user_avatar_image = wp_get_attachment_image_src($wp_user_avatar_meta, $get_size);
234
+ $dimensions = is_numeric($size) ? ' width="'.$wp_user_avatar_image[1].'" height="'.$wp_user_avatar_image[2].'"' : '';
235
+ $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" />';
236
+ } else {
237
+ $default = '';
238
+ $alt = '';
239
+ if($size == 'original' || $size == 'large'){
240
+ $get_size = get_option('large_size_w');
241
+ } elseif($size == 'medium'){
242
+ $get_size = get_option('medium_size_w');
243
+ } elseif($size == 'thumbnail'){
244
+ $get_size = get_option('thumbnail_size_w');
245
+ } else {
246
+ $get_size = $size;
247
+ }
248
+ $avatar = get_avatar($id_or_email, $get_size, $default, $alt);
249
+ $gravatar = str_replace("class='", "class='wp-user-avatar wp-user-avatar-".$get_size.$alignclass." ", $avatar);
250
+ $wp_user_avatar = $gravatar;
251
+ }
252
+ return $wp_user_avatar;
253
+ }
254
+
255
+ // Return just the image src
256
+ function get_wp_user_avatar_src($id_or_email, $size = '', $align = ''){
257
+ $wp_user_avatar_image = get_wp_user_avatar($id_or_email, $size, $align);
258
+ $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $wp_user_avatar_image, $matches, PREG_SET_ORDER);
259
+ $wp_user_avatar_image_src = $matches [0] [1];
260
+ return $wp_user_avatar_image_src;
261
+ }
262
+
263
+ // Replace get_avatar()
264
+ function get_wp_user_avatar_alt($avatar, $id_or_email, $size = '', $default = '', $alt = false){
265
+ global $post, $pagenow, $comment;
266
+ // Find user ID on comment, author page, or post
267
+ if(is_object($id_or_email)){
268
+ $id_or_email = $comment->user_id != '0' ? $comment->user_id : $comment->comment_author_email;
269
+ $alt = $comment->comment_author;
270
+ } else {
271
+ if(!empty($id_or_email)){
272
+ $user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
273
+ } else {
274
+ $author_name = get_query_var('author_name');
275
+ if(is_author()){
276
+ $user = get_user_by('slug', $author_name);
277
+ } else {
278
+ $user_id = get_the_author_meta('ID');
279
+ $user = get_user_by('id', $user_id);
280
+ }
281
+ }
282
+ $id_or_email = $user->ID;
283
+ $alt = $user->display_name;
284
+ }
285
+ $wp_user_avatar_meta = !empty($id_or_email) ? 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
+ // Get orginal avatar
313
+ function get_avatar_original($avatar, $id_or_email, $size = '', $default = '', $alt = false){
314
+ remove_filter('get_avatar', 'get_wp_user_avatar_alt');
315
+ $wp_user_avatar_image = get_avatar($avatar);
316
+ $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $wp_user_avatar_image, $matches, PREG_SET_ORDER);
317
+ $wp_user_avatar_image_src = $matches [0] [1];
318
+ return $wp_user_avatar_image_src;
319
+ }
320
+
321
+ // Initialize wp_user_avatar
322
+ global $wp_user_avatar_instance;
323
+ $wp_user_avatar_instance = new wp_user_avatar();
324
+ }
325
+ ?>