Version Description
- Bug Fix: Allow multipart data in form
- Bug Fix: Use wp_die for errors
Download this release
Release Info
Developer | bangbay |
Plugin | WP User Avatar |
Version | 1.4.1 |
Comparing to | |
See all releases |
Version 1.4.1
- css/wp-user-avatar.css +10 -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 +47 -0
- includes/tinymce/editor_plugin.js +1 -0
- includes/tinymce/window.php +119 -0
- index.html +1 -0
- js/wp-user-avatar.js +1 -0
- readme.txt +357 -0
- uninstall.php +46 -0
- wp-user-avatar.php +900 -0
css/wp-user-avatar.css
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#wp-user-avatar-errors { color: #c00; font-weight: 700; }
|
2 |
+
#wp-user-avatar-message { color: #c00; display: none; }
|
3 |
+
#wp-user-avatar-preview, #wp-user-avatar-thumbnail { display: inline-block; text-align: center; vertical-align: top; }
|
4 |
+
#wp-user-avatar-preview { margin-right: 10px; }
|
5 |
+
#wp-user-avatar-preview img, #wp-user-avatar-thumbnail img { height: 96px; border: 1px solid #dfdfdf; display: block; }
|
6 |
+
.defaultavatarpicker #wp-user-avatar-preview { width: 32px; height: 32px; margin-right: 0; display: inline-block; overflow: hidden; vertical-align: middle; }
|
7 |
+
.defaultavatarpicker #wp-user-avatar-preview img { width: 32px; height: auto; border: 0; }
|
8 |
+
#edit-wp-user-avatar { padding-left: 15px; }
|
9 |
+
#edit-wp-user-avatar #remove-wp-user-avatar { margin-left: 10px; }
|
10 |
+
.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,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package WP User Avatar
|
4 |
+
* @version 1.4.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 |
+
|
12 |
+
function wpua_myplugin_addbuttons(){
|
13 |
+
// Don't bother doing this stuff if the current user lacks permissions
|
14 |
+
if(!current_user_can('edit_posts') && !current_user_can('edit_pages')){
|
15 |
+
return;
|
16 |
+
}
|
17 |
+
// Add only in Rich Editor mode
|
18 |
+
if(get_user_option('rich_editing') == 'true'){
|
19 |
+
add_filter('mce_external_plugins', 'wpua_add_myplugin_tinymce_plugin');
|
20 |
+
add_filter('mce_buttons', 'wpua_register_myplugin_button');
|
21 |
+
}
|
22 |
+
}
|
23 |
+
// init process for button control
|
24 |
+
add_action('init', 'wpua_myplugin_addbuttons');
|
25 |
+
|
26 |
+
|
27 |
+
function wpua_register_myplugin_button($buttons){
|
28 |
+
array_push($buttons, 'separator', 'wpUserAvatar');
|
29 |
+
return $buttons;
|
30 |
+
}
|
31 |
+
|
32 |
+
// Load the TinyMCE plugin : editor_plugin.js (wp2.5)
|
33 |
+
function wpua_add_myplugin_tinymce_plugin($plugin_array){
|
34 |
+
$plugin_array['wpUserAvatar'] = WPUA_URLPATH.'includes/tinymce/editor_plugin.js';
|
35 |
+
return $plugin_array;
|
36 |
+
}
|
37 |
+
|
38 |
+
// Call TinyMCE window content via admin-ajax
|
39 |
+
function wpua_ajax_tinymce(){
|
40 |
+
if(!current_user_can('edit_posts') && !current_user_can('edit_pages')){
|
41 |
+
die('You are not allowed to call this page directly.');
|
42 |
+
}
|
43 |
+
include_once(WPUA_ABSPATH.'includes/tinymce/window.php');
|
44 |
+
die();
|
45 |
+
}
|
46 |
+
add_action('wp_ajax_wp_user_avatar_tinymce', 'wpua_ajax_tinymce');
|
47 |
+
?>
|
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:295,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.4.1"}}});tinymce.PluginManager.add('wpUserAvatar',tinymce.plugins.wpUserAvatar)})();
|
includes/tinymce/window.php
ADDED
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package WP User Avatar
|
4 |
+
* @version 1.4.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 |
+
?>
|
12 |
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
13 |
+
<head>
|
14 |
+
<title>WP User Avatar</title>
|
15 |
+
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
|
16 |
+
<base target="_self" />
|
17 |
+
<script type="text/javascript" src="<?php echo site_url(); ?>/wp-includes/js/jquery/jquery.js"></script>
|
18 |
+
<script type="text/javascript" src="<?php echo site_url(); ?>/wp-includes/js/tinymce/tiny_mce_popup.js"></script>
|
19 |
+
<script type="text/javascript" src="<?php echo site_url(); ?>/wp-includes/js/tinymce/utils/form_utils.js"></script>
|
20 |
+
<script type="text/javascript">
|
21 |
+
function insert_wp_user_avatar(){
|
22 |
+
// Custom shortcode values
|
23 |
+
var shortcode;
|
24 |
+
var user = document.getElementById('wp_user_avatar_user').value;
|
25 |
+
var size = document.getElementById('wp_user_avatar_size').value;
|
26 |
+
var size_number = document.getElementById('wp_user_avatar_size_number').value;
|
27 |
+
var align = document.getElementById('wp_user_avatar_align').value;
|
28 |
+
var link = document.getElementById('wp_user_avatar_link').value;
|
29 |
+
var link_external = document.getElementById('wp_user_avatar_link_external').value;
|
30 |
+
var target = document.getElementById('wp_user_avatar_target').value;
|
31 |
+
|
32 |
+
// Add tag to shortcode only if not blank
|
33 |
+
var user_tag = (user != '') ? ' user="' + user + '"' : '';
|
34 |
+
var size_tag = (size != '' && size_number == '') ? ' size="' + size + '"' : '';
|
35 |
+
size_tag = (size_number != '') ? ' size="' + size_number + '"' : size_tag;
|
36 |
+
var align_tag = (align != '') ? ' align="' + align + '"' : '';
|
37 |
+
var link_tag = (link != '' && link_external == '') ? ' link="' + link + '"' : '';
|
38 |
+
link_tag = (link_external != '') ? ' link="' + link_external + '"' : link_tag;
|
39 |
+
var target_tag = document.getElementById('wp_user_avatar_target').checked && (link_tag != '') ? ' target="' + target + '"' : '';
|
40 |
+
|
41 |
+
shortcode = "<p>[avatar" + user_tag + size_tag + align_tag + link_tag + target_tag + "]</p>";
|
42 |
+
|
43 |
+
if(window.tinyMCE){
|
44 |
+
window.tinyMCE.execInstanceCommand(window.tinyMCE.activeEditor.id, 'mceInsertContent', false, shortcode);
|
45 |
+
tinyMCEPopup.editor.execCommand('mceRepaint');
|
46 |
+
tinyMCEPopup.close();
|
47 |
+
}
|
48 |
+
return;
|
49 |
+
}
|
50 |
+
</script>
|
51 |
+
<style type="text/css">
|
52 |
+
form { background: #fff; border: 1px solid #eee; }
|
53 |
+
p, h4 { margin: 0; padding: 12px 0 0; }
|
54 |
+
h4.center { text-align: center; }
|
55 |
+
label { width: 90px; display: inline-block; text-align: right; }
|
56 |
+
.mceActionPanel { padding: 7px 0 12px; text-align: center; }
|
57 |
+
.mceActionPanel #insert { float: none; width: 180px; margin: 0 auto; }
|
58 |
+
</style>
|
59 |
+
</head>
|
60 |
+
<body id="link" class="wp-core-ui" onload="document.body.style.display='';" style="display:none;">
|
61 |
+
<form name="wpUserAvatar" action="#">
|
62 |
+
<p><label for="<?php esc_attr_e('wp_user_avatar_user'); ?>"><strong><?php _e("User:"); ?></strong></label>
|
63 |
+
<select id="<?php esc_attr_e('wp_user_avatar_user'); ?>" name="<?php esc_attr_e('wp_user_avatar_user'); ?>">
|
64 |
+
<option value=""></option>
|
65 |
+
<?php $users = get_users(); foreach($users as $user) : ?>
|
66 |
+
<option value="<?php echo $user->user_login; ?>"><?php echo $user->display_name; ?></option>
|
67 |
+
<?php endforeach; ?>
|
68 |
+
</select></p>
|
69 |
+
|
70 |
+
<h4 class="center">Choose a preset size or enter a number value.</h4>
|
71 |
+
|
72 |
+
<p>
|
73 |
+
<label for="<?php esc_attr_e('wp_user_avatar_size'); ?>"><strong><?php _e("Size:"); ?></strong></label>
|
74 |
+
<select id="<?php esc_attr_e('wp_user_avatar_size'); ?>" name="<?php esc_attr_e('wp_user_avatar_size'); ?>">
|
75 |
+
<option value=""></option>
|
76 |
+
<option value="original"><?php _e("Original"); ?></option>
|
77 |
+
<option value="large"><?php _e("Large"); ?></option>
|
78 |
+
<option value="medium"><?php _e("Medium"); ?></option>
|
79 |
+
<option value="thumbnail"><?php _e("Thumbnail"); ?></option>
|
80 |
+
</select>
|
81 |
+
or
|
82 |
+
<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="" />
|
83 |
+
</p>
|
84 |
+
|
85 |
+
<p><label for="<?php esc_attr_e('wp_user_avatar_align'); ?>"><strong><?php _e("Alignment:"); ?></strong></label>
|
86 |
+
<select id="<?php esc_attr_e('wp_user_avatar_align'); ?>" name="<?php esc_attr_e('wp_user_avatar_align'); ?>">
|
87 |
+
<option value=""></option>
|
88 |
+
<option value="center"><?php _e("Center"); ?></option>
|
89 |
+
<option value="left"><?php _e("Left"); ?></option>
|
90 |
+
<option value="right"><?php _e("Right"); ?></option>
|
91 |
+
</select></p>
|
92 |
+
|
93 |
+
<h4 class="center">Link to image file, attachment page, or custom URL.</h4>
|
94 |
+
|
95 |
+
<p>
|
96 |
+
<label for="<?php esc_attr_e('wp_user_avatar_link'); ?>"><strong><?php _e("Link to:"); ?></strong></label>
|
97 |
+
<select id="<?php esc_attr_e('wp_user_avatar_link'); ?>" name="<?php esc_attr_e('wp_user_avatar_link'); ?>">
|
98 |
+
<option value=""></option>
|
99 |
+
<option value="file"><?php _e("Image File"); ?></option>
|
100 |
+
<option value="attachment"><?php _e("Attachment Page"); ?></option>
|
101 |
+
</select>
|
102 |
+
</p>
|
103 |
+
|
104 |
+
<p>
|
105 |
+
<label for="<?php esc_attr_e('wp_user_avatar_link_external'); ?>">or</label>
|
106 |
+
<input type="text" size="36" id="<?php esc_attr_e('wp_user_avatar_link_external'); ?>" name="<?php esc_attr_e('wp_user_avatar_link_external'); ?>" value="" />
|
107 |
+
</p>
|
108 |
+
|
109 |
+
<p>
|
110 |
+
<label for="<?php esc_attr_e('wp_user_avatar_target'); ?>"></label>
|
111 |
+
<input type="checkbox" id="<?php esc_attr_e('wp_user_avatar_target'); ?>" name="<?php esc_attr_e('wp_user_avatar_target'); ?>" value="_blank" /> <strong>Open link in a new window</strong>
|
112 |
+
</p>
|
113 |
+
|
114 |
+
<div class="mceActionPanel">
|
115 |
+
<input type="submit" id="insert" class="button-primary" name="insert" value="<?php _e("Insert WP User Avatar"); ?>" onclick="insert_wp_user_avatar();" />
|
116 |
+
</div>
|
117 |
+
</form>
|
118 |
+
</body>
|
119 |
+
</html>
|
index.html
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
<!-- Thanks for using WP User Avatar! -->
|
js/wp-user-avatar.js
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('5 16(c){0.7.k={s:5(){x 0.7.y.B.i.o},X:5(a){v b=0.7.y.B;b.i.o=a;b.i.T=2(\'19.j-18\').K(\'M\').p(\'q\');r(b.i.o){R(b.i.o,b.i.T);2(\'#t\').u(\'g\')}},w:5(){r(4.8){x 4.8}4.8=0.7({z:\'Q\',12:[11 0.7.1d.1a({13:"U H I G: "+c})]});4.8.f(\'O\',5(){v a=4.z().s(\'l\');L=2(\'#0-3-6\').F();j=0.7.j(L);j.17();a.E(j?[j]:[])},4.8);4.8.f(\'1b:1c:m\',5(a){4.1e(a,{1f:\'1g H I G\'})},4.8);4.8.z(\'Q\').f(\'m\',4.m);x 4.8},m:5(a){v b=0.7.y.B,l=4.s(\'l\').1h();0.7.k.X(l?l.L:-1)},P:5(){2(\'C\').f(\'g\',\'#E-0-3-6\',5(e){e.A();e.14();0.7.k.w().O()})}};2(0.7.k.P)}5 15(a,b){2(\'C\').f(\'g\',\'#E-0-3-6\',5(e){e.A();1o(\'U H I G: \'+a,b)})}5 R(a,b){2(\'#0-3-6\',d.9.h).F(a);2(\'#0-3-6-S\',d.9.h).K(\'M\').p(\'q\',b).n(\'N\',\'\').n(\'V\',\'\');2(\'#0-3-6-W\',d.9.h).J();2(\'#Y-0-3-6\',d.9.h).J();2(\'#0-3-6-Z\',d.9.h).D();2(\'#t\',d.9.h).u(\'g\');r(1i(0)!=\'1j\'){0.7.k.w().1k()}1l{d.9.1m()}}5 1n(a){2(\'C\').f(\'g\',\'#Y-0-3-6\',5(e){e.A();2(4).D();2(\'#10-0-3-6, #0-3-6-Z\').D();2(\'#0-3-6-S\').K(\'M\').p(\'q\',a).n(\'N\',\'\').n(\'V\',\'\');2(\'#0-3-6\').F(\'\');2(\'#0-3-6-W\').J();2(\'#t\').u(\'g\')})}',62,87,'wp||jQuery|user|this|function|avatar|media|_frame|parent||||window||on|click|document|post|attachment|wpUserAvatar|selection|select|removeAttr|wpUserAvatarId|attr|src|if|get|wp_user_avatar_radio|trigger|var|frame|return|view|state|preventDefault|settings|body|hide|add|val|Avatar|WP|User|show|find|id|img|width|open|init|library|setWPUserAvatar|preview|wpUserAvatarSrc|Edit|height|message|set|remove|thumbnail|edit|new|states|title|stopPropagation|openThickboxUploader|openMediaUploader|fetch|info|div|Library|toolbar|create|controller|createSelectToolbar|text|Set|single|typeof|undefined|close|else|tb_remove|removeWPUserAvatar|tb_show'.split('|'),0,{}))
|
readme.txt
ADDED
@@ -0,0 +1,357 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.4
|
7 |
+
Tested up to: 3.5.1
|
8 |
+
Stable tag: 1.4.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 |
+
* Allow Contributors and Subscribers to upload their own avatars.
|
24 |
+
|
25 |
+
This plugin uses the Media uploader introduced in WordPress 3.5, but is also backwards-compatible to WordPress 3.4. It is also compatible with WordPress Multisite.
|
26 |
+
|
27 |
+
== Installation ==
|
28 |
+
|
29 |
+
1. Download, install, and activate the WP User Avatar plugin.
|
30 |
+
2. On your edit profile page, click "Edit WP User Avatar".
|
31 |
+
3. Choose an image, then click "Set WP User Avatar".
|
32 |
+
4. Click "Update Profile".
|
33 |
+
5. Upload your own Default Avatar in your Discussion settings (optional).
|
34 |
+
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/).
|
35 |
+
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.
|
36 |
+
|
37 |
+
**Example Usage**
|
38 |
+
|
39 |
+
= Posts =
|
40 |
+
|
41 |
+
Within [The Loop](http://codex.wordpress.org/The_Loop), you may be using:
|
42 |
+
|
43 |
+
`<?php echo get_avatar(get_the_author_meta('ID'), 96); ?>`
|
44 |
+
|
45 |
+
Replace this function with:
|
46 |
+
|
47 |
+
`<?php echo get_wp_user_avatar(get_the_author_meta('ID'), 96); ?>`
|
48 |
+
|
49 |
+
You can also use the values "original", "large", "medium", or "thumbnail" for your avatar size:
|
50 |
+
|
51 |
+
`<?php echo get_wp_user_avatar(get_the_author_meta('ID'), 'medium'); ?>`
|
52 |
+
|
53 |
+
You can also add an alignment of "left", "right", or "center":
|
54 |
+
|
55 |
+
`<?php echo get_wp_user_avatar(get_the_author_meta('ID'), 96, 'left'); ?>`
|
56 |
+
|
57 |
+
= Author Page =
|
58 |
+
|
59 |
+
On an author page outside of [The Loop](http://codex.wordpress.org/The_Loop), you may be using:
|
60 |
+
|
61 |
+
`<?php
|
62 |
+
$user = get_user_by('slug', $author_name);
|
63 |
+
echo get_avatar($user->ID, 96);
|
64 |
+
?>`
|
65 |
+
|
66 |
+
Replace this function with:
|
67 |
+
|
68 |
+
`<?php
|
69 |
+
$user = get_user_by('slug', $author_name);
|
70 |
+
echo get_wp_user_avatar($user->ID, 96);
|
71 |
+
?>`
|
72 |
+
|
73 |
+
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:
|
74 |
+
|
75 |
+
`<?php echo get_wp_user_avatar(); ?>`
|
76 |
+
|
77 |
+
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.
|
78 |
+
|
79 |
+
= Comments =
|
80 |
+
|
81 |
+
For comments, you might have in your template:
|
82 |
+
|
83 |
+
`<?php echo get_avatar($comment, 32); ?>`
|
84 |
+
|
85 |
+
Replace this function with:
|
86 |
+
|
87 |
+
`<?php echo get_wp_user_avatar($comment, 32); ?>`
|
88 |
+
|
89 |
+
For comments, you must specify the $comment variable.
|
90 |
+
|
91 |
+
**Other Available Functions**
|
92 |
+
|
93 |
+
= [avatar] shortcode =
|
94 |
+
|
95 |
+
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.
|
96 |
+
|
97 |
+
`[avatar user="admin" size="medium" align="left" link="file"]`
|
98 |
+
|
99 |
+
= get_wp_user_avatar_src =
|
100 |
+
|
101 |
+
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:
|
102 |
+
|
103 |
+
`<a href="<?php echo get_wp_user_avatar_src($user_id, 'large'); ?>">
|
104 |
+
<?php echo get_wp_user_avatar($user_id, 'thumbnail'); ?>
|
105 |
+
</a>`
|
106 |
+
|
107 |
+
= has_wp_user_avatar =
|
108 |
+
|
109 |
+
Returns true if the user has a WP User Avatar image. You must specify the user ID:
|
110 |
+
|
111 |
+
`<?php
|
112 |
+
if ( has_wp_user_avatar($user_id) ) {
|
113 |
+
echo get_wp_user_avatar($user_id, 96);
|
114 |
+
} else {
|
115 |
+
echo '<img src="my-alternate-image.jpg" />';
|
116 |
+
}
|
117 |
+
?>`
|
118 |
+
|
119 |
+
== Frequently Asked Questions ==
|
120 |
+
|
121 |
+
= How do I use WP User Avatar? =
|
122 |
+
|
123 |
+
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:
|
124 |
+
|
125 |
+
= get_wp_user_avatar =
|
126 |
+
|
127 |
+
1. Allows you to use the values "original", "large", "medium", or "thumbnail" for your avatar size.
|
128 |
+
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.
|
129 |
+
3. Optionally adds CSS classes "alignleft", "alignright", or "aligncenter" to position your avatar.
|
130 |
+
4. Shows nothing if the user has no WP User Avatar image.
|
131 |
+
5. Shows the user's [gravatar.com](http://gravatar.com/) avatar or Default Avatar only if "Show Avatars" is enabled in your Discussion settings.
|
132 |
+
|
133 |
+
= get_avatar =
|
134 |
+
|
135 |
+
1. Requires you to enable "Show Avatars" in your Discussion settings to show any avatars.
|
136 |
+
2. Accepts only numeric values for your avatar size.
|
137 |
+
3. Always adds a fixed width and height to your image. This may cause problems if you use responsive CSS in your theme.
|
138 |
+
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.)
|
139 |
+
5. Requires no changes to your theme files if you are currently using <code>get_avatar</code>.
|
140 |
+
|
141 |
+
[Read more about get_avatar in the WordPress Function Reference](http://codex.wordpress.org/Function_Reference/get_avatar).
|
142 |
+
|
143 |
+
= Can I create a custom Default Avatar? =
|
144 |
+
In your Discussion settings, you can upload your own Default Avatar.
|
145 |
+
|
146 |
+
= Can I insert WP User Avatar directly into a post? =
|
147 |
+
|
148 |
+
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.
|
149 |
+
|
150 |
+
`[avatar user="admin" size="96" align="left" link="file"]`
|
151 |
+
|
152 |
+
Outputs:
|
153 |
+
|
154 |
+
`<a href="{fileURL}" class="wp-user-avatar-link wp-user-avatar-file">
|
155 |
+
<img src="{imageURL}" width="96" height="96" class="wp-user-avatar wp-user-avatar-96 alignleft" />
|
156 |
+
</a>`
|
157 |
+
|
158 |
+
= Can Contributors or Subscribers choose their own WP User Avatar image? =
|
159 |
+
Yes, if you enable "Allow Contributors & Subscribers to upload avatars" in the WP User Avatar settings. These users will see a slightly different interface because they are allowed only one image upload.
|
160 |
+
|
161 |
+
= Will WP User Avatar work with comment author avatars? =
|
162 |
+
|
163 |
+
Yes, for registered users. Non-registered comment authors will show their [gravatar.com](http://gravatar.com/) avatars or Default Avatar.
|
164 |
+
|
165 |
+
= Will WP User Avatar work with bbPress? =
|
166 |
+
|
167 |
+
Yes!
|
168 |
+
|
169 |
+
= Will WP User Avatar work with WordPress Multisite? =
|
170 |
+
|
171 |
+
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.
|
172 |
+
|
173 |
+
= How can I see which users have an avatar? =
|
174 |
+
|
175 |
+
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.
|
176 |
+
|
177 |
+
= What CSS can I use with WP User Avatar? =
|
178 |
+
|
179 |
+
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:
|
180 |
+
|
181 |
+
`<?php echo get_wp_user_avatar($user_id, 96, 'left'); ?>`
|
182 |
+
|
183 |
+
Outputs:
|
184 |
+
|
185 |
+
`<img src="{imageURL}" width="96" height="96" class="wp-user-avatar wp-user-avatar-96 alignleft" />`
|
186 |
+
|
187 |
+
**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.
|
188 |
+
|
189 |
+
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:
|
190 |
+
|
191 |
+
`<?php echo get_wp_user_avatar($user_id, 'medium'); ?>`
|
192 |
+
|
193 |
+
Outputs:
|
194 |
+
|
195 |
+
`<img src="{imageURL}" class="wp-user-avatar wp-user-avatar-medium" />`
|
196 |
+
|
197 |
+
**Note:** WordPress adds more CSS classes to the avatar not listed here.
|
198 |
+
|
199 |
+
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.
|
200 |
+
|
201 |
+
* Image File: wp-user-avatar-file
|
202 |
+
* Attachment: wp-user-avatar-attachment
|
203 |
+
* Custom URL: wp-user-avatar-custom
|
204 |
+
|
205 |
+
`[avatar user="admin" size="96" align="left" link="attachment"]`
|
206 |
+
|
207 |
+
Outputs:
|
208 |
+
|
209 |
+
`<a href="{attachmentURL}" class="wp-user-avatar-link wp-user-avatar-attachment">
|
210 |
+
<img src="{imageURL}" width="96" height="96" class="wp-user-avatar wp-user-avatar-96 alignleft" />
|
211 |
+
</a>`
|
212 |
+
|
213 |
+
= What other functions are available for WP User Avatar? =
|
214 |
+
* <code>get_wp_user_avatar_src</code>: retrieves just the image URL
|
215 |
+
* <code>has_wp_user_avatar</code>: checks if the user has a WP User Avatar image
|
216 |
+
* [See example usage here](http://wordpress.org/extend/plugins/wp-user-avatar/installation/)
|
217 |
+
|
218 |
+
== Screenshots ==
|
219 |
+
|
220 |
+
1. WP User Avatar lets you upload your own Default Avatar.
|
221 |
+
2. WP User Avatar adds a field to your edit profile page.
|
222 |
+
3. After you've chosen a WP User Avatar image, you will see the option to remove it.
|
223 |
+
4. WP User Avatar adds a button to insert the [avatar] shortcode in the Visual Editor.
|
224 |
+
5. Options for the [avatar] shortcode.
|
225 |
+
6. WP User Avatar admin settings.
|
226 |
+
|
227 |
+
== Changelog ==
|
228 |
+
|
229 |
+
= 1.4.1 =
|
230 |
+
* Bug Fix: Allow multipart data in form
|
231 |
+
* Bug Fix: Use wp_die for errors
|
232 |
+
|
233 |
+
= 1.4 =
|
234 |
+
* Add: Uploader for Subscribers and Contributors
|
235 |
+
* Add: Media states for avatar images
|
236 |
+
* Add: Plugin admin settings
|
237 |
+
* Update: Change support only to WP 3.4+
|
238 |
+
|
239 |
+
= 1.3.6 =
|
240 |
+
* Add: Target for link in shortcode
|
241 |
+
* Update: Clean up code and add more comments
|
242 |
+
|
243 |
+
= 1.3.5 =
|
244 |
+
* Bug Fix: Swap TinyMCE file locations
|
245 |
+
|
246 |
+
= 1.3.4 =
|
247 |
+
* Update: Change support only to WP 3.3+ because of jQuery 1.7.1 support
|
248 |
+
|
249 |
+
= 1.3.3 =
|
250 |
+
* Update: Shortcode checks for user ID, login, slug, or e-mail address
|
251 |
+
* Update: Move jquery to register_script for < WP 3.5
|
252 |
+
|
253 |
+
= 1.3.2 =
|
254 |
+
* Bug Fix: Check for user before setting name in alt tag
|
255 |
+
* Update: readme.txt
|
256 |
+
|
257 |
+
= 1.3.1 =
|
258 |
+
* Bug Fix: Rename usermeta only if found
|
259 |
+
|
260 |
+
= 1.3 =
|
261 |
+
* Add: Multisite support
|
262 |
+
* Bug Fix: Warnings if no user found
|
263 |
+
* Update: Enable action_show_user_profile for any class using show_user_profile hook
|
264 |
+
|
265 |
+
= 1.2.6 =
|
266 |
+
* Bug Fix: options-discussion.php page doesn't show default avatars
|
267 |
+
|
268 |
+
= 1.2.5 =
|
269 |
+
* Bug Fix: Comment author showing wrong avatar
|
270 |
+
* Bug Fix: Avatar adds fixed dimensions when non-numeric size is used
|
271 |
+
* Update: Use local image for default avatar instead of calling image from Gravatar
|
272 |
+
|
273 |
+
= 1.2.4 =
|
274 |
+
* Bug Fix: Show default avatar when user removes custom avatar
|
275 |
+
* Bug Fix: Default Avatar save setting
|
276 |
+
|
277 |
+
= 1.2.3 =
|
278 |
+
* Bug Fix: Show default avatar when user removes custom avatar
|
279 |
+
* Bug Fix: Default Avatar save setting
|
280 |
+
|
281 |
+
= 1.2.2 =
|
282 |
+
* Add: Ability for bbPress users to edit avatar on front profile page
|
283 |
+
* Add: Link options for shortcode
|
284 |
+
* Bug Fix: Show WP User Avatar only to users with upload_files capability
|
285 |
+
|
286 |
+
= 1.2.1 =
|
287 |
+
* Add: TinyMCE button
|
288 |
+
* Update: Clean up redundant code
|
289 |
+
* Update: Compatibility only back to WordPress 3.3
|
290 |
+
|
291 |
+
= 1.2 =
|
292 |
+
* Add: Default Avatar setting
|
293 |
+
|
294 |
+
= 1.1.7 =
|
295 |
+
* Bug Fix: Change update_usermeta to update_user_meta
|
296 |
+
|
297 |
+
= 1.1.6 =
|
298 |
+
* Bug Fix: Image not showing in user profile edit
|
299 |
+
|
300 |
+
= 1.1.5a =
|
301 |
+
* Update: readme.txt
|
302 |
+
|
303 |
+
= 1.1.5 =
|
304 |
+
* Bug Fix: Remove stray curly bracket
|
305 |
+
|
306 |
+
= 1.1.4 =
|
307 |
+
* Bug Fix: Change get_usermeta to get_user_meta
|
308 |
+
* Bug Fix: Non-object warning when retrieving user ID
|
309 |
+
|
310 |
+
= 1.1.3 =
|
311 |
+
* Bug Fix: Comment author with no e-mail address
|
312 |
+
|
313 |
+
= 1.1.2 =
|
314 |
+
* Remove: Unused variables
|
315 |
+
|
316 |
+
= 1.1.1 =
|
317 |
+
* Bug Fix: Capabilities error in comment avatar
|
318 |
+
|
319 |
+
= 1.1 =
|
320 |
+
* Add: Add filter for get_avatar
|
321 |
+
* Add: CSS alignment classes
|
322 |
+
* Add: Replace comment author avatar
|
323 |
+
* Add: Shortcode
|
324 |
+
* Update: readme.txt
|
325 |
+
|
326 |
+
= 1.0.2 =
|
327 |
+
* Update: FAQ
|
328 |
+
* Remove: CSS that hides "Insert into Post"
|
329 |
+
|
330 |
+
= 1.0.1 =
|
331 |
+
* Add: CSS classes to image output
|
332 |
+
|
333 |
+
= 1.0 =
|
334 |
+
* Initial release
|
335 |
+
|
336 |
+
== Upgrade Notice ==
|
337 |
+
|
338 |
+
= 1.4 =
|
339 |
+
* New Feature: Setting to allow all users to upload avatars
|
340 |
+
* New Feature: Setting to add or remove Visual Editor button
|
341 |
+
* New Feature: Media states for avatar images
|
342 |
+
* Notice: WP User Avatar 1.4 only supports WordPress 3.4 and above. If you are using an older version of WordPress, please upgrade your version of WordPress first.
|
343 |
+
|
344 |
+
= 1.3 =
|
345 |
+
* New Feature: Multisite support
|
346 |
+
|
347 |
+
= 1.2.2 =
|
348 |
+
* New Features: Link options for shortcode, bbPress integration
|
349 |
+
|
350 |
+
= 1.2.1 =
|
351 |
+
* New Feature: Shortcode insertion button for Visual Editor
|
352 |
+
|
353 |
+
= 1.2 =
|
354 |
+
* New Feature: Default Avatar customization
|
355 |
+
|
356 |
+
= 1.1 =
|
357 |
+
* New Features: [avatar] shortcode, direct replacement of get_avatar() and comment author avatar, more CSS classes
|
uninstall.php
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package WP User Avatar
|
4 |
+
* @version 1.4.1
|
5 |
+
*/
|
6 |
+
|
7 |
+
// Remove user metadata and options on plugin delete
|
8 |
+
if(!defined('WP_UNINSTALL_PLUGIN')){
|
9 |
+
die('You are not allowed to call this page directly.');
|
10 |
+
}
|
11 |
+
|
12 |
+
global $wpdb, $blog_id, $switched;
|
13 |
+
$users = get_users();
|
14 |
+
// Remove settings for all sites in multisite
|
15 |
+
if(is_multisite()){
|
16 |
+
$blogs = $wpdb->get_results("SELECT * FROM $wpdb->blogs");
|
17 |
+
foreach($users as $user){
|
18 |
+
foreach($blogs as $blog){
|
19 |
+
delete_user_meta($user->ID, $wpdb->get_blog_prefix($blog->blog_id).'user_avatar');
|
20 |
+
}
|
21 |
+
}
|
22 |
+
foreach($blogs as $blog){
|
23 |
+
switch_to_blog($blog->blog_id);
|
24 |
+
delete_option('avatar_default_wp_user_avatar');
|
25 |
+
delete_option('wp_user_avatar_tinymce');
|
26 |
+
delete_option('wp_user_avatar_allow_upload');
|
27 |
+
delete_option('wp_user_avatar_default_avatar_updated');
|
28 |
+
delete_option('wp_user_avatar_users_updated');
|
29 |
+
delete_option('wp_user_avatar_media_updated');
|
30 |
+
}
|
31 |
+
} else {
|
32 |
+
foreach($users as $user){
|
33 |
+
delete_user_meta($user->ID, $wpdb->get_blog_prefix($blog_id).'user_avatar');
|
34 |
+
}
|
35 |
+
delete_option('avatar_default_wp_user_avatar');
|
36 |
+
delete_option('wp_user_avatar_tinymce');
|
37 |
+
delete_option('wp_user_avatar_allow_upload');
|
38 |
+
delete_option('wp_user_avatar_default_avatar_updated');
|
39 |
+
delete_option('wp_user_avatar_users_updated');
|
40 |
+
delete_option('wp_user_avatar_media_updated');
|
41 |
+
}
|
42 |
+
// Delete post meta
|
43 |
+
delete_post_meta_by_key('_wp_attachment_wp_user_avatar');
|
44 |
+
// Reset all default avatars to Mystery Man
|
45 |
+
update_option('avatar_default', 'mystery');
|
46 |
+
?>
|
wp-user-avatar.php
ADDED
@@ -0,0 +1,900 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package WP User Avatar
|
4 |
+
* @version 1.4.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.4.1
|
11 |
+
Author: Bangbay Siboliban
|
12 |
+
Author URI: http://siboliban.org/
|
13 |
+
*/
|
14 |
+
|
15 |
+
if(!defined('ABSPATH')){
|
16 |
+
die('You are not allowed to call this page directly.');
|
17 |
+
@header('Content-Type:'.get_option('html_type').';charset='.get_option('blog_charset'));
|
18 |
+
}
|
19 |
+
|
20 |
+
// Define paths and variables
|
21 |
+
define('WPUA_VERSION', '1.4.1');
|
22 |
+
define('WPUA_FOLDER', basename(dirname(__FILE__)));
|
23 |
+
define('WPUA_ABSPATH', trailingslashit(str_replace('\\', '/', WP_PLUGIN_DIR.'/'.WPUA_FOLDER)));
|
24 |
+
define('WPUA_URLPATH', trailingslashit(plugins_url(WPUA_FOLDER)));
|
25 |
+
|
26 |
+
// Define global variables
|
27 |
+
$avatar_default = get_option('avatar_default');
|
28 |
+
$wpua_avatar_default = get_option('avatar_default_wp_user_avatar');
|
29 |
+
$show_avatars = get_option('show_avatars');
|
30 |
+
$wpua_tinymce = get_option('wp_user_avatar_tinymce');
|
31 |
+
$wpua_allow_upload = get_option('wp_user_avatar_allow_upload');
|
32 |
+
$mustache_original = WPUA_URLPATH.'images/wp-user-avatar.png';
|
33 |
+
$mustache_medium = WPUA_URLPATH.'images/wp-user-avatar-300x300.png';
|
34 |
+
$mustache_thumbnail = WPUA_URLPATH.'images/wp-user-avatar-150x150.png';
|
35 |
+
$mustache_avatar = WPUA_URLPATH.'images/wp-user-avatar-96x96.png';
|
36 |
+
$mustache_admin = WPUA_URLPATH.'images/wp-user-avatar-32x32.png';
|
37 |
+
$ssl = is_ssl() ? 's' : "";
|
38 |
+
|
39 |
+
// Check for updates
|
40 |
+
$wpua_default_avatar_updated = get_option('wp_user_avatar_default_avatar_updated');
|
41 |
+
$wpua_users_updated = get_option('wp_user_avatar_users_updated');
|
42 |
+
$wpua_media_updated = get_option('wp_user_avatar_media_updated');
|
43 |
+
|
44 |
+
// Load add-ons
|
45 |
+
if($wpua_tinymce == 1){
|
46 |
+
include_once(WPUA_ABSPATH.'includes/tinymce.php');
|
47 |
+
}
|
48 |
+
|
49 |
+
// Initialize default settings
|
50 |
+
register_activation_hook(WPUA_ABSPATH.'wp-user-avatar.php', 'wpua_options');
|
51 |
+
|
52 |
+
// Remove subscribers edit_posts capability
|
53 |
+
register_deactivation_hook(WPUA_ABSPATH.'wp-user-avatar.php', 'wpua_deactivate');
|
54 |
+
|
55 |
+
// Settings saved to wp_options
|
56 |
+
function wpua_options(){
|
57 |
+
global $wp_user_roles;
|
58 |
+
add_option('avatar_default_wp_user_avatar', "");
|
59 |
+
add_option('wp_user_avatar_tinymce', '1');
|
60 |
+
add_option('wp_user_avatar_allow_upload', '0');
|
61 |
+
}
|
62 |
+
add_action('admin_init', 'wpua_options');
|
63 |
+
|
64 |
+
// Update default avatar to new format
|
65 |
+
if(empty($wpua_default_avatar_updated)){
|
66 |
+
function wpua_default_avatar(){
|
67 |
+
global $avatar_default, $wpua_avatar_default, $mustache_original;
|
68 |
+
// If default avatar is the old mustache URL, update it
|
69 |
+
if($avatar_default == $mustache_original){
|
70 |
+
update_option('avatar_default', 'wp_user_avatar');
|
71 |
+
}
|
72 |
+
// If user had an image URL as the default avatar, replace with ID instead
|
73 |
+
if(!empty($wpua_avatar_default)){
|
74 |
+
$wpua_avatar_default_image = wp_get_attachment_image_src($wpua_avatar_default, 'medium');
|
75 |
+
if($avatar_default == $wpua_avatar_default_image[0]){
|
76 |
+
update_option('avatar_default', 'wp_user_avatar');
|
77 |
+
}
|
78 |
+
}
|
79 |
+
update_option('wp_user_avatar_default_avatar_updated', '1');
|
80 |
+
}
|
81 |
+
add_action('admin_init', 'wpua_default_avatar');
|
82 |
+
}
|
83 |
+
|
84 |
+
// Rename user meta to match database settings
|
85 |
+
if(empty($wpua_users_updated)){
|
86 |
+
function wpua_user_meta(){
|
87 |
+
global $wpdb, $blog_id;
|
88 |
+
$wpua_metakey = $wpdb->get_blog_prefix($blog_id).'user_avatar';
|
89 |
+
// If database tables start with something other than wp_
|
90 |
+
if($wpua_metakey != 'wp_user_avatar'){
|
91 |
+
$users = get_users();
|
92 |
+
// Move current user metakeys to new metakeys
|
93 |
+
foreach($users as $user){
|
94 |
+
$wpua = get_user_meta($user->ID, 'wp_user_avatar', true);
|
95 |
+
if(!empty($wpua)){
|
96 |
+
update_user_meta($user->ID, $wpua_metakey, $wpua);
|
97 |
+
delete_user_meta($user->ID, 'wp_user_avatar');
|
98 |
+
}
|
99 |
+
}
|
100 |
+
}
|
101 |
+
update_option('wp_user_avatar_users_updated', '1');
|
102 |
+
}
|
103 |
+
add_action('admin_init', 'wpua_user_meta');
|
104 |
+
}
|
105 |
+
|
106 |
+
// Add media state to existing avatars
|
107 |
+
if(empty($wpua_media_updated)){
|
108 |
+
function wpua_media_state(){
|
109 |
+
global $wpdb, $blog_id;
|
110 |
+
// Find all users with WPUA
|
111 |
+
$wpua_metakey = $wpdb->get_blog_prefix($blog_id).'user_avatar';
|
112 |
+
$wpuas = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->usermeta WHERE meta_key = %s AND meta_value != %d AND meta_value != %d", $wpua_metakey, 0, ""));
|
113 |
+
foreach($wpuas as $usermeta){
|
114 |
+
add_post_meta($usermeta->meta_value, '_wp_attachment_wp_user_avatar', $usermeta->user_id);
|
115 |
+
}
|
116 |
+
update_option('wp_user_avatar_media_updated', '1');
|
117 |
+
}
|
118 |
+
add_action('admin_init', 'wpua_media_state');
|
119 |
+
}
|
120 |
+
|
121 |
+
// Settings for Subscribers
|
122 |
+
if($wpua_allow_upload == 1){
|
123 |
+
// Allow multipart data in form
|
124 |
+
function wpua_add_edit_form_multipart_encoding(){
|
125 |
+
echo ' enctype="multipart/form-data"';
|
126 |
+
}
|
127 |
+
add_action('user_edit_form_tag', 'wpua_add_edit_form_multipart_encoding');
|
128 |
+
|
129 |
+
// Check user role
|
130 |
+
function check_user_role($role, $user_id=null){
|
131 |
+
global $current_user;
|
132 |
+
if(is_numeric($user_id)){
|
133 |
+
$user = get_userdata($user_id);
|
134 |
+
} else {
|
135 |
+
$user = $current_user->ID;
|
136 |
+
}
|
137 |
+
if(empty($user)){
|
138 |
+
return false;
|
139 |
+
}
|
140 |
+
return in_array($role, (array) $user->roles);
|
141 |
+
}
|
142 |
+
|
143 |
+
// Give subscribers edit_posts capability
|
144 |
+
function wpua_subscriber_add_cap(){
|
145 |
+
global $wpdb, $blog_id;
|
146 |
+
$wp_user_roles = $wpdb->get_blog_prefix($blog_id).'user_roles';
|
147 |
+
$user_roles = get_option($wp_user_roles);
|
148 |
+
$user_roles['subscriber']['capabilities']['edit_posts'] = true;
|
149 |
+
update_option($wp_user_roles, $user_roles);
|
150 |
+
}
|
151 |
+
add_action('admin_init', 'wpua_subscriber_add_cap');
|
152 |
+
|
153 |
+
// Remove menu items
|
154 |
+
function wpua_subscriber_remove_menu_pages(){
|
155 |
+
global $current_user;
|
156 |
+
if(check_user_role('subscriber', $current_user->ID)){
|
157 |
+
remove_menu_page('edit.php');
|
158 |
+
remove_menu_page('edit-comments.php');
|
159 |
+
remove_menu_page('tools.php');
|
160 |
+
}
|
161 |
+
}
|
162 |
+
add_action('admin_menu', 'wpua_subscriber_remove_menu_pages');
|
163 |
+
|
164 |
+
// Remove dashboard items
|
165 |
+
function wpua_subscriber_remove_dashboard_widgets(){
|
166 |
+
global $current_user;
|
167 |
+
if(check_user_role('subscriber', $current_user->ID)){
|
168 |
+
remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
|
169 |
+
remove_meta_box('dashboard_recent_drafts', 'dashboard', 'side');
|
170 |
+
remove_meta_box('dashboard_right_now', 'dashboard', 'normal');
|
171 |
+
}
|
172 |
+
}
|
173 |
+
add_action('wp_dashboard_setup', 'wpua_subscriber_remove_dashboard_widgets');
|
174 |
+
|
175 |
+
// Restrict access to pages
|
176 |
+
function wpua_subscriber_offlimits(){
|
177 |
+
global $current_user, $pagenow;
|
178 |
+
$offlimits = array('edit.php', 'post-new.php', 'edit-comments.php', 'tools.php');
|
179 |
+
if(check_user_role('subscriber', $current_user->ID)){
|
180 |
+
if(in_array($pagenow, $offlimits)){
|
181 |
+
do_action('admin_page_access_denied');
|
182 |
+
wp_die(__('You do not have sufficient permissions to access this page.'));
|
183 |
+
}
|
184 |
+
}
|
185 |
+
}
|
186 |
+
add_action('admin_init', 'wpua_subscriber_offlimits');
|
187 |
+
}
|
188 |
+
|
189 |
+
// Remove subscribers edit_posts capability
|
190 |
+
function wpua_subscriber_remove_cap(){
|
191 |
+
global $wpdb, $blog_id;
|
192 |
+
$wp_user_roles = $wpdb->get_blog_prefix($blog_id).'user_roles';
|
193 |
+
$user_roles = get_option($wp_user_roles);
|
194 |
+
unset($user_roles['subscriber']['capabilities']['edit_posts']);
|
195 |
+
update_option($wp_user_roles, $user_roles);
|
196 |
+
}
|
197 |
+
|
198 |
+
// On deactivation
|
199 |
+
function wpua_deactivate(){
|
200 |
+
// Remove subscribers edit_posts capability
|
201 |
+
wpua_subscriber_remove_cap();
|
202 |
+
// Reset all default avatar to Mystery Man
|
203 |
+
update_option('avatar_default', 'mystery');
|
204 |
+
}
|
205 |
+
|
206 |
+
// WP User Avatar
|
207 |
+
if(!class_exists('wp_user_avatar')){
|
208 |
+
class wp_user_avatar{
|
209 |
+
function wp_user_avatar(){
|
210 |
+
global $current_user, $show_avatars, $wpua_allow_upload, $pagenow;
|
211 |
+
// Adds WPUA to profile
|
212 |
+
if(current_user_can('upload_files') || ($wpua_allow_upload == 1 && is_user_logged_in())){
|
213 |
+
add_action('show_user_profile', array('wp_user_avatar', 'wpua_action_show_user_profile'));
|
214 |
+
add_action('edit_user_profile', array($this, 'wpua_action_show_user_profile'));
|
215 |
+
add_action('personal_options_update', array($this, 'wpua_action_process_option_update'));
|
216 |
+
add_action('edit_user_profile_update', array($this, 'wpua_action_process_option_update'));
|
217 |
+
if(is_admin()){
|
218 |
+
// Adds scripts to admin
|
219 |
+
add_action('admin_enqueue_scripts', array($this, 'wpua_media_upload_scripts'));
|
220 |
+
// Admin settings
|
221 |
+
add_action('admin_menu', 'wpua_admin');
|
222 |
+
add_filter('plugin_action_links', array($this, 'wpua_plugin_settings_links'), 10, 2);
|
223 |
+
} else {
|
224 |
+
// Adds scripts to front pages
|
225 |
+
add_action('wp_enqueue_scripts', array($this, 'wpua_media_upload_scripts'));
|
226 |
+
}
|
227 |
+
// Only add attachment field for WP 3.4 and older
|
228 |
+
if(!function_exists('wp_enqueue_media') && $pagenow == 'media-upload.php'){
|
229 |
+
add_filter('attachment_fields_to_edit', array($this, 'wpua_add_attachment_field_to_edit'), 10, 2);
|
230 |
+
}
|
231 |
+
// Hide column in Users table if default avatars are enabled
|
232 |
+
if(is_admin() && $show_avatars != '1'){
|
233 |
+
add_filter('manage_users_columns', array($this, 'wpua_add_column'), 10, 1);
|
234 |
+
add_filter('manage_users_custom_column', array($this, 'wpua_show_column'), 10, 3);
|
235 |
+
}
|
236 |
+
}
|
237 |
+
}
|
238 |
+
|
239 |
+
// Add to edit user profile
|
240 |
+
function wpua_action_show_user_profile($user){
|
241 |
+
global $wpdb, $blog_id, $current_user, $show_avatars;
|
242 |
+
// Get WPUA attachment ID
|
243 |
+
$wpua = get_user_meta($user->ID, $wpdb->get_blog_prefix($blog_id).'user_avatar', true);
|
244 |
+
// Show remove button if WPUA is set
|
245 |
+
$hide_notice = has_wp_user_avatar($user->ID) ? ' class="hide-me"' : "";
|
246 |
+
$hide_remove = !has_wp_user_avatar($user->ID) ? ' hide-me' : "";
|
247 |
+
// If avatars are enabled, get original avatar image or show blank
|
248 |
+
$avatar_medium_src = ($show_avatars == 1 && is_admin()) ? wpua_get_avatar_original($user->user_email, 96) : includes_url().'images/blank.gif';
|
249 |
+
// Check if user has wp_user_avatar, if not show image from above
|
250 |
+
$avatar_medium = has_wp_user_avatar($user->ID) ? get_wp_user_avatar_src($user->ID, 'medium') : $avatar_medium_src;
|
251 |
+
// Check if user has wp_user_avatar, if not show image from above
|
252 |
+
$avatar_thumbnail = has_wp_user_avatar($user->ID) ? get_wp_user_avatar_src($user->ID, 96) : $avatar_medium_src;
|
253 |
+
// Change text on message based on current user
|
254 |
+
$profile = ($current_user->ID == $user->ID) ? 'Profile' : 'User';
|
255 |
+
// Max upload size
|
256 |
+
if(!function_exists('wp_max_upload_size')){
|
257 |
+
require_once(ABSPATH.'wp-admin/includes/template.php');
|
258 |
+
}
|
259 |
+
$upload_size_unit = wp_max_upload_size();
|
260 |
+
$byte_sizes = array('KB', 'MB', 'GB');
|
261 |
+
for($u = -1; $upload_size_unit > 1024 && $u < count($byte_sizes) - 1; $u++){
|
262 |
+
$upload_size_unit /= 1024;
|
263 |
+
}
|
264 |
+
if($u < 0){
|
265 |
+
$upload_size_unit = 0;
|
266 |
+
$u = 0;
|
267 |
+
} else {
|
268 |
+
$upload_size_unit = (int) $upload_size_unit;
|
269 |
+
}
|
270 |
+
?>
|
271 |
+
<?php if(class_exists('bbPress') && !is_admin()) : // Add to bbPress profile with same style ?>
|
272 |
+
<h2 class="entry-title"><?php _e('WP User Avatar'); ?></h2>
|
273 |
+
<fieldset class="bbp-form">
|
274 |
+
<legend><?php _e('WP User Avatar'); ?></legend>
|
275 |
+
<?php else : // Add to profile with admin style ?>
|
276 |
+
<h3><?php _e('WP User Avatar') ?></h3>
|
277 |
+
<table class="form-table">
|
278 |
+
<tr>
|
279 |
+
<th><label for="wp_user_avatar"><?php _e('WP User Avatar'); ?></label></th>
|
280 |
+
<td>
|
281 |
+
<?php endif; ?>
|
282 |
+
<input type="hidden" name="wp-user-avatar" id="wp-user-avatar" value="<?php echo $wpua; ?>" />
|
283 |
+
<?php if(current_user_can('upload_files')) : // Button to launch Media uploader ?>
|
284 |
+
<p><button type="button" class="button" id="add-wp-user-avatar" name="add-wp-user-avatar"><?php _e('Edit WP User Avatar'); ?></button></p>
|
285 |
+
<?php elseif(!current_user_can('upload_files') && !has_wp_user_avatar($current_user->ID)) : // Upload button ?>
|
286 |
+
<input name="wp-user-avatar-file" id="wp-user-avatar-file" type="file" />
|
287 |
+
<button type="submit" class="button" id="upload-wp-user-avatar" name="upload-wp-user-avatar" value="<?php _e('Upload'); ?>"><?php _e('Upload'); ?></button>
|
288 |
+
<p>
|
289 |
+
<?php _e('Maximum upload file size: '.esc_html($upload_size_unit).esc_html($byte_sizes[$u])); ?>
|
290 |
+
<br />
|
291 |
+
<?php _e('Allowed file formats: JPG, GIF, PNG'); ?>
|
292 |
+
</p>
|
293 |
+
<?php elseif(!current_user_can('upload_files') && has_wp_user_avatar($current_user->ID) && wpua_author($wpua, $current_user->ID)) : // Edit button ?>
|
294 |
+
<?php $edit_attachment_link = function_exists('wp_enqueue_media') ? add_query_arg(array('post' => $wpua, 'action' => 'edit'), admin_url('post.php')) : add_query_arg(array('attachment_id' => $wpua, 'action' => 'edit'), admin_url('media.php')) ?>
|
295 |
+
<p><button type="button" class="button" id="edit-wp-user-avatar" name="edit-wp-user-avatar" onclick="window.open('<?php echo $edit_attachment_link; ?>', '_self');"><?php _e('Edit WP User Avatar'); ?></button></p>
|
296 |
+
<?php endif; ?>
|
297 |
+
<p id="wp-user-avatar-preview">
|
298 |
+
<img src="<?php echo $avatar_medium; ?>" alt="" />
|
299 |
+
<?php _e('Original'); ?>
|
300 |
+
</p>
|
301 |
+
<p id="wp-user-avatar-thumbnail">
|
302 |
+
<img src="<?php echo $avatar_thumbnail; ?>" alt="" />
|
303 |
+
<?php _e('Thumbnail'); ?>
|
304 |
+
</p>
|
305 |
+
<p><button type="button" class="button<?php echo $hide_remove; ?>" id="remove-wp-user-avatar" name="remove-wp-user-avatar"><?php _e('Remove'); ?></button></p>
|
306 |
+
<p id="wp-user-avatar-message"><?php _e('Press "Update '.$profile.'" to save your changes.'); ?></p>
|
307 |
+
<?php if(class_exists('bbPress') && !is_admin()) : // Add to bbPress profile with same style ?>
|
308 |
+
</fieldset>
|
309 |
+
<?php else : // Add to profile with admin style ?>
|
310 |
+
</td>
|
311 |
+
</tr>
|
312 |
+
</table>
|
313 |
+
<?php endif; ?>
|
314 |
+
<?php echo wpua_js($user->display_name, $avatar_medium_src); // Add JS ?>
|
315 |
+
<?php
|
316 |
+
}
|
317 |
+
|
318 |
+
// Update user meta
|
319 |
+
function wpua_action_process_option_update($user_id){
|
320 |
+
global $wpdb, $blog_id;
|
321 |
+
// Check if user has upload_files capability
|
322 |
+
if(current_user_can('upload_files')){
|
323 |
+
$wpua_id = isset($_POST['wp-user-avatar']) ? intval($_POST['wp-user-avatar']) : "";
|
324 |
+
$wpdb->query($wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %d", '_wp_attachment_wp_user_avatar', $user_id));
|
325 |
+
add_post_meta($wpua_id, '_wp_attachment_wp_user_avatar', $user_id);
|
326 |
+
update_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', $wpua_id);
|
327 |
+
} else {
|
328 |
+
if(isset($_POST['wp-user-avatar']) && empty($_POST['wp-user-avatar'])){
|
329 |
+
// Uploads by user
|
330 |
+
$attachments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE post_author = %d AND post_type = %s", $user_id, 'attachment'));
|
331 |
+
foreach($attachments as $attachment){
|
332 |
+
// Delete attachment if not used by another user
|
333 |
+
if(!wpua_image($attachment->ID, $user_id)){
|
334 |
+
wp_delete_post($attachment->ID);
|
335 |
+
}
|
336 |
+
}
|
337 |
+
update_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', "");
|
338 |
+
}
|
339 |
+
// Create attachment from upload
|
340 |
+
if(isset($_POST['upload-wp-user-avatar']) && $_POST['upload-wp-user-avatar']){
|
341 |
+
if(!function_exists('wp_handle_upload')){
|
342 |
+
require_once(ABSPATH.'wp-admin/includes/admin.php');
|
343 |
+
require_once(ABSPATH.'wp-admin/includes/file.php');
|
344 |
+
}
|
345 |
+
$name = $_FILES['wp-user-avatar-file']['name'];
|
346 |
+
$file = wp_handle_upload($_FILES['wp-user-avatar-file'], array('test_form' => false));
|
347 |
+
$type = $file['type'];
|
348 |
+
// Allow only JPG, GIF, PNG
|
349 |
+
if($file['error'] || !preg_match('/(jpe?g|gif|png)$/i', $type)){
|
350 |
+
if($file['error']){
|
351 |
+
wp_die($file['error']);
|
352 |
+
} else {
|
353 |
+
wp_die(__('Sorry, this file type is not permitted for security reasons.'));
|
354 |
+
}
|
355 |
+
}
|
356 |
+
// Break out file info
|
357 |
+
$name_parts = pathinfo($name);
|
358 |
+
$name = trim(substr($name, 0, -(1 + strlen($name_parts['extension']))));
|
359 |
+
$url = $file['url'];
|
360 |
+
$file = $file['file'];
|
361 |
+
$title = $name;
|
362 |
+
// Use image exif/iptc data for title if possible
|
363 |
+
if($image_meta = @wp_read_image_metadata($file)){
|
364 |
+
if(trim($image_meta['title']) && !is_numeric(sanitize_title($image_meta['title']))){
|
365 |
+
$title = $image_meta['title'];
|
366 |
+
}
|
367 |
+
}
|
368 |
+
// Construct the attachment array
|
369 |
+
$attachment = array(
|
370 |
+
'guid' => $url,
|
371 |
+
'post_mime_type' => $type,
|
372 |
+
'post_title' => $title
|
373 |
+
);
|
374 |
+
// This should never be set as it would then overwrite an existing attachment
|
375 |
+
if(isset($attachment['ID'])){
|
376 |
+
unset($attachment['ID']);
|
377 |
+
}
|
378 |
+
// Save the attachment metadata
|
379 |
+
$attachment_id = wp_insert_attachment($attachment, $file);
|
380 |
+
if(!is_wp_error($attachment_id)){
|
381 |
+
require_once(ABSPATH.'wp-admin/includes/image.php');
|
382 |
+
wp_update_attachment_metadata($attachment_id, wp_generate_attachment_metadata($attachment_id, $file));
|
383 |
+
$wpdb->query($wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %d", '_wp_attachment_wp_user_avatar', $user_id));
|
384 |
+
add_post_meta($attachment_id, '_wp_attachment_wp_user_avatar', $user_id);
|
385 |
+
update_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', $attachment_id);
|
386 |
+
}
|
387 |
+
}
|
388 |
+
}
|
389 |
+
}
|
390 |
+
|
391 |
+
// Add button to attach image for WP 3.4 and older
|
392 |
+
function wpua_add_attachment_field_to_edit($fields, $post){
|
393 |
+
$image = wp_get_attachment_image_src($post->ID, "medium");
|
394 |
+
$button = '<button type="button" class="button" id="set-wp-user-avatar-image" name="set-wp-user-avatar-image" onclick="setWPUserAvatar(\''.$post->ID.'\', \''.$image[0].'\')">Set WP User Avatar</button>';
|
395 |
+
$fields['wp-user-avatar'] = array(
|
396 |
+
'label' => __('WP User Avatar'),
|
397 |
+
'input' => 'html',
|
398 |
+
'html' => $button
|
399 |
+
);
|
400 |
+
return $fields;
|
401 |
+
}
|
402 |
+
|
403 |
+
// Add settings link on plugin page
|
404 |
+
function wpua_plugin_settings_links($links, $file){
|
405 |
+
if(basename($file) == basename(plugin_basename(__FILE__))){
|
406 |
+
$settings_link = '<a href="'.add_query_arg(array('page' => 'wp-user-avatar'), admin_url('options-general.php')).'">'.__('Settings').'</a>';
|
407 |
+
$links = array_merge($links, array($settings_link));
|
408 |
+
}
|
409 |
+
return $links;
|
410 |
+
}
|
411 |
+
|
412 |
+
// Add column to Users table
|
413 |
+
function wpua_add_column($columns){
|
414 |
+
return $columns + array('wp-user-avatar' => __('WP User Avatar'));
|
415 |
+
}
|
416 |
+
|
417 |
+
// Show thumbnail in Users table
|
418 |
+
function wpua_show_column($value, $column_name, $user_id){
|
419 |
+
global $wpdb, $blog_id;
|
420 |
+
$wpua = get_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', true);
|
421 |
+
$wpua_image = wp_get_attachment_image($wpua, array(32,32));
|
422 |
+
if($column_name == 'wp-user-avatar'){
|
423 |
+
return $wpua_image;
|
424 |
+
}
|
425 |
+
}
|
426 |
+
|
427 |
+
// Media uploader
|
428 |
+
function wpua_media_upload_scripts(){
|
429 |
+
if(function_exists('wp_enqueue_media')){
|
430 |
+
wp_enqueue_script('admin-bar');
|
431 |
+
wp_enqueue_media();
|
432 |
+
} else {
|
433 |
+
wp_enqueue_script('media-upload');
|
434 |
+
wp_enqueue_script('thickbox');
|
435 |
+
wp_enqueue_style('thickbox');
|
436 |
+
}
|
437 |
+
wp_enqueue_script('wp-user-avatar', WPUA_URLPATH.'js/wp-user-avatar.js', "", WPUA_VERSION);
|
438 |
+
wp_enqueue_style('wp-user-avatar', WPUA_URLPATH.'css/wp-user-avatar.css', "", WPUA_VERSION);
|
439 |
+
}
|
440 |
+
}
|
441 |
+
|
442 |
+
// Uploader scripts
|
443 |
+
function wpua_js($section, $avatar_thumb){ ?>
|
444 |
+
<script type="text/javascript">
|
445 |
+
jQuery(function(){
|
446 |
+
<?php if(current_user_can('upload_files')) : ?>
|
447 |
+
<?php if(function_exists('wp_enqueue_media')) : // Backbone uploader for WP 3.5+ ?>
|
448 |
+
openMediaUploader("<?php echo $section; ?>");
|
449 |
+
<?php else : // Fall back to Thickbox uploader ?>
|
450 |
+
openThickboxUploader("<?php echo $section; ?>", "<?php echo get_admin_url(); ?>media-upload.php?post_id=0&type=image&tab=library&TB_iframe=1");
|
451 |
+
<?php endif; ?>
|
452 |
+
<?php endif; ?>
|
453 |
+
removeWPUserAvatar("<?php echo htmlspecialchars_decode($avatar_thumb); ?>");
|
454 |
+
});
|
455 |
+
</script>
|
456 |
+
<?php
|
457 |
+
}
|
458 |
+
|
459 |
+
// Returns true if user has Gravatar-hosted image
|
460 |
+
function wpua_has_gravatar($id_or_email, $has_gravatar=false, $user="", $email=""){
|
461 |
+
global $ssl;
|
462 |
+
if(!is_object($id_or_email) && !empty($id_or_email)){
|
463 |
+
// Find user by ID or e-mail address
|
464 |
+
$user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
|
465 |
+
// Get registered user e-mail address
|
466 |
+
$email = !empty($user) ? $user->user_email : "";
|
467 |
+
}
|
468 |
+
// Check if Gravatar image returns 200 (OK) or 404 (Not Found)
|
469 |
+
if(!empty($email)){
|
470 |
+
$hash = md5(strtolower(trim($email)));
|
471 |
+
$gravatar = 'http'.$ssl.'://www.gravatar.com/avatar/'.$hash.'?d=404';
|
472 |
+
$headers = @get_headers($gravatar);
|
473 |
+
$has_gravatar = !preg_match("|200|", $headers[0]) ? false : true;
|
474 |
+
}
|
475 |
+
return $has_gravatar;
|
476 |
+
}
|
477 |
+
|
478 |
+
// Returns true if user has wp_user_avatar
|
479 |
+
function has_wp_user_avatar($id_or_email="", $has_wpua=false, $user="", $user_id=""){
|
480 |
+
global $wpdb, $blog_id;
|
481 |
+
if(!is_object($id_or_email) && !empty($id_or_email)){
|
482 |
+
// Find user by ID or e-mail address
|
483 |
+
$user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
|
484 |
+
// Get registered user ID
|
485 |
+
$user_id = !empty($user) ? $user->ID : "";
|
486 |
+
}
|
487 |
+
$wpua = get_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', true);
|
488 |
+
$has_wpua = !empty($wpua) ? true : false;
|
489 |
+
return $has_wpua;
|
490 |
+
}
|
491 |
+
|
492 |
+
// Replace get_avatar only in get_wp_user_avatar
|
493 |
+
function wpua_get_avatar_filter($avatar, $id_or_email, $size="", $default="", $alt=""){
|
494 |
+
global $post, $comment, $avatar_default, $wpua_avatar_default, $mustache_original, $mustache_medium, $mustache_thumbnail, $mustache_avatar, $mustache_admin;
|
495 |
+
// User has WPUA
|
496 |
+
if(is_object($id_or_email)){
|
497 |
+
if(!empty($comment->comment_author_email)){
|
498 |
+
$avatar = get_wp_user_avatar($comment->comment_author_email, $size, $default, $alt);
|
499 |
+
} else {
|
500 |
+
$avatar = get_wp_user_avatar('unknown@gravatar.com', $size, $default, $alt);
|
501 |
+
}
|
502 |
+
} else {
|
503 |
+
if(has_wp_user_avatar($id_or_email)){
|
504 |
+
$avatar = get_wp_user_avatar($id_or_email, $size, $default, $alt);
|
505 |
+
// User has Gravatar
|
506 |
+
} elseif(wpua_has_gravatar($id_or_email)){
|
507 |
+
$avatar = $avatar;
|
508 |
+
// User doesn't have WPUA or Gravatar and Default Avatar is wp_user_avatar, show custom Default Avatar
|
509 |
+
} elseif($avatar_default == 'wp_user_avatar'){
|
510 |
+
// Show custom Default Avatar
|
511 |
+
if(!empty($wpua_avatar_default)){
|
512 |
+
// Get image
|
513 |
+
$wpua_avatar_default_image = wp_get_attachment_image_src($wpua_avatar_default, array($size,$size));
|
514 |
+
// Image src
|
515 |
+
$default = $wpua_avatar_default_image[0];
|
516 |
+
// Add dimensions if numeric size
|
517 |
+
$dimensions = ' width="'.$wpua_avatar_default_image[1].'" height="'.$wpua_avatar_default_image[2].'"';
|
518 |
+
$defaultcss = "";
|
519 |
+
} else {
|
520 |
+
// Get mustache image based on numeric size comparison
|
521 |
+
if($size > get_option('medium_size_w')){
|
522 |
+
$default = $mustache_original;
|
523 |
+
} elseif($size <= get_option('medium_size_w') && $size > get_option('thumbnail_size_w')){
|
524 |
+
$default = $mustache_medium;
|
525 |
+
} elseif($size <= get_option('thumbnail_size_w') && $size > 96){
|
526 |
+
$default = $mustache_thumbnail;
|
527 |
+
} elseif($size <= 96 && $size > 32){
|
528 |
+
$default = $mustache_avatar;
|
529 |
+
} elseif($size <= 32){
|
530 |
+
$default = $mustache_admin;
|
531 |
+
}
|
532 |
+
// Add dimensions if numeric size
|
533 |
+
$dimensions = ' width="'.$size.'" height="'.$size.'"';
|
534 |
+
$defaultcss = ' avatar-default';
|
535 |
+
}
|
536 |
+
// Construct the img tag
|
537 |
+
$avatar = "<img src='".$default."'".$dimensions." alt='".$alt."' class='wp-user-avatar wp-user-avatar-".$size." avatar avatar-".$size." photo'".$defaultcss." />";
|
538 |
+
}
|
539 |
+
}
|
540 |
+
return $avatar;
|
541 |
+
}
|
542 |
+
add_filter('get_avatar', 'wpua_get_avatar_filter', 10, 6);
|
543 |
+
|
544 |
+
// Get original avatar, for when user removes wp_user_avatar
|
545 |
+
function wpua_get_avatar_original($id_or_email, $size="", $default="", $alt=""){
|
546 |
+
global $avatar_default, $wpua_avatar_default, $mustache_avatar, $pagenow;
|
547 |
+
// Remove get_avatar filter
|
548 |
+
if(is_admin()){
|
549 |
+
remove_filter('get_avatar', 'wpua_get_avatar_filter');
|
550 |
+
}
|
551 |
+
// User doesn't Gravatar and Default Avatar is wp_user_avatar, show custom Default Avatar
|
552 |
+
if(!wpua_has_gravatar($id_or_email) && $avatar_default == 'wp_user_avatar'){
|
553 |
+
// Show custom Default Avatar
|
554 |
+
if(!empty($wpua_avatar_default)){
|
555 |
+
$wpua_avatar_default_image = wp_get_attachment_image_src($wpua_avatar_default, array($size,$size));
|
556 |
+
$default = $wpua_avatar_default_image[0];
|
557 |
+
} else {
|
558 |
+
$default = $mustache_avatar;
|
559 |
+
}
|
560 |
+
} else {
|
561 |
+
// Get image from Gravatar, whether it's the user's image or default image
|
562 |
+
$wpua_image = get_avatar($id_or_email, $size);
|
563 |
+
// Takes the img tag, extracts the src
|
564 |
+
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $wpua_image, $matches, PREG_SET_ORDER);
|
565 |
+
$default = $matches [0] [1];
|
566 |
+
}
|
567 |
+
return $default;
|
568 |
+
}
|
569 |
+
|
570 |
+
// Find WPUA, show get_avatar if empty
|
571 |
+
function get_wp_user_avatar($id_or_email="", $size='96', $align="", $alt=""){
|
572 |
+
global $post, $comment, $avatar_default, $wpdb, $blog_id;
|
573 |
+
// Checks if comment
|
574 |
+
if(is_object($id_or_email)){
|
575 |
+
// Checks if comment author is registered user by user ID
|
576 |
+
if($comment->user_id != '0'){
|
577 |
+
$id_or_email = $comment->user_id;
|
578 |
+
$user = get_user_by('id', $id_or_email);
|
579 |
+
// Checks that comment author isn't anonymous
|
580 |
+
} elseif(!empty($comment->comment_author_email)){
|
581 |
+
// Checks if comment author is registered user by e-mail address
|
582 |
+
$user = get_user_by('email', $comment->comment_author_email);
|
583 |
+
// Get registered user info from profile, otherwise e-mail address should be value
|
584 |
+
$id_or_email = !empty($user) ? $user->ID : $comment->comment_author_email;
|
585 |
+
}
|
586 |
+
$alt = $comment->comment_author;
|
587 |
+
} else {
|
588 |
+
if(!empty($id_or_email)){
|
589 |
+
// Find user by ID or e-mail address
|
590 |
+
$user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
|
591 |
+
} else {
|
592 |
+
// Find author's name if id_or_email is empty
|
593 |
+
$author_name = get_query_var('author_name');
|
594 |
+
if(is_author()){
|
595 |
+
// On author page, get user by page slug
|
596 |
+
$user = get_user_by('slug', $author_name);
|
597 |
+
} else {
|
598 |
+
// On post, get user by author meta
|
599 |
+
$user_id = get_the_author_meta('ID');
|
600 |
+
$user = get_user_by('id', $user_id);
|
601 |
+
}
|
602 |
+
}
|
603 |
+
// Set user's ID and name
|
604 |
+
if(!empty($user)){
|
605 |
+
$id_or_email = $user->ID;
|
606 |
+
$alt = $user->display_name;
|
607 |
+
}
|
608 |
+
}
|
609 |
+
// Checks if user has WPUA
|
610 |
+
$wpua_meta = !empty($id_or_email) ? get_the_author_meta($wpdb->get_blog_prefix($blog_id).'user_avatar', $id_or_email) : "";
|
611 |
+
// Add alignment class
|
612 |
+
$alignclass = !empty($align) ? ' align'.$align : "";
|
613 |
+
// User has WPUA, bypass get_avatar
|
614 |
+
if(!empty($wpua_meta)){
|
615 |
+
// Numeric size use size array
|
616 |
+
$get_size = is_numeric($size) ? array($size,$size) : $size;
|
617 |
+
// Get image src
|
618 |
+
$wpua_image = wp_get_attachment_image_src($wpua_meta, $get_size);
|
619 |
+
// Add dimensions to img only if numeric size was specified
|
620 |
+
$dimensions = is_numeric($size) ? ' width="'.$wpua_image[1].'" height="'.$wpua_image[2].'"' : "";
|
621 |
+
// Construct the img tag
|
622 |
+
$avatar = '<img src="'.$wpua_image[0].'"'.$dimensions.' alt="'.$alt.'" class="wp-user-avatar wp-user-avatar-'.$size.$alignclass.' avatar avatar avatar-'.$size.' photo" />';
|
623 |
+
} else {
|
624 |
+
// Get numeric sizes for non-numeric sizes based on media options
|
625 |
+
if($size == 'original' || $size == 'large' || $size == 'medium' || $size == 'thumbnail'){
|
626 |
+
$get_size = ($size == 'original') ? get_option('large_size_w') : get_option($size.'_size_w');
|
627 |
+
} else {
|
628 |
+
// Numeric sizes leave as-is
|
629 |
+
$get_size = $size;
|
630 |
+
}
|
631 |
+
// User with no WPUA uses get_avatar
|
632 |
+
$avatar = get_avatar($id_or_email, $get_size, $default="", $alt="");
|
633 |
+
// Remove width and height for non-numeric sizes
|
634 |
+
if(!is_numeric($size)){
|
635 |
+
$avatar = preg_replace("/(width|height)=\'\d*\'\s/", "", $avatar);
|
636 |
+
$avatar = preg_replace('/(width|height)=\"\d*\"\s/', "", $avatar);
|
637 |
+
$avatar = str_replace('wp-user-avatar wp-user-avatar-'.$get_size.' ', "", $avatar);
|
638 |
+
$avatar = str_replace("class='", "class='wp-user-avatar wp-user-avatar-".$size.$alignclass." ", $avatar);
|
639 |
+
}
|
640 |
+
}
|
641 |
+
return $avatar;
|
642 |
+
}
|
643 |
+
|
644 |
+
// Return just the image src
|
645 |
+
function get_wp_user_avatar_src($id_or_email, $size="", $align=""){
|
646 |
+
$wpua_image_src = "";
|
647 |
+
// Gets the avatar img tag
|
648 |
+
$wpua_image = get_wp_user_avatar($id_or_email, $size, $align);
|
649 |
+
// Takes the img tag, extracts the src
|
650 |
+
if(!empty($wpua_image)){
|
651 |
+
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $wpua_image, $matches, PREG_SET_ORDER);
|
652 |
+
$wpua_image_src = $matches [0] [1];
|
653 |
+
}
|
654 |
+
return $wpua_image_src;
|
655 |
+
}
|
656 |
+
|
657 |
+
// Shortcode
|
658 |
+
function wpua_shortcode($atts, $content){
|
659 |
+
global $wpdb, $blog_id;
|
660 |
+
// Set shortcode attributes
|
661 |
+
extract(shortcode_atts(array('user' => "", 'size' => '96', 'align' => "", 'link' => "", 'target' => ""), $atts));
|
662 |
+
// Find user by ID, login, slug, or e-mail address
|
663 |
+
if(!empty($user)){
|
664 |
+
$user = is_numeric($user) ? get_user_by('id', $user) : get_user_by('login', $user);
|
665 |
+
$user = empty($user) ? get_user_by('slug', $user) : $user;
|
666 |
+
$user = empty($user) ? get_user_by('email', $user) : $user;
|
667 |
+
}
|
668 |
+
// Get user ID
|
669 |
+
$id_or_email = !empty($user) ? $user->ID : "";
|
670 |
+
// Check if link is set
|
671 |
+
if(!empty($link)){
|
672 |
+
// CSS class is same as link type, except for URL
|
673 |
+
$link_class = $link;
|
674 |
+
// Open in new window
|
675 |
+
$target_link = !empty($target) ? ' target="'.$target.'"' : "";
|
676 |
+
if($link == 'file'){
|
677 |
+
// Get image src
|
678 |
+
$image_link = get_wp_user_avatar_src($id_or_email, 'original', $align);
|
679 |
+
} elseif($link == 'attachment'){
|
680 |
+
// Get attachment URL
|
681 |
+
$image_link = get_attachment_link(get_the_author_meta($wpdb->get_blog_prefix($blog_id).'user_avatar', $id_or_email));
|
682 |
+
} else {
|
683 |
+
// URL
|
684 |
+
$image_link = $link;
|
685 |
+
$link_class = 'custom';
|
686 |
+
}
|
687 |
+
// Wrap the avatar inside the link
|
688 |
+
$avatar = '<a href="'.$image_link.'" class="wp-user-avatar-link wp-user-avatar-'.$link_class.'"'.$target_link.'>'.get_wp_user_avatar($id_or_email, $size, $align).'</a>';
|
689 |
+
} else {
|
690 |
+
// Get WPUA as normal
|
691 |
+
$avatar = get_wp_user_avatar($id_or_email, $size, $align);
|
692 |
+
}
|
693 |
+
return $avatar;
|
694 |
+
}
|
695 |
+
add_shortcode('avatar', 'wpua_shortcode');
|
696 |
+
|
697 |
+
// Add default avatar
|
698 |
+
function wpua_add_default_avatar($avatar_list=null){
|
699 |
+
global $avatar_default, $wpua_avatar_default, $mustache_medium, $mustache_admin;
|
700 |
+
// Remove get_avatar filter
|
701 |
+
remove_filter('get_avatar', 'wpua_get_avatar_filter');
|
702 |
+
// Set avatar_list variable
|
703 |
+
$avatar_list = "";
|
704 |
+
// Set avatar defaults
|
705 |
+
$avatar_defaults = array(
|
706 |
+
'mystery' => __('Mystery Man'),
|
707 |
+
'blank' => __('Blank'),
|
708 |
+
'gravatar_default' => __('Gravatar Logo'),
|
709 |
+
'identicon' => __('Identicon (Generated)'),
|
710 |
+
'wavatar' => __('Wavatar (Generated)'),
|
711 |
+
'monsterid' => __('MonsterID (Generated)'),
|
712 |
+
'retro' => __('Retro (Generated)')
|
713 |
+
);
|
714 |
+
// No Default Avatar, set to Mystery Man
|
715 |
+
if(empty($avatar_default)){
|
716 |
+
$avatar_default = 'mystery';
|
717 |
+
}
|
718 |
+
// Take avatar_defaults and get examples for unknown@gravatar.com
|
719 |
+
foreach($avatar_defaults as $default_key => $default_name){
|
720 |
+
$avatar = get_avatar('unknown@gravatar.com', 32, $default_key);
|
721 |
+
$selected = ($avatar_default == $default_key) ? 'checked="checked" ' : "";
|
722 |
+
$avatar_list .= "\n\t<label><input type='radio' name='avatar_default' id='avatar_{$default_key}' value='".esc_attr($default_key)."' {$selected}/> ";
|
723 |
+
$avatar_list .= preg_replace("/src='(.+?)'/", "src='\$1&forcedefault=1'", $avatar);
|
724 |
+
$avatar_list .= ' '.$default_name.'</label>';
|
725 |
+
$avatar_list .= '<br />';
|
726 |
+
}
|
727 |
+
// Show remove link if custom Default Avatar is set
|
728 |
+
if(!empty($wpua_avatar_default)){
|
729 |
+
$avatar_thumb_src = wp_get_attachment_image_src($wpua_avatar_default, array(32,32));
|
730 |
+
$avatar_thumb = $avatar_thumb_src[0];
|
731 |
+
$hide_remove = "";
|
732 |
+
} else {
|
733 |
+
$avatar_thumb = $mustache_admin;
|
734 |
+
$hide_remove = ' class="hide-me"';
|
735 |
+
}
|
736 |
+
// Default Avatar is wp_user_avatar, check the radio button next to it
|
737 |
+
$selected_avatar = ($avatar_default == 'wp_user_avatar') ? ' checked="checked" ' : "";
|
738 |
+
// Wrap WPUA in div
|
739 |
+
$avatar_thumb_img = '<div id="wp-user-avatar-preview"><img src="'.$avatar_thumb.'" width="32" /></div>';
|
740 |
+
// Add WPUA to list
|
741 |
+
$wpua_list = "\n\t<label><input type='radio' name='avatar_default' id='wp_user_avatar_radio' value='wp_user_avatar'$selected_avatar /> ";
|
742 |
+
$wpua_list .= preg_replace("/src='(.+?)'/", "src='\$1'", $avatar_thumb_img);
|
743 |
+
$wpua_list .= ' '.__('WP User Avatar').'</label>';
|
744 |
+
$wpua_list .= '<p id="edit-wp-user-avatar"><button type="button" class="button" id="add-wp-user-avatar" name="add-wp-user-avatar">'.__('Edit WP User Avatar').'</button>';
|
745 |
+
$wpua_list .= '<a href="#" id="remove-wp-user-avatar"'.$hide_remove.'>'.__('Remove').'</a></p>';
|
746 |
+
$wpua_list .= '<input type="hidden" id="wp-user-avatar" name="avatar_default_wp_user_avatar" value="'.$wpua_avatar_default.'">';
|
747 |
+
$wpua_list .= '<p id="wp-user-avatar-message">'.__('Press "Save Changes" to save your changes.').'</p>';
|
748 |
+
$wpua_list .= wpua_js('Default Avatar', $mustache_admin);
|
749 |
+
return $wpua_list.$avatar_list;
|
750 |
+
}
|
751 |
+
add_filter('default_avatar_select', 'wpua_add_default_avatar', 10);
|
752 |
+
|
753 |
+
// Add default avatar_default to whitelist
|
754 |
+
function wpua_whitelist_options($whitelist_options){
|
755 |
+
$whitelist_options['discussion'][] = 'avatar_default_wp_user_avatar';
|
756 |
+
return $whitelist_options;
|
757 |
+
}
|
758 |
+
add_filter('whitelist_options', 'wpua_whitelist_options', 10);
|
759 |
+
|
760 |
+
// Add media state
|
761 |
+
function wpua_add_media_state($media_states){
|
762 |
+
global $post, $wpua_avatar_default;
|
763 |
+
$is_wpua = get_post_custom_values('_wp_attachment_wp_user_avatar', $post->ID);
|
764 |
+
if(!empty($is_wpua)){
|
765 |
+
$media_states[] = __('Avatar');
|
766 |
+
}
|
767 |
+
if(!empty($wpua_avatar_default) && ($wpua_avatar_default == $post->ID)){
|
768 |
+
$media_states[] = __('Default Avatar');
|
769 |
+
}
|
770 |
+
return apply_filters('wpua_add_media_state', $media_states);
|
771 |
+
}
|
772 |
+
add_filter('display_media_states', 'wpua_add_media_state', 10, 1);
|
773 |
+
|
774 |
+
// Check if image is used as WPUA
|
775 |
+
function wpua_image($attachment_id, $user_id, $wpua_image=false){
|
776 |
+
global $wpdb;
|
777 |
+
$wpua = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s AND meta_value != %d", $attachment_id, '_wp_attachment_wp_user_avatar', $user_id));
|
778 |
+
if(!empty($wpua)){
|
779 |
+
$wpua_image = true;
|
780 |
+
}
|
781 |
+
return $wpua_image;
|
782 |
+
}
|
783 |
+
|
784 |
+
// Check who owns image
|
785 |
+
function wpua_author($attachment_id, $user_id, $wpua_author=false){
|
786 |
+
$attachment = get_post($attachment_id);
|
787 |
+
if(!empty($attachment) && $attachment->post_author == $user_id){
|
788 |
+
$wpua_author = true;
|
789 |
+
}
|
790 |
+
return $wpua_author;
|
791 |
+
}
|
792 |
+
|
793 |
+
// Admin page
|
794 |
+
function wpua_options_page(){
|
795 |
+
// Give subscribers edit_posts capability
|
796 |
+
if(isset($_GET['settings-updated']) && $_GET['settings-updated'] == 'true' && empty($wpua_allow_upload)){
|
797 |
+
wpua_subscriber_remove_cap();
|
798 |
+
}
|
799 |
+
?>
|
800 |
+
<div class="wrap">
|
801 |
+
<?php screen_icon(); ?>
|
802 |
+
<h2><?php _e('WP User Avatar'); ?></h2>
|
803 |
+
<form method="post" action="options.php">
|
804 |
+
<?php settings_fields('wpua-settings-group'); ?>
|
805 |
+
<?php do_settings_fields('wpua-settings-group', ""); ?>
|
806 |
+
<table class="form-table">
|
807 |
+
<tr valign="top">
|
808 |
+
<th scope="row"><?php _e('WP User Avatar Settings') ?></th>
|
809 |
+
<td>
|
810 |
+
<fieldset>
|
811 |
+
<legend class="screen-reader-text"><span><?php _e('WP User Avatar Settings') ?></span></legend>
|
812 |
+
<label for="wp_user_avatar_tinymce">
|
813 |
+
<input name="wp_user_avatar_tinymce" type="checkbox" id="wp_user_avatar_tinymce" value="1" <?php checked('1', get_option('wp_user_avatar_tinymce')); ?> />
|
814 |
+
<?php _e('Add avatar button to Visual Editor'); ?>
|
815 |
+
</label>
|
816 |
+
<br />
|
817 |
+
<label for="wp_user_avatar_allow_upload">
|
818 |
+
<input name="wp_user_avatar_allow_upload" type="checkbox" id="wp_user_avatar_allow_upload" value="1" <?php checked('1', get_option('wp_user_avatar_allow_upload')); ?> />
|
819 |
+
<?php _e('Allow Contributors & Subscribers to upload avatars'); ?>
|
820 |
+
</label>
|
821 |
+
</fieldset>
|
822 |
+
</td>
|
823 |
+
</tr>
|
824 |
+
</table>
|
825 |
+
<h3 class="title"><?php _e('Avatars'); ?></h3>
|
826 |
+
<p><?php _e('An avatar is an image that follows you from weblog to weblog appearing beside your name when you comment on avatar enabled sites. Here you can enable the display of avatars for people who comment on your site.'); ?></p>
|
827 |
+
<table class="form-table">
|
828 |
+
<tr valign="top">
|
829 |
+
<th scope="row"><?php _e('Avatar Display'); ?></th>
|
830 |
+
<td>
|
831 |
+
<fieldset>
|
832 |
+
<legend class="screen-reader-text"><span><?php _e('Avatar Display'); ?></span></legend>
|
833 |
+
<label for="show_avatars">
|
834 |
+
<input type="checkbox" id="show_avatars" name="show_avatars" value="1" <?php checked('1', get_option('show_avatars')); ?> />
|
835 |
+
<?php _e('Show Avatars'); ?>
|
836 |
+
</label>
|
837 |
+
</fieldset>
|
838 |
+
</td>
|
839 |
+
</tr>
|
840 |
+
<tr valign="top">
|
841 |
+
<th scope="row"><?php _e('Maximum Rating'); ?></th>
|
842 |
+
<td>
|
843 |
+
<fieldset>
|
844 |
+
<legend class="screen-reader-text"><span><?php _e('Maximum Rating'); ?></span></legend>
|
845 |
+
<?php
|
846 |
+
$ratings = array(
|
847 |
+
'G' => __('G — Suitable for all audiences'),
|
848 |
+
'PG' => __('PG — Possibly offensive, usually for audiences 13 and above'),
|
849 |
+
'R' => __('R — Intended for adult audiences above 17'),
|
850 |
+
'X' => __('X — Even more mature than above')
|
851 |
+
);
|
852 |
+
foreach ($ratings as $key => $rating) :
|
853 |
+
$selected = (get_option('avatar_rating') == $key) ? 'checked="checked"' : "";
|
854 |
+
echo "\n\t<label><input type='radio' name='avatar_rating' value='" . esc_attr($key) . "' $selected/> $rating</label><br />";
|
855 |
+
endforeach;
|
856 |
+
?>
|
857 |
+
</fieldset>
|
858 |
+
</td>
|
859 |
+
</tr>
|
860 |
+
<tr valign="top">
|
861 |
+
<th scope="row"><?php _e('Default Avatar') ?></th>
|
862 |
+
<td class="defaultavatarpicker">
|
863 |
+
<fieldset>
|
864 |
+
<legend class="screen-reader-text"><span><?php _e('Default Avatar'); ?></span></legend>
|
865 |
+
<?php _e('For users without a custom avatar of their own, you can either display a generic logo or a generated one based on their e-mail address.'); ?><br />
|
866 |
+
<?php echo wpua_add_default_avatar(); ?>
|
867 |
+
</fieldset>
|
868 |
+
</td>
|
869 |
+
</tr>
|
870 |
+
</table>
|
871 |
+
<?php submit_button(); ?>
|
872 |
+
</form>
|
873 |
+
</div>
|
874 |
+
<?php
|
875 |
+
}
|
876 |
+
|
877 |
+
// Whitelist settings
|
878 |
+
function wpua_admin_settings(){
|
879 |
+
register_setting('wpua-settings-group', 'wp_user_avatar_tinymce');
|
880 |
+
register_setting('wpua-settings-group', 'wp_user_avatar_allow_upload');
|
881 |
+
register_setting('wpua-settings-group', 'show_avatars');
|
882 |
+
register_setting('wpua-settings-group', 'avatar_rating');
|
883 |
+
register_setting('wpua-settings-group', 'avatar_default');
|
884 |
+
register_setting('wpua-settings-group', 'avatar_default_wp_user_avatar');
|
885 |
+
}
|
886 |
+
|
887 |
+
// Add options page and settings
|
888 |
+
function wpua_admin(){
|
889 |
+
add_options_page('WP User Avatar Plugin Settings', 'WP User Avatar', 'manage_options', 'wp-user-avatar', 'wpua_options_page');
|
890 |
+
add_action('admin_init', 'wpua_admin_settings');
|
891 |
+
}
|
892 |
+
|
893 |
+
// Initialize WPUA after other plugins are loaded
|
894 |
+
function wpua_load(){
|
895 |
+
global $wpua_instance;
|
896 |
+
$wpua_instance = new wp_user_avatar();
|
897 |
+
}
|
898 |
+
add_action('plugins_loaded', 'wpua_load');
|
899 |
+
}
|
900 |
+
?>
|