Version Description
- Bug Fix: Show default avatar when user removes custom avatar
- Bug Fix: Default Avatar save setting
Download this release
Release Info
Developer | bangbay |
Plugin | WP User Avatar |
Version | 1.2.3 |
Comparing to | |
See all releases |
Version 1.2.3
- css/wp-user-avatar.css +4 -0
- images/wp-user-avatar-32x32.png +0 -0
- images/wp-user-avatar.png +0 -0
- includes/tinymce.php +42 -0
- includes/tinymce/editor_plugin.js +1 -0
- includes/tinymce/editor_plugin.src.js +77 -0
- includes/tinymce/window.php +110 -0
- index.html +1 -0
- js/wp-user-avatar.js +89 -0
- readme.txt +281 -0
- wp-user-avatar.php +364 -0
css/wp-user-avatar.css
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
1 |
+
#wp-user-avatar-message { color: #c00; display: none; }
|
2 |
+
#wp-user-avatar-preview img { max-width: 96px; }
|
3 |
+
.defaultavatarpicker #wp-user-avatar-preview { width: 32px; height: 32px; display: inline-block; overflow: hidden; vertical-align: middle; }
|
4 |
+
.defaultavatarpicker #wp-user-avatar-preview img { width: 32px; }
|
images/wp-user-avatar-32x32.png
ADDED
Binary file
|
images/wp-user-avatar.png
ADDED
Binary file
|
includes/tinymce.php
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package WP User Avatar
|
4 |
+
* @version 1.2.3
|
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.png'});ed.onNodeChange.add(function(ed,cm,n){cm.setActive('wpUserAvatar',n.nodeName=='IMG')})},createControl:function(n,cm){return null},getInfo:function(){return{longname:'WP User Avatar',author:'Bangbay Siboliban',authorurl:'http://siboliban.org/',infourl:'http://wordpress.org/extend/plugins/wp-user-avatar/',version:"1.2.3"}}});tinymce.PluginManager.add('wpUserAvatar',tinymce.plugins.wpUserAvatar)})();
|
includes/tinymce/editor_plugin.src.js
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Docu : http://wiki.moxiecode.com/index.php/TinyMCE:Create_plugin/3.x#Creating_your_own_plugins
|
2 |
+
|
3 |
+
(function() {
|
4 |
+
// Load plugin specific language pack
|
5 |
+
tinymce.PluginManager.requireLangPack('wpUserAvatar');
|
6 |
+
|
7 |
+
tinymce.create('tinymce.plugins.wpUserAvatar', {
|
8 |
+
/**
|
9 |
+
* Initializes the plugin, this will be executed after the plugin has been created.
|
10 |
+
* This call is done before the editor instance has finished it's initialization so use the onInit event
|
11 |
+
* of the editor instance to intercept that event.
|
12 |
+
*
|
13 |
+
* @param {tinymce.Editor} ed Editor instance that the plugin is initialized in.
|
14 |
+
* @param {string} url Absolute URL to where the plugin is located.
|
15 |
+
*/
|
16 |
+
init : function(ed, url) {
|
17 |
+
// Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('mceExample');
|
18 |
+
|
19 |
+
ed.addCommand('mceWpUserAvatar', function() {
|
20 |
+
ed.windowManager.open({
|
21 |
+
// call content via admin-ajax, no need to know the full plugin path
|
22 |
+
file : ajaxurl + '?action=wp_user_avatar_tinymce',
|
23 |
+
width : 400,
|
24 |
+
height : 260,
|
25 |
+
inline : 1
|
26 |
+
}, {
|
27 |
+
plugin_url : url // Plugin absolute URL
|
28 |
+
});
|
29 |
+
});
|
30 |
+
|
31 |
+
// Register example button
|
32 |
+
ed.addButton('wpUserAvatar', {
|
33 |
+
title : 'Insert WP User Avatar',
|
34 |
+
cmd : 'mceWpUserAvatar',
|
35 |
+
image : url + '/../../images/wp-user-avatar.png'
|
36 |
+
});
|
37 |
+
|
38 |
+
// Add a node change handler, selects the button in the UI when a image is selected
|
39 |
+
ed.onNodeChange.add(function(ed, cm, n) {
|
40 |
+
cm.setActive('wpUserAvatar', n.nodeName == 'IMG');
|
41 |
+
});
|
42 |
+
},
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Creates control instances based in the incomming name. This method is normally not
|
46 |
+
* needed since the addButton method of the tinymce.Editor class is a more easy way of adding buttons
|
47 |
+
* but you sometimes need to create more complex controls like listboxes, split buttons etc then this
|
48 |
+
* method can be used to create those.
|
49 |
+
*
|
50 |
+
* @param {String} n Name of the control to create.
|
51 |
+
* @param {tinymce.ControlManager} cm Control manager to use inorder to create new control.
|
52 |
+
* @return {tinymce.ui.Control} New control instance or null if no control was created.
|
53 |
+
*/
|
54 |
+
createControl : function(n, cm) {
|
55 |
+
return null;
|
56 |
+
},
|
57 |
+
|
58 |
+
/**
|
59 |
+
* Returns information about the plugin as a name/value array.
|
60 |
+
* The current keys are longname, author, authorurl, infourl and version.
|
61 |
+
*
|
62 |
+
* @return {Object} Name/value array containing information about the plugin.
|
63 |
+
*/
|
64 |
+
getInfo : function() {
|
65 |
+
return {
|
66 |
+
longname : 'WP User Avatar',
|
67 |
+
author : 'Bangbay Siboliban',
|
68 |
+
authorurl : 'http://siboliban.org/',
|
69 |
+
infourl : 'http://wordpress.org/extend/plugins/wp-user-avatar/',
|
70 |
+
version : "1.2.3"
|
71 |
+
};
|
72 |
+
}
|
73 |
+
});
|
74 |
+
|
75 |
+
// Register plugin
|
76 |
+
tinymce.PluginManager.add('wpUserAvatar', tinymce.plugins.muluBox);
|
77 |
+
})();
|
includes/tinymce/window.php
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package WP User Avatar
|
4 |
+
* @version 1.2.3
|
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 |
+
label { width: 90px; display: inline-block; text-align: right; }
|
52 |
+
.mceActionPanel { padding: 7px 0 12px; text-align: center; }
|
53 |
+
.mceActionPanel #insert { float: none; width: 180px; margin: 0 auto; }
|
54 |
+
</style>
|
55 |
+
</head>
|
56 |
+
<body id="link" class="wp-core-ui" onload="document.body.style.display='';" style="display:none;">
|
57 |
+
<form name="wpUserAvatar" action="#">
|
58 |
+
<p><label for="<?php esc_attr_e('wp_user_avatar_user'); ?>"><strong><?php _e("User:"); ?></strong></label>
|
59 |
+
<select id="<?php esc_attr_e('wp_user_avatar_user'); ?>" name="<?php esc_attr_e('wp_user_avatar_user'); ?>">
|
60 |
+
<option value=""></option>
|
61 |
+
<?php $users = get_users(); foreach($users as $user) : ?>
|
62 |
+
<option value="<?php echo $user->user_login; ?>"><?php echo $user->display_name; ?></option>
|
63 |
+
<?php endforeach; ?>
|
64 |
+
</select></p>
|
65 |
+
|
66 |
+
<h4 style="text-align:center;">Choose a preset size or enter a number value.</h4>
|
67 |
+
|
68 |
+
<p>
|
69 |
+
<label for="<?php esc_attr_e('wp_user_avatar_size'); ?>"><strong><?php _e("Size:"); ?></strong></label>
|
70 |
+
<select id="<?php esc_attr_e('wp_user_avatar_size'); ?>" name="<?php esc_attr_e('wp_user_avatar_size'); ?>">
|
71 |
+
<option value=""></option>
|
72 |
+
<option value="original"><?php _e("Original"); ?></option>
|
73 |
+
<option value="large"><?php _e("Large"); ?></option>
|
74 |
+
<option value="medium"><?php _e("Medium"); ?></option>
|
75 |
+
<option value="thumbnail"><?php _e("Thumbnail"); ?></option>
|
76 |
+
</select>
|
77 |
+
or
|
78 |
+
<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="" />
|
79 |
+
</p>
|
80 |
+
|
81 |
+
<p><label for="<?php esc_attr_e('wp_user_avatar_align'); ?>"><strong><?php _e("Alignment:"); ?></strong></label>
|
82 |
+
<select id="<?php esc_attr_e('wp_user_avatar_align'); ?>" name="<?php esc_attr_e('wp_user_avatar_align'); ?>">
|
83 |
+
<option value=""></option>
|
84 |
+
<option value="center"><?php _e("Center"); ?></option>
|
85 |
+
<option value="left"><?php _e("Left"); ?></option>
|
86 |
+
<option value="right"><?php _e("Right"); ?></option>
|
87 |
+
</select></p>
|
88 |
+
|
89 |
+
<h4 style="text-align:center;">Link to image file, attachment page, or custom URL.</h4>
|
90 |
+
|
91 |
+
<p>
|
92 |
+
<label for="<?php esc_attr_e('wp_user_avatar_link'); ?>"><strong><?php _e("Link to:"); ?></strong></label>
|
93 |
+
<select id="<?php esc_attr_e('wp_user_avatar_link'); ?>" name="<?php esc_attr_e('wp_user_avatar_link'); ?>">
|
94 |
+
<option value=""></option>
|
95 |
+
<option value="file"><?php _e("Image File"); ?></option>
|
96 |
+
<option value="attachment"><?php _e("Attachment Page"); ?></option>
|
97 |
+
</select>
|
98 |
+
</p>
|
99 |
+
|
100 |
+
<p>
|
101 |
+
<label for="<?php esc_attr_e('wp_user_avatar_link_external'); ?>">or</label>
|
102 |
+
<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="" />
|
103 |
+
</p>
|
104 |
+
|
105 |
+
<div class="mceActionPanel">
|
106 |
+
<input type="submit" id="insert" class="button-primary" name="insert" value="<?php _e("Insert WP User Avatar"); ?>" onclick="insert_wp_user_avatar();" />
|
107 |
+
</div>
|
108 |
+
</form>
|
109 |
+
</body>
|
110 |
+
</html>
|
index.html
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
<!-- Thanks for using WP User Avatar! -->
|
js/wp-user-avatar.js
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Backbone uploader for WP 3.5
|
2 |
+
function openMediaUploader(section){
|
3 |
+
wp.media.wpUserAvatar = {
|
4 |
+
get: function(){
|
5 |
+
return wp.media.view.settings.post.wpUserAvatarId;
|
6 |
+
},
|
7 |
+
set: function(id){
|
8 |
+
var settings = wp.media.view.settings;
|
9 |
+
settings.post.wpUserAvatarId = id;
|
10 |
+
settings.post.wpUserAvatarSrc = jQuery('div.attachment-info').find('img').attr('src');
|
11 |
+
if(settings.post.wpUserAvatarId){
|
12 |
+
setWPUserAvatar(settings.post.wpUserAvatarId, settings.post.wpUserAvatarSrc);
|
13 |
+
jQuery('#wp_user_avatar_radio').val(settings.post.wpUserAvatarSrc).trigger('click');
|
14 |
+
}
|
15 |
+
},
|
16 |
+
frame: function(){
|
17 |
+
if(this._frame){
|
18 |
+
return this._frame;
|
19 |
+
}
|
20 |
+
this._frame = wp.media({
|
21 |
+
state: 'library',
|
22 |
+
states: [ new wp.media.controller.Library({ title: "Edit WP User Avatar: " + section }) ]
|
23 |
+
});
|
24 |
+
this._frame.on('open', function(){
|
25 |
+
var selection = this.state().get('selection');
|
26 |
+
id = jQuery('#wp-user-avatar').val();
|
27 |
+
attachment = wp.media.attachment(id);
|
28 |
+
attachment.fetch();
|
29 |
+
selection.add(attachment ? [ attachment ] : []);
|
30 |
+
}, this._frame);
|
31 |
+
this._frame.on('toolbar:create:select', function(toolbar){
|
32 |
+
this.createSelectToolbar(toolbar, {
|
33 |
+
text: 'Set WP User Avatar'
|
34 |
+
});
|
35 |
+
}, this._frame);
|
36 |
+
this._frame.state('library').on('select', this.select);
|
37 |
+
return this._frame;
|
38 |
+
},
|
39 |
+
select: function(id){
|
40 |
+
var settings = wp.media.view.settings,
|
41 |
+
selection = this.get('selection').single();
|
42 |
+
wp.media.wpUserAvatar.set(selection ? selection.id : -1);
|
43 |
+
},
|
44 |
+
init: function(){
|
45 |
+
jQuery('body').on('click', '#add-wp-user-avatar', function(e){
|
46 |
+
e.preventDefault();
|
47 |
+
e.stopPropagation();
|
48 |
+
wp.media.wpUserAvatar.frame().open();
|
49 |
+
});
|
50 |
+
}
|
51 |
+
};
|
52 |
+
jQuery(wp.media.wpUserAvatar.init);
|
53 |
+
}
|
54 |
+
|
55 |
+
// Thickbox uploader
|
56 |
+
function openThickboxUploader(section, iframe){
|
57 |
+
jQuery('body').on('click', '#add-wp-user-avatar', function(e){
|
58 |
+
e.preventDefault();
|
59 |
+
tb_show('Edit WP User Avatar: ' + section, iframe);
|
60 |
+
});
|
61 |
+
}
|
62 |
+
|
63 |
+
// Set WP User Avatar
|
64 |
+
function setWPUserAvatar(attachment, imageURL){
|
65 |
+
jQuery('#wp-user-avatar', window.parent.document).val(attachment);
|
66 |
+
jQuery('#wp-user-avatar-preview', window.parent.document).find('img').attr('src', imageURL).removeAttr('width', '').removeAttr('height', '');
|
67 |
+
jQuery('#wp-user-avatar-message', window.parent.document).show();
|
68 |
+
jQuery('#remove-wp-user-avatar', window.parent.document).show();
|
69 |
+
jQuery('#gravatar-notice', window.parent.document).hide();
|
70 |
+
jQuery('#wp_user_avatar_radio', window.parent.document).val(imageURL).trigger('click');
|
71 |
+
// Check if WP 3.5
|
72 |
+
if(typeof(wp) != 'undefined'){
|
73 |
+
wp.media.wpUserAvatar.frame().close()
|
74 |
+
} else {
|
75 |
+
window.parent.tb_remove();
|
76 |
+
}
|
77 |
+
}
|
78 |
+
|
79 |
+
// Remove WP User Avatar
|
80 |
+
function removeWPUserAvatar(avatar_full, avatar_thumb){
|
81 |
+
jQuery('body').on('click', '#remove-wp-user-avatar', function(e){
|
82 |
+
e.preventDefault();
|
83 |
+
jQuery(this).hide();
|
84 |
+
jQuery('#wp-user-avatar-preview').find('img').attr('src', avatar_thumb).removeAttr('width', '').removeAttr('height', '');
|
85 |
+
jQuery('#wp-user-avatar').val('');
|
86 |
+
jQuery('#wp-user-avatar-message').show();
|
87 |
+
jQuery('#wp_user_avatar_radio').val(avatar_full).trigger('click');
|
88 |
+
});
|
89 |
+
}
|
readme.txt
ADDED
@@ -0,0 +1,281 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.2.3
|
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.
|
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 |
+
= How can I see which users have an avatar? =
|
156 |
+
|
157 |
+
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.
|
158 |
+
|
159 |
+
= What CSS can I use with WP User Avatar? =
|
160 |
+
|
161 |
+
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:
|
162 |
+
|
163 |
+
`<?php echo get_wp_user_avatar($user_id, 96, 'left'); ?>`
|
164 |
+
|
165 |
+
Outputs:
|
166 |
+
|
167 |
+
`<img src="{imageURL}" width="96" height="96" class="wp-user-avatar wp-user-avatar-96 alignleft" />`
|
168 |
+
|
169 |
+
**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.
|
170 |
+
|
171 |
+
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:
|
172 |
+
|
173 |
+
`<?php echo get_wp_user_avatar($user_id, 'medium'); ?>`
|
174 |
+
|
175 |
+
Outputs:
|
176 |
+
|
177 |
+
`<img src="{imageURL}" class="wp-user-avatar wp-user-avatar-medium" />`
|
178 |
+
|
179 |
+
**Note:** WordPress adds more CSS classes to the avatar not listed here.
|
180 |
+
|
181 |
+
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.
|
182 |
+
|
183 |
+
* Image File: wp-user-avatar-file
|
184 |
+
* Attachment: wp-user-avatar-attachment
|
185 |
+
* Custom URL: wp-user-avatar-custom
|
186 |
+
|
187 |
+
`[avatar user="admin" size="96" align="left" link="attachment"]`
|
188 |
+
|
189 |
+
Outputs:
|
190 |
+
|
191 |
+
`<a href="{attachmentURL}" class="wp-user-avatar-link wp-user-avatar-attachment">
|
192 |
+
<img src="{imageURL}" width="96" height="96" class="wp-user-avatar wp-user-avatar-96 alignleft" />
|
193 |
+
</a>`
|
194 |
+
|
195 |
+
= What other functions are available for WP User Avatar? =
|
196 |
+
* <code>get_wp_user_avatar_src</code>: retrieves just the image URL
|
197 |
+
* <code>has_wp_user_avatar</code>: checks if the user has a WP User Avatar image
|
198 |
+
* [See example usage here](http://wordpress.org/extend/plugins/wp-user-avatar/installation/)
|
199 |
+
|
200 |
+
== Screenshots ==
|
201 |
+
|
202 |
+
1. WP User Avatar lets you upload your own Default Avatar.
|
203 |
+
2. WP User Avatar adds a field to your edit profile page.
|
204 |
+
3. After you've chosen a WP User Avatar image, you will see the option to remove it.
|
205 |
+
4. WP User Avatar adds a button to insert the [avatar] shortcode in the Visual Editor.
|
206 |
+
5. Options for the [avatar] shortcode.
|
207 |
+
|
208 |
+
== Changelog ==
|
209 |
+
|
210 |
+
= 1.2.3 =
|
211 |
+
* Bug Fix: Show default avatar when user removes custom avatar
|
212 |
+
* Bug Fix: Default Avatar save setting
|
213 |
+
|
214 |
+
= 1.2.2 =
|
215 |
+
* Add: Ability for bbPress users to edit avatar on front profile page
|
216 |
+
* Add: Link options for shortcode
|
217 |
+
* Bug Fix: Show WP User Avatar only to users with upload_files capability
|
218 |
+
|
219 |
+
= 1.2.1 =
|
220 |
+
* Add: TinyMCE button
|
221 |
+
* Update: Clean up redundant code
|
222 |
+
* Update: Compatibility only back to WordPress 3.3
|
223 |
+
|
224 |
+
= 1.2 =
|
225 |
+
* Add: Default Avatar setting
|
226 |
+
|
227 |
+
= 1.1.7 =
|
228 |
+
* Bug Fix: Change update_usermeta to update_user_meta
|
229 |
+
|
230 |
+
= 1.1.6 =
|
231 |
+
* Bug Fix: Image not showing in user profile edit
|
232 |
+
|
233 |
+
= 1.1.5a =
|
234 |
+
* Update: readme.txt
|
235 |
+
|
236 |
+
= 1.1.5 =
|
237 |
+
* Bug Fix: Remove stray curly bracket
|
238 |
+
|
239 |
+
= 1.1.4 =
|
240 |
+
* Bug Fix: Change get_usermeta to get_user_meta
|
241 |
+
* Bug Fix: Non-object warning when retrieving user ID
|
242 |
+
|
243 |
+
= 1.1.3 =
|
244 |
+
* Bug Fix: Comment author with no e-mail address
|
245 |
+
|
246 |
+
= 1.1.2 =
|
247 |
+
* Remove: Unused variables
|
248 |
+
|
249 |
+
= 1.1.1 =
|
250 |
+
* Bug Fix: Capabilities error in comment avatar
|
251 |
+
|
252 |
+
= 1.1 =
|
253 |
+
* Add: Add filter for get_avatar
|
254 |
+
* Add: CSS alignment classes
|
255 |
+
* Add: Replace comment author avatar
|
256 |
+
* Add: Shortcode
|
257 |
+
* Update: readme.txt
|
258 |
+
|
259 |
+
= 1.0.2 =
|
260 |
+
* Update: FAQ
|
261 |
+
* Remove: CSS that hides "Insert into Post"
|
262 |
+
|
263 |
+
= 1.0.1 =
|
264 |
+
* Add: CSS classes to image output
|
265 |
+
|
266 |
+
= 1.0 =
|
267 |
+
* Initial release
|
268 |
+
|
269 |
+
== Upgrade Notice ==
|
270 |
+
|
271 |
+
= 1.2.2 =
|
272 |
+
* New Features: Link options for shortcode, bbPress integration
|
273 |
+
|
274 |
+
= 1.2.1 =
|
275 |
+
* New Feature: Shortcode insertion button for Visual Editor
|
276 |
+
|
277 |
+
= 1.2 =
|
278 |
+
* New Feature: Default Avatar customization
|
279 |
+
|
280 |
+
= 1.1 =
|
281 |
+
* New Features: [avatar] shortcode, direct replacement of get_avatar() and comment author avatar, more CSS classes
|
wp-user-avatar.php
ADDED
@@ -0,0 +1,364 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package WP User Avatar
|
4 |
+
* @version 1.2.3
|
5 |
+
*/
|
6 |
+
/*
|
7 |
+
Plugin Name: WP User Avatar
|
8 |
+
Plugin URI: http://wordpress.org/extend/plugins/wp-user-avatar/
|
9 |
+
Description: Use any image from your WordPress Media Library as a custom user avatar. Add your own Default Avatar.
|
10 |
+
Version: 1.2.3
|
11 |
+
Author: Bangbay Siboliban
|
12 |
+
Author URI: http://siboliban.org/
|
13 |
+
*/
|
14 |
+
|
15 |
+
// Define paths and variables
|
16 |
+
define('WP_USER_AVATAR_FOLDER', basename(dirname(__FILE__)));
|
17 |
+
define('WP_USER_AVATAR_ABSPATH', trailingslashit(str_replace('\\','/', WP_PLUGIN_DIR.'/'.WP_USER_AVATAR_FOLDER)));
|
18 |
+
define('WP_USER_AVATAR_URLPATH', trailingslashit(plugins_url(WP_USER_AVATAR_FOLDER)));
|
19 |
+
|
20 |
+
// Load add-ons
|
21 |
+
include_once(WP_USER_AVATAR_ABSPATH.'includes/tinymce.php');
|
22 |
+
|
23 |
+
// Initialize default settings
|
24 |
+
register_activation_hook(__FILE__, 'wp_user_avatar_options');
|
25 |
+
|
26 |
+
// Remove user metadata on plugin delete
|
27 |
+
register_uninstall_hook(__FILE__, 'wp_user_avatar_delete_setup');
|
28 |
+
|
29 |
+
// Settings saved to wp_options
|
30 |
+
function wp_user_avatar_options(){
|
31 |
+
add_option('avatar_default_wp_user_avatar','');
|
32 |
+
}
|
33 |
+
add_action('init', 'wp_user_avatar_options');
|
34 |
+
|
35 |
+
// Remove user metadata
|
36 |
+
function wp_user_avatar_delete_setup(){
|
37 |
+
$users = get_users();
|
38 |
+
foreach($users as $user){
|
39 |
+
delete_user_meta($user->ID, 'wp_user_avatar');
|
40 |
+
}
|
41 |
+
delete_option('avatar_default_wp_user_avatar');
|
42 |
+
}
|
43 |
+
|
44 |
+
// WP User Avatar
|
45 |
+
if(!class_exists('wp_user_avatar')){
|
46 |
+
class wp_user_avatar{
|
47 |
+
function wp_user_avatar(){
|
48 |
+
// Only works if user can upload files
|
49 |
+
if(current_user_can('upload_files')){
|
50 |
+
add_action('show_user_profile', array('wp_user_avatar','action_show_user_profile'));
|
51 |
+
add_action('edit_user_profile', array($this,'action_show_user_profile'));
|
52 |
+
add_action('personal_options_update', array($this,'action_process_option_update'));
|
53 |
+
add_action('edit_user_profile_update', array($this,'action_process_option_update'));
|
54 |
+
add_action('discussion_update', array($this,'action_process_option_update'));
|
55 |
+
add_action('admin_enqueue_scripts', array($this, 'media_upload_scripts'));
|
56 |
+
}
|
57 |
+
// Only add attachment field for WP 3.4 and older
|
58 |
+
if(!function_exists('wp_enqueue_media')){
|
59 |
+
add_filter('attachment_fields_to_edit', array($this, 'add_wp_user_avatar_attachment_field_to_edit'), 10, 2);
|
60 |
+
}
|
61 |
+
// Hide column in Users table if avatars are shown
|
62 |
+
if(get_option('show_avatars') != '1'){
|
63 |
+
add_filter('manage_users_columns', array($this, 'add_wp_user_avatar_column'), 10, 1);
|
64 |
+
add_filter('manage_users_custom_column', array($this, 'show_wp_user_avatar_column'), 10, 3);
|
65 |
+
}
|
66 |
+
// Load scripts in front pages for logged in bbPress users
|
67 |
+
if(class_exists('bbPress') && is_user_logged_in() && current_user_can('upload_files')){
|
68 |
+
add_action('wp_enqueue_scripts', array($this, 'media_upload_scripts'));
|
69 |
+
}
|
70 |
+
}
|
71 |
+
|
72 |
+
// Add to edit user profile
|
73 |
+
function action_show_user_profile($user){
|
74 |
+
$wp_user_avatar = get_user_meta($user->ID, 'wp_user_avatar', true);
|
75 |
+
$hide_notice = has_wp_user_avatar($user->ID) ? ' style="display:none;"' : '';
|
76 |
+
$hide_remove = !has_wp_user_avatar($user->ID) ? ' style="display:none;"' : '';
|
77 |
+
$avatar_full_src = get_option('show_avatars') == '1' ? get_avatar_original($user->user_email, 96) : includes_url().'images/blank.gif';
|
78 |
+
$avatar_full = has_wp_user_avatar($user->ID) ? get_wp_user_avatar_src($user->ID, 'medium') : $avatar_full_src;
|
79 |
+
global $current_user;
|
80 |
+
$profile = $current_user->ID == $user->ID ? 'Profile' : 'User';
|
81 |
+
?>
|
82 |
+
<?php if(is_admin()) : ?>
|
83 |
+
<h3><?php _e('WP User Avatar') ?></h3>
|
84 |
+
<table class="form-table">
|
85 |
+
<tr>
|
86 |
+
<th><label for="wp_user_avatar"><?php _e('WP User Avatar'); ?></label></th>
|
87 |
+
<td>
|
88 |
+
<input type="hidden" name="wp-user-avatar" id="wp-user-avatar" value="<?php echo $wp_user_avatar; ?>" />
|
89 |
+
<p><button type="button" class="button" id="add-wp-user-avatar"><?php _e('Edit WP User Avatar'); ?></button></p>
|
90 |
+
<p id="wp-user-avatar-preview"><?php echo '<img src="'.$avatar_full.'" alt="" />'; ?></p>
|
91 |
+
<?php if(get_option('show_avatars') == '1') : ?>
|
92 |
+
<p id="wp-user-avatar-notice"<?php echo $hide_notice; ?>>This is your default avatar.</p>
|
93 |
+
<?php endif; ?>
|
94 |
+
<p><button type="button" class="button" id="remove-wp-user-avatar"<?php echo $hide_remove; ?>><?php _e('Remove'); ?></button></p>
|
95 |
+
<p id="wp-user-avatar-message"><?php _e('Press "Update '.$profile.'" to save your changes.'); ?></p>
|
96 |
+
</td>
|
97 |
+
</tr>
|
98 |
+
</table>
|
99 |
+
<?php elseif(class_exists('bbPress')) : ?>
|
100 |
+
<h2 class="entry-title"><?php _e('WP User Avatar'); ?></h2>
|
101 |
+
<fieldset class="bbp-form">
|
102 |
+
<legend><?php _e('WP User Avatar'); ?></legend>
|
103 |
+
<input type="hidden" name="wp-user-avatar" id="wp-user-avatar" value="<?php echo $wp_user_avatar; ?>" />
|
104 |
+
<p><button type="button" class="button" id="add-wp-user-avatar"><?php _e('Edit WP User Avatar'); ?></button></p>
|
105 |
+
<p id="wp-user-avatar-preview"><?php echo '<img src="'.$avatar_full.'" alt="" />'; ?></p>
|
106 |
+
<?php if(get_option('show_avatars') == '1') : ?>
|
107 |
+
<p id="wp-user-avatar-notice"<?php echo $hide_notice; ?>>This is your default avatar.</p>
|
108 |
+
<?php endif; ?>
|
109 |
+
<p><button type="button" class="button" id="remove-wp-user-avatar"<?php echo $hide_remove; ?>><?php _e('Remove'); ?></button></p>
|
110 |
+
<p id="wp-user-avatar-message"><?php _e('Press "Update '.$profile.'" to save your changes.'); ?></p>
|
111 |
+
</fieldset>
|
112 |
+
<?php endif; ?>
|
113 |
+
<?php
|
114 |
+
echo edit_default_wp_user_avatar($user->display_name, $avatar_full_src, $avatar_full_src);
|
115 |
+
}
|
116 |
+
|
117 |
+
// Update user meta
|
118 |
+
function action_process_option_update($user_id){
|
119 |
+
update_user_meta($user_id, 'wp_user_avatar', (isset($_POST['wp-user-avatar']) ? $_POST['wp-user-avatar'] : ''));
|
120 |
+
}
|
121 |
+
|
122 |
+
// Add button to attach image
|
123 |
+
function add_wp_user_avatar_attachment_field_to_edit($fields, $post){
|
124 |
+
$image = wp_get_attachment_image_src($post->ID, "medium");
|
125 |
+
$button = '<button type="button" class="button" id="set-wp-user-avatar-image" onclick="setWPUserAvatar(\''.$post->ID.'\', \''.$image[0].'\')">Set WP User Avatar</button>';
|
126 |
+
$fields['wp-user-avatar'] = array(
|
127 |
+
'label' => __('WP User Avatar'),
|
128 |
+
'input' => 'html',
|
129 |
+
'html' => $button
|
130 |
+
);
|
131 |
+
return $fields;
|
132 |
+
}
|
133 |
+
|
134 |
+
// Add column to Users page
|
135 |
+
function add_wp_user_avatar_column($columns){
|
136 |
+
return $columns + array('wp-user-avatar' => __('WP User Avatar'));;
|
137 |
+
}
|
138 |
+
|
139 |
+
// Show thumbnail of wp_user_avatar
|
140 |
+
function show_wp_user_avatar_column($value, $column_name, $user_id){
|
141 |
+
$wp_user_avatar = get_user_meta($user_id, 'wp_user_avatar', true);
|
142 |
+
$wp_user_avatar_image = wp_get_attachment_image($wp_user_avatar, array(32,32));
|
143 |
+
if($column_name == 'wp-user-avatar'){
|
144 |
+
return $wp_user_avatar_image;
|
145 |
+
}
|
146 |
+
}
|
147 |
+
|
148 |
+
// Media uploader
|
149 |
+
function media_upload_scripts(){
|
150 |
+
if(!function_exists('wp_enqueue_media')){
|
151 |
+
wp_enqueue_script('media-upload');
|
152 |
+
wp_enqueue_script('thickbox');
|
153 |
+
wp_enqueue_style('thickbox');
|
154 |
+
} else {
|
155 |
+
wp_enqueue_media();
|
156 |
+
}
|
157 |
+
wp_enqueue_script('wp-user-avatar', WP_USER_AVATAR_URLPATH.'js/wp-user-avatar.js');
|
158 |
+
wp_enqueue_style('wp-user-avatar', WP_USER_AVATAR_URLPATH.'css/wp-user-avatar.css');
|
159 |
+
}
|
160 |
+
}
|
161 |
+
|
162 |
+
// Uploader scripts
|
163 |
+
function edit_default_wp_user_avatar($section, $avatar_full, $avatar_thumb){ ?>
|
164 |
+
<script type="text/javascript">
|
165 |
+
jQuery(function(){
|
166 |
+
<?php if(function_exists('wp_enqueue_media')) : // Backbone uploader for WP 3.5+ ?>
|
167 |
+
openMediaUploader("<?php echo $section; ?>");
|
168 |
+
<?php else : // Fall back to Thickbox uploader ?>
|
169 |
+
openThickboxUploader("<?php echo $section; ?>", "<?php echo get_admin_url(); ?>media-upload.php?post_id=0&type=image&tab=library&TB_iframe=1");
|
170 |
+
<?php endif; ?>
|
171 |
+
removeWPUserAvatar("<?php echo htmlspecialchars_decode($avatar_full); ?>", "<?php echo htmlspecialchars_decode($avatar_thumb); ?>");
|
172 |
+
});
|
173 |
+
</script>
|
174 |
+
<?php
|
175 |
+
}
|
176 |
+
|
177 |
+
// Add default avatar
|
178 |
+
function add_default_wp_user_avatar($avatar_list){
|
179 |
+
$avatar_default = get_option('avatar_default');
|
180 |
+
$avatar_default_wp_user_avatar = get_option('avatar_default_wp_user_avatar');
|
181 |
+
$mustache_full = WP_USER_AVATAR_URLPATH.'images/wp-user-avatar.png';
|
182 |
+
$mustache_thumb = WP_USER_AVATAR_URLPATH.'images/wp-user-avatar-32x32.png';
|
183 |
+
if(!empty($avatar_default_wp_user_avatar)){
|
184 |
+
$avatar_full_src = wp_get_attachment_image_src($avatar_default_wp_user_avatar, 'medium');
|
185 |
+
$avatar_thumb_src = wp_get_attachment_image_src($avatar_default_wp_user_avatar, array(32,32));
|
186 |
+
$avatar_full = $avatar_full_src[0];
|
187 |
+
$avatar_thumb = $avatar_thumb_src[0];
|
188 |
+
$hide_remove = '';
|
189 |
+
} else {
|
190 |
+
$avatar_full = $mustache_full;
|
191 |
+
$avatar_thumb = $mustache_thumb;
|
192 |
+
$hide_remove = ' style="display:none;"';
|
193 |
+
}
|
194 |
+
$selected_avatar = ($avatar_default == $avatar_full) ? ' checked="checked" ' : '';
|
195 |
+
$avatar_thumb_img = '<div id="wp-user-avatar-preview"><img src="'.$avatar_thumb.'" width="32" /></div>';
|
196 |
+
$wp_user_avatar_list = "\n\t<label><input type='radio' name='avatar_default' id='wp_user_avatar_radio' value='$avatar_full'$selected_avatar /> ";
|
197 |
+
$wp_user_avatar_list .= preg_replace("/src='(.+?)'/", "src='\$1&forcedefault=1'", $avatar_thumb_img);
|
198 |
+
$wp_user_avatar_list .= ' WP User Avatar</label>';
|
199 |
+
$wp_user_avatar_list .= '<p style="padding-left:15px;"><button type="button" class="button" id="add-wp-user-avatar">Edit WP User Avatar</button>';
|
200 |
+
$wp_user_avatar_list .= ' <a href="#" id="remove-wp-user-avatar"'.$hide_remove.'>Remove</a></p>';
|
201 |
+
$wp_user_avatar_list .= '<input type="hidden" id="wp-user-avatar" name="avatar_default_wp_user_avatar" value="'.$avatar_default_wp_user_avatar.'">';
|
202 |
+
$wp_user_avatar_list .= '<p id="wp-user-avatar-message">Press "Save Changes" to save your changes.</p>';
|
203 |
+
$wp_user_avatar_list .= edit_default_wp_user_avatar('Default Avatar', $mustache_full, $mustache_thumb);
|
204 |
+
return $wp_user_avatar_list.$avatar_list;
|
205 |
+
}
|
206 |
+
add_filter('default_avatar_select', 'add_default_wp_user_avatar');
|
207 |
+
|
208 |
+
// Add default avatar field to whitelist
|
209 |
+
function wp_user_avatar_whitelist_options($whitelist_options){
|
210 |
+
$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' );
|
211 |
+
return $whitelist_options;
|
212 |
+
}
|
213 |
+
add_filter('whitelist_options', 'wp_user_avatar_whitelist_options');
|
214 |
+
|
215 |
+
// Returns true if user has wp_user_avatar
|
216 |
+
function has_wp_user_avatar($user_id = ''){
|
217 |
+
global $post;
|
218 |
+
if(empty($user_id)){
|
219 |
+
$author_name = get_query_var('author_name');
|
220 |
+
$user = is_author() ? get_user_by('slug', $author_name) : get_the_author_meta('ID');
|
221 |
+
$user_id = $user->ID;
|
222 |
+
}
|
223 |
+
$wp_user_avatar = get_user_meta($user_id, 'wp_user_avatar', true);
|
224 |
+
if(!empty($wp_user_avatar)){
|
225 |
+
return true;
|
226 |
+
}
|
227 |
+
}
|
228 |
+
|
229 |
+
// Find wp_user_avatar, show get_avatar if empty
|
230 |
+
function get_wp_user_avatar($id_or_email = '', $size = '96', $align = ''){
|
231 |
+
global $post, $comment;
|
232 |
+
// Find user ID on comment, author page, or post
|
233 |
+
if(is_object($id_or_email)){
|
234 |
+
$id_or_email = $comment->user_id != '0' ? $comment->user_id : $comment->comment_author_email;
|
235 |
+
$alt = $comment->comment_author;
|
236 |
+
} else {
|
237 |
+
if(!empty($id_or_email)){
|
238 |
+
$user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
|
239 |
+
} else {
|
240 |
+
$author_name = get_query_var('author_name');
|
241 |
+
if(is_author()){
|
242 |
+
$user = get_user_by('slug', $author_name);
|
243 |
+
} else {
|
244 |
+
$user_id = get_the_author_meta('ID');
|
245 |
+
$user = get_user_by('id', $user_id);
|
246 |
+
}
|
247 |
+
}
|
248 |
+
$id_or_email = !empty($user) ? $user->ID: '';
|
249 |
+
$alt = $user->display_name;
|
250 |
+
}
|
251 |
+
$wp_user_avatar_meta = !empty($id_or_email) ? get_the_author_meta('wp_user_avatar', $id_or_email) : '';
|
252 |
+
$alignclass = !empty($align) ? ' align'.$align : '';
|
253 |
+
if(!empty($wp_user_avatar_meta)){
|
254 |
+
$get_size = is_numeric($size) ? array($size,$size) : $size;
|
255 |
+
$wp_user_avatar_image = wp_get_attachment_image_src($wp_user_avatar_meta, $get_size);
|
256 |
+
$dimensions = is_numeric($size) ? ' width="'.$wp_user_avatar_image[1].'" height="'.$wp_user_avatar_image[2].'"' : '';
|
257 |
+
$wp_user_avatar = '<img src="'.$wp_user_avatar_image[0].'"'.$dimensions.' alt="'.$alt.'" class="wp-user-avatar wp-user-avatar-'.$size.$alignclass.' avatar avatar-'.$size.' photo" />';
|
258 |
+
} else {
|
259 |
+
$default = '';
|
260 |
+
$alt = '';
|
261 |
+
if($size == 'original' || $size == 'large'){
|
262 |
+
$get_size = get_option('large_size_w');
|
263 |
+
} elseif($size == 'medium'){
|
264 |
+
$get_size = get_option('medium_size_w');
|
265 |
+
} elseif($size == 'thumbnail'){
|
266 |
+
$get_size = get_option('thumbnail_size_w');
|
267 |
+
} else {
|
268 |
+
$get_size = $size;
|
269 |
+
}
|
270 |
+
$avatar = get_avatar($id_or_email, $get_size, $default, $alt);
|
271 |
+
$gravatar = str_replace("class='", "class='wp-user-avatar wp-user-avatar-".$get_size.$alignclass." ", $avatar);
|
272 |
+
$wp_user_avatar = $gravatar;
|
273 |
+
}
|
274 |
+
return $wp_user_avatar;
|
275 |
+
}
|
276 |
+
|
277 |
+
// Return just the image src
|
278 |
+
function get_wp_user_avatar_src($id_or_email, $size = '', $align = ''){
|
279 |
+
$wp_user_avatar_image = get_wp_user_avatar($id_or_email, $size, $align);
|
280 |
+
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $wp_user_avatar_image, $matches, PREG_SET_ORDER);
|
281 |
+
$wp_user_avatar_image_src = $matches [0] [1];
|
282 |
+
return $wp_user_avatar_image_src;
|
283 |
+
}
|
284 |
+
|
285 |
+
// Replace get_avatar()
|
286 |
+
function get_wp_user_avatar_alt($avatar, $id_or_email, $size = '', $default = '', $alt = false){
|
287 |
+
global $post, $pagenow, $comment;
|
288 |
+
// Find user ID on comment, author page, or post
|
289 |
+
if(is_object($id_or_email)){
|
290 |
+
$id_or_email = $comment->user_id != '0' ? $comment->user_id : $comment->comment_author_email;
|
291 |
+
$alt = $comment->comment_author;
|
292 |
+
} else {
|
293 |
+
if(!empty($id_or_email)){
|
294 |
+
$user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
|
295 |
+
} else {
|
296 |
+
$author_name = get_query_var('author_name');
|
297 |
+
if(is_author()){
|
298 |
+
$user = get_user_by('slug', $author_name);
|
299 |
+
} else {
|
300 |
+
$user_id = get_the_author_meta('ID');
|
301 |
+
$user = get_user_by('id', $user_id);
|
302 |
+
}
|
303 |
+
}
|
304 |
+
$id_or_email = $user->ID;
|
305 |
+
$alt = $user->display_name;
|
306 |
+
}
|
307 |
+
$wp_user_avatar_meta = !empty($id_or_email) ? get_the_author_meta('wp_user_avatar', $id_or_email) : '';
|
308 |
+
if(!empty($wp_user_avatar_meta) && $pagenow != 'options-discussion.php'){
|
309 |
+
$wp_user_avatar_image = wp_get_attachment_image_src($wp_user_avatar_meta, array($size,$size));
|
310 |
+
$dimensions = is_numeric($size) ? ' width="'.$wp_user_avatar_image[1].'" height="'.$wp_user_avatar_image[2].'"' : '';
|
311 |
+
$wp_user_avatar = '<img src="'.$wp_user_avatar_image[0].'"'.$dimensions.' alt="'.$alt.'" class="wp-user-avatar wp-user-avatar-'.$size.' avatar avatar-'.$size.' photo" />';
|
312 |
+
} else {
|
313 |
+
$gravatar = str_replace("class='", "class='wp-user-avatar wp-user-avatar-".$size." ", $avatar);
|
314 |
+
$wp_user_avatar = $gravatar;
|
315 |
+
}
|
316 |
+
return $wp_user_avatar;
|
317 |
+
}
|
318 |
+
add_filter('get_avatar', 'get_wp_user_avatar_alt', 10, 6);
|
319 |
+
|
320 |
+
// Shortcode
|
321 |
+
function wp_user_avatar_shortcode($atts, $content){
|
322 |
+
// EXAMPLE USAGE:
|
323 |
+
// [avatar size="medium"]
|
324 |
+
|
325 |
+
// Set shortcode attributes
|
326 |
+
extract(shortcode_atts(array('user' => '', 'size' => '96', 'align' => '', 'link' => ''), $atts));
|
327 |
+
$get_user = get_user_by('slug', $user);
|
328 |
+
$id_or_email = !empty($get_user) ? $get_user->ID : '';
|
329 |
+
if(!empty($link)){
|
330 |
+
if($link == 'file'){
|
331 |
+
$image_link = get_wp_user_avatar_src($id_or_email, 'original', $align);
|
332 |
+
$link_class = $link;
|
333 |
+
} elseif($link == 'attachment'){
|
334 |
+
$image_link = get_attachment_link(get_the_author_meta('wp_user_avatar', $id_or_email));
|
335 |
+
$link_class = $link;
|
336 |
+
} else {
|
337 |
+
$image_link = $link;
|
338 |
+
$link_class = 'custom';
|
339 |
+
}
|
340 |
+
$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>';
|
341 |
+
} else {
|
342 |
+
$wp_user_avatar = get_wp_user_avatar($id_or_email, $size, $align);
|
343 |
+
}
|
344 |
+
return $wp_user_avatar;
|
345 |
+
}
|
346 |
+
add_shortcode('avatar','wp_user_avatar_shortcode');
|
347 |
+
|
348 |
+
// Get original avatar
|
349 |
+
function get_avatar_original($id_or_email, $size = '', $default = '', $alt = false){
|
350 |
+
remove_filter('get_avatar', 'get_wp_user_avatar_alt');
|
351 |
+
$wp_user_avatar_image = get_avatar($id_or_email);
|
352 |
+
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $wp_user_avatar_image, $matches, PREG_SET_ORDER);
|
353 |
+
$wp_user_avatar_image_src = $matches [0] [1];
|
354 |
+
return $wp_user_avatar_image_src;
|
355 |
+
}
|
356 |
+
|
357 |
+
// Initialize wp_user_avatar
|
358 |
+
function wp_user_avatar_load(){
|
359 |
+
global $wp_user_avatar_instance;
|
360 |
+
$wp_user_avatar_instance = new wp_user_avatar();
|
361 |
+
}
|
362 |
+
add_action('plugins_loaded','wp_user_avatar_load');
|
363 |
+
}
|
364 |
+
?>
|