WP User Avatar - Version 1.9.4

Version Description

  • Add: Widget for [avatar_upload]
  • Add: wpua_before_avatar_admin and wpua_after_avatar_admin for admin pages
  • Bug Fix: Load functions class on plugins_loaded
  • Update: Allow non-numeric WPUA value
Download this release

Release Info

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

Code changes from version 1.5.4 to 1.9.4

Files changed (39) hide show
  1. css/wp-user-avatar.css +7 -5
  2. images/{wp-user-avatar-150x150.png → wpua-150x150.png} +0 -0
  3. images/wpua-20x20.png +0 -0
  4. images/{wp-user-avatar-300x300.png → wpua-300x300.png} +0 -0
  5. images/{wp-user-avatar-32x32.png → wpua-32x32.png} +0 -0
  6. images/{wp-user-avatar-96x96.png → wpua-96x96.png} +0 -0
  7. images/wpua-icon.png +0 -0
  8. images/{wp-user-avatar.png → wpua.png} +0 -0
  9. includes/class-wp-user-avatar-admin.php +256 -0
  10. includes/class-wp-user-avatar-functions.php +245 -0
  11. includes/class-wp-user-avatar-list-table.php +288 -0
  12. includes/class-wp-user-avatar-shortcode.php +162 -0
  13. includes/class-wp-user-avatar-subscriber.php +84 -0
  14. includes/class-wp-user-avatar-update.php +77 -0
  15. includes/class-wp-user-avatar-widget.php +56 -0
  16. includes/class-wp-user-avatar.php +312 -0
  17. includes/tinymce/editor_plugin.js +1 -1
  18. includes/tinymce/window.php +122 -71
  19. includes/wpua-functions.php +124 -0
  20. includes/wpua-globals.php +80 -0
  21. includes/wpua-media-page.php +85 -0
  22. includes/wpua-options-page.php +165 -0
  23. includes/{tinymce.php → wpua-tinymce.php} +12 -17
  24. js/wp-user-avatar-admin.js +25 -22
  25. js/wp-user-avatar-user.js +31 -0
  26. js/wp-user-avatar.js +1 -1
  27. lang/wp-user-avatar-de_DE.mo +0 -0
  28. lang/wp-user-avatar-de_DE.po +35 -15
  29. lang/wp-user-avatar-es_ES.mo +0 -0
  30. lang/wp-user-avatar-es_ES.po +35 -15
  31. lang/wp-user-avatar-fr_FR.mo +0 -0
  32. lang/wp-user-avatar-fr_FR.po +35 -15
  33. lang/wp-user-avatar-pl_PL.mo +0 -0
  34. lang/wp-user-avatar-pl_PL.po +81 -0
  35. lang/wp-user-avatar-sv_SE.mo +0 -0
  36. lang/wp-user-avatar-sv_SE.po +35 -15
  37. readme.txt +319 -33
  38. uninstall.php +20 -10
  39. wp-user-avatar.php +37 -961
css/wp-user-avatar.css CHANGED
@@ -1,11 +1,13 @@
1
- #wpua-errors, #wpua-message, #wpua-readable-size-error, .wpua-error { color: #c00 !important; font-weight: 700 !important; }
2
- #wpua-message, #wpua-readable-size-error { display: none; }
3
#wpua-preview, #wpua-thumbnail { display: inline-block; text-align: center; vertical-align: top; }
4
- #wpua-preview { margin-right: 10px !important; }
5
#wpua-preview img, #wpua-thumbnail img { max-height: 96px; border: 1px solid #dfdfdf; display: block; }
6
.defaultavatarpicker #wpua-preview { width: 32px; height: 32px; margin-right: 0; display: inline-block; overflow: hidden; vertical-align: middle; }
7
.defaultavatarpicker #wpua-preview img { width: 32px; height: auto; border: 0; }
8
- #wpua-edit { padding-left: 15px !important; }
9
- #wpua-edit #wpua-remove { margin-left: 10px !important; }
10
#wpua-slider { width: 22.75em; }
11
.wpua-hide { display: none !important; }
1
+ #wpua-errors, #wpua-readable-size-error, .wpua-error { color: #c00 !important; font-weight: 700 !important; }
2
+ #wpua-readable-size-error, #wpua-undo-button { display: none; }
3
+ #wpua-preview { margin-right: 10px; }
4
#wpua-preview, #wpua-thumbnail { display: inline-block; text-align: center; vertical-align: top; }
5
#wpua-preview img, #wpua-thumbnail img { max-height: 96px; border: 1px solid #dfdfdf; display: block; }
6
+ .widget_wp_user_avatar #wpua-preview img, .widget_wp_user_avatar #wpua-thumbnail img { max-height: 64px; }
7
.defaultavatarpicker #wpua-preview { width: 32px; height: 32px; margin-right: 0; display: inline-block; overflow: hidden; vertical-align: middle; }
8
.defaultavatarpicker #wpua-preview img { width: 32px; height: auto; border: 0; }
9
+ #wpua-edit #wpua-remove, #wpua-edit #wpua-undo, #wpua-edit-attachment { margin-left: 10px !important; }
10
#wpua-slider { width: 22.75em; }
11
+ #wpua-upload-messages span { display: block; }
12
.wpua-hide { display: none !important; }
13
+ .wpua-no-avatars { display: none; }
images/{wp-user-avatar-150x150.png → wpua-150x150.png} RENAMED
File without changes
images/wpua-20x20.png ADDED
Binary file
images/{wp-user-avatar-300x300.png → wpua-300x300.png} RENAMED
File without changes
images/{wp-user-avatar-32x32.png → wpua-32x32.png} RENAMED
File without changes
images/{wp-user-avatar-96x96.png → wpua-96x96.png} RENAMED
File without changes
images/wpua-icon.png ADDED
Binary file
images/{wp-user-avatar.png → wpua.png} RENAMED
File without changes
includes/class-wp-user-avatar-admin.php ADDED
@@ -0,0 +1,256 @@
1
+ <?php
2
+ /**
3
+ * Defines all of administrative, activation, and deactivation settings.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.4
7
+ */
8
+
9
+ class WP_User_Avatar_Admin {
10
+ public function __construct() {
11
+ global $show_avatars, $wpua_allow_upload, $wpua_tinymce;
12
+ // Initialize default settings
13
+ register_activation_hook(WPUA_DIR.'wp-user-avatar.php', array($this, 'wpua_options'));
14
+ // Settings saved to wp_options
15
+ add_action('admin_init', array($this, 'wpua_options'));
16
+ // Remove subscribers edit_posts capability
17
+ register_deactivation_hook(WPUA_DIR.'wp-user-avatar.php', array($this, 'wpua_deactivate'));
18
+ // Translations
19
+ load_plugin_textdomain('wp-user-avatar', "", WPUA_FOLDER.'/lang');
20
+ // Admin menu settings
21
+ add_action('admin_menu', array($this, 'wpua_admin'));
22
+ add_action('admin_init', array($this, 'wpua_register_settings'));
23
+ // Default avatar
24
+ add_filter('default_avatar_select', array($this, 'wpua_add_default_avatar'), 10);
25
+ add_filter('whitelist_options', array($this, 'wpua_whitelist_options'), 10);
26
+ // Additional plugin info
27
+ add_filter('plugin_action_links', array($this, 'wpua_action_links'), 10, 2);
28
+ add_filter('plugin_row_meta', array($this, 'wpua_row_meta'), 10, 2);
29
+ // Hide column in Users table if default avatars are enabled
30
+ if((bool) $show_avatars == 0 && is_admin()) {
31
+ add_filter('manage_users_columns', array($this, 'wpua_add_column'), 10, 1);
32
+ add_filter('manage_users_custom_column', array($this, 'wpua_show_column'), 10, 3);
33
+ }
34
+ // Media states
35
+ add_filter('display_media_states', array($this, 'wpua_add_media_state'), 10, 1);
36
+ // Load TinyMCE only if enabled
37
+ if((bool) $wpua_tinymce == 1) {
38
+ include_once(WPUA_INC.'wpua-tinymce.php');
39
+ }
40
+ }
41
+
42
+ // Settings saved to wp_options
43
+ public function wpua_options() {
44
+ add_option('avatar_default_wp_user_avatar', "");
45
+ add_option('wp_user_avatar_allow_upload', '0');
46
+ add_option('wp_user_avatar_disable_gravatar', '0');
47
+ add_option('wp_user_avatar_edit_avatar', '1');
48
+ add_option('wp_user_avatar_resize_crop', '0');
49
+ add_option('wp_user_avatar_resize_h', '96');
50
+ add_option('wp_user_avatar_resize_upload', '0');
51
+ add_option('wp_user_avatar_resize_w', '96');
52
+ add_option('wp_user_avatar_tinymce', '1');
53
+ add_option('wp_user_avatar_upload_size_limit', '0');
54
+ }
55
+
56
+ // On deactivation
57
+ public function wpua_deactivate() {
58
+ global $blog_id, $wpdb;
59
+ $wp_user_roles = $wpdb->get_blog_prefix($blog_id).'user_roles';
60
+ $user_roles = get_option($wp_user_roles);
61
+ // Remove subscribers edit_posts capability
62
+ unset($user_roles['subscriber']['capabilities']['edit_posts']);
63
+ update_option($wp_user_roles, $user_roles);
64
+ // Reset all default avatar to Mystery Man
65
+ update_option('avatar_default', 'mystery');
66
+ }
67
+
68
+ // Add options page and settings
69
+ public function wpua_admin() {
70
+ add_menu_page(__('WP User Avatar', 'wp-user-avatar'), __('Avatars'), 'manage_options', 'wp-user-avatar', array($this, 'wpua_options_page'), WPUA_URL.'images/wpua-icon.png');
71
+ add_submenu_page('wp-user-avatar', __('Settings'), __('Settings'), 'manage_options', 'wp-user-avatar', array($this, 'wpua_options_page'));
72
+ $hook = add_submenu_page('wp-user-avatar', __('Library'), __('Library'), 'manage_options', 'wp-user-avatar-library', array($this, 'wpua_media_page'));
73
+ add_action("load-$hook", array($this, 'wpua_media_screen_option'));
74
+ add_filter('set-screen-option', array($this, 'wpua_set_media_screen_option'), 10, 3);
75
+
76
+ }
77
+
78
+ // Checks if current page is settings page
79
+ public function wpua_is_menu_page() {
80
+ global $pagenow;
81
+ $is_menu_page = ($pagenow == 'admin.php' && isset($_GET['page']) && $_GET['page'] == 'wp-user-avatar') ? true : false;
82
+ return $is_menu_page;
83
+ }
84
+
85
+ // Media page
86
+ public function wpua_media_page() {
87
+ require_once(WPUA_INC.'wpua-media-page.php');
88
+ }
89
+
90
+ // Avatars per page
91
+ public function wpua_media_screen_option() {
92
+ $option = 'per_page';
93
+ $args = array(
94
+ 'label' => __('Avatars'),
95
+ 'default' => 10,
96
+ 'option' => 'upload_per_page'
97
+ );
98
+ add_screen_option($option, $args);
99
+ }
100
+
101
+ // Save per page setting
102
+ public function wpua_set_media_screen_option($status, $option, $value) {
103
+ if($option == 'upload_per_page') {
104
+ return $value;
105
+ }
106
+ return $status;
107
+ }
108
+
109
+ // Options page
110
+ public function wpua_options_page() {
111
+ require_once(WPUA_INC.'wpua-options-page.php');
112
+ }
113
+
114
+ // Whitelist settings
115
+ public function wpua_register_settings() {
116
+ $settings = array();
117
+ $settings[] = register_setting('wpua-settings-group', 'avatar_rating');
118
+ $settings[] = register_setting('wpua-settings-group', 'avatar_default');
119
+ $settings[] = register_setting('wpua-settings-group', 'avatar_default_wp_user_avatar');
120
+ $settings[] = register_setting('wpua-settings-group', 'show_avatars', 'intval');
121
+ $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_tinymce', 'intval');
122
+ $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_allow_upload', 'intval');
123
+ $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_disable_gravatar', 'intval');
124
+ $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_edit_avatar', 'intval');
125
+ $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_resize_crop', 'intval');
126
+ $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_resize_h', 'intval');
127
+ $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_resize_upload', 'intval');
128
+ $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_resize_w', 'intval');
129
+ $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_upload_size_limit', 'intval');
130
+ return apply_filters('wpua_register_settings', $settings);
131
+ }
132
+
133
+ // Add default avatar
134
+ public function wpua_add_default_avatar($avatar_list=null) {
135
+ global $avatar_default, $mustache_admin, $mustache_medium, $wpua_avatar_default, $wpua_disable_gravatar, $wpua_functions;
136
+ // Remove get_avatar filter
137
+ remove_filter('get_avatar', array($wpua_functions, 'wpua_get_avatar_filter'));
138
+ // Set avatar_list variable
139
+ $avatar_list = "";
140
+ // Set avatar defaults
141
+ $avatar_defaults = array(
142
+ 'mystery' => __('Mystery Man'),
143
+ 'blank' => __('Blank'),
144
+ 'gravatar_default' => __('Gravatar Logo'),
145
+ 'identicon' => __('Identicon (Generated)'),
146
+ 'wavatar' => __('Wavatar (Generated)'),
147
+ 'monsterid' => __('MonsterID (Generated)'),
148
+ 'retro' => __('Retro (Generated)')
149
+ );
150
+ // No Default Avatar, set to Mystery Man
151
+ if(empty($avatar_default)) {
152
+ $avatar_default = 'mystery';
153
+ }
154
+ // Take avatar_defaults and get examples for unknown@gravatar.com
155
+ foreach($avatar_defaults as $default_key => $default_name) {
156
+ $avatar = get_avatar('unknown@gravatar.com', 32, $default_key);
157
+ $selected = ($avatar_default == $default_key) ? 'checked="checked" ' : "";
158
+ $avatar_list .= "\n\t<label><input type='radio' name='avatar_default' id='avatar_{$default_key}' value='".esc_attr($default_key)."' {$selected}/> ";
159
+ $avatar_list .= preg_replace("/src='(.+?)'/", "src='\$1&amp;forcedefault=1'", $avatar);
160
+ $avatar_list .= ' '.$default_name.'</label>';
161
+ $avatar_list .= '<br />';
162
+ }
163
+ // Show remove link if custom Default Avatar is set
164
+ if(!empty($wpua_avatar_default) && $wpua_functions->wpua_attachment_is_image($wpua_avatar_default)) {
165
+ $avatar_thumb_src = $wpua_functions->wpua_get_attachment_image_src($wpua_avatar_default, array(32,32));
166
+ $avatar_thumb = $avatar_thumb_src[0];
167
+ $hide_remove = "";
168
+ } else {
169
+ $avatar_thumb = $mustache_admin;
170
+ $hide_remove = ' class="wpua-hide"';
171
+ }
172
+ // Default Avatar is wp_user_avatar, check the radio button next to it
173
+ $selected_avatar = ((bool) $wpua_disable_gravatar == 1 || $avatar_default == 'wp_user_avatar') ? ' checked="checked" ' : "";
174
+ // Wrap WPUA in div
175
+ $avatar_thumb_img = '<div id="wpua-preview"><img src="'.$avatar_thumb.'" width="32" /></div>';
176
+ // Add WPUA to list
177
+ $wpua_list = "\n\t<label><input type='radio' name='avatar_default' id='wp_user_avatar_radio' value='wp_user_avatar'$selected_avatar /> ";
178
+ $wpua_list .= preg_replace("/src='(.+?)'/", "src='\$1'", $avatar_thumb_img);
179
+ $wpua_list .= ' '.__('WP User Avatar', 'wp-user-avatar').'</label>';
180
+ $wpua_list .= '<p id="wpua-edit"><button type="button" class="button" id="wpua-add" name="wpua-add" data-avatar_default="true" data-title="'._('Choose Image').': '._('Default Avatar').'">'.__('Choose Image').'</button>';
181
+ $wpua_list .= '<span id="wpua-remove-button"'.$hide_remove.'><a href="#" id="wpua-remove">'.__('Remove').'</a></span><span id="wpua-undo-button"><a href="#" id="wpua-undo">'.__('Undo').'</a></span></p>';
182
+ $wpua_list .= '<input type="hidden" id="wp-user-avatar" name="avatar_default_wp_user_avatar" value="'.$wpua_avatar_default.'">';
183
+ $wpua_list .= '<div id="wpua-modal"></div>';
184
+ if((bool) $wpua_disable_gravatar != 1) {
185
+ return $wpua_list.'<div id="wp-avatars">'.$avatar_list.'</div>';
186
+ } else {
187
+ return $wpua_list;
188
+ }
189
+ }
190
+
191
+ // Add default avatar_default to whitelist
192
+ public function wpua_whitelist_options($options) {
193
+ $options['discussion'][] = 'avatar_default_wp_user_avatar';
194
+ return $options;
195
+ }
196
+
197
+ // Add actions links on plugin page
198
+ public function wpua_action_links($links, $file) {
199
+ if(basename(dirname($file)) == 'wp-user-avatar') {
200
+ $links[] = '<a href="'.add_query_arg(array('page' => 'wp-user-avatar'), admin_url('admin.php')).'">'.__('Settings').'</a>';
201
+ }
202
+ return $links;
203
+ }
204
+
205
+ // Add row meta on plugin page
206
+ public function wpua_row_meta($links, $file) {
207
+ if(basename(dirname($file)) == 'wp-user-avatar') {
208
+ $links[] = '<a href="http://wordpress.org/support/plugin/wp-user-avatar" target="_blank">'.__('Support Forums').'</a>';
209
+ $links[] = '<a href="http://siboliban.org/donate" target="_blank">'.__('Donate', 'wp-user-avatar').'</a>';
210
+ }
211
+ return $links;
212
+ }
213
+
214
+ // Add column to Users table
215
+ public function wpua_add_column($columns) {
216
+ return $columns + array('wp-user-avatar' => __('WP User Avatar', 'wp-user-avatar'));
217
+ }
218
+
219
+ // Show thumbnail in Users table
220
+ public function wpua_show_column($value, $column_name, $user_id) {
221
+ global $blog_id, $wpdb;
222
+ $wpua = get_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', true);
223
+ $wpua_image = wp_get_attachment_image($wpua, array(32,32));
224
+ if($column_name == 'wp-user-avatar') {
225
+ $value = $wpua_image;
226
+ }
227
+ return $value;
228
+ }
229
+
230
+ // Get list table
231
+ public function _wpua_get_list_table($class, $args = array()) {
232
+ require_once(WPUA_INC.'class-wp-user-avatar-list-table.php');
233
+ $args['screen'] = 'wp-user-avatar';
234
+ return new $class($args);
235
+ }
236
+
237
+ // Add media states
238
+ public function wpua_add_media_state($states) {
239
+ global $post, $wpua_avatar_default;
240
+ $is_wpua = get_post_custom_values('_wp_attachment_wp_user_avatar', $post->ID);
241
+ if(!empty($is_wpua)) {
242
+ $states[] = __('Avatar');
243
+ }
244
+ if(!empty($wpua_avatar_default) && ($wpua_avatar_default == $post->ID)) {
245
+ $states[] = __('Default Avatar');
246
+ }
247
+ return apply_filters('wpua_add_media_state', $states);
248
+ }
249
+ }
250
+
251
+ // Initialize WP_User_Avatar_Admin
252
+ function wpua_admin_init() {
253
+ global $wpua_admin;
254
+ $wpua_admin = new WP_User_Avatar_Admin();
255
+ }
256
+ add_action('init', 'wpua_admin_init');
includes/class-wp-user-avatar-functions.php ADDED
@@ -0,0 +1,245 @@
1
+ <?php
2
+ /**
3
+ * Core user functions.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.4
7
+ */
8
+
9
+ class WP_User_Avatar_Functions {
10
+ public function __construct() {
11
+ add_filter('get_avatar', array($this, 'wpua_get_avatar_filter'), 10, 5);
12
+ }
13
+
14
+ // Returns true if user has Gravatar-hosted image
15
+ public function wpua_has_gravatar($id_or_email="", $has_gravatar=false, $user="", $email="") {
16
+ if(!is_object($id_or_email) && !empty($id_or_email)) {
17
+ // Find user by ID or e-mail address
18
+ $user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
19
+ // Get registered user e-mail address
20
+ $email = !empty($user) ? $user->user_email : "";
21
+ }
22
+ // Check if Gravatar image returns 200 (OK) or 404 (Not Found)
23
+ $hash = md5(strtolower(trim($email)));
24
+ $gravatar = 'http://www.gravatar.com/avatar/'.$hash.'?d=404';
25
+ $data = wp_cache_get($hash);
26
+ if(false === $data) {
27
+ $response = wp_remote_head($gravatar);
28
+ $data = is_wp_error($response) ? 'not200' : $response['response']['code'];
29
+ wp_cache_set($hash, $data, $group="", $expire=60*5);
30
+ }
31
+ $has_gravatar = ($data == '200') ? true : false;
32
+ return $has_gravatar;
33
+ }
34
+
35
+ // Check if local image
36
+ public function wpua_attachment_is_image($attachment_id) {
37
+ $is_image = wp_attachment_is_image($attachment_id);
38
+ $is_image = apply_filters('wpua_attachment_is_image', $is_image, $attachment_id);
39
+ return $is_image;
40
+ }
41
+
42
+ // Get image src
43
+ public function wpua_get_attachment_image_src($attachment_id, $size='thumbnail', $icon=false) {
44
+ $image_src_array = wp_get_attachment_image_src($attachment_id, $size, $icon);
45
+ return apply_filters('wpua_get_attachment_image_src', $image_src_array, $attachment_id, $size, $icon);
46
+ }
47
+
48
+ // Returns true if user has wp_user_avatar
49
+ public function has_wp_user_avatar($id_or_email="", $has_wpua=false, $user="", $user_id="") {
50
+ global $blog_id, $wpdb, $wpua_avatar_default, $wpua_functions;
51
+ if(!is_object($id_or_email) && !empty($id_or_email)) {
52
+ // Find user by ID or e-mail address
53
+ $user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
54
+ // Get registered user ID
55
+ $user_id = !empty($user) ? $user->ID : "";
56
+ }
57
+ $wpua = get_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', true);
58
+ // Check if avatar is same as default avatar or on excluded list
59
+ $has_wpua = !empty($wpua) && ($wpua != $wpua_avatar_default) && $wpua_functions->wpua_attachment_is_image($wpua) ? true : false;
60
+ return $has_wpua;
61
+ }
62
+
63
+ // Replace get_avatar only in get_wp_user_avatar
64
+ public function wpua_get_avatar_filter($avatar, $id_or_email="", $size="", $default="", $alt="") {
65
+ global $avatar_default, $mustache_admin, $mustache_avatar, $mustache_medium, $mustache_original, $mustache_thumbnail, $post, $wpua_avatar_default, $wpua_disable_gravatar, $wpua_functions;
66
+ // User has WPUA
67
+ if(is_object($id_or_email)) {
68
+ if(!empty($id_or_email->comment_author_email)) {
69
+ $avatar = get_wp_user_avatar($id_or_email, $size, $default, $alt);
70
+ } else {
71
+ $avatar = get_wp_user_avatar('unknown@gravatar.com', $size, $default, $alt);
72
+ }
73
+ } else {
74
+ if(has_wp_user_avatar($id_or_email)) {
75
+ $avatar = get_wp_user_avatar($id_or_email, $size, $default, $alt);
76
+ // User has Gravatar and Gravatar is not disabled
77
+ } elseif((bool) $wpua_disable_gravatar != 1 && $wpua_functions->wpua_has_gravatar($id_or_email)) {
78
+ $avatar = $avatar;
79
+ // User doesn't have WPUA or Gravatar and Default Avatar is wp_user_avatar, show custom Default Avatar
80
+ } elseif($avatar_default == 'wp_user_avatar') {
81
+ // Show custom Default Avatar
82
+ if(!empty($wpua_avatar_default) && $wpua_functions->wpua_attachment_is_image($wpua_avatar_default)) {
83
+ // Get image
84
+ $wpua_avatar_default_image = $wpua_functions->wpua_get_attachment_image_src($wpua_avatar_default, array($size,$size));
85
+ // Image src
86
+ $default = $wpua_avatar_default_image[0];
87
+ // Add dimensions if numeric size
88
+ $dimensions = ' width="'.$wpua_avatar_default_image[1].'" height="'.$wpua_avatar_default_image[2].'"';
89
+ } else {
90
+ // Get mustache image based on numeric size comparison
91
+ if($size > get_option('medium_size_w')) {
92
+ $default = $mustache_original;
93
+ } elseif($size <= get_option('medium_size_w') && $size > get_option('thumbnail_size_w')) {
94
+ $default = $mustache_medium;
95
+ } elseif($size <= get_option('thumbnail_size_w') && $size > 96) {
96
+ $default = $mustache_thumbnail;
97
+ } elseif($size <= 96 && $size > 32) {
98
+ $default = $mustache_avatar;
99
+ } elseif($size <= 32) {
100
+ $default = $mustache_admin;
101
+ }
102
+ // Add dimensions if numeric size
103
+ $dimensions = ' width="'.$size.'" height="'.$size.'"';
104
+ }
105
+ // Construct the img tag
106
+ $avatar = '<img src="'.$default.'"'.$dimensions.' alt="'.$alt.'" class="avatar avatar-'.$size.' wp-user-avatar wp-user-avatar-'.$size.' photo avatar-default" />';
107
+ }
108
+ }
109
+ return apply_filters('wpua_get_avatar_filter', $avatar, $id_or_email, $size, $default, $alt);
110
+ }
111
+
112
+ // Get original avatar, for when user removes wp_user_avatar
113
+ public function wpua_get_avatar_original($id_or_email="", $size="", $default="", $alt="") {
114
+ global $avatar_default, $mustache_avatar, $wpua_avatar_default, $wpua_disable_gravatar, $wpua_functions;
115
+ // Remove get_avatar filter
116
+ remove_filter('get_avatar', array($wpua_functions, 'wpua_get_avatar_filter'));
117
+ if((bool) $wpua_disable_gravatar != 1) {
118
+ // User doesn't have Gravatar and Default Avatar is wp_user_avatar, show custom Default Avatar
119
+ if(!$wpua_functions->wpua_has_gravatar($id_or_email) && $avatar_default == 'wp_user_avatar') {
120
+ // Show custom Default Avatar
121
+ if(!empty($wpua_avatar_default) && $wpua_functions->wpua_attachment_is_image($wpua_avatar_default)) {
122
+ $wpua_avatar_default_image = $wpua_functions->wpua_get_attachment_image_src($wpua_avatar_default, array($size,$size));
123
+ $default = $wpua_avatar_default_image[0];
124
+ } else {
125
+ $default = $mustache_avatar;
126
+ }
127
+ } else {
128
+ // Get image from Gravatar, whether it's the user's image or default image
129
+ $wpua_image = get_avatar($id_or_email, $size);
130
+ // Takes the img tag, extracts the src
131
+ $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $wpua_image, $matches, PREG_SET_ORDER);
132
+ $default = !empty($matches) ? $matches [0] [1] : "";
133
+ }
134
+ } else {
135
+ if(!empty($wpua_avatar_default) && $wpua_functions->wpua_attachment_is_image($wpua_avatar_default)) {
136
+ $wpua_avatar_default_image = $wpua_functions->wpua_get_attachment_image_src($wpua_avatar_default, array($size,$size));
137
+ $default = $wpua_avatar_default_image[0];
138
+ } else {
139
+ $default = $mustache_avatar;
140
+ }
141
+ }
142
+ // Enable get_avatar filter
143
+ add_filter('get_avatar', array($wpua_functions, 'wpua_get_avatar_filter'), 10, 5);
144
+ return apply_filters('wpua_get_avatar_original', $default);
145
+ }
146
+
147
+ // Find WPUA, show get_avatar if empty
148
+ public function get_wp_user_avatar($id_or_email="", $size='96', $align="", $alt="") {
149
+ global $all_sizes, $avatar_default, $blog_id, $post, $wpdb, $wpua_avatar_default, $wpua_functions, $_wp_additional_image_sizes;
150
+ $email='unknown@gravatar.com';
151
+ // Checks if comment
152
+ if(is_object($id_or_email)) {
153
+ // Checks if comment author is registered user by user ID
154
+ if($id_or_email->user_id != 0) {
155
+ $email = $id_or_email->user_id;
156
+ // Checks that comment author isn't anonymous
157
+ } elseif(!empty($id_or_email->comment_author_email)) {
158
+ // Checks if comment author is registered user by e-mail address
159
+ $user = get_user_by('email', $id_or_email->comment_author_email);
160
+ // Get registered user info from profile, otherwise e-mail address should be value
161
+ $email = !empty($user) ? $user->ID : $id_or_email->comment_author_email;
162
+ }
163
+ $alt = $id_or_email->comment_author;
164
+ } else {
165
+ if(!empty($id_or_email)) {
166
+ // Find user by ID or e-mail address
167
+ $user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
168
+ } else {
169
+ // Find author's name if id_or_email is empty
170
+ $author_name = get_query_var('author_name');
171
+ if(is_author()) {
172
+ // On author page, get user by page slug
173
+ $user = get_user_by('slug', $author_name);
174
+ } else {
175
+ // On post, get user by author meta
176
+ $user_id = get_the_author_meta('ID');
177
+ $user = get_user_by('id', $user_id);
178
+ }
179
+ }
180
+ // Set user's ID and name
181
+ if(!empty($user)) {
182
+ $email = $user->ID;
183
+ $alt = $user->display_name;
184
+ }
185
+ }
186
+ // Checks if user has WPUA
187
+ $wpua_meta = get_the_author_meta($wpdb->get_blog_prefix($blog_id).'user_avatar', $email);
188
+ // Add alignment class
189
+ $alignclass = !empty($align) && ($align == 'left' || $align == 'right' || $align == 'center') ? ' align'.$align : ' alignnone';
190
+ // User has WPUA, check if on excluded list and bypass get_avatar
191
+ if(!empty($wpua_meta) && $wpua_functions->wpua_attachment_is_image($wpua_meta)) {
192
+ // Numeric size use size array
193
+ $get_size = is_numeric($size) ? array($size,$size) : $size;
194
+ // Get image src
195
+ $wpua_image = $wpua_functions->wpua_get_attachment_image_src($wpua_meta, $get_size);
196
+ // Add dimensions to img only if numeric size was specified
197
+ $dimensions = is_numeric($size) ? ' width="'.$wpua_image[1].'" height="'.$wpua_image[2].'"' : "";
198
+ // Construct the img tag
199
+ $avatar = '<img src="'.$wpua_image[0].'"'.$dimensions.' alt="'.$alt.'" class="avatar avatar-'.$size.' wp-user-avatar wp-user-avatar-'.$size.$alignclass.' photo" />';
200
+ } else {
201
+ // Check for custom image sizes
202
+ if(in_array($size, $all_sizes)) {
203
+ if(in_array($size, array('original', 'large', 'medium', 'thumbnail'))) {
204
+ $get_size = ($size == 'original') ? get_option('large_size_w') : get_option($size.'_size_w');
205
+ } else {
206
+ $get_size = $_wp_additional_image_sizes[$size]['width'];
207
+ }
208
+ } else {
209
+ // Numeric sizes leave as-is
210
+ $get_size = $size;
211
+ }
212
+ // User with no WPUA uses get_avatar
213
+ $avatar = get_avatar($email, $get_size, $default="", $alt="");
214
+ // Remove width and height for non-numeric sizes
215
+ if(in_array($size, array('original', 'large', 'medium', 'thumbnail'))) {
216
+ $avatar = preg_replace('/(width|height)=\"\d*\"\s/', "", $avatar);
217
+ $avatar = preg_replace("/(width|height)=\'\d*\'\s/", "", $avatar);
218
+ }
219
+ $str_replace = array('wp-user-avatar ', 'wp-user-avatar-'.$get_size.' ', 'wp-user-avatar-'.$size.' ', 'avatar-'.$get_size, 'photo');
220
+ $str_replacements = array("", "", "", 'avatar-'.$size, 'wp-user-avatar wp-user-avatar-'.$size.$alignclass.' photo');
221
+ $avatar = str_replace($str_replace, $str_replacements, $avatar);
222
+ }
223
+ return apply_filters('get_wp_user_avatar', $avatar, $id_or_email, $size, $align, $alt);
224
+ }
225
+
226
+ // Return just the image src
227
+ public function get_wp_user_avatar_src($id_or_email="", $size="", $align="") {
228
+ $wpua_image_src = "";
229
+ // Gets the avatar img tag
230
+ $wpua_image = get_wp_user_avatar($id_or_email, $size, $align);
231
+ // Takes the img tag, extracts the src
232
+ if(!empty($wpua_image)) {
233
+ $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $wpua_image, $matches, PREG_SET_ORDER);
234
+ $wpua_image_src = !empty($matches) ? $matches [0] [1] : "";
235
+ }
236
+ return $wpua_image_src;
237
+ }
238
+ }
239
+
240
+ // Initialize WP_User_Avatar_Functions
241
+ function wpua_functions_init() {
242
+ global $wpua_functions;
243
+ $wpua_functions = new WP_User_Avatar_Functions();
244
+ }
245
+ add_action('plugins_loaded', 'wpua_functions_init');
includes/class-wp-user-avatar-list-table.php ADDED
@@ -0,0 +1,288 @@
1
+ <?php
2
+ /**
3
+ * Based on WP_Media_List_Table class.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.4
7
+ */
8
+
9
+ class WP_User_Avatar_List_Table extends WP_List_Table {
10
+ public function __construct($args = array()) {
11
+ global $avatars_array, $post, $wpua_avatar_default;
12
+ $paged = (get_query_var('page')) ? get_query_var('page') : 1;
13
+ $q = array(
14
+ 'paged' => $paged,
15
+ 'post_type' => 'attachment',
16
+ 'post_status' => 'inherit',
17
+ 'posts_per_page' => '-1',
18
+ 'meta_query' => array(
19
+ array(
20
+ 'key' => '_wp_attachment_wp_user_avatar',
21
+ 'value' => "",
22
+ 'compare' => '!='
23
+ )
24
+ )
25
+ );
26
+ $avatars_wp_query = new WP_Query($q);
27
+ $avatars_array = array();
28
+ while($avatars_wp_query->have_posts()) : $avatars_wp_query->the_post();
29
+ $avatars_array[] = $post->ID;
30
+ endwhile;
31
+ wp_reset_query();
32
+ // Include default avatar
33
+ $avatars_array[] = $wpua_avatar_default;
34
+ parent::__construct(array(
35
+ 'plural' => 'media',
36
+ 'screen' => isset($args['screen']) ? $args['screen'] : null
37
+ ));
38
+ }
39
+
40
+ public function ajax_user_can() {
41
+ return current_user_can('upload_files');
42
+ }
43
+
44
+ public function search_box($text, $input_id) {
45
+ if(empty($_REQUEST['s']) && !$this->has_items())
46
+ return;
47
+ $input_id = $input_id.'-search-input';
48
+ if(!empty($_REQUEST['orderby']))
49
+ echo '<input type="hidden" name="orderby" value="'.esc_attr($_REQUEST['orderby']).'" />';
50
+ if(!empty($_REQUEST['order']))
51
+ echo '<input type="hidden" name="order" value="'.esc_attr($_REQUEST['order']).'" />';
52
+ if(!empty($_REQUEST['post_mime_type']))
53
+ echo '<input type="hidden" name="post_mime_type" value="'.esc_attr($_REQUEST['post_mime_type']).'" />';
54
+ if(!empty( $_REQUEST['detached']))
55
+ echo '<input type="hidden" name="detached" value="'.esc_attr($_REQUEST['detached']).'" />';
56
+ ?>
57
+ <p class="search-box">
58
+ <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
59
+ <input type="hidden" id="page" name="page" value="wp-user-avatar-library" />
60
+ <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" />
61
+ <?php submit_button($text, 'button', false, false, array('id' => 'search-submit')); ?>
62
+ </p>
63
+ <?php
64
+ }
65
+
66
+ public function prepare_items() {
67
+ global $avatars_array, $lost, $wpdb, $wp_query, $post_mime_types, $avail_post_mime_types, $post;
68
+ $q = $_REQUEST;
69
+ $q['post__in'] = $avatars_array;
70
+ list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query($q);
71
+ $this->is_trash = isset($_REQUEST['status']) && 'trash' == $_REQUEST['status'];
72
+ $this->set_pagination_args(array(
73
+ 'total_items' => $wp_query->found_posts,
74
+ 'total_pages' => $wp_query->max_num_pages,
75
+ 'per_page' => $wp_query->query_vars['posts_per_page'],
76
+ ));
77
+ }
78
+
79
+ public function get_views() {
80
+ global $avatars_array;
81
+ $type_links = array();
82
+ $_total_posts = count(array_filter($avatars_array));
83
+ $class = (empty($_GET['post_mime_type']) && !isset($_GET['status'])) ? ' class="current"' : "";
84
+ $type_links['all'] = sprintf('<a href="%s">',esc_url(add_query_arg(array('page' => 'wp-user-avatar-library'), 'admin.php'))).sprintf(_nx('All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $_total_posts, 'uploaded files'), number_format_i18n($_total_posts)).'</a>';
85
+ return $type_links;
86
+ }
87
+
88
+ public function get_bulk_actions() {
89
+ $actions = array();
90
+ $actions['delete'] = __('Delete Permanently');
91
+ return $actions;
92
+ }
93
+
94
+ public function current_action() {
95
+ return parent::current_action();
96
+ }
97
+
98
+ public function has_items() {
99
+ return have_posts();
100
+ }
101
+
102
+ public function no_items() {
103
+ _e('No media attachments found.');
104
+ }
105
+
106
+ public function get_columns() {
107
+ $posts_columns = array();
108
+ $posts_columns['cb'] = '<input type="checkbox" />';
109
+ $posts_columns['icon'] = "";
110
+ $posts_columns['title'] = _x('File', 'column name');
111
+ $posts_columns['author'] = __('Author');
112
+ $posts_columns['parent'] = _x('Uploaded to', 'column name');
113
+ $posts_columns['date'] = _x('Date', 'column name');
114
+ return $posts_columns;
115
+ }
116
+
117
+ public function get_sortable_columns() {
118
+ return array(
119
+ 'title' => 'title',
120
+ 'author' => 'author',
121
+ 'date' => array('date', true),
122
+ );
123
+ }
124
+
125
+ public function display_rows() {
126
+ global $post, $wpdb;
127
+ add_filter('the_title','esc_html');
128
+ $alt = "";
129
+ while (have_posts()) : the_post();
130
+ $user_can_edit = current_user_can('edit_post', $post->ID);
131
+
132
+ if($this->is_trash && $post->post_status != 'trash' || !$this->is_trash && $post->post_status == 'trash')
133
+ continue;
134
+
135
+ $alt = ('alternate' == $alt) ? "" : 'alternate';
136
+ $post_owner = (get_current_user_id() == $post->post_author) ? 'self' : 'other';
137
+ $att_title = _draft_or_post_title();
138
+ ?>
139
+ <tr id='post-<?php echo $post->ID; ?>' class='<?php echo trim($alt.' author-'.$post_owner.' status-'.$post->post_status); ?>' valign="top">
140
+ <?php
141
+ list( $columns, $hidden ) = $this->get_column_info();
142
+ foreach($columns as $column_name => $column_display_name) {
143
+ $class = "class='$column_name column-$column_name'";
144
+ $style = "";
145
+ if(in_array($column_name, $hidden)) {
146
+ $style = ' style="display:none;"';
147
+ }
148
+ $attributes = $class.$style;
149
+ switch($column_name) {
150
+ case 'cb':
151
+ ?>
152
+ <th scope="row" class="check-column">
153
+ <?php if ( $user_can_edit ) { ?>
154
+ <label class="screen-reader-text" for="cb-select-<?php the_ID(); ?>"><?php echo sprintf(__('Select %s'), $att_title);?></label>
155
+ <input type="checkbox" name="media[]" id="cb-select-<?php the_ID(); ?>" value="<?php the_ID(); ?>" />
156
+ <?php } ?>
157
+ </th>
158
+ <?php
159
+ break;
160
+ case 'icon':
161
+ $attributes = 'class="column-icon media-icon"'.$style;
162
+ ?>
163
+ <td <?php echo $attributes ?>><?php
164
+ if ( $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true ) ) {
165
+ if ( $this->is_trash || ! $user_can_edit ) {
166
+ echo $thumb;
167
+ } else {
168
+ ?>
169
+ <a href="<?php echo get_edit_post_link( $post->ID, true ); ?>" title="<?php echo esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ); ?>">
170
+ <?php echo $thumb; ?>
171
+ </a>
172
+ <?php } }
173
+ ?>
174
+ </td>
175
+ <?php
176
+ break;
177
+ case 'title':
178
+ ?>
179
+ <td <?php echo $attributes ?>><strong>
180
+ <?php if ( $this->is_trash || ! $user_can_edit ) {
181
+ echo $att_title;
182
+ } else { ?>
183
+ <a href="<?php echo get_edit_post_link( $post->ID, true ); ?>"
184
+ title="<?php echo esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ); ?>">
185
+ <?php echo $att_title; ?></a>
186
+ <?php };
187
+ _media_states( $post ); ?></strong>
188
+ <p>
189
+ <?php
190
+ if ( preg_match( '/^.*?\.(\w+)#x2F;', get_attached_file( $post->ID ), $matches ) )
191
+ echo esc_html( strtoupper( $matches[1] ) );
192
+ else
193
+ echo strtoupper( str_replace( 'image/', "", get_post_mime_type() ) );
194
+ ?>
195
+ </p>
196
+ <?php echo $this->row_actions( $this->_get_row_actions( $post, $att_title ) ); ?>
197
+ </td>
198
+ <?php
199
+ break;
200
+ case 'author':
201
+ ?>
202
+ <td <?php echo $attributes ?>>
203
+ <?php
204
+ printf( '<a href="%s">%s</a>',
205
+ esc_url( add_query_arg( array( 'author' => get_the_author_meta('ID') ), 'upload.php' ) ),
206
+ get_the_author()
207
+ ); ?>
208
+ </td>
209
+ <?php
210
+ break;
211
+ case 'date':
212
+ if ( '0000-00-00 00:00:00' == $post->post_date ) {
213
+ $h_time = __( 'Unpublished' );
214
+ } else {
215
+ $m_time = $post->post_date;
216
+ $time = get_post_time( 'G', true, $post, false );
217
+ if ( ( abs( $t_diff = time() - $time ) ) < DAY_IN_SECONDS ) {
218
+ if ( $t_diff < 0 )
219
+ $h_time = sprintf( __( '%s from now' ), human_time_diff( $time ) );
220
+ else
221
+ $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
222
+ } else {
223
+ $h_time = mysql2date( __( 'Y/m/d' ), $m_time );
224
+ }
225
+ }
226
+ ?>
227
+ <td <?php echo $attributes ?>><?php echo $h_time ?></td>
228
+ <?php
229
+ break;
230
+ case 'parent':
231
+ global $blog_id, $wpdb;
232
+ // Find all users with this WPUA
233
+ $wpua_metakey = $wpdb->get_blog_prefix($blog_id).'user_avatar';
234
+ $wpuas = $wpdb->get_results($wpdb->prepare("SELECT wpum.user_id FROM $wpdb->usermeta AS wpum, $wpdb->users AS wpu WHERE wpum.meta_key = %s AND wpum.meta_value = %d AND wpum.user_id = wpu.ID ORDER BY wpu.user_login", $wpua_metakey, $post->ID));
235
+ // Find users without WPUA
236
+ $nowpuas = $wpdb->get_results($wpdb->prepare("SELECT wpu.ID FROM $wpdb->users AS wpu, $wpdb->usermeta AS wpum WHERE wpum.meta_key = %s AND wpum.meta_value = %d AND wpum.user_id = wpu.ID ORDER BY wpu.user_login", $wpua_metakey, ""));
237
+ $user_array = array();
238
+ ?>
239
+ <td <?php echo $attributes ?>>
240
+ <strong>
241
+ <?php
242
+ if(!empty($wpuas)) {
243
+ foreach($wpuas as $usermeta) {
244
+ $user = get_userdata($usermeta->user_id);
245
+ $user_array[] = '<a href="'.get_edit_user_link($user->ID).'">'.$user->user_login.'</a>';
246
+ }
247
+ } else {
248
+ foreach($nowpuas as $usermeta) {
249
+ $user = get_userdata($usermeta->ID);
250
+ $user_array[] = '<a href="'.get_edit_user_link($user->ID).'">'.$user->user_login.'</a>';
251
+ }
252
+ }
253
+ ?>
254
+ <?php echo implode(', ', array_filter($user_array)); ?>
255
+ </strong>
256
+ </td>
257
+ <?php
258
+ break;
259
+ }
260
+ }
261
+ ?>
262
+ </tr>
263
+ <?php endwhile;
264
+ }
265
+
266
+ public function _get_row_actions($post, $att_title) {
267
+ $actions = array();
268
+ if(current_user_can('edit_post', $post->ID) && !$this->is_trash) {
269
+ $actions['edit'] = '<a href="'.get_edit_post_link($post->ID, true).'">'.__('Edit').'</a>';
270
+ }
271
+ if(current_user_can('delete_post', $post->ID)) {
272
+ if($this->is_trash) {
273
+ $actions['untrash'] = "<a class='submitdelete' href='".wp_nonce_url("post.php?action=untrash&amp;post=$post->ID", 'untrash-post_'.$post->ID)."'>".__('Restore')."</a>";
274
+ } elseif (EMPTY_TRASH_DAYS && MEDIA_TRASH) {
275
+ $actions['trash'] = "<a class='submitdelete' href='".wp_nonce_url("post.php?action=trash&amp;post=$post->ID", 'trash-post_'. $post->ID)."'>".__('Trash')."</a>";
276
+ }
277
+ if($this->is_trash || !EMPTY_TRASH_DAYS || !MEDIA_TRASH) {
278
+ $delete_ays = (!$this->is_trash && !MEDIA_TRASH) ? " onclick='return showNotice.warn();'" : "";
279
+ $actions['delete'] = "<a class='submitdelete'$delete_ays href='".wp_nonce_url("post.php?action=delete&amp;post=$post->ID", 'delete-post_'.$post->ID)."'>".__('Delete Permanently')."</a>";
280
+ }
281
+ }
282
+ if(!$this->is_trash) {
283
+ $title =_draft_or_post_title($post->post_parent);
284
+ $actions['view'] = '<a href="'.get_permalink($post->ID).'" title="'.esc_attr(sprintf(__('View &#8220;%s&#8221;'), $title)).'" rel="permalink">'.__('View').'</a>';
285
+ }
286
+ return $actions;
287
+ }
288
+ }
includes/class-wp-user-avatar-shortcode.php ADDED
@@ -0,0 +1,162 @@
1
+ <?php
2
+ /**
3
+ * Defines shortcodes.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.4
7
+ */
8
+
9
+ class WP_User_Avatar_Shortcode {
10
+ public function __construct() {
11
+ global $wp_user_avatar;
12
+ add_shortcode('avatar', array($this, 'wpua_shortcode'));
13
+ add_shortcode('avatar_upload', array($this, 'wpua_edit_shortcode'));
14
+ // Add avatar and scripts to avatar_upload
15
+ add_action('wpua_show_profile', array($wp_user_avatar, 'wpua_action_show_user_profile'));
16
+ add_action('wpua_show_profile', array($wp_user_avatar, 'wpua_media_upload_scripts'));
17
+ add_action('wpua_update', array($wp_user_avatar, 'wpua_action_process_option_update'));
18
+ // Add error messages to avatar_upload
19
+ add_action('wpua_update_errors', array($wp_user_avatar, 'wpua_upload_errors'), 10, 3);
20
+ }
21
+
22
+ // Display shortcode
23
+ public function wpua_shortcode($atts, $content=null) {
24
+ global $all_sizes, $blog_id, $post, $wpdb;
25
+ // Set shortcode attributes
26
+ extract(shortcode_atts(array('user' => "", 'size' => '96', 'align' => "", 'link' => "", 'target' => ""), $atts));
27
+ // Find user by ID, login, slug, or e-mail address
28
+ if(!empty($user)) {
29
+ $user = is_numeric($user) ? get_user_by('id', $user) : get_user_by('login', $user);
30
+ $user = empty($user) ? get_user_by('slug', $user) : $user;
31
+ $user = empty($user) ? get_user_by('email', $user) : $user;
32
+ } else {
33
+ // Find author's name if id_or_email is empty
34
+ $author_name = get_query_var('author_name');
35
+ if(is_author()) {
36
+ // On author page, get user by page slug
37
+ $user = get_user_by('slug', $author_name);
38
+ } else {
39
+ // On post, get user by author meta
40
+ $user_id = get_the_author_meta('ID');
41
+ $user = get_user_by('id', $user_id);
42
+ }
43
+ }
44
+ // Numeric sizes leave as-is
45
+ $get_size = $size;
46
+ // Check for custom image sizes if there are captions
47
+ if(!empty($content)) {
48
+ if(in_array($size, $all_sizes)) {
49
+ if(in_array($size, array('original', 'large', 'medium', 'thumbnail'))) {
50
+ $get_size = ($size == 'original') ? get_option('large_size_w') : get_option($size.'_size_w');
51
+ } else {
52
+ $get_size = $_wp_additional_image_sizes[$size]['width'];
53
+ }
54
+ }
55
+ }
56
+ // Get user ID
57
+ $id_or_email = !empty($user) ? $user->ID : 'unknown@gravatar.com';
58
+ // Check if link is set
59
+ if(!empty($link)) {
60
+ // CSS class is same as link type, except for URL
61
+ $link_class = $link;
62
+ if($link == 'file') {
63
+ // Get image src
64
+ $link = get_wp_user_avatar_src($id_or_email, 'original');
65
+ } elseif($link == 'attachment') {
66
+ // Get attachment URL
67
+ $link = get_attachment_link(get_the_author_meta($wpdb->get_blog_prefix($blog_id).'user_avatar', $id_or_email));
68
+ } else {
69
+ // URL
70
+ $link_class = 'custom';
71
+ }
72
+ // Open in new window
73
+ $target_link = !empty($target) ? ' target="'.$target.'"' : "";
74
+ // Wrap the avatar inside the link
75
+ $html = '<a href="'.$link.'" class="wp-user-avatar-link wp-user-avatar-'.$link_class.'"'.$target_link.'>'.get_wp_user_avatar($id_or_email, $get_size, $align).'</a>';
76
+ } else {
77
+ $html = get_wp_user_avatar($id_or_email, $get_size, $align);
78
+ }
79
+ // Check if caption is set
80
+ if(!empty($content)) {
81
+ // Get attachment ID
82
+ $wpua = get_user_meta($id_or_email, $wpdb->get_blog_prefix($blog_id).'user_avatar', true);
83
+ // Clean up caption
84
+ $content = trim($content);
85
+ $content = preg_replace('/\r|\n/', "", $content);
86
+ $content = preg_replace('/<\/p><p>/', "", $content, 1);
87
+ $content = preg_replace('/<\/p><p>#x2F;', "", $content);
88
+ $content = str_replace('</p><p>', "<br /><br />", $content);
89
+ $avatar = do_shortcode(image_add_caption($html, $wpua, $content, $title="", $align, $link, $get_size, $alt=""));
90
+ } else {
91
+ $avatar = $html;
92
+ }
93
+ return $avatar;
94
+ }
95
+
96
+ // Update user
97
+ private function wpua_edit_user($user_id = 0) {
98
+ global $post;
99
+ $user = new stdClass;
100
+ if($user_id) {
101
+ $update = true;
102
+ $user->ID = (int) $user_id;
103
+ } else {
104
+ $update = false;
105
+ }
106
+ $errors = new WP_Error();
107
+ do_action_ref_array('wpua_update_errors', array(&$errors, $update, &$user));
108
+ if($errors->get_error_codes()) {
109
+ return $errors;
110
+ }
111
+ if($update) {
112
+ $user_id = wp_update_user($user);
113
+ wp_redirect(add_query_arg(array('updated' => 'true'), get_permalink($post)));
114
+ }
115
+ return $user_id;
116
+ }
117
+
118
+ // Edit shortcode
119
+ public function wpua_edit_shortcode($atts) {
120
+ global $current_user, $errors;
121
+ // Shortcode only works with logged-in user
122
+ if(is_user_logged_in()) {
123
+ // Save
124
+ if(isset($_POST['submit']) && $_POST['submit'] && $_POST['action'] == 'update') {
125
+ do_action('wpua_update', $current_user->ID);
126
+ // Check for errors
127
+ $errors = $this->wpua_edit_user($current_user->ID);
128
+ }
129
+ // Errors
130
+ if(isset($errors) && is_wp_error($errors)) {
131
+ echo '<div class="error"><p>'.implode( "</p>\n<p>", $errors->get_error_messages()).'</p></div>';
132
+ } elseif(isset($errors) && !is_wp_error($errors)) {
133
+ echo '<div class="updated"><p><strong>'.__('Profile updated.').'</strong></p></div>';
134
+ }
135
+ // Edit form
136
+ return $this->wpua_edit_form();
137
+ }
138
+ }
139
+
140
+ // Edit form
141
+ public function wpua_edit_form() {
142
+ global $current_user, $post;
143
+ ob_start();
144
+ ?>
145
+ <form id="wpua-edit-<?php echo $current_user->ID; ?>" class="wpua-edit" action="<?php echo get_permalink($post); ?>" method="post" enctype="multipart/form-data">
146
+ <?php do_action('wpua_show_profile', $current_user); ?>
147
+ <input type="hidden" name="action" value="update" />
148
+ <input type="hidden" name="user_id" id="user_id" value="<?php echo esc_attr($current_user->ID); ?>" />
149
+ <?php wp_nonce_field('update-user_'.$current_user->ID); ?>
150
+ <?php submit_button(__('Update Profile')); ?>
151
+ </form>
152
+ <?php
153
+ return ob_get_clean();
154
+ }
155
+ }
156
+
157
+ // Initialize WP_User_Avatar_Shortcode
158
+ function wpua_shortcode_init() {
159
+ global $wpua_shortcode;
160
+ $wpua_shortcode = new WP_User_Avatar_Shortcode();
161
+ }
162
+ add_action('init', 'wpua_shortcode_init');
includes/class-wp-user-avatar-subscriber.php ADDED
@@ -0,0 +1,84 @@
1
+ <?php
2
+ /**
3
+ * Settings only for subscribers and contributors.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.4
7
+ */
8
+
9
+ class WP_User_Avatar_Subscriber {
10
+ public function __construct() {
11
+ global $wp_user_avatar, $wpua_allow_upload;
12
+ if((bool) $wpua_allow_upload == 1) {
13
+ add_action('user_edit_form_tag', array($this, 'wpua_add_edit_form_multipart_encoding'));
14
+ // Only Subscribers lack delete_posts capability
15
+ if(!current_user_can('delete_posts') && !$wp_user_avatar->wpua_is_author_or_above()) {
16
+ add_action('admin_menu', array($this, 'wpua_subscriber_remove_menu_pages'));
17
+ add_action('wp_before_admin_bar_render', array($this, 'wpua_subscriber_remove_menu_bar_items'));
18
+ add_action('wp_dashboard_setup', array($this, 'wpua_subscriber_remove_dashboard_widgets'));
19
+ add_action('admin_init', array($this, 'wpua_subscriber_offlimits'));
20
+ }
21
+ }
22
+ add_action('admin_init', array($this, 'wpua_subscriber_capability'));
23
+ }
24
+
25
+ // Allow multipart data in form
26
+ public function wpua_add_edit_form_multipart_encoding() {
27
+ echo ' enctype="multipart/form-data"';
28
+ }
29
+
30
+ // Remove menu items
31
+ public function wpua_subscriber_remove_menu_pages() {
32
+ remove_menu_page('edit.php');
33
+ remove_menu_page('edit-comments.php');
34
+ remove_menu_page('tools.php');
35
+ }
36
+
37
+ // Remove menu bar items
38
+ public function wpua_subscriber_remove_menu_bar_items() {
39
+ global $wp_admin_bar;
40
+ $wp_admin_bar->remove_menu('comments');
41
+ $wp_admin_bar->remove_menu('new-content');
42
+ }
43
+
44
+ // Remove dashboard items
45
+ public function wpua_subscriber_remove_dashboard_widgets() {
46
+ remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
47
+ remove_meta_box('dashboard_recent_drafts', 'dashboard', 'side');
48
+ remove_meta_box('dashboard_right_now', 'dashboard', 'normal');
49
+ }
50
+
51
+ // Restrict access to pages
52
+ public function wpua_subscriber_offlimits() {
53
+ global $pagenow, $wpua_edit_avatar;
54
+ $offlimits = array('edit.php', 'edit-comments.php', 'post-new.php', 'tools.php');
55
+ if((bool) $wpua_edit_avatar != 1) {
56
+ array_push($offlimits, 'post.php');
57
+ }
58
+ $offlimits = apply_filters('wpua_subscriber_offlimits', $offlimits);
59
+ if(in_array($pagenow, $offlimits)) {
60
+ do_action('admin_page_access_denied');
61
+ wp_die(__('You do not have sufficient permissions to access this page.'));
62
+ }
63
+ }
64
+
65
+ // Give subscribers edit_posts capability
66
+ public function wpua_subscriber_capability() {
67
+ global $blog_id, $wpdb, $wpua_allow_upload, $wpua_edit_avatar;;
68
+ $wp_user_roles = $wpdb->get_blog_prefix($blog_id).'user_roles';
69
+ $user_roles = get_option($wp_user_roles);
70
+ if((bool) $wpua_allow_upload == 1 && (bool) $wpua_edit_avatar == 1) {
71
+ $user_roles['subscriber']['capabilities']['edit_posts'] = true;
72
+ } else {
73
+ unset($user_roles['subscriber']['capabilities']['edit_posts']);
74
+ }
75
+ update_option($wp_user_roles, $user_roles);
76
+ }
77
+ }
78
+
79
+ // Initialize WP_User_Avatar_Subscriber
80
+ function wpua_subcriber_init() {
81
+ global $wpua_subscriber;
82
+ $wpua_subscriber = new WP_User_Avatar_Subscriber();
83
+ }
84
+ add_action('init', 'wpua_subcriber_init');
includes/class-wp-user-avatar-update.php ADDED
@@ -0,0 +1,77 @@
1
+ <?php
2
+ /**
3
+ * Updates for legacy settings.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.4
7
+ */
8
+
9
+ class WP_User_Avatar_Update {
10
+ public function __construct() {
11
+ global $wpua_default_avatar_updated, $wpua_media_updated, $wpua_users_updated;
12
+ if(empty($wpua_default_avatar_updated)) {
13
+ add_action('admin_init', array($this, 'wpua_default_avatar'));
14
+ }
15
+ if(empty($wpua_users_updated)) {
16
+ add_action('admin_init', array($this, 'wpua_user_meta'));
17
+ }
18
+ if(empty($wpua_media_updated)) {
19
+ add_action('admin_init', array($this, 'wpua_media_state'));
20
+ }
21
+ }
22
+
23
+ // Update default avatar to new format
24
+ public function wpua_default_avatar() {
25
+ global $avatar_default, $mustache_original, $wpua_avatar_default;
26
+ // If default avatar is the old mustache URL, update it
27
+ if($avatar_default == $mustache_original) {
28
+ update_option('avatar_default', 'wp_user_avatar');
29
+ }
30
+ // If user had an image URL as the default avatar, replace with ID instead
31
+ if(!empty($wpua_avatar_default)) {
32
+ $wpua_avatar_default_image = wp_get_attachment_image_src($wpua_avatar_default, 'medium');
33
+ if($avatar_default == $wpua_avatar_default_image[0]) {
34
+ update_option('avatar_default', 'wp_user_avatar');
35
+ }
36
+ }
37
+ update_option('wp_user_avatar_default_avatar_updated', '1');
38
+ }
39
+
40
+ // Rename user meta to match database settings
41
+ public function wpua_user_meta() {
42
+ global $blog_id, $wpdb;
43
+ $wpua_metakey = $wpdb->get_blog_prefix($blog_id).'user_avatar';
44
+ // If database tables start with something other than wp_
45
+ if($wpua_metakey != 'wp_user_avatar') {
46
+ $users = get_users();
47
+ // Move current user metakeys to new metakeys
48
+ foreach($users as $user) {
49
+ $wpua = get_user_meta($user->ID, 'wp_user_avatar', true);
50
+ if(!empty($wpua)) {
51
+ update_user_meta($user->ID, $wpua_metakey, $wpua);
52
+ delete_user_meta($user->ID, 'wp_user_avatar');
53
+ }
54
+ }
55
+ }
56
+ update_option('wp_user_avatar_users_updated', '1');
57
+ }
58
+
59
+ // Add media state to existing avatars
60
+ public function wpua_media_state() {
61
+ global $blog_id, $wpdb;
62
+ // Find all users with WPUA
63
+ $wpua_metakey = $wpdb->get_blog_prefix($blog_id).'user_avatar';
64
+ $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, ""));
65
+ foreach($wpuas as $usermeta) {
66
+ add_post_meta($usermeta->meta_value, '_wp_attachment_wp_user_avatar', $usermeta->user_id);
67
+ }
68
+ update_option('wp_user_avatar_media_updated', '1');
69
+ }
70
+ }
71
+
72
+ // Initialize WP_User_Avatar_Update
73
+ function wpua_update_init() {
74
+ global $wpua_update;
75
+ $wpua_update = new WP_User_Avatar_Update();
76
+ }
77
+ add_action('init', 'wpua_update_init');
includes/class-wp-user-avatar-widget.php ADDED
@@ -0,0 +1,56 @@
1
+ <?php
2
+ /**
3
+ * Defines widgets.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.4
7
+ */
8
+
9
+ class WP_User_Avatar_Profile_Widget extends WP_Widget {
10
+ public function __construct() {
11
+ $widget_ops = array('classname' => 'widget_wp_user_avatar', 'description' => __('Insert').' '.__('[avatar_upload]', 'wp-user-avatar').'.');
12
+ parent::__construct('wp_user_avatar_profile', __('WP User Avatar', 'wp-user-avatar'), $widget_ops);
13
+ }
14
+
15
+ // Add [avatar_upload] to widget
16
+ public function widget($args, $instance) {
17
+ global $wpua_shortcode;
18
+ extract($args);
19
+ $instance = apply_filters('wpua_widget_instance', $instance);
20
+ $title = apply_filters('widget_title', empty($instance['title']) ? "" : $instance['title'], $instance, $this->id_base);
21
+ // Show widget only for logged-in users
22
+ if(is_user_logged_in()) {
23
+ echo $before_widget;
24
+ if($title){
25
+ echo $before_title.$title.$after_title;
26
+ }
27
+ // Remove profile title
28
+ add_filter('wpua_profile_title', '__return_null');
29
+ // Get [avatar_upload] shortcode
30
+ echo $wpua_shortcode->wpua_edit_shortcode("");
31
+ remove_filter('wpua_profile_title', '__return_null');
32
+ }
33
+ }
34
+
35
+ // Set title
36
+ public function form($instance) {
37
+ $instance = wp_parse_args((array) $instance, array('title' => ""));
38
+ $title = isset($instance['title']) ? esc_attr($instance['title']) : "";
39
+ ?>
40
+ <p>
41
+ <label for="<?php echo $this->get_field_id('title'); ?>">
42
+ <?php _e('Title:'); ?>
43
+ <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
44
+ </label>
45
+ </p>
46
+ <?php
47
+ }
48
+
49
+ // Update widget
50
+ public function update($new_instance, $old_instance) {
51
+ $instance = $old_instance;
52
+ $new_instance = wp_parse_args((array) $new_instance, array('title' => ""));
53
+ $instance['title'] = strip_tags($new_instance['title']);
54
+ return $instance;
55
+ }
56
+ }
includes/class-wp-user-avatar.php ADDED
@@ -0,0 +1,312 @@
1
+ <?php
2
+ /**
3
+ * Defines all profile and upload settings.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.4
7
+ */
8
+
9
+ class WP_User_Avatar {
10
+ public function __construct() {
11
+ global $pagenow, $show_avatars, $wpua_admin, $wpua_allow_upload;
12
+ // Add WPUA to profile
13
+ if($this->wpua_is_author_or_above() || ((bool) $wpua_allow_upload == 1 && is_user_logged_in())) {
14
+ // Profile functions and scripts
15
+ add_action('show_user_profile', array('wp_user_avatar', 'wpua_action_show_user_profile'));
16
+ add_action('personal_options_update', array($this, 'wpua_action_process_option_update'));
17
+ add_action('edit_user_profile', array('wp_user_avatar', 'wpua_action_show_user_profile'));
18
+ add_action('edit_user_profile_update', array($this, 'wpua_action_process_option_update'));
19
+ add_action('user_new_form', array($this, 'wpua_action_show_user_profile'));
20
+ add_action('user_register', array($this, 'wpua_action_process_option_update'));
21
+ // Admin scripts
22
+ $pages = array('profile.php', 'options-discussion.php', 'user-edit.php', 'user-new.php');
23
+ if(in_array($pagenow, $pages) || $wpua_admin->wpua_is_menu_page()) {
24
+ add_action('admin_enqueue_scripts', array($this, 'wpua_media_upload_scripts'));
25
+ }
26
+ // Front pages
27
+ if(!is_admin()) {
28
+ add_action('show_user_profile', array('wp_user_avatar', 'wpua_media_upload_scripts'));
29
+ add_action('edit_user_profile', array('wp_user_avatar', 'wpua_media_upload_scripts'));
30
+ }
31
+ if(!$this->wpua_is_author_or_above()) {
32
+ // Upload errors
33
+ add_action('user_profile_update_errors', array($this, 'wpua_upload_errors'), 10, 3);
34
+ // Prefilter upload size
35
+ add_filter('wp_handle_upload_prefilter', array($this, 'wpua_handle_upload_prefilter'));
36
+ }
37
+ }
38
+ add_filter('media_view_settings', array($this, 'wpua_media_view_settings'), 10, 1);
39
+ }
40
+
41
+ // Avatars have no parent posts
42
+ public function wpua_media_view_settings($settings) {
43
+ global $post, $wpua_is_profile;
44
+ // Get post ID so not to interfere with media uploads
45
+ $post_id = is_object($post) ? $post->ID : 0;
46
+ // Don't use post ID on front pages if there's a WPUA uploader
47
+ $settings['post']['id'] = (!is_admin() && $wpua_is_profile == 1) ? 0 : $post_id;
48
+ return $settings;
49
+ }
50
+
51
+ // Media Uploader
52
+ public static function wpua_media_upload_scripts($user="") {
53
+ global $current_user, $mustache_admin, $pagenow, $post, $show_avatars, $wp_user_avatar, $wpua_admin, $wpua_functions, $wpua_is_profile, $wpua_upload_size_limit;
54
+ // This is a profile page
55
+ $wpua_is_profile = true;
56
+ $user = ($pagenow == 'user-edit.php' && isset($_GET['user_id'])) ? get_user_by('id', $_GET['user_id']) : $current_user;
57
+ wp_enqueue_script('jquery');
58
+ if($wp_user_avatar->wpua_is_author_or_above()) {
59
+ wp_enqueue_script('admin-bar');
60
+ wp_enqueue_media(array('post' => $post));
61
+ wp_enqueue_script('wp-user-avatar', WPUA_URL.'js/wp-user-avatar.js', array('jquery', 'media-editor'), WPUA_VERSION, true);
62
+ } else {
63
+ wp_enqueue_script('wp-user-avatar', WPUA_URL.'js/wp-user-avatar-user.js', array('jquery'), WPUA_VERSION, true);
64
+ }
65
+ wp_enqueue_style('wp-user-avatar', WPUA_URL.'css/wp-user-avatar.css', array('media-views'), WPUA_VERSION);
66
+ // Admin scripts
67
+ if($pagenow == 'options-discussion.php' || $wpua_admin->wpua_is_menu_page()) {
68
+ // Size limit slider
69
+ wp_enqueue_script('jquery-ui-slider');
70
+ wp_enqueue_style('wp-user-avatar-jqueryui', WPUA_URL.'css/jquery.ui.slider.css', "", null);
71
+ // Default avatar
72
+ wp_localize_script('wp-user-avatar', 'wpua_custom', array('avatar_thumb' => $mustache_admin));
73
+ // Settings control
74
+ wp_enqueue_script('wp-user-avatar-admin', WPUA_URL.'js/wp-user-avatar-admin.js', array('wp-user-avatar'), WPUA_VERSION, true);
75
+ wp_localize_script('wp-user-avatar-admin', 'wpua_admin', array('upload_size_limit' => $wpua_upload_size_limit, 'max_upload_size' => wp_max_upload_size()));
76
+ } else {
77
+ // Original user avatar
78
+ $avatar_medium_src = (bool) $show_avatars == 1 ? $wpua_functions->wpua_get_avatar_original($user->user_email, 'medium') : includes_url().'images/blank.gif';
79
+ wp_localize_script('wp-user-avatar', 'wpua_custom', array('avatar_thumb' => $avatar_medium_src));
80
+ }
81
+ }
82
+
83
+ // Add to edit user profile
84
+ public static function wpua_action_show_user_profile($user) {
85
+ global $blog_id, $current_user, $show_avatars, $wpdb, $wp_user_avatar, $wpua_allow_upload, $wpua_edit_avatar, $wpua_functions, $wpua_upload_size_limit_with_units;
86
+ // Get WPUA attachment ID
87
+ $wpua = get_user_meta($user->ID, $wpdb->get_blog_prefix($blog_id).'user_avatar', true);
88
+ // Show remove button if WPUA is set
89
+ $hide_remove = !has_wp_user_avatar($user->ID) ? 'wpua-hide' : "";
90
+ // Hide image tags if show avatars is off
91
+ $hide_images = !has_wp_user_avatar($user->ID) && (bool) $show_avatars == 0 ? 'wpua-no-avatars' : "";
92
+ // If avatars are enabled, get original avatar image or show blank
93
+ $avatar_medium_src = (bool) $show_avatars == 1 ? $wpua_functions->wpua_get_avatar_original($user->user_email, 'medium') : includes_url().'images/blank.gif';
94
+ // Check if user has wp_user_avatar, if not show image from above
95
+ $avatar_medium = has_wp_user_avatar($user->ID) ? get_wp_user_avatar_src($user->ID, 'medium') : $avatar_medium_src;
96
+ // Check if user has wp_user_avatar, if not show image from above
97
+ $avatar_thumbnail = has_wp_user_avatar($user->ID) ? get_wp_user_avatar_src($user->ID, 96) : $avatar_medium_src;
98
+ $edit_attachment_link = add_query_arg(array('post' => $wpua, 'action' => 'edit'), admin_url('post.php'));
99
+ // Chck if admin page
100
+ $is_admin = is_admin() ? '_admin' : "";
101
+ ?>
102
+ <?php do_action('wpua_before_avatar'.$is_admin); ?>
103
+ <input type="hidden" name="wp-user-avatar" id="wp-user-avatar" value="<?php echo $wpua; ?>" />
104
+ <?php if($wp_user_avatar->wpua_is_author_or_above()) : // Button to launch Media Uploader ?>
105
+ <p id="wpua-add-button"><button type="button" class="button" id="wpua-add" name="wpua-add" data-title="<?php _e('Choose Image'); ?>: <?php echo $user->display_name; ?>"><?php _e('Choose Image'); ?></button></p>
106
+ <?php elseif(!$wp_user_avatar->wpua_is_author_or_above()) : // Upload button ?>
107
+ <p id="wpua-upload-button">
108
+ <input name="wpua-file" id="wpua-file" type="file" />
109
+ <button type="submit" class="button" id="wpua-upload" name="submit" value="<?php _e('Upload'); ?>"><?php _e('Upload'); ?></button>
110
+ </p>
111
+ <p id="wpua-upload-messages">
112
+ <span id="wpua-max-upload" class="description"><?php printf(__('Maximum upload file size: %d%s.'), esc_html($wpua_upload_size_limit_with_units), esc_html('KB')); ?></span>
113
+ <span id="wpua-allowed-files" class="description"><?php _e('Allowed Files'); ?>: <?php _e('<code>jpg jpeg png gif</code>'); ?></span>
114
+ </p>
115
+ <?php endif; ?>
116
+ <div id="wpua-images" class="<?php echo $hide_images; ?>">
117
+ <p id="wpua-preview">
118
+ <img src="<?php echo $avatar_medium; ?>" alt="" />
119
+ <span class="description"><?php _e('Original Size'); ?></span>
120
+ </p>
121
+ <p id="wpua-thumbnail">
122
+ <img src="<?php echo $avatar_thumbnail; ?>" alt="" />
123
+ <span class="description"><?php _e('Thumbnail'); ?></span>
124
+ </p>
125
+ <p id="wpua-remove-button" class="<?php echo $hide_remove; ?>">
126
+ <button type="button" class="button" id="wpua-remove" name="wpua-remove"><?php _e('Remove Image'); ?></button>
127
+ <?php if((bool) $wpua_edit_avatar == 1 && !$wp_user_avatar->wpua_is_author_or_above() && has_wp_user_avatar($current_user->ID) && $wp_user_avatar->wpua_author($wpua, $current_user->ID)) : // Edit button ?>
128
+ <span id="wpua-edit-attachment"><a href="<?php echo $edit_attachment_link; ?>" class="edit-attachment" target="_blank"><?php _e('Edit Image'); ?></a></span>
129
+ <?php endif; ?>
130
+ </p>
131
+ <p id="wpua-undo-button"><button type="button" class="button" id="wpua-undo" name="wpua-undo"><?php _e('Undo'); ?></button></p>
132
+ </div>
133
+ <?php do_action('wpua_after_avatar'.$is_admin); ?>
134
+ <?php
135
+ }
136
+
137
+ // Add upload error messages
138
+ public static function wpua_upload_errors($errors, $update, $user) {
139
+ global $wpua_upload_size_limit;
140
+ if($update && !empty($_FILES['wpua-file'])) {
141
+ $size = $_FILES['wpua-file']['size'];
142
+ $type = $_FILES['wpua-file']['type'];
143
+ $upload_dir = wp_upload_dir();
144
+ // Allow only JPG, GIF, PNG
145
+ if(!empty($type) && !preg_match('/(jpe?g|gif|png)#x2F;i', $type)) {
146
+ $errors->add('wpua_file_type', __('This file is not an image. Please try another.'));
147
+ }
148
+ // Upload size limit
149
+ if(!empty($size) && $size > $wpua_upload_size_limit) {
150
+ $errors->add('wpua_file_size', __('Memory exceeded. Please try another smaller file.'));
151
+ }
152
+ // Check if directory is writeable
153
+ if(!is_writeable($upload_dir['path'])) {
154
+ $errors->add('wpua_file_directory', sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), $upload_dir['path']));
155
+ }
156
+ }
157
+ }
158
+
159
+ // Set upload size limit
160
+ public function wpua_handle_upload_prefilter($file) {
161
+ global $wpua_upload_size_limit;
162
+ $size = $file['size'];
163
+ if(!empty($size) && $size > $wpua_upload_size_limit) {
164
+ function wpua_file_size_error($errors, $update, $user) {
165
+ $errors->add('wpua_file_size', __('Memory exceeded. Please try another smaller file.'));
166
+ }
167
+ add_action('user_profile_update_errors', 'wpua_file_size_error', 10, 3);
168
+ return;
169
+ }
170
+ return $file;
171
+ }
172
+
173
+ // Update user meta
174
+ public static function wpua_action_process_option_update($user_id) {
175
+ global $blog_id, $post, $wpdb, $wp_user_avatar, $wpua_resize_crop, $wpua_resize_h, $wpua_resize_upload, $wpua_resize_w;
176
+ // Check if user has publish_posts capability
177
+ if($wp_user_avatar->wpua_is_author_or_above()) {
178
+ $wpua_id = isset($_POST['wp-user-avatar']) ? strip_tags($_POST['wp-user-avatar']) : "";
179
+ // Remove old attachment postmeta
180
+ delete_metadata('post', null, '_wp_attachment_wp_user_avatar', $user_id, true);
181
+ // Create new attachment postmeta
182
+ add_post_meta($wpua_id, '_wp_attachment_wp_user_avatar', $user_id);
183
+ // Update usermeta
184
+ update_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', $wpua_id);
185
+ } else {
186
+ // Remove attachment info if avatar is blank
187
+ if(isset($_POST['wp-user-avatar']) && empty($_POST['wp-user-avatar'])) {
188
+ // Delete other uploads by user
189
+ $q = array(
190
+ 'author' => $user_id,
191
+ 'post_type' => 'attachment',
192
+ 'post_status' => 'inherit',
193
+ 'posts_per_page' => '-1',
194
+ 'meta_query' => array(
195
+ array(
196
+ 'key' => '_wp_attachment_wp_user_avatar',
197
+ 'value' => "",
198
+ 'compare' => '!='
199
+ )
200
+ )
201
+ );
202
+ $avatars_wp_query = new WP_Query($q);
203
+ while($avatars_wp_query->have_posts()) : $avatars_wp_query->the_post();
204
+ wp_delete_attachment($post->ID);
205
+ endwhile;
206
+ wp_reset_query();
207
+ // Remove attachment postmeta
208
+ delete_metadata('post', null, '_wp_attachment_wp_user_avatar', $user_id, true);
209
+ // Remove usermeta
210
+ update_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', "");
211
+ }
212
+ // Create attachment from upload
213
+ if(isset($_POST['submit']) && $_POST['submit'] && !empty($_FILES['wpua-file'])) {
214
+ $name = $_FILES['wpua-file']['name'];
215
+ $file = wp_handle_upload($_FILES['wpua-file'], array('test_form' => false));
216
+ $type = $_FILES['wpua-file']['type'];
217
+ $upload_dir = wp_upload_dir();
218
+ if(is_writeable($upload_dir['path'])) {
219
+ if(!empty($type) && preg_match('/(jpe?g|gif|png)#x2F;i', $type)) {
220
+ // Resize uploaded image
221
+ if((bool) $wpua_resize_upload == 1) {
222
+ // Original image
223
+ $uploaded_image = wp_get_image_editor($file['file']);
224
+ // Check for errors
225
+ if(!is_wp_error($uploaded_image)) {
226
+ // Resize image
227
+ $uploaded_image->resize($wpua_resize_w, $wpua_resize_h, $wpua_resize_crop);
228
+ // Save image
229
+ $resized_image = $uploaded_image->save($file['file']);
230
+ }
231
+ }
232
+ // Break out file info
233
+ $name_parts = pathinfo($name);
234
+ $name = trim(substr($name, 0, -(1 + strlen($name_parts['extension']))));
235
+ $url = $file['url'];
236
+ $file = $file['file'];
237
+ $title = $name;
238
+ // Use image exif/iptc data for title if possible
239
+ if($image_meta = @wp_read_image_metadata($file)) {
240
+ if(trim($image_meta['title']) && !is_numeric(sanitize_title($image_meta['title']))) {
241
+ $title = $image_meta['title'];
242
+ }
243
+ }
244
+ // Construct the attachment array
245
+ $attachment = array(
246
+ 'guid' => $url,
247
+ 'post_mime_type' => $type,
248
+ 'post_title' => $title,
249
+ 'post_content' => ""
250
+ );
251
+ // This should never be set as it would then overwrite an existing attachment
252
+ if(isset($attachment['ID'])) {
253
+ unset($attachment['ID']);
254
+ }
255
+ // Save the attachment metadata
256
+ $attachment_id = wp_insert_attachment($attachment, $file);
257
+ if(!is_wp_error($attachment_id)) {
258
+ // Delete other uploads by user
259
+ $q = array(
260
+ 'author' => $user_id,
261
+ 'post_type' => 'attachment',
262
+ 'post_status' => 'inherit',
263
+ 'posts_per_page' => '-1',
264
+ 'meta_query' => array(
265
+ array(
266
+ 'key' => '_wp_attachment_wp_user_avatar',
267
+ 'value' => "",
268
+ 'compare' => '!='
269
+ )
270
+ )
271
+ );
272
+ $avatars_wp_query = new WP_Query($q);
273
+ while($avatars_wp_query->have_posts()) : $avatars_wp_query->the_post();
274
+ wp_delete_attachment($post->ID);
275
+ endwhile;
276
+ wp_reset_query();
277
+ wp_update_attachment_metadata($attachment_id, wp_generate_attachment_metadata($attachment_id, $file));
278
+ // Remove old attachment postmeta
279
+ delete_metadata('post', null, '_wp_attachment_wp_user_avatar', $user_id, true);
280
+ // Create new attachment postmeta
281
+ update_post_meta($attachment_id, '_wp_attachment_wp_user_avatar', $user_id);
282
+ // Update usermeta
283
+ update_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', $attachment_id);
284
+ }
285
+ }
286
+ }
287
+ }
288
+ }
289
+ }
290
+
291
+ // Check who owns image
292
+ private function wpua_author($attachment_id, $user_id, $wpua_author=false) {
293
+ $attachment = get_post($attachment_id);
294
+ if(!empty($attachment) && $attachment->post_author == $user_id) {
295
+ $wpua_author = true;
296
+ }
297
+ return $wpua_author;
298
+ }
299
+
300
+ // Check if current user has at least Author privileges
301
+ public function wpua_is_author_or_above() {
302
+ $is_author_or_above = (current_user_can('edit_published_posts') && current_user_can('upload_files') && current_user_can('publish_posts') && current_user_can('delete_published_posts')) ? true : false;
303
+ return apply_filters('wpua_is_author_or_above', $is_author_or_above);
304
+ }
305
+ }
306
+
307
+ // Initialize WP_User_Avatar
308
+ function wpua_init() {
309
+ global $wp_user_avatar;
310
+ $wp_user_avatar = new WP_User_Avatar();
311
+ }
312
+ add_action('init', 'wpua_init');
includes/tinymce/editor_plugin.js CHANGED
@@ -1 +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:500,height:265,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.5.4"}}});tinymce.PluginManager.add('wpUserAvatar',tinymce.plugins.wpUserAvatar)})();
1
+ (function(){tinymce.create('tinymce.plugins.wpUserAvatar',{init:function(c,d){c.addCommand('mceWpUserAvatar',function(){c.windowManager.open({file:ajaxurl+'?action=wp_user_avatar_tinymce',width:500,height:360,inline:1},{plugin_url:d})});c.addButton('wpUserAvatar',{title:'Insert WP User Avatar',cmd:'mceWpUserAvatar',image:d+'/../../images/wpua-20x20.png'});c.onNodeChange.add(function(a,b,n){b.setActive('wpUserAvatar',n.nodeName=='IMG')})},createControl:function(n,a){return null},getInfo:function(){return{longname:'WP User Avatar',author:'Bangbay Siboliban',authorurl:'http://siboliban.org/',infourl:'http://wordpress.org/plugins/wp-user-avatar/',version:"1.9.4"}}});tinymce.PluginManager.add('wpUserAvatar',tinymce.plugins.wpUserAvatar)})();
includes/tinymce/window.php CHANGED
@@ -1,26 +1,31 @@
1
<?php
2
/**
3
* @package WP User Avatar
4
- * @version 1.5.4
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><?php _e('WP User Avatar', '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;
@@ -28,102 +33,148 @@ if(!defined('ABSPATH')){
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 != 'custom-url' && 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
- jQuery(function(){
51
- jQuery('#wp_user_avatar_link').change(function(){
52
- jQuery('#wp_user_avatar_link_external_section').toggle(jQuery('#wp_user_avatar_link').val() == 'custom-url');
53
});
54
- jQuery('#wp_user_avatar_size').change(function(){
55
- jQuery('#wp_user_avatar_size_number_section').toggle(jQuery('#wp_user_avatar_size').val() == 'custom');
56
});
57
});
58
</script>
59
<style type="text/css">
60
- form { background: #fff; border: 1px solid #eee; }
61
p, h4 { margin: 0; padding: 12px 0 0; }
62
h4.center { text-align: center; }
63
- label { width: 150px; display: inline-block; text-align: right; }
64
.mceActionPanel { padding: 7px 0 12px; text-align: center; }
65
.mceActionPanel #insert { float: none; width: 180px; margin: 0 auto; }
66
#wp_user_avatar_size_number_section, #wp_user_avatar_link_external_section { display: none; }
67
</style>
68
</head>
69
- <body id="link" class="wp-core-ui" onload="document.body.style.display="";" style="display:none;">
70
- <form name="wpUserAvatar" action="#">
71
- <p><label for="<?php esc_attr_e('wp_user_avatar_user'); ?>"><strong><?php _e('User Name'); ?>:</strong></label>
72
- <select id="<?php esc_attr_e('wp_user_avatar_user'); ?>" name="<?php esc_attr_e('wp_user_avatar_user'); ?>">
73
- <option value=""></option>
74
- <?php $users = get_users(); foreach($users as $user) : ?>
75
- <option value="<?php echo $user->user_login; ?>"><?php echo $user->display_name; ?></option>
76
- <?php endforeach; ?>
77
- </select></p>
78
79
- <p>
80
- <label for="<?php esc_attr_e('wp_user_avatar_size'); ?>"><strong><?php _e('Size'); ?>:</strong></label>
81
- <select id="<?php esc_attr_e('wp_user_avatar_size'); ?>" name="<?php esc_attr_e('wp_user_avatar_size'); ?>">
82
- <option value=""></option>
83
- <option value="original"><?php _e('Original Size'); ?></option>
84
- <option value="large"><?php _e('Large'); ?></option>
85
- <option value="medium"><?php _e('Medium'); ?></option>
86
- <option value="thumbnail"><?php _e('Thumbnail'); ?></option>
87
- <option value="custom"><?php _e('Custom'); ?></option>
88
- </select>
89
- </p>
90
91
- <p id="<?php esc_attr_e('wp_user_avatar_size_number_section'); ?>">
92
- <label for="<?php esc_attr_e('wp_user_avatar_size_number'); ?>"><?php _e('Size'); ?></label>
93
- <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="" />
94
- </p>
95
96
- <p><label for="<?php esc_attr_e('wp_user_avatar_align'); ?>"><strong><?php _e('Alignment'); ?>:</strong></label>
97
- <select id="<?php esc_attr_e('wp_user_avatar_align'); ?>" name="<?php esc_attr_e('wp_user_avatar_align'); ?>">
98
- <option value=""></option>
99
- <option value="center"><?php _e('Center'); ?></option>
100
- <option value="left"><?php _e('Left'); ?></option>
101
- <option value="right"><?php _e('Right'); ?></option>
102
- </select></p>
103
104
- <p>
105
- <label for="<?php esc_attr_e('wp_user_avatar_link'); ?>"><strong><?php _e('Link To'); ?>:</strong></label>
106
- <select id="<?php esc_attr_e('wp_user_avatar_link'); ?>" name="<?php esc_attr_e('wp_user_avatar_link'); ?>">
107
- <option value=""></option>
108
- <option value="file"><?php _e('Image File'); ?></option>
109
- <option value="attachment"><?php _e('Attachment Page'); ?></option>
110
- <option value="custom-url"><?php _e('Custom URL'); ?></option>
111
- </select>
112
- </p>
113
114
- <p id="<?php esc_attr_e('wp_user_avatar_link_external_section'); ?>">
115
- <label for="<?php esc_attr_e('wp_user_avatar_link_external'); ?>"><?php _e('URL'); ?></label>
116
- <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="" />
117
- </p>
118
119
- <p>
120
- <label for="<?php esc_attr_e('wp_user_avatar_target'); ?>"></label>
121
- <input type="checkbox" id="<?php esc_attr_e('wp_user_avatar_target'); ?>" name="<?php esc_attr_e('wp_user_avatar_target'); ?>" value="_blank" /> <strong><?php _e('Open link in a new window'); ?></strong>
122
- </p>
123
124
- <div class="mceActionPanel">
125
- <input type="submit" id="insert" class="button-primary" name="insert" value="<?php _e('Insert into Post'); ?>" onclick="insert_wp_user_avatar();" />
126
- </div>
127
- </form>
128
</body>
129
</html>
1
<?php
2
/**
3
+ * TinyMCE modal window.
4
+ *
5
* @package WP User Avatar
6
+ * @version 1.9.4
7
*/
8
9
+ if(!defined('ABSPATH')) {
10
+ die('You are not allowed to call this page directly.');
11
}
12
?>
13
+ <!DOCTYPE html>
14
+ <html>
15
<head>
16
<title><?php _e('WP User Avatar', 'wp-user-avatar'); ?></title>
17
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
18
<base target="_self" />
19
<script type="text/javascript" src="<?php echo site_url(); ?>/wp-includes/js/jquery/jquery.js"></script>
20
+ <script type="text/javascript" src="<?php echo site_url(); ?>/wp-includes/js/jquery/ui/jquery.ui.core.min.js"></script>
21
+ <script type="text/javascript" src="<?php echo site_url(); ?>/wp-includes/js/jquery/ui/jquery.ui.widget.min.js"></script>
22
+ <script type="text/javascript" src="<?php echo site_url(); ?>/wp-includes/js/jquery/ui/jquery.ui.tabs.min.js"></script>
23
<script type="text/javascript" src="<?php echo site_url(); ?>/wp-includes/js/tinymce/tiny_mce_popup.js"></script>
24
<script type="text/javascript" src="<?php echo site_url(); ?>/wp-includes/js/tinymce/utils/form_utils.js"></script>
25
<script type="text/javascript">
26
+ function wpuaInsertAvatar() {
27
// Custom shortcode values
28
+ var shortcode, closing_tag;
29
var user = document.getElementById('wp_user_avatar_user').value;
30
var size = document.getElementById('wp_user_avatar_size').value;
31
var size_number = document.getElementById('wp_user_avatar_size_number').value;
33
var link = document.getElementById('wp_user_avatar_link').value;
34
var link_external = document.getElementById('wp_user_avatar_link_external').value;
35
var target = document.getElementById('wp_user_avatar_target').value;
36
+ var caption = document.getElementById('wp_user_avatar_caption').value;
37
38
// Add tag to shortcode only if not blank
39
var user_tag = (user != "") ? ' user="' + user + '"' : "";
40
var size_tag = (size != "" && size_number == "") ? ' size="' + size + '"' : "";
41
+ size_tag = (size_number != "") ? ' size="' + size_number + '"' : size_tag;
42
var align_tag = (align != "") ? ' align="' + align + '"' : "";
43
var link_tag = (link != "" && link != 'custom-url' && link_external == "") ? ' link="' + link + '"' : "";
44
+ link_tag = (link_external != "") ? ' link="' + link_external + '"' : link_tag;
45
var target_tag = document.getElementById('wp_user_avatar_target').checked && (link_tag != "") ? ' target="' + target + '"' : "";
46
47
+ // Assemble the shortcode
48
+ closing_tag = (caption != "") ? "]" + caption + "[/avatar]" : " /]";
49
+ shortcode = "<p>[avatar" + user_tag + size_tag + align_tag + link_tag + target_tag + closing_tag + "</p>";
50
+
51
+ if(window.tinyMCE) {
52
+ window.tinyMCE.execInstanceCommand(window.tinyMCE.activeEditor.id, 'mceInsertContent', false, shortcode);
53
+ tinyMCEPopup.editor.execCommand('mceRepaint');
54
+ tinyMCEPopup.close();
55
+ }
56
+ return;
57
+ }
58
+ function wpuaInsertAvatarUpload() {
59
+ // Upload shortcode
60
+ var shortcode = "<p>[avatar_upload]</p>";
61
+
62
+ if(window.tinyMCE) {
63
window.tinyMCE.execInstanceCommand(window.tinyMCE.activeEditor.id, 'mceInsertContent', false, shortcode);
64
tinyMCEPopup.editor.execCommand('mceRepaint');
65
tinyMCEPopup.close();
66
}
67
return;
68
}
69
+ jQuery(function($) {
70
+ $('#wp_user_avatar_link').change(function() {
71
+ $('#wp_user_avatar_link_external_section').toggle($('#wp_user_avatar_link').val() == 'custom-url');
72
});
73
+ $('#wp_user_avatar_size').change(function() {
74
+ $('#wp_user_avatar_size_number_section').toggle($('#wp_user_avatar_size').val() == 'custom');
75
});
76
+ $('#wpua-tabs').tabs();
77
});
78
</script>
79
<style type="text/css">
80
+ ul { margin: 0; padding: 0; list-style: none; }
81
+ ul li { float: left; }
82
+ ul li a { float: left; padding: 2px 5px; background: #ddd; border: 1px solid #eee; border-bottom: 0; display: block; font-weight: 700; outline: none; text-decoration: none; }
83
+ ul li.ui-tabs-active a { background: #fff; }
84
+ form { clear: both; background: #fff; border: 1px solid #eee; }
85
p, h4 { margin: 0; padding: 12px 0 0; }
86
h4.center { text-align: center; }
87
+ label { width: 150px; margin-right: 3px; display: inline-block; text-align: right; vertical-align: top; }
88
.mceActionPanel { padding: 7px 0 12px; text-align: center; }
89
.mceActionPanel #insert { float: none; width: 180px; margin: 0 auto; }
90
#wp_user_avatar_size_number_section, #wp_user_avatar_link_external_section { display: none; }
91
</style>
92
</head>
93
+ <body id="link" class="wp-core-ui" onload="document.body.style.display='';" style="display:none;">
94
+ <div id="wpua-tabs">
95
+ <ul>
96
+ <li><a href="#wpua"><?php _e('Avatar'); ?></a></li>
97
+ <li><a href="#wpua-upload"><?php _e('Upload'); ?></a></li>
98
+ </ul>
99
+ <form name="wpUserAvatar" action="#">
100
+ <div id="wpua">
101
+ <p>
102
+ <label for="<?php esc_attr_e('wp_user_avatar_user'); ?>"><strong><?php _e('User Name'); ?>:</strong></label>
103
+ <select id="<?php esc_attr_e('wp_user_avatar_user'); ?>" name="<?php esc_attr_e('wp_user_avatar_user'); ?>">
104
+ <option value=""></option>
105
+ <?php $users = get_users(); foreach($users as $user) : ?>
106
+ <option value="<?php echo $user->user_login; ?>"><?php echo $user->display_name; ?></option>
107
+ <?php endforeach; ?>
108
+ </select>
109
+ </p>
110
+
111
+ <p>
112
+ <label for="<?php esc_attr_e('wp_user_avatar_size'); ?>"><strong><?php _e('Size'); ?>:</strong></label>
113
+ <select id="<?php esc_attr_e('wp_user_avatar_size'); ?>" name="<?php esc_attr_e('wp_user_avatar_size'); ?>">
114
+ <option value=""></option>
115
+ <option value="original"><?php _e('Original Size'); ?></option>
116
+ <option value="large"><?php _e('Large'); ?></option>
117
+ <option value="medium"><?php _e('Medium'); ?></option>
118
+ <option value="thumbnail"><?php _e('Thumbnail'); ?></option>
119
+ <option value="custom"><?php _e('Custom'); ?></option>
120
+ </select>
121
+ </p>
122
+
123
+ <p id="<?php esc_attr_e('wp_user_avatar_size_number_section'); ?>">
124
+ <label for="<?php esc_attr_e('wp_user_avatar_size_number'); ?>"><?php _e('Size'); ?>:</label>
125
+ <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="" />
126
+ </p>
127
128
+ <p>
129
+ <label for="<?php esc_attr_e('wp_user_avatar_align'); ?>"><strong><?php _e('Alignment'); ?>:</strong></label>
130
+ <select id="<?php esc_attr_e('wp_user_avatar_align'); ?>" name="<?php esc_attr_e('wp_user_avatar_align'); ?>">
131
+ <option value=""></option>
132
+ <option value="center"><?php _e('Center'); ?></option>
133
+ <option value="left"><?php _e('Left'); ?></option>
134
+ <option value="right"><?php _e('Right'); ?></option>
135
+ </select>
136
+ </p>
137
138
+ <p>
139
+ <label for="<?php esc_attr_e('wp_user_avatar_link'); ?>"><strong><?php _e('Link To'); ?>:</strong></label>
140
+ <select id="<?php esc_attr_e('wp_user_avatar_link'); ?>" name="<?php esc_attr_e('wp_user_avatar_link'); ?>">
141
+ <option value=""></option>
142
+ <option value="file"><?php _e('Image File'); ?></option>
143
+ <option value="attachment"><?php _e('Attachment Page'); ?></option>
144
+ <option value="custom-url"><?php _e('Custom URL'); ?></option>
145
+ </select>
146
+ </p>
147
148
+ <p id="<?php esc_attr_e('wp_user_avatar_link_external_section'); ?>">
149
+ <label for="<?php esc_attr_e('wp_user_avatar_link_external'); ?>"><?php _e('URL'); ?>:</label>
150
+ <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="" />
151
+ </p>
152
153
+ <p>
154
+ <label for="<?php esc_attr_e('wp_user_avatar_target'); ?>"></label>
155
+ <input type="checkbox" id="<?php esc_attr_e('wp_user_avatar_target'); ?>" name="<?php esc_attr_e('wp_user_avatar_target'); ?>" value="_blank" /> <strong><?php _e('Open link in a new window'); ?></strong>
156
+ </p>
157
158
+ <p>
159
+ <label for="<?php esc_attr_e('wp_user_avatar_caption'); ?>"><strong><?php _e('Caption'); ?>:</strong></label>
160
+ <textarea cols="36" rows="2" id="<?php esc_attr_e('wp_user_avatar_caption'); ?>" name="<?php esc_attr_e('wp_user_avatar_size'); ?>"></textarea>
161
+ </p>
162
163
+ <div class="mceActionPanel">
164
+ <input type="submit" id="insert" class="button-primary" name="insert" value="<?php _e('Insert into Post'); ?>" onclick="wpuaInsertAvatar();" />
165
+ </div>
166
+ </div>
167
+ <div id="wpua-upload">
168
+ <p id="<?php esc_attr_e('wp_user_avatar_upload'); ?>">
169
+ <label for="<?php esc_attr_e('wp_user_avatar_upload'); ?>"><strong><?php _e('Upload'); ?>:</strong></label>
170
+ <input type="text" size="36" id="<?php esc_attr_e('wp_user_avatar_upload'); ?>" name="<?php esc_attr_e('wp_user_avatar_upload'); ?>" value="<?php esc_attr_e('[avatar_upload]'); ?>" readonly="readonly" />
171
+ </p>
172
173
+ <div class="mceActionPanel">
174
+ <input type="submit" id="insert" class="button-primary" name="insert" value="<?php _e('Insert into Post'); ?>" onclick="wpuaInsertAvatarUpload();" />
175
+ </div>
176
+ </div>
177
+ </form>
178
+ </div>
179
</body>
180
</html>
includes/wpua-functions.php ADDED
@@ -0,0 +1,124 @@
1
+ <?php
2
+ /**
3
+ * Public user functions.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.4
7
+ */
8
+
9
+ function has_wp_user_avatar($id_or_email="", $has_wpua="", $user="", $user_id="") {
10
+ global $wpua_functions;
11
+ return $wpua_functions->has_wp_user_avatar($id_or_email, $has_wpua, $user, $user_id);
12
+ }
13
+
14
+ function get_wp_user_avatar($id_or_email="", $size="", $align="", $alt="") {
15
+ global $wpua_functions;
16
+ return $wpua_functions->get_wp_user_avatar($id_or_email, $size, $align, $alt);
17
+ }
18
+
19
+ function get_wp_user_avatar_src($id_or_email="", $size="", $align="") {
20
+ global $wpua_functions;
21
+ return $wpua_functions->get_wp_user_avatar_src($id_or_email, $size, $align);
22
+ }
23
+
24
+ // Before wrapper for profile
25
+ function wpua_before_avatar() {
26
+ do_action('wpua_before_avatar');
27
+ }
28
+
29
+ // After wrapper for profile
30
+ function wpua_after_avatar() {
31
+ do_action('wpua_after_avatar');
32
+ }
33
+
34
+ // Before avatar container
35
+ function wpua_do_before_avatar() {
36
+ $wpua_profile_title = '<h3>'.__('Avatar').'</h3>';
37
+ $wpua_profile_title = apply_filters('wpua_profile_title', $wpua_profile_title);
38
+ ?>
39
+ <?php if(class_exists('bbPress') && bbp_is_edit()) : // Add to bbPress profile with same style ?>
40
+ <h2 class="entry-title"><?php _e('Avatar'); ?></h2>
41
+ <fieldset class="bbp-form">
42
+ <legend><?php _e('Image'); ?></legend>
43
+ <?php elseif(class_exists('WPUF_Main') && wpuf_has_shortcode('wpuf_editprofile')) : // Add to WP User Frontend profile with same style ?>
44
+ <fieldset>
45
+ <legend><?php _e('Avatar') ?></legend>
46
+ <table class="wpuf-table">
47
+ <tr>
48
+ <th><label for="wp_user_avatar"><?php _e('Image'); ?></label></th>
49
+ <td>
50
+ <?php else : // Add to profile without table ?>
51
+ <div class="wpua-edit-container">
52
+ <?php echo $wpua_profile_title; ?>
53
+ <?php endif; ?>
54
+ <?php
55
+ }
56
+ add_action('wpua_before_avatar', 'wpua_do_before_avatar');
57
+
58
+ // After avatar container
59
+ function wpua_do_after_avatar() {
60
+ ?>
61
+ <?php if(class_exists('bbPress') && bbp_is_edit()) : // Add to bbPress profile with same style ?>
62
+ </fieldset>
63
+ <?php elseif(class_exists('WPUF_Main') && wpuf_has_shortcode('wpuf_editprofile')) : // Add to WP User Frontend profile with same style ?>
64
+ </td>
65
+ </tr>
66
+ </table>
67
+ </fieldset>
68
+ <?php else : // Add to profile without table ?>
69
+ </div>
70
+ <?php endif; ?>
71
+ <?php
72
+ }
73
+ add_action('wpua_after_avatar', 'wpua_do_after_avatar');
74
+
75
+ // Before wrapper for profile
76
+ function wpua_before_avatar_admin() {
77
+ do_action('wpua_before_avatar_admin');
78
+ }
79
+
80
+ // After wrapper for profile
81
+ function wpua_after_avatar_admin() {
82
+ do_action('wpua_after_avatar_admin');
83
+ }
84
+
85
+ // Before avatar container
86
+ function wpua_do_before_avatar_admin() {
87
+ ?>
88
+ <h3><?php _e('Avatar') ?></h3>
89
+ <table class="form-table">
90
+ <tr>
91
+ <th><label for="wp_user_avatar"><?php _e('Image'); ?></label></th>
92
+ <td>
93
+ <?php
94
+ }
95
+ add_action('wpua_before_avatar_admin', 'wpua_do_before_avatar_admin');
96
+
97
+ // After avatar container
98
+ function wpua_do_after_avatar_admin() {
99
+ ?>
100
+ </td>
101
+ </tr>
102
+ </table>
103
+ <?php
104
+ }
105
+ add_action('wpua_after_avatar_admin', 'wpua_do_after_avatar_admin');
106
+
107
+ // Filter for the inevitable complaints about the donation message :(
108
+ function wpua_donation_message() {
109
+ do_action('wpua_donation_message');
110
+