Version Description
- Bug Fix: Rename usermeta only if found
Download this release
Release Info
Developer | bangbay |
Plugin | WP User Avatar |
Version | 1.3.1 |
Comparing to | |
See all releases |
Version 1.3.1
- css/wp-user-avatar.css +7 -0
- images/wp-user-avatar-150x150.png +0 -0
- images/wp-user-avatar-300x300.png +0 -0
- images/wp-user-avatar-32x32.png +0 -0
- images/wp-user-avatar-96x96.png +0 -0
- images/wp-user-avatar.png +0 -0
- includes/tinymce.php +42 -0
- includes/tinymce/editor_plugin.js +1 -0
- includes/tinymce/window.php +111 -0
- index.html +1 -0
- js/wp-user-avatar.js +1 -0
- readme.txt +308 -0
- wp-user-avatar.php +507 -0
css/wp-user-avatar.css
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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; }
|
5 |
+
#edit-wp-user-avatar { padding-left: 15px; }
|
6 |
+
#edit-wp-user-avatar #remove-wp-user-avatar { margin-left: 10px; }
|
7 |
+
.hide-me, .wp-core-ui .hide-me { display: none; }
|
images/wp-user-avatar-150x150.png
ADDED
Binary file
|
images/wp-user-avatar-300x300.png
ADDED
Binary file
|
images/wp-user-avatar-32x32.png
ADDED
Binary file
|
images/wp-user-avatar-96x96.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.3.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:400,height:260,inline:1},{plugin_url:url})});ed.addButton('wpUserAvatar',{title:'Insert WP User Avatar',cmd:'mceWpUserAvatar',image:url+'/../../images/wp-user-avatar-32x32.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.3.1"}}});tinymce.PluginManager.add('wpUserAvatar',tinymce.plugins.wpUserAvatar)})();
|
includes/tinymce/window.php
ADDED
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package WP User Avatar
|
4 |
+
* @version 1.3.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 |
+
var link = document.getElementById('wp_user_avatar_link').value;
|
28 |
+
var link_external = document.getElementById('wp_user_avatar_link_external').value;
|
29 |
+
|
30 |
+
// Add tag to shortcode only if not blank
|
31 |
+
var user_tag = (user != '') ? ' user="' + user + '"' : '';
|
32 |
+
var size_tag = (size != '' && size_number == '') ? ' size="' + size + '"' : '';
|
33 |
+
size_tag = (size_number != '') ? ' size="' + size_number + '"' : size_tag;
|
34 |
+
var align_tag = (align != '') ? ' align="' + align + '"' : '';
|
35 |
+
var link_tag = (link != '' && link_external == '') ? ' link="' + link + '"' : '';
|
36 |
+
link_tag = (link_external != '') ? ' link="' + link_external + '"' : link_tag;
|
37 |
+
|
38 |
+
shortcode = "<p>[avatar" + user_tag + size_tag + align_tag + link_tag + "]</p>";
|
39 |
+
|
40 |
+
if(window.tinyMCE) {
|
41 |
+
window.tinyMCE.execInstanceCommand(window.tinyMCE.activeEditor.id, 'mceInsertContent', false, shortcode);
|
42 |
+
tinyMCEPopup.editor.execCommand('mceRepaint');
|
43 |
+
tinyMCEPopup.close();
|
44 |
+
}
|
45 |
+
return;
|
46 |
+
}
|
47 |
+
</script>
|
48 |
+
<style type="text/css">
|
49 |
+
form { background: #fff; border: 1px solid #eee; }
|
50 |
+
p, h4 { margin: 0; padding: 12px 0 0; }
|
51 |
+
h4.center { text-align: center; }
|
52 |
+
label { width: 90px; display: inline-block; text-align: right; }
|
53 |
+
.mceActionPanel { padding: 7px 0 12px; text-align: center; }
|
54 |
+
.mceActionPanel #insert { float: none; width: 180px; margin: 0 auto; }
|
55 |
+
</style>
|
56 |
+
</head>
|
57 |
+
<body id="link" class="wp-core-ui" onload="document.body.style.display='';" style="display:none;">
|
58 |
+
<form name="wpUserAvatar" action="#">
|
59 |
+
<p><label for="<?php esc_attr_e('wp_user_avatar_user'); ?>"><strong><?php _e("User:"); ?></strong></label>
|
60 |
+
<select id="<?php esc_attr_e('wp_user_avatar_user'); ?>" name="<?php esc_attr_e('wp_user_avatar_user'); ?>">
|
61 |
+
<option value=""></option>
|
62 |
+
<?php $users = get_users(); foreach($users as $user) : ?>
|
63 |
+
<option value="<?php echo $user->user_login; ?>"><?php echo $user->display_name; ?></option>
|
64 |
+
<?php endforeach; ?>
|
65 |
+
</select></p>
|
66 |
+
|
67 |
+
<h4 class="center">Choose a preset size or enter a number value.</h4>
|
68 |
+
|
69 |
+
<p>
|
70 |
+
<label for="<?php esc_attr_e('wp_user_avatar_size'); ?>"><strong><?php _e("Size:"); ?></strong></label>
|
71 |
+
<select id="<?php esc_attr_e('wp_user_avatar_size'); ?>" name="<?php esc_attr_e('wp_user_avatar_size'); ?>">
|
72 |
+
<option value=""></option>
|
73 |
+
<option value="original"><?php _e("Original"); ?></option>
|
74 |
+
<option value="large"><?php _e("Large"); ?></option>
|
75 |
+
<option value="medium"><?php _e("Medium"); ?></option>
|
76 |
+
<option value="thumbnail"><?php _e("Thumbnail"); ?></option>
|
77 |
+
</select>
|
78 |
+
or
|
79 |
+
<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="" />
|
80 |
+
</p>
|
81 |
+
|
82 |
+
<p><label for="<?php esc_attr_e('wp_user_avatar_align'); ?>"><strong><?php _e("Alignment:"); ?></strong></label>
|
83 |
+
<select id="<?php esc_attr_e('wp_user_avatar_align'); ?>" name="<?php esc_attr_e('wp_user_avatar_align'); ?>">
|
84 |
+
<option value=""></option>
|
85 |
+
<option value="center"><?php _e("Center"); ?></option>
|
86 |
+
<option value="left"><?php _e("Left"); ?></option>
|
87 |
+
<option value="right"><?php _e("Right"); ?></option>
|
88 |
+
</select></p>
|
89 |
+
|
90 |
+
<h4 class="center">Link to image file, attachment page, or custom URL.</h4>
|
91 |
+
|
92 |
+
<p>
|
93 |
+
<label for="<?php esc_attr_e('wp_user_avatar_link'); ?>"><strong><?php _e("Link to:"); ?></strong></label>
|
94 |
+
<select id="<?php esc_attr_e('wp_user_avatar_link'); ?>" name="<?php esc_attr_e('wp_user_avatar_link'); ?>">
|
95 |
+
<option value=""></option>
|
96 |
+
<option value="file"><?php _e("Image File"); ?></option>
|
97 |
+
<option value="attachment"><?php _e("Attachment Page"); ?></option>
|
98 |
+
</select>
|
99 |
+
</p>
|
100 |
+
|
101 |
+
<p>
|
102 |
+
<label for="<?php esc_attr_e('wp_user_avatar_link_external'); ?>">or</label>
|
103 |
+
<input type="text" size="36" id="<?php esc_attr_e('wp_user_avatar_link_external'); ?>" name="<?php esc_attr_e('wp_user_avatar_link'); ?>" value="" />
|
104 |
+
</p>
|
105 |
+
|
106 |
+
<div class="mceActionPanel">
|
107 |
+
<input type="submit" id="insert" class="button-primary" name="insert" value="<?php _e("Insert WP User Avatar"); ?>" onclick="insert_wp_user_avatar();" />
|
108 |
+
</div>
|
109 |
+
</form>
|
110 |
+
</body>
|
111 |
+
</html>
|
index.html
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
<!-- Thanks for using WP User Avatar! -->
|
js/wp-user-avatar.js
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
function openMediaUploader(a){wp.media.wpUserAvatar={get:function(){return wp.media.view.settings.post.wpUserAvatarId},set:function(c){var b=wp.media.view.settings;b.post.wpUserAvatarId=c;b.post.wpUserAvatarSrc=jQuery("div.attachment-info").find("img").attr("src");if(b.post.wpUserAvatarId){setWPUserAvatar(b.post.wpUserAvatarId,b.post.wpUserAvatarSrc);jQuery("#wp_user_avatar_radio").trigger("click")}},frame:function(){if(this._frame){return this._frame}this._frame=wp.media({state:"library",states:[new wp.media.controller.Library({title:"Edit WP User Avatar: "+a})]});this._frame.on("open",function(){var b=this.state().get("selection");id=jQuery("#wp-user-avatar").val();attachment=wp.media.attachment(id);attachment.fetch();b.add(attachment?[attachment]:[])},this._frame);this._frame.on("toolbar:create:select",function(b){this.createSelectToolbar(b,{text:"Set WP User Avatar"})},this._frame);this._frame.state("library").on("select",this.select);return this._frame},select:function(d){var c=wp.media.view.settings,b=this.get("selection").single();wp.media.wpUserAvatar.set(b?b.id:-1)},init:function(){jQuery("body").on("click","#add-wp-user-avatar",function(b){b.preventDefault();b.stopPropagation();wp.media.wpUserAvatar.frame().open()})}};jQuery(wp.media.wpUserAvatar.init)}function openThickboxUploader(b,a){jQuery("body").on("click","#add-wp-user-avatar",function(c){c.preventDefault();tb_show("Edit WP User Avatar: "+b,a)})}function setWPUserAvatar(b,a){jQuery("#wp-user-avatar",window.parent.document).val(b);jQuery("#wp-user-avatar-preview",window.parent.document).find("img").attr("src",a).removeAttr("width","").removeAttr("height","");jQuery("#wp-user-avatar-message",window.parent.document).show();jQuery("#remove-wp-user-avatar",window.parent.document).show();jQuery("#wp-user-avatar-notice",window.parent.document).hide();jQuery("#wp_user_avatar_radio",window.parent.document).trigger("click");if(typeof(wp)!="undefined"){wp.media.wpUserAvatar.frame().close()}else{window.parent.tb_remove()}}function removeWPUserAvatar(a,b){jQuery("body").on("click","#remove-wp-user-avatar",function(c){c.preventDefault();jQuery(this).hide();jQuery("#wp-user-avatar-preview").find("img").attr("src",b).removeAttr("width","").removeAttr("height","");jQuery("#wp-user-avatar").val("");jQuery("#wp-user-avatar-message, #wp-user-avatar-notice").show();jQuery("#wp_user_avatar_radio").trigger("click")})};
|
readme.txt
ADDED
@@ -0,0 +1,308 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== WP User Avatar ===
|
2 |
+
|
3 |
+
Contributors: bangbay
|
4 |
+
Donate link: http://siboliban.org/donate
|
5 |
+
Tags: author image, author photo, author avatar, avatar, bbPress, profile avatar, profile image, user avatar, user image, user photo
|
6 |
+
Requires at least: 3.3
|
7 |
+
Tested up to: 3.5.1
|
8 |
+
Stable tag: 1.3.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](http://gravatar.com/) avatar or Default Avatar if the user doesn't have a WP User Avatar image.
|
22 |
+
* Use the <code>[avatar]</code> shortcode in your posts. The shortcode will work with any theme, whether it has avatar support or not.
|
23 |
+
|
24 |
+
This plugin uses the Media uploader introduced in WordPress 3.5, but is also backwards-compatible to WordPress 3.3. It is also compatible with WordPress Multisite.
|
25 |
+
|
26 |
+
== Installation ==
|
27 |
+
|
28 |
+
1. Download, install, and activate the WP User Avatar plugin.
|
29 |
+
2. On your edit profile page, click "Edit WP User Avatar".
|
30 |
+
3. Choose an image, then click "Set WP User Avatar".
|
31 |
+
4. Click "Update Profile".
|
32 |
+
5. Upload your own Default Avatar in your Discussion settings (optional).
|
33 |
+
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/).
|
34 |
+
7. You can also use the <code>[avatar]</code> shortcode in your posts. The shortcode will work with any theme, whether it has avatar support or not.
|
35 |
+
|
36 |
+
**Example Usage**
|
37 |
+
|
38 |
+
Within [The Loop](http://codex.wordpress.org/The_Loop), you may be using:
|
39 |
+
|
40 |
+
`<?php echo get_avatar(get_the_author_meta('ID'), 96); ?>`
|
41 |
+
|
42 |
+
Replace this function with:
|
43 |
+
|
44 |
+
`<?php echo get_wp_user_avatar(get_the_author_meta('ID'), 96); ?>`
|
45 |
+
|
46 |
+
You can also use the values "original", "large", "medium", or "thumbnail" for your avatar size:
|
47 |
+
|
48 |
+
`<?php echo get_wp_user_avatar(get_the_author_meta('ID'), 'medium'); ?>`
|
49 |
+
|
50 |
+
You can also add an alignment of "left", "right", or "center":
|
51 |
+
|
52 |
+
`<?php echo get_wp_user_avatar(get_the_author_meta('ID'), 96, 'left'); ?>`
|
53 |
+
|
54 |
+
On an author page outside of [The Loop](http://codex.wordpress.org/The_Loop), you may be using:
|
55 |
+
|
56 |
+
`<?php
|
57 |
+
$user = get_user_by('slug', $author_name);
|
58 |
+
echo get_avatar($user->ID, 96);
|
59 |
+
?>`
|
60 |
+
|
61 |
+
Replace this function with:
|
62 |
+
|
63 |
+
`<?php
|
64 |
+
$user = get_user_by('slug', $author_name);
|
65 |
+
echo get_wp_user_avatar($user->ID, 96);
|
66 |
+
?>`
|
67 |
+
|
68 |
+
If you leave the options blank, WP User Avatar will detect whether you're inside [The Loop](http://codex.wordpress.org/The_Loop) or on an author page and return the correct avatar in the default 96x96 size:
|
69 |
+
|
70 |
+
`<?php echo get_wp_user_avatar(); ?>`
|
71 |
+
|
72 |
+
The function <code>get_wp_user_avatar</code> can also fall back to <code>get_avatar</code> if there is 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](http://gravatar.com/) avatar or Default Avatar.
|
73 |
+
|
74 |
+
**Other Available Functions**
|
75 |
+
|
76 |
+
= [avatar] shortcode =
|
77 |
+
|
78 |
+
You can use the <code>[avatar]</code> shortcode in your posts. It will detect the author of the post or you can specify an author by username. You can specify a size, alignment, and link, but they are optional. For links, you can link to the original image file, attachment page, or a custom URL.
|
79 |
+
|
80 |
+
`[avatar user="admin" size="medium" align="left" link="file"]`
|
81 |
+
|
82 |
+
= get_wp_user_avatar_src =
|
83 |
+
|
84 |
+
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:
|
85 |
+
|
86 |
+
`<a href="<?php echo get_wp_user_avatar_src($user_id, 'large'); ?>">
|
87 |
+
<?php echo get_wp_user_avatar($user_id, 'thumbnail'); ?>
|
88 |
+
</a>`
|
89 |
+
|
90 |
+
= has_wp_user_avatar =
|
91 |
+
|
92 |
+
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](http://codex.wordpress.org/The_Loop) or author page:
|
93 |
+
|
94 |
+
`<?php
|
95 |
+
if ( has_wp_user_avatar($user_id) ) {
|
96 |
+
echo get_wp_user_avatar($user_id, 96);
|
97 |
+
} else {
|
98 |
+
echo '<img src="my-alternate-image.jpg" />';
|
99 |
+
}
|
100 |
+
?>`
|
101 |
+
|
102 |
+
== Frequently Asked Questions ==
|
103 |
+
|
104 |
+
= How do I use WP User Avatar? =
|
105 |
+
|
106 |
+
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:
|
107 |
+
|
108 |
+
= get_wp_user_avatar =
|
109 |
+
|
110 |
+
1. Allows you to use the values "original", "large", "medium", or "thumbnail" for your avatar size.
|
111 |
+
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.
|
112 |
+
3. Optionally adds CSS classes "alignleft", "alignright", or "aligncenter" to position your avatar.
|
113 |
+
4. Shows nothing if the user has no WP User Avatar image.
|
114 |
+
5. Shows the user's [gravatar.com](http://gravatar.com/) avatar or Default Avatar only if "Show Avatars" is enabled in your Discussion settings.
|
115 |
+
|
116 |
+
= get_avatar =
|
117 |
+
|
118 |
+
1. Requires you to enable "Show Avatars" in your Discussion settings to show any avatars.
|
119 |
+
2. Accepts only numeric values for your avatar size.
|
120 |
+
3. Always adds a fixed width and height to your image. This may cause problems if you use responsive CSS in your theme.
|
121 |
+
4. Shows the user's [gravatar.com](http://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.)
|
122 |
+
5. Requires no changes to your theme files if you are currently using <code>get_avatar</code>.
|
123 |
+
|
124 |
+
[Read more about get_avatar in the WordPress Function Reference](http://codex.wordpress.org/Function_Reference/get_avatar).
|
125 |
+
|
126 |
+
= Can I create a custom Default Avatar? =
|
127 |
+
In your Discussion settings, you can upload your own Default Avatar.
|
128 |
+
|
129 |
+
= Can I insert WP User Avatar directly into a post? =
|
130 |
+
|
131 |
+
You can use the <code>[avatar]</code> shortcode in your posts. It will detect the author of the post or you can specify an author by username. You can specify a size, alignment, and link, but they are optional. For links, you can link to the original image file, attachment page, or a custom URL.
|
132 |
+
|
133 |
+
`[avatar user="admin" size="96" align="left" link="file"]`
|
134 |
+
|
135 |
+
Outputs:
|
136 |
+
|
137 |
+
`<a href="{fileURL}" class="wp-user-avatar-link wp-user-avatar-file">
|
138 |
+
<img src="{imageURL}" width="96" height="96" class="wp-user-avatar wp-user-avatar-96 alignleft" />
|
139 |
+
</a>`
|
140 |
+
|
141 |
+
= Can Contributors or Subscribers choose their own WP User Avatar image? =
|
142 |
+
|
143 |
+
Users need <code>upload_files</code> capability to choose their own WP User Avatar image. This means that only Administrators, Editors, and Authors can choose their own WP User Avatar image. Contributors and Subscribers cannot upload images. Administators can choose WP User Avatar images for Contributors and Subscribers.
|
144 |
+
|
145 |
+
[Read more about Roles and Capabilities here](http://codex.wordpress.org/Roles_and_Capabilities).
|
146 |
+
|
147 |
+
= Will WP User Avatar work with comment author avatars? =
|
148 |
+
|
149 |
+
Yes, for registered users. Non-registered comment authors will show their [gravatar.com](http://gravatar.com/) avatars or Default Avatar.
|
150 |
+
|
151 |
+
= Will WP User Avatar work with bbPress? =
|
152 |
+
|
153 |
+
Yes, but only users that have <code>upload_files</code> capability can choose their own WP User Avatar image.
|
154 |
+
|
155 |
+
= Will WP User Avatar work with WordPress Multisite? =
|
156 |
+
|
157 |
+
Yes, however, each site has its own avatar settings. If you set a WP User Avatar image on one site, you have to set it again for different sites in your network.
|
158 |
+
|
159 |
+
= How can I see which users have an avatar? =
|
160 |
+
|
161 |
+
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.
|
162 |
+
|
163 |
+
= What CSS can I use with WP User Avatar? =
|
164 |
+
|
165 |
+
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:
|
166 |
+
|
167 |
+
`<?php echo get_wp_user_avatar($user_id, 96, 'left'); ?>`
|
168 |
+
|
169 |
+
Outputs:
|
170 |
+
|
171 |
+
`<img src="{imageURL}" width="96" height="96" class="wp-user-avatar wp-user-avatar-96 alignleft" />`
|
172 |
+
|
173 |
+
**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.
|
174 |
+
|
175 |
+
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:
|
176 |
+
|
177 |
+
`<?php echo get_wp_user_avatar($user_id, 'medium'); ?>`
|
178 |
+
|
179 |
+
Outputs:
|
180 |
+
|
181 |
+
`<img src="{imageURL}" class="wp-user-avatar wp-user-avatar-medium" />`
|
182 |
+
|
183 |
+
**Note:** WordPress adds more CSS classes to the avatar not listed here.
|
184 |
+
|
185 |
+
If you use the <code>[avatar]</code> shortcode, WP User Avatar will add the CSS class "wp-user-avatar-link" to the link. It will also add CSS classes based on link type.
|
186 |
+
|
187 |
+
* Image File: wp-user-avatar-file
|
188 |
+
* Attachment: wp-user-avatar-attachment
|
189 |
+
* Custom URL: wp-user-avatar-custom
|
190 |
+
|
191 |
+
`[avatar user="admin" size="96" align="left" link="attachment"]`
|
192 |
+
|
193 |
+
Outputs:
|
194 |
+
|
195 |
+
`<a href="{attachmentURL}" class="wp-user-avatar-link wp-user-avatar-attachment">
|
196 |
+
<img src="{imageURL}" width="96" height="96" class="wp-user-avatar wp-user-avatar-96 alignleft" />
|
197 |
+
</a>`
|
198 |
+
|
199 |
+
= What other functions are available for WP User Avatar? =
|
200 |
+
* <code>get_wp_user_avatar_src</code>: retrieves just the image URL
|
201 |
+
* <code>has_wp_user_avatar</code>: checks if the user has a WP User Avatar image
|
202 |
+
* [See example usage here](http://wordpress.org/extend/plugins/wp-user-avatar/installation/)
|
203 |
+
|
204 |
+
== Screenshots ==
|
205 |
+
|
206 |
+
1. WP User Avatar lets you upload your own Default Avatar.
|
207 |
+
2. WP User Avatar adds a field to your edit profile page.
|
208 |
+
3. After you've chosen a WP User Avatar image, you will see the option to remove it.
|
209 |
+
4. WP User Avatar adds a button to insert the [avatar] shortcode in the Visual Editor.
|
210 |
+
5. Options for the [avatar] shortcode.
|
211 |
+
|
212 |
+
== Changelog ==
|
213 |
+
|
214 |
+
= 1.3.1 =
|
215 |
+
* Bug Fix: Rename usermeta only if found
|
216 |
+
|
217 |
+
= 1.3 =
|
218 |
+
* Add: Multisite support
|
219 |
+
* Bug Fix: Warnings if no user found
|
220 |
+
* Update: Enable action_show_user_profile for any class using show_user_profile hook
|
221 |
+
|
222 |
+
= 1.2.6 =
|
223 |
+
* Bug Fix: options-discussion.php page doesn't show default avatars
|
224 |
+
|
225 |
+
= 1.2.5 =
|
226 |
+
* Bug Fix: Comment author showing wrong avatar
|
227 |
+
* Bug Fix: Avatar adds fixed dimensions when non-numeric size is used
|
228 |
+
* Update: Use local image for default avatar instead of calling image from Gravatar
|
229 |
+
|
230 |
+
= 1.2.4 =
|
231 |
+
* Bug Fix: Show default avatar when user removes custom avatar
|
232 |
+
* Bug Fix: Default Avatar save setting
|
233 |
+
|
234 |
+
= 1.2.3 =
|
235 |
+
* Bug Fix: Show default avatar when user removes custom avatar
|
236 |
+
* Bug Fix: Default Avatar save setting
|
237 |
+
|
238 |
+
= 1.2.2 =
|
239 |
+
* Add: Ability for bbPress users to edit avatar on front profile page
|
240 |
+
* Add: Link options for shortcode
|
241 |
+
* Bug Fix: Show WP User Avatar only to users with upload_files capability
|
242 |
+
|
243 |
+
= 1.2.1 =
|
244 |
+
* Add: TinyMCE button
|
245 |
+
* Update: Clean up redundant code
|
246 |
+
* Update: Compatibility only back to WordPress 3.3
|
247 |
+
|
248 |
+
= 1.2 =
|
249 |
+
* Add: Default Avatar setting
|
250 |
+
|
251 |
+
= 1.1.7 =
|
252 |
+
* Bug Fix: Change update_usermeta to update_user_meta
|
253 |
+
|
254 |
+
= 1.1.6 =
|
255 |
+
* Bug Fix: Image not showing in user profile edit
|
256 |
+
|
257 |
+
= 1.1.5a =
|
258 |
+
* Update: readme.txt
|
259 |
+
|
260 |
+
= 1.1.5 =
|
261 |
+
* Bug Fix: Remove stray curly bracket
|
262 |
+
|
263 |
+
= 1.1.4 =
|
264 |
+
* Bug Fix: Change get_usermeta to get_user_meta
|
265 |
+
* Bug Fix: Non-object warning when retrieving user ID
|
266 |
+
|
267 |
+
= 1.1.3 =
|
268 |
+
* Bug Fix: Comment author with no e-mail address
|
269 |
+
|
270 |
+
= 1.1.2 =
|
271 |
+
* Remove: Unused variables
|
272 |
+
|
273 |
+
= 1.1.1 =
|
274 |
+
* Bug Fix: Capabilities error in comment avatar
|
275 |
+
|
276 |
+
= 1.1 =
|
277 |
+
* Add: Add filter for get_avatar
|
278 |
+
* Add: CSS alignment classes
|
279 |
+
* Add: Replace comment author avatar
|
280 |
+
* Add: Shortcode
|
281 |
+
* Update: readme.txt
|
282 |
+
|
283 |
+
= 1.0.2 =
|
284 |
+
* Update: FAQ
|
285 |
+
* Remove: CSS that hides "Insert into Post"
|
286 |
+
|
287 |
+
= 1.0.1 =
|
288 |
+
* Add: CSS classes to image output
|
289 |
+
|
290 |
+
= 1.0 =
|
291 |
+
* Initial release
|
292 |
+
|
293 |
+
== Upgrade Notice ==
|
294 |
+
|
295 |
+
= 1.3 =
|
296 |
+
* New Feature: Multisite support
|
297 |
+
|
298 |
+
= 1.2.2 =
|
299 |
+
* New Features: Link options for shortcode, bbPress integration
|
300 |
+
|
301 |
+
= 1.2.1 =
|
302 |
+
* New Feature: Shortcode insertion button for Visual Editor
|
303 |
+
|
304 |
+
= 1.2 =
|
305 |
+
* New Feature: Default Avatar customization
|
306 |
+
|
307 |
+
= 1.1 =
|
308 |
+
* New Features: [avatar] shortcode, direct replacement of get_avatar() and comment author avatar, more CSS classes
|
wp-user-avatar.php
ADDED
@@ -0,0 +1,507 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package WP User Avatar
|
4 |
+
* @version 1.3.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.3.1
|
11 |
+
Author: Bangbay Siboliban
|
12 |
+
Author URI: http://siboliban.org/
|
13 |
+
*/
|
14 |
+
|
15 |
+
// Define paths and variables
|
16 |
+
define('WP_USER_AVATAR_VERSION', '1.3.1');
|
17 |
+
define('WP_USER_AVATAR_FOLDER', basename(dirname(__FILE__)));
|
18 |
+
define('WP_USER_AVATAR_ABSPATH', trailingslashit(str_replace('\\','/', WP_PLUGIN_DIR.'/'.WP_USER_AVATAR_FOLDER)));
|
19 |
+
define('WP_USER_AVATAR_URLPATH', trailingslashit(plugins_url(WP_USER_AVATAR_FOLDER)));
|
20 |
+
|
21 |
+
// Define global variables
|
22 |
+
$avatar_default = get_option('avatar_default');
|
23 |
+
$avatar_default_wp_user_avatar = get_option('avatar_default_wp_user_avatar');
|
24 |
+
$mustache_original = WP_USER_AVATAR_URLPATH.'images/wp-user-avatar.png';
|
25 |
+
$mustache_medium = WP_USER_AVATAR_URLPATH.'images/wp-user-avatar-300x300.png';
|
26 |
+
$mustache_thumbnail = WP_USER_AVATAR_URLPATH.'images/wp-user-avatar-150x150.png';
|
27 |
+
$mustache_avatar = WP_USER_AVATAR_URLPATH.'images/wp-user-avatar-96x96.png';
|
28 |
+
$mustache_admin = WP_USER_AVATAR_URLPATH.'images/wp-user-avatar-32x32.png';
|
29 |
+
$ssl = is_ssl() ? 's' : '';
|
30 |
+
|
31 |
+
// Load add-ons
|
32 |
+
include_once(WP_USER_AVATAR_ABSPATH.'includes/tinymce.php');
|
33 |
+
|
34 |
+
// Initialize default settings
|
35 |
+
register_activation_hook(__FILE__, 'wp_user_avatar_options');
|
36 |
+
|
37 |
+
// Remove user metadata and options on plugin delete
|
38 |
+
register_uninstall_hook(__FILE__, 'wp_user_avatar_delete_setup');
|
39 |
+
|
40 |
+
// Settings saved to wp_options
|
41 |
+
function wp_user_avatar_options(){
|
42 |
+
add_option('avatar_default_wp_user_avatar','');
|
43 |
+
}
|
44 |
+
add_action('init', 'wp_user_avatar_options');
|
45 |
+
|
46 |
+
// Update default avatar to new format
|
47 |
+
function wp_user_avatar_default_avatar(){
|
48 |
+
global $avatar_default, $avatar_default_wp_user_avatar, $mustache_original;
|
49 |
+
if($avatar_default == $mustache_original){
|
50 |
+
update_option('avatar_default', 'wp_user_avatar');
|
51 |
+
}
|
52 |
+
if(!empty($avatar_default_wp_user_avatar)){
|
53 |
+
$avatar_default_wp_user_avatar_image = wp_get_attachment_image_src($avatar_default_wp_user_avatar, 'medium');
|
54 |
+
if($avatar_default == $avatar_default_wp_user_avatar_image[0]){
|
55 |
+
update_option('avatar_default', 'wp_user_avatar');
|
56 |
+
}
|
57 |
+
}
|
58 |
+
}
|
59 |
+
add_action('init', 'wp_user_avatar_default_avatar');
|
60 |
+
|
61 |
+
// Rename user meta to match database settings
|
62 |
+
function wp_user_avatar_user_meta(){
|
63 |
+
global $wpdb, $blog_id;
|
64 |
+
$wp_user_avatar_metakey = $wpdb->get_blog_prefix($blog_id).'user_avatar';
|
65 |
+
if($wp_user_avatar_metakey != 'wp_user_avatar'){
|
66 |
+
$users = get_users();
|
67 |
+
foreach($users as $user){
|
68 |
+
$wp_user_avatar = get_user_meta($user->ID, 'wp_user_avatar', true);
|
69 |
+
if(!empty($wp_user_avatar)){
|
70 |
+
update_user_meta($user->ID, $wpdb->get_blog_prefix($blog_id).'user_avatar', $wp_user_avatar);
|
71 |
+
delete_user_meta($user->ID, 'wp_user_avatar');
|
72 |
+
}
|
73 |
+
}
|
74 |
+
}
|
75 |
+
}
|
76 |
+
add_action('init', 'wp_user_avatar_user_meta');
|
77 |
+
|
78 |
+
// Remove user metadata and options on plugin delete
|
79 |
+
function wp_user_avatar_delete_setup(){
|
80 |
+
global $wpdb, $blog_id, $switched;
|
81 |
+
$users = get_users();
|
82 |
+
if(is_multisite()){
|
83 |
+
$blogs = $wpdb->get_results($wpdb->prepare("SELECT * FROM wp_blogs"));
|
84 |
+
foreach($users as $user){
|
85 |
+
foreach($blogs as $blog){
|
86 |
+
delete_user_meta($user->ID, $wpdb->get_blog_prefix($blog->blog_id).'user_avatar');
|
87 |
+
}
|
88 |
+
}
|
89 |
+
foreach($blogs as $blog){
|
90 |
+
switch_to_blog($blog->blog_id);
|
91 |
+
delete_option('avatar_default_wp_user_avatar');
|
92 |
+
}
|
93 |
+
} else {
|
94 |
+
foreach($users as $user){
|
95 |
+
delete_user_meta($user->ID, $wpdb->get_blog_prefix($blog_id).'user_avatar');
|
96 |
+
}
|
97 |
+
delete_option('avatar_default_wp_user_avatar');
|
98 |
+
}
|
99 |
+
update_option('avatar_default', 'mystery');
|
100 |
+
}
|
101 |
+
|
102 |
+
// WP User Avatar
|
103 |
+
if(!class_exists('wp_user_avatar')){
|
104 |
+
class wp_user_avatar{
|
105 |
+
function wp_user_avatar(){
|
106 |
+
// Only works if user can upload files
|
107 |
+
if(current_user_can('upload_files')){
|
108 |
+
add_action('show_user_profile', array('wp_user_avatar','action_show_user_profile'));
|
109 |
+
add_action('edit_user_profile', array($this,'action_show_user_profile'));
|
110 |
+
add_action('personal_options_update', array($this,'action_process_option_update'));
|
111 |
+
add_action('edit_user_profile_update', array($this,'action_process_option_update'));
|
112 |
+
add_action('discussion_update', array($this,'action_process_option_update'));
|
113 |
+
add_action('admin_enqueue_scripts', array($this, 'media_upload_scripts'));
|
114 |
+
}
|
115 |
+
// Only add attachment field for WP 3.4 and older
|
116 |
+
if(!function_exists('wp_enqueue_media')){
|
117 |
+
add_filter('attachment_fields_to_edit', array($this, 'add_wp_user_avatar_attachment_field_to_edit'), 10, 2);
|
118 |
+
}
|
119 |
+
// Hide column in Users table if avatars are shown
|
120 |
+
if(get_option('show_avatars') != '1'){
|
121 |
+
add_filter('manage_users_columns', array($this, 'add_wp_user_avatar_column'), 10, 1);
|
122 |
+
add_filter('manage_users_custom_column', array($this, 'show_wp_user_avatar_column'), 10, 3);
|
123 |
+
}
|
124 |
+
// Load scripts in front pages for logged in users
|
125 |
+
if(is_user_logged_in() && current_user_can('upload_files')){
|
126 |
+
add_action('wp_enqueue_scripts', array($this, 'media_upload_scripts'));
|
127 |
+
}
|
128 |
+
}
|
129 |
+
|
130 |
+
// Add to edit user profile
|
131 |
+
function action_show_user_profile($user){
|
132 |
+
global $current_user, $wpdb, $blog_id;
|
133 |
+
$wp_user_avatar = get_user_meta($user->ID, $wpdb->get_blog_prefix($blog_id).'user_avatar', true);
|
134 |
+
$hide_notice = has_wp_user_avatar($user->ID) ? ' class="hide-me"' : '';
|
135 |
+
$hide_remove = !has_wp_user_avatar($user->ID) ? ' hide-me' : '';
|
136 |
+
$avatar_medium_src = (get_option('show_avatars') == '1') ? get_avatar_original($user->user_email, 96) : includes_url().'images/blank.gif';
|
137 |
+
$avatar_medium = has_wp_user_avatar($user->ID) ? get_wp_user_avatar_src($user->ID, 'medium') : $avatar_medium_src;
|
138 |
+
$profile = ($current_user->ID == $user->ID) ? 'Profile' : 'User';
|
139 |
+
?>
|
140 |
+
<?php if(class_exists('bbPress')) : ?>
|
141 |
+
<h2 class="entry-title"><?php _e('WP User Avatar'); ?></h2>
|
142 |
+
<fieldset class="bbp-form">
|
143 |
+
<legend><?php _e('WP User Avatar'); ?></legend>
|
144 |
+
<input type="hidden" name="wp-user-avatar" id="wp-user-avatar" value="<?php echo $wp_user_avatar; ?>" />
|
145 |
+
<p><button type="button" class="button" id="add-wp-user-avatar"><?php _e('Edit WP User Avatar'); ?></button></p>
|
146 |
+
<p id="wp-user-avatar-preview"><?php echo '<img src="'.$avatar_medium.'" alt="" />'; ?></p>
|
147 |
+
<?php if(get_option('show_avatars') == '1') : ?>
|
148 |
+
<p id="wp-user-avatar-notice"<?php echo $hide_notice; ?>><?php _e('This is your default avatar.'); ?></p>
|
149 |
+
<?php endif; ?>
|
150 |
+
<p><button type="button" class="button<?php echo $hide_remove; ?>" id="remove-wp-user-avatar">><?php _e('Remove'); ?></button></p>
|
151 |
+
<p id="wp-user-avatar-message"><?php _e('Press "Update '.$profile.'" to save your changes.'); ?></p>
|
152 |
+
</fieldset>
|
153 |
+
<?php else : ?>
|
154 |
+
<h3><?php _e('WP User Avatar') ?></h3>
|
155 |
+
<table class="form-table">
|
156 |
+
<tr>
|
157 |
+
<th><label for="wp_user_avatar"><?php _e('WP User Avatar'); ?></label></th>
|
158 |
+
<td>
|
159 |
+
<input type="hidden" name="wp-user-avatar" id="wp-user-avatar" value="<?php echo $wp_user_avatar; ?>" />
|
160 |
+
<p><button type="button" class="button" id="add-wp-user-avatar"><?php _e('Edit WP User Avatar'); ?></button></p>
|
161 |
+
<p id="wp-user-avatar-preview"><?php echo '<img src="'.$avatar_medium.'" alt="" />'; ?></p>
|
162 |
+
<?php if(get_option('show_avatars') == '1') : ?>
|
163 |
+
<p id="wp-user-avatar-notice"<?php echo $hide_notice; ?>><?php _e('This is your default avatar.'); ?></p>
|
164 |
+
<?php endif; ?>
|
165 |
+
<p><button type="button" class="button<?php echo $hide_remove; ?>" id="remove-wp-user-avatar"><?php _e('Remove'); ?></button></p>
|
166 |
+
<p id="wp-user-avatar-message"><?php _e('Press "Update '.$profile.'" to save your changes.'); ?></p>
|
167 |
+
</td>
|
168 |
+
</tr>
|
169 |
+
</table>
|
170 |
+
<?php endif; ?>
|
171 |
+
<?php
|
172 |
+
echo edit_default_wp_user_avatar($user->display_name, $avatar_medium_src, $avatar_medium_src);
|
173 |
+
}
|
174 |
+
|
175 |
+
// Update user meta
|
176 |
+
function action_process_option_update($user_id){
|
177 |
+
global $wpdb, $blog_id;
|
178 |
+
update_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', (isset($_POST['wp-user-avatar']) ? intval($_POST['wp-user-avatar']) : ''));
|
179 |
+
}
|
180 |
+
|
181 |
+
// Add button to attach image
|
182 |
+
function add_wp_user_avatar_attachment_field_to_edit($fields, $post){
|
183 |
+
$image = wp_get_attachment_image_src($post->ID, "medium");
|
184 |
+
$button = '<button type="button" class="button" id="set-wp-user-avatar-image" onclick="setWPUserAvatar(\''.$post->ID.'\', \''.$image[0].'\')">Set WP User Avatar</button>';
|
185 |
+
$fields['wp-user-avatar'] = array(
|
186 |
+
'label' => __('WP User Avatar'),
|
187 |
+
'input' => 'html',
|
188 |
+
'html' => $button
|
189 |
+
);
|
190 |
+
return $fields;
|
191 |
+
}
|
192 |
+
|
193 |
+
// Add column to Users page
|
194 |
+
function add_wp_user_avatar_column($columns){
|
195 |
+
return $columns + array('wp-user-avatar' => __('WP User Avatar'));;
|
196 |
+
}
|
197 |
+
|
198 |
+
// Show thumbnail of wp_user_avatar
|
199 |
+
function show_wp_user_avatar_column($value, $column_name, $user_id){
|
200 |
+
global $wpdb, $blog_id;
|
201 |
+
$wp_user_avatar = get_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', true);
|
202 |
+
$wp_user_avatar_image = wp_get_attachment_image($wp_user_avatar, array(32,32));
|
203 |
+
if($column_name == 'wp-user-avatar'){
|
204 |
+
return $wp_user_avatar_image;
|
205 |
+
}
|
206 |
+
}
|
207 |
+
|
208 |
+
// Media uploader
|
209 |
+
function media_upload_scripts(){
|
210 |
+
global $ssl;
|
211 |
+
if(function_exists('wp_enqueue_media')){
|
212 |
+
wp_enqueue_media();
|
213 |
+
} else {
|
214 |
+
wp_enqueue_script('media-upload');
|
215 |
+
wp_enqueue_script('thickbox');
|
216 |
+
wp_enqueue_style('thickbox');
|
217 |
+
}
|
218 |
+
wp_enqueue_script('wp-user-avatar', WP_USER_AVATAR_URLPATH.'js/wp-user-avatar.js', '', WP_USER_AVATAR_VERSION);
|
219 |
+
wp_enqueue_style('wp-user-avatar', WP_USER_AVATAR_URLPATH.'css/wp-user-avatar.css', '', WP_USER_AVATAR_VERSION);
|
220 |
+
}
|
221 |
+
}
|
222 |
+
|
223 |
+
// Uploader scripts
|
224 |
+
function edit_default_wp_user_avatar($section, $avatar_medium, $avatar_thumb){ ?>
|
225 |
+
<script type="text/javascript">
|
226 |
+
jQuery(function(){
|
227 |
+
<?php if(function_exists('wp_enqueue_media')) : // Backbone uploader for WP 3.5+ ?>
|
228 |
+
openMediaUploader("<?php echo $section; ?>");
|
229 |
+
<?php else : // Fall back to Thickbox uploader ?>
|
230 |
+
openThickboxUploader("<?php echo $section; ?>", "<?php echo get_admin_url(); ?>media-upload.php?post_id=0&type=image&tab=library&TB_iframe=1");
|
231 |
+
<?php endif; ?>
|
232 |
+
removeWPUserAvatar("<?php echo htmlspecialchars_decode($avatar_medium); ?>", "<?php echo htmlspecialchars_decode($avatar_thumb); ?>");
|
233 |
+
});
|
234 |
+
</script>
|
235 |
+
<?php
|
236 |
+
}
|
237 |
+
|
238 |
+
// Returns true if user has Gravatar-hosted image
|
239 |
+
function has_gravatar($id_or_email, $has_gravatar=false){
|
240 |
+
global $ssl;
|
241 |
+
$user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
|
242 |
+
$email = !empty($user) ? $user->user_email : $id_or_email;
|
243 |
+
if(!empty($email)){
|
244 |
+
$hash = md5(strtolower(trim($email)));
|
245 |
+
$gravatar = 'http'.$ssl.'://www.gravatar.com/avatar/'.$hash.'?d=404';
|
246 |
+
$headers = @get_headers($gravatar);
|
247 |
+
$has_gravatar = !preg_match("|200|", $headers[0]) ? false : true;
|
248 |
+
}
|
249 |
+
return $has_gravatar;
|
250 |
+
}
|
251 |
+
|
252 |
+
// Returns true if user has wp_user_avatar
|
253 |
+
function has_wp_user_avatar($user_id=''){
|
254 |
+
global $post, $wpdb, $blog_id;
|
255 |
+
if(empty($user_id)){
|
256 |
+
$author_name = get_query_var('author_name');
|
257 |
+
$user = is_author() ? get_user_by('slug', $author_name) : get_the_author_meta('ID');
|
258 |
+
$user_id = $user->ID;
|
259 |
+
}
|
260 |
+
$wp_user_avatar = get_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', true);
|
261 |
+
if(!empty($wp_user_avatar)){
|
262 |
+
return true;
|
263 |
+
}
|
264 |
+
}
|
265 |
+
|
266 |
+
// Find wp_user_avatar, show get_avatar if empty
|
267 |
+
function get_wp_user_avatar($id_or_email='', $size='96', $align=''){
|
268 |
+
global $post, $comment, $avatar_default, $wpdb, $blog_id;
|
269 |
+
// Find user ID on comment, author page, or post
|
270 |
+
if(is_object($id_or_email)){
|
271 |
+
if($comment->user_id != '0'){
|
272 |
+
$id_or_email = $comment->user_id;
|
273 |
+
$user = get_user_by('id', $id_or_email);
|
274 |
+
$email = $user->user_email;
|
275 |
+
} elseif(!empty($comment->comment_author_email)){
|
276 |
+
$user = get_user_by('email', $comment->comment_author_email);
|
277 |
+
$id_or_email = !empty($user) ? $user->ID : $comment->comment_author_email;
|
278 |
+
$email = !empty($user) ? $user->user_email : $id_or_email;
|
279 |
+
}
|
280 |
+
$alt = $comment->comment_author;
|
281 |
+
} else {
|
282 |
+
if(!empty($id_or_email)){
|
283 |
+
$user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
|
284 |
+
} else {
|
285 |
+
$author_name = get_query_var('author_name');
|
286 |
+
if(is_author()){
|
287 |
+
$user = get_user_by('slug', $author_name);
|
288 |
+
} else {
|
289 |
+
$user_id = get_the_author_meta('ID');
|
290 |
+
$user = get_user_by('id', $user_id);
|
291 |
+
}
|
292 |
+
}
|
293 |
+
$id_or_email = !empty($user) ? $user->ID : '';
|
294 |
+
$alt = $user->display_name;
|
295 |
+
}
|
296 |
+
$wp_user_avatar_meta = !empty($id_or_email) ? get_the_author_meta($wpdb->get_blog_prefix($blog_id).'user_avatar', $id_or_email) : '';
|
297 |
+
$alignclass = !empty($align) ? ' align'.$align : '';
|
298 |
+
if(!empty($wp_user_avatar_meta)){
|
299 |
+
$get_size = is_numeric($size) ? array($size,$size) : $size;
|
300 |
+
$wp_user_avatar_image = wp_get_attachment_image_src($wp_user_avatar_meta, $get_size);
|
301 |
+
$dimensions = is_numeric($size) ? ' width="'.$wp_user_avatar_image[1].'" height="'.$wp_user_avatar_image[2].'"' : '';
|
302 |
+
$wp_user_avatar = '<img src="'.$wp_user_avatar_image[0].'"'.$dimensions.' alt="'.$alt.'" class="wp-user-avatar wp-user-avatar-'.$size.$alignclass.' avatar avatar avatar-'.$size.' photo" />';
|
303 |
+
} else {
|
304 |
+
if($size == 'original' || $size == 'large' || $size == 'medium' || $size == 'thumbnail'){
|
305 |
+
$get_size = ($size == 'original') ? get_option('large_size_w') : get_option($size.'_size_w');
|
306 |
+
} else {
|
307 |
+
$get_size = $size;
|
308 |
+
}
|
309 |
+
$avatar = get_avatar($id_or_email, $get_size, $default='', $alt='');
|
310 |
+
if(!is_numeric($size)){
|
311 |
+
$avatar = preg_replace("/(width|height)=\'\d*\'\s/", '', $avatar);
|
312 |
+
$avatar = preg_replace('/(width|height)=\"\d*\"\s/', '', $avatar);
|
313 |
+
$avatar = str_replace('wp-user-avatar wp-user-avatar-'.$get_size.' ', '', $avatar);
|
314 |
+
$avatar = str_replace("class='", "class='wp-user-avatar wp-user-avatar-".$size.$alignclass." ", $avatar);
|
315 |
+
}
|
316 |
+
$wp_user_avatar = $avatar;
|
317 |
+
}
|
318 |
+
return $wp_user_avatar;
|
319 |
+
}
|
320 |
+
|
321 |
+
// Return just the image src
|
322 |
+
function get_wp_user_avatar_src($id_or_email, $size='', $align=''){
|
323 |
+
$wp_user_avatar_image = get_wp_user_avatar($id_or_email, $size, $align);
|
324 |
+
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $wp_user_avatar_image, $matches, PREG_SET_ORDER);
|
325 |
+
$wp_user_avatar_image_src = $matches [0] [1];
|
326 |
+
return $wp_user_avatar_image_src;
|
327 |
+
}
|
328 |
+
|
329 |
+
// Replace get_avatar
|
330 |
+
function get_wp_user_avatar_alt($avatar, $id_or_email, $size='', $default='', $alt=''){
|
331 |
+
global $post, $pagenow, $comment, $avatar_default, $avatar_default_wp_user_avatar, $mustache_original, $mustache_medium, $mustache_thumbnail, $mustache_avatar, $mustache_admin, $wpdb, $blog_id;
|
332 |
+
// Find user ID on comment, author page, or post
|
333 |
+
$email = '';
|
334 |
+
if(is_object($id_or_email)){
|
335 |
+
if($comment->user_id != '0'){
|
336 |
+
$id_or_email = $comment->user_id;
|
337 |
+
$user = get_user_by('id', $id_or_email);
|
338 |
+
$email = $user->user_email;
|
339 |
+
} elseif(!empty($comment->comment_author_email)){
|
340 |
+
$user = get_user_by('email', $comment->comment_author_email);
|
341 |
+
$id_or_email = !empty($user) ? $user->ID : $comment->comment_author_email;
|
342 |
+
$email = !empty($user) ? $user->user_email : $id_or_email;
|
343 |
+
}
|
344 |
+
$alt = $comment->comment_author;
|
345 |
+
} else {
|
346 |
+
if(!empty($id_or_email)){
|
347 |
+
$user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
|
348 |
+
} else {
|
349 |
+
$author_name = get_query_var('author_name');
|
350 |
+
if(is_author()){
|
351 |
+
$user = get_user_by('slug', $author_name);
|
352 |
+
} else {
|
353 |
+
$user_id = get_the_author_meta('ID');
|
354 |
+
$user = get_user_by('id', $user_id);
|
355 |
+
}
|
356 |
+
}
|
357 |
+
$id_or_email = !empty($user) ? $user->ID : '';
|
358 |
+
$email = !empty($user) ? $user->user_email : '';
|
359 |
+
$alt = !empty($user) ? $user->display_name : '';
|
360 |
+
}
|
361 |
+
$wp_user_avatar_meta = !empty($id_or_email) ? get_the_author_meta($wpdb->get_blog_prefix($blog_id).'user_avatar', $id_or_email) : '';
|
362 |
+
if(!empty($wp_user_avatar_meta)){
|
363 |
+
$wp_user_avatar_image = wp_get_attachment_image_src($wp_user_avatar_meta, array($size,$size));
|
364 |
+
$dimensions = is_numeric($size) ? ' width="'.$wp_user_avatar_image[1].'" height="'.$wp_user_avatar_image[2].'"' : '';
|
365 |
+
$default = $wp_user_avatar_image[0];
|
366 |
+
$avatar = '<img src="'.$default.'"'.$dimensions.' alt="'.$alt.'" class="wp-user-avatar wp-user-avatar-'.$size.' avatar avatar-'.$size.' photo" />';
|
367 |
+
} else {
|
368 |
+
if(!has_gravatar($email) && $avatar_default == 'wp_user_avatar'){
|
369 |
+
if(!empty($avatar_default_wp_user_avatar)){
|
370 |
+
$avatar_default_wp_user_avatar_image = wp_get_attachment_image_src($avatar_default_wp_user_avatar, array($size,$size));
|
371 |
+
$default = $avatar_default_wp_user_avatar_image[0];
|
372 |
+
$dimensions = is_numeric($size) ? ' width="'.$avatar_default_wp_user_avatar_image[1].'" height="'.$avatar_default_wp_user_avatar_image[2].'"' : '';
|
373 |
+
} else {
|
374 |
+
if($size > get_option('medium_size_w')){
|
375 |
+
$default = $mustache_original;
|
376 |
+
} elseif($size <= get_option('medium_size_w') && $size > get_option('thumbnail_size_w')){
|
377 |
+
$default = $mustache_medium;
|
378 |
+
} elseif($size <= get_option('thumbnail_size_w') && $size > 96){
|
379 |
+
$default = $mustache_thumbnail;
|
380 |
+
} elseif($size <= 96 && $size > 32){
|
381 |
+
$default = $mustache_avatar;
|
382 |
+
} elseif($size <= 32){
|
383 |
+
$default = $mustache_admin;
|
384 |
+
}
|
385 |
+
$dimensions = is_numeric($size) ? ' width="'.$size.'" height="'.$size.'"' : '';
|
386 |
+
}
|
387 |
+
$avatar = "<img src='".$default."'".$dimensions." alt='".$alt."' class='wp-user-avatar wp-user-avatar-".$size." avatar avatar-".$size." photo avatar-default' />";
|
388 |
+
}
|
389 |
+
}
|
390 |
+
$wp_user_avatar = $avatar;
|
391 |
+
return $wp_user_avatar;
|
392 |
+
}
|
393 |
+
add_filter('get_avatar', 'get_wp_user_avatar_alt', 10, 6);
|
394 |
+
|
395 |
+
// Get original avatar
|
396 |
+
function get_avatar_original($id_or_email, $size='', $default='', $alt=''){
|
397 |
+
global $avatar_default, $avatar_default_wp_user_avatar, $mustache_avatar;
|
398 |
+
remove_filter('get_avatar', 'get_wp_user_avatar_alt');
|
399 |
+
if(!has_gravatar($id_or_email) && $avatar_default == 'wp_user_avatar'){
|
400 |
+
if(!empty($avatar_default_wp_user_avatar)){
|
401 |
+
$avatar_default_wp_user_avatar_image = wp_get_attachment_image_src($avatar_default_wp_user_avatar, array($size,$size));
|
402 |
+
$default = $avatar_default_wp_user_avatar_image[0];
|
403 |
+
} else {
|
404 |
+
$default = $mustache_avatar;
|
405 |
+
}
|
406 |
+
} else {
|
407 |
+
$wp_user_avatar_image = get_avatar($id_or_email);
|
408 |
+
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $wp_user_avatar_image, $matches, PREG_SET_ORDER);
|
409 |
+
$default = $matches [0] [1];
|
410 |
+
}
|
411 |
+
return $default;
|
412 |
+
}
|
413 |
+
|
414 |
+
// Shortcode
|
415 |
+
function wp_user_avatar_shortcode($atts, $content){
|
416 |
+
global $wpdb, $blog_id;
|
417 |
+
// EXAMPLE USAGE:
|
418 |
+
// [avatar size="medium"]
|
419 |
+
|
420 |
+
// Set shortcode attributes
|
421 |
+
extract(shortcode_atts(array('user' => '', 'size' => '96', 'align' => '', 'link' => ''), $atts));
|
422 |
+
$get_user = get_user_by('slug', $user);
|
423 |
+
$id_or_email = !empty($get_user) ? $get_user->ID : '';
|
424 |
+
if(!empty($link)){
|
425 |
+
$link_class = $link;
|
426 |
+
if($link == 'file'){
|
427 |
+
$image_link = get_wp_user_avatar_src($id_or_email, 'original', $align);
|
428 |
+
} elseif($link == 'attachment'){
|
429 |
+
$image_link = get_attachment_link(get_the_author_meta($wpdb->get_blog_prefix($blog_id).'user_avatar', $id_or_email));
|
430 |
+
} else {
|
431 |
+
$image_link = $link;
|
432 |
+
$link_class = 'custom';
|
433 |
+
}
|
434 |
+
$wp_user_avatar = '<a href="'.$image_link.'" class="wp-user-avatar-link wp-user-avatar-'.$link_class.'">'.get_wp_user_avatar($id_or_email, $size, $align).'</a>';
|
435 |
+
} else {
|
436 |
+
$wp_user_avatar = get_wp_user_avatar($id_or_email, $size, $align);
|
437 |
+
}
|
438 |
+
return $wp_user_avatar;
|
439 |
+
}
|
440 |
+
add_shortcode('avatar','wp_user_avatar_shortcode');
|
441 |
+
|
442 |
+
// Add default avatar
|
443 |
+
function add_default_wp_user_avatar($avatar_list){
|
444 |
+
global $avatar_default, $avatar_default_wp_user_avatar, $mustache_medium, $mustache_admin;
|
445 |
+
remove_filter('get_avatar', 'get_wp_user_avatar_alt');
|
446 |
+
$avatar_defaults = array(
|
447 |
+
'mystery' => __('Mystery Man'),
|
448 |
+
'blank' => __('Blank'),
|
449 |
+
'gravatar_default' => __('Gravatar Logo'),
|
450 |
+
'identicon' => __('Identicon (Generated)'),
|
451 |
+
'wavatar' => __('Wavatar (Generated)'),
|
452 |
+
'monsterid' => __('MonsterID (Generated)'),
|
453 |
+
'retro' => __('Retro (Generated)')
|
454 |
+
);
|
455 |
+
if(empty($avatar_default)){
|
456 |
+
$avatar_default = 'mystery';
|
457 |
+
}
|
458 |
+
$size = 32;
|
459 |
+
$avatar_list = '';
|
460 |
+
foreach($avatar_defaults as $default_key => $default_name){
|
461 |
+
$selected = ($avatar_default == $default_key) ? 'checked="checked" ' : '';
|
462 |
+
$avatar_list .= "\n\t<label><input type='radio' name='avatar_default' id='avatar_{$default_key}' value='".esc_attr($default_key)."' {$selected}/> ";
|
463 |
+
$avatar = get_avatar('unknown@gravatar.com', $size, $default_key);
|
464 |
+
$avatar_list .= preg_replace("/src='(.+?)'/", "src='\$1&forcedefault=1'", $avatar);
|
465 |
+
$avatar_list .= ' '.$default_name.'</label>';
|
466 |
+
$avatar_list .= '<br />';
|
467 |
+
}
|
468 |
+
if(!empty($avatar_default_wp_user_avatar)){
|
469 |
+
$avatar_medium_src = wp_get_attachment_image_src($avatar_default_wp_user_avatar, 'medium');
|
470 |
+
$avatar_thumb_src = wp_get_attachment_image_src($avatar_default_wp_user_avatar, array(32,32));
|
471 |
+
$avatar_medium = $avatar_medium_src[0];
|
472 |
+
$avatar_thumb = $avatar_thumb_src[0];
|
473 |
+
$hide_remove = '';
|
474 |
+
} else {
|
475 |
+
$avatar_medium = $mustache_medium;
|
476 |
+
$avatar_thumb = $mustache_admin;
|
477 |
+
$hide_remove = ' class="hide-me"';
|
478 |
+
}
|
479 |
+
$selected_avatar = ($avatar_default == 'wp_user_avatar') ? ' checked="checked" ' : '';
|
480 |
+
$avatar_thumb_img = '<div id="wp-user-avatar-preview"><img src="'.$avatar_thumb.'" width="32" /></div>';
|
481 |
+
$wp_user_avatar_list = "\n\t<label><input type='radio' name='avatar_default' id='wp_user_avatar_radio' value='wp_user_avatar'$selected_avatar /> ";
|
482 |
+
$wp_user_avatar_list .= preg_replace("/src='(.+?)'/", "src='\$1'", $avatar_thumb_img);
|
483 |
+
$wp_user_avatar_list .= ' '.__('WP User Avatar').'</label>';
|
484 |
+
$wp_user_avatar_list .= '<p id="edit-wp-user-avatar"><button type="button" class="button" id="add-wp-user-avatar">'.__('Edit WP User Avatar').'</button>';
|
485 |
+
$wp_user_avatar_list .= '<a href="#" id="remove-wp-user-avatar"'.$hide_remove.'>'.__('Remove').'</a></p>';
|
486 |
+
$wp_user_avatar_list .= '<input type="hidden" id="wp-user-avatar" name="avatar_default_wp_user_avatar" value="'.$avatar_default_wp_user_avatar.'">';
|
487 |
+
$wp_user_avatar_list .= '<p id="wp-user-avatar-message">'.__('Press "Save Changes" to save your changes.').'</p>';
|
488 |
+
$wp_user_avatar_list .= edit_default_wp_user_avatar('Default Avatar', $mustache_medium, $mustache_admin);
|
489 |
+
return $wp_user_avatar_list.$avatar_list;
|
490 |
+
}
|
491 |
+
add_filter('default_avatar_select', 'add_default_wp_user_avatar');
|
492 |
+
|
493 |
+
// Add default avatar field to whitelist
|
494 |
+
function wp_user_avatar_whitelist_options($whitelist_options){
|
495 |
+
$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');
|
496 |
+
return $whitelist_options;
|
497 |
+
}
|
498 |
+
add_filter('whitelist_options', 'wp_user_avatar_whitelist_options');
|
499 |
+
|
500 |
+
// Initialize wp_user_avatar
|
501 |
+
function wp_user_avatar_load(){
|
502 |
+
global $wp_user_avatar_instance;
|
503 |
+
$wp_user_avatar_instance = new wp_user_avatar();
|
504 |
+
}
|
505 |
+
add_action('plugins_loaded','wp_user_avatar_load');
|
506 |
+
}
|
507 |
+
?>
|