WP User Avatar - Version 1.9.5

Version Description

  • Add: Start documentation of functions
  • Bug Fix: [avatar_upload] permalink and redirect
Download this release

Release Info

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

Code changes from version 1.5.4 to 1.9.5

Files changed (41) 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 +369 -0
  10. includes/class-wp-user-avatar-functions.php +423 -0
  11. includes/class-wp-user-avatar-list-table.php +387 -0
  12. includes/class-wp-user-avatar-resource-manager.php +132 -0
  13. includes/class-wp-user-avatar-shortcode.php +217 -0
  14. includes/class-wp-user-avatar-subscriber.php +126 -0
  15. includes/class-wp-user-avatar-update.php +111 -0
  16. includes/class-wp-user-avatar-widget.php +80 -0
  17. includes/class-wp-user-avatar.php +437 -0
  18. includes/tinymce.php +0 -47
  19. includes/tinymce/editor_plugin.js +1 -1
  20. includes/tinymce/window.php +133 -78
  21. includes/wpua-functions.php +188 -0
  22. includes/wpua-globals.php +92 -0
  23. includes/wpua-media-page.php +115 -0
  24. includes/wpua-options-page.php +207 -0
  25. includes/wpua-tinymce.php +50 -0
  26. js/wp-user-avatar-admin.js +25 -22
  27. js/wp-user-avatar-user.js +31 -0
  28. js/wp-user-avatar.js +1 -1
  29. lang/wp-user-avatar-de_DE.mo +0 -0
  30. lang/wp-user-avatar-de_DE.po +35 -15
  31. lang/wp-user-avatar-es_ES.mo +0 -0
  32. lang/wp-user-avatar-es_ES.po +35 -15
  33. lang/wp-user-avatar-fr_FR.mo +0 -0
  34. lang/wp-user-avatar-fr_FR.po +35 -15
  35. lang/wp-user-avatar-pl_PL.mo +0 -0
  36. lang/wp-user-avatar-pl_PL.po +81 -0
  37. lang/wp-user-avatar-sv_SE.mo +0 -0
  38. lang/wp-user-avatar-sv_SE.po +35 -15
  39. readme.txt +323 -33
  40. uninstall.php +22 -11
  41. wp-user-avatar.php +60 -967
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,369 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Defines all of administrative, activation, and deactivation settings.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.5
7
+ */
8
+
9
+ class WP_User_Avatar_Admin {
10
+ /**
11
+ * Constructor
12
+ * @uses bool $show_avatars
13
+ * @uses bool $wpua_allow_upload
14
+ * @uses bool $wpua_tinymce
15
+ * @uses add_action()
16
+ * @uses add_filter()
17
+ * @uses current_user_can()
18
+ * @uses is_admin()
19
+ * @uses load_plugin_textdomain()
20
+ * @uses register_activation_hook()
21
+ * @uses register_deactivation_hook()
22
+ */
23
+ public function __construct() {
24
+ global $show_avatars, $wpua_allow_upload, $wpua_tinymce;
25
+ // Initialize default settings
26
+ register_activation_hook(WPUA_DIR.'wp-user-avatar.php', array($this, 'wpua_options'));
27
+ // Settings saved to wp_options
28
+ add_action('admin_init', array($this, 'wpua_options'));
29
+ // Remove subscribers edit_posts capability
30
+ register_deactivation_hook(WPUA_DIR.'wp-user-avatar.php', array($this, 'wpua_deactivate'));
31
+ // Translations
32
+ load_plugin_textdomain('wp-user-avatar', "", WPUA_FOLDER.'/lang');
33
+ // Admin menu settings
34
+ add_action('admin_menu', array($this, 'wpua_admin'));
35
+ add_action('admin_init', array($this, 'wpua_register_settings'));
36
+ // Default avatar
37
+ add_filter('default_avatar_select', array($this, 'wpua_add_default_avatar'), 10);
38
+ add_filter('whitelist_options', array($this, 'wpua_whitelist_options'), 10);
39
+ // Additional plugin info
40
+ add_filter('plugin_action_links', array($this, 'wpua_action_links'), 10, 2);
41
+ add_filter('plugin_row_meta', array($this, 'wpua_row_meta'), 10, 2);
42
+ // Hide column in Users table if default avatars are enabled
43
+ if((bool) $show_avatars == 0 && is_admin()) {
44
+ add_filter('manage_users_columns', array($this, 'wpua_add_column'), 10, 1);
45
+ add_filter('manage_users_custom_column', array($this, 'wpua_show_column'), 10, 3);
46
+ }
47
+ // Media states
48
+ add_filter('display_media_states', array($this, 'wpua_add_media_state'), 10, 1);
49
+ // Load TinyMCE only if enabled and user has editing privileges
50
+ if((bool) $wpua_tinymce == 1 && current_user_can('edit_posts') && current_user_can('edit_pages')) {
51
+ include_once(WPUA_INC.'wpua-tinymce.php');
52
+ }
53
+ }
54
+
55
+ /**
56
+ * Settings saved to wp_options
57
+ * @uses add_option()
58
+ */
59
+ public function wpua_options() {
60
+ add_option('avatar_default_wp_user_avatar', "");
61
+ add_option('wp_user_avatar_allow_upload', '0');
62
+ add_option('wp_user_avatar_disable_gravatar', '0');
63
+ add_option('wp_user_avatar_edit_avatar', '1');
64
+ add_option('wp_user_avatar_resize_crop', '0');
65
+ add_option('wp_user_avatar_resize_h', '96');
66
+ add_option('wp_user_avatar_resize_upload', '0');
67
+ add_option('wp_user_avatar_resize_w', '96');
68
+ add_option('wp_user_avatar_tinymce', '1');
69
+ add_option('wp_user_avatar_upload_size_limit', '0');
70
+ }
71
+
72
+ /**
73
+ * On deactivation
74
+ * @uses int $blog_id
75
+ * @uses object $wpdb
76
+ * @uses get_blog_prefix()
77
+ * @uses get_option()
78
+ * @uses update_option()
79
+ */
80
+ public function wpua_deactivate() {
81
+ global $blog_id, $wpdb;
82
+ $wp_user_roles = $wpdb->get_blog_prefix($blog_id).'user_roles';
83
+ // Get user roles and capabilities
84
+ $user_roles = get_option($wp_user_roles);
85
+ // Remove subscribers edit_posts capability
86
+ unset($user_roles['subscriber']['capabilities']['edit_posts']);
87
+ update_option($wp_user_roles, $user_roles);
88
+ // Reset all default avatars to Mystery Man
89
+ update_option('avatar_default', 'mystery');
90
+ }
91
+
92
+ /**
93
+ * Add options page and settings
94
+ * @uses add_menu_page()
95
+ * @uses add_submenu_page()
96
+ */
97
+ public function wpua_admin() {
98
+ 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');
99
+ add_submenu_page('wp-user-avatar', __('Settings'), __('Settings'), 'manage_options', 'wp-user-avatar', array($this, 'wpua_options_page'));
100
+ $hook = add_submenu_page('wp-user-avatar', __('Library'), __('Library'), 'manage_options', 'wp-user-avatar-library', array($this, 'wpua_media_page'));
101
+ add_action("load-$hook", array($this, 'wpua_media_screen_option'));
102
+ add_filter('set-screen-option', array($this, 'wpua_set_media_screen_option'), 10, 3);
103
+ }
104
+
105
+ /**
106
+ * Checks if current page is settings page
107
+ * @uses string $pagenow
108
+ * @return bool
109
+ */
110
+ public function wpua_is_menu_page() {
111
+ global $pagenow;
112
+ $is_menu_page = ($pagenow == 'admin.php' && isset($_GET['page']) && $_GET['page'] == 'wp-user-avatar') ? true : false;
113
+ return $is_menu_page;
114
+ }
115
+
116
+ /**
117
+ * Media page
118
+ */
119
+ public function wpua_media_page() {
120
+ require_once(WPUA_INC.'wpua-media-page.php');
121
+ }
122
+
123
+ /**
124
+ * Avatars per page
125
+ * @uses add_screen_option()
126
+ */
127
+ public function wpua_media_screen_option() {
128
+ $option = 'per_page';
129
+ $args = array(
130
+ 'label' => __('Avatars'),
131
+ 'default' => 10,
132
+ 'option' => 'upload_per_page'
133
+ );
134
+ add_screen_option($option, $args);
135
+ }
136
+
137
+ /**
138
+ * Save per page setting
139
+ * @param int $status
140
+ * @param string $option
141
+ * @param int $value
142
+ * @return int $status
143
+ */
144
+ public function wpua_set_media_screen_option($status, $option, $value) {
145
+ $status = ($option == 'upload_per_page') ? $value : $status;
146
+ return $status;
147
+ }
148
+
149
+ /**
150
+ * Options page
151
+ */
152
+ public function wpua_options_page() {
153
+ require_once(WPUA_INC.'wpua-options-page.php');
154
+ }
155
+
156
+ /**
157
+ * Whitelist settings
158
+ * @uses apply_filters()
159
+ * @uses register_setting()
160
+ * @return array
161
+ */
162
+ public function wpua_register_settings() {
163
+ $settings = array();
164
+ $settings[] = register_setting('wpua-settings-group', 'avatar_rating');
165
+ $settings[] = register_setting('wpua-settings-group', 'avatar_default');
166
+ $settings[] = register_setting('wpua-settings-group', 'avatar_default_wp_user_avatar');
167
+ $settings[] = register_setting('wpua-settings-group', 'show_avatars', 'intval');
168
+ $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_tinymce', 'intval');
169
+ $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_allow_upload', 'intval');
170
+ $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_disable_gravatar', 'intval');
171
+ $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_edit_avatar', 'intval');
172
+ $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_resize_crop', 'intval');
173
+ $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_resize_h', 'intval');
174
+ $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_resize_upload', 'intval');
175
+ $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_resize_w', 'intval');
176
+ $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_upload_size_limit', 'intval');
177
+ /**
178
+ * Filter admin whitelist settings
179
+ * @param array $settings
180
+ */
181
+ return apply_filters('wpua_register_settings', $settings);
182
+ }
183
+
184
+ /**
185
+ * Add default avatar
186
+ * @uses string $avatar_default
187
+ * @uses string $mustache_admin
188
+ * @uses string $mustache_medium
189
+ * @uses int $wpua_avatar_default
190
+ * @uses bool $wpua_disable_gravatar
191
+ * @uses object $wpua_functions
192
+ * @uses get_avatar()
193
+ * @uses remove_filter()
194
+ * @uses wpua_attachment_is_image()
195
+ * @uses wpua_get_attachment_image_src()
196
+ * @return string
197
+ */
198
+ public function wpua_add_default_avatar() {
199
+ global $avatar_default, $mustache_admin, $mustache_medium, $wpua_avatar_default, $wpua_disable_gravatar, $wpua_functions;
200
+ // Remove get_avatar filter
201
+ remove_filter('get_avatar', array($wpua_functions, 'wpua_get_avatar_filter'));
202
+ // Set avatar_list variable
203
+ $avatar_list = "";
204
+ // Set avatar defaults
205
+ $avatar_defaults = array(
206
+ 'mystery' => __('Mystery Man'),
207
+ 'blank' => __('Blank'),
208
+ 'gravatar_default' => __('Gravatar Logo'),
209
+ 'identicon' => __('Identicon (Generated)'),
210
+ 'wavatar' => __('Wavatar (Generated)'),
211
+ 'monsterid' => __('MonsterID (Generated)'),
212
+ 'retro' => __('Retro (Generated)')
213
+ );
214
+ // No Default Avatar, set to Mystery Man
215
+ if(empty($avatar_default)) {
216
+ $avatar_default = 'mystery';
217
+ }
218
+ // Take avatar_defaults and get examples for unknown@gravatar.com
219
+ foreach($avatar_defaults as $default_key => $default_name) {
220
+ $avatar = get_avatar('unknown@gravatar.com', 32, $default_key);
221
+ $selected = ($avatar_default == $default_key) ? 'checked="checked" ' : "";
222
+ $avatar_list .= "\n\t<label><input type='radio' name='avatar_default' id='avatar_{$default_key}' value='".esc_attr($default_key)."' {$selected}/> ";
223
+ $avatar_list .= preg_replace("/src='(.+?)'/", "src='\$1&amp;forcedefault=1'", $avatar);
224
+ $avatar_list .= ' '.$default_name.'</label>';
225
+ $avatar_list .= '<br />';
226
+ }
227
+ // Show remove link if custom Default Avatar is set
228
+ if(!empty($wpua_avatar_default) && $wpua_functions->wpua_attachment_is_image($wpua_avatar_default)) {
229
+ $avatar_thumb_src = $wpua_functions->wpua_get_attachment_image_src($wpua_avatar_default, array(32,32));
230
+ $avatar_thumb = $avatar_thumb_src[0];
231
+ $hide_remove = "";
232
+ } else {
233
+ $avatar_thumb = $mustache_admin;
234
+ $hide_remove = ' class="wpua-hide"';
235
+ }
236
+ // Default Avatar is wp_user_avatar, check the radio button next to it
237
+ $selected_avatar = ((bool) $wpua_disable_gravatar == 1 || $avatar_default == 'wp_user_avatar') ? ' checked="checked" ' : "";
238
+ // Wrap WPUA in div
239
+ $avatar_thumb_img = '<div id="wpua-preview"><img src="'.$avatar_thumb.'" width="32" /></div>';
240
+ // Add WPUA to list
241
+ $wpua_list = "\n\t<label><input type='radio' name='avatar_default' id='wp_user_avatar_radio' value='wp_user_avatar'$selected_avatar /> ";
242
+ $wpua_list .= preg_replace("/src='(.+?)'/", "src='\$1'", $avatar_thumb_img);
243
+ $wpua_list .= ' '.__('WP User Avatar', 'wp-user-avatar').'</label>';
244
+ $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>';
245
+ $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>';
246
+ $wpua_list .= '<input type="hidden" id="wp-user-avatar" name="avatar_default_wp_user_avatar" value="'.$wpua_avatar_default.'">';
247
+ $wpua_list .= '<div id="wpua-modal"></div>';
248
+ if((bool) $wpua_disable_gravatar != 1) {
249
+ return $wpua_list.'<div id="wp-avatars">'.$avatar_list.'</div>';
250
+ } else {
251
+ return $wpua_list;
252
+ }
253
+ }
254
+
255
+ /**
256
+ * Add default avatar_default to whitelist
257
+ * @param array $options
258
+ * @return array $options
259
+ */
260
+ public function wpua_whitelist_options($options) {
261
+ $options['discussion'][] = 'avatar_default_wp_user_avatar';
262
+ return $options;
263
+ }
264
+
265
+ /**
266
+ * Add actions links on plugin page
267
+ * @param array $links
268
+ * @param string $file
269
+ * @return array $links
270
+ */
271
+ public function wpua_action_links($links, $file) {
272
+ if(basename(dirname($file)) == 'wp-user-avatar') {
273
+ $links[] = '<a href="'.add_query_arg(array('page' => 'wp-user-avatar'), admin_url('admin.php')).'">'.__('Settings').'</a>';
274
+ }
275
+ return $links;
276
+ }
277
+
278
+ /**
279
+ * Add row meta on plugin page
280
+ * @param array $links
281
+ * @param string $file
282
+ * @return array $links
283
+ */
284
+ public function wpua_row_meta($links, $file) {
285
+ if(basename(dirname($file)) == 'wp-user-avatar') {
286
+ $links[] = '<a href="http://wordpress.org/support/plugin/wp-user-avatar" target="_blank">'.__('Support Forums').'</a>';
287
+ $links[] = '<a href="http://siboliban.org/donate" target="_blank">'.__('Donate', 'wp-user-avatar').'</a>';
288
+ }
289
+ return $links;
290
+ }
291
+
292
+ /**
293
+ * Add column to Users table
294
+ * @param array $columns
295
+ * @return array
296
+ */
297
+ public function wpua_add_column($columns) {
298
+ return $columns + array('wp-user-avatar' => __('Avatar'));
299
+ }
300
+
301
+ /**
302
+ * Show thumbnail in Users table
303
+ * @param string $value
304
+ * @param string $column_name
305
+ * @param int $user_id
306
+ * @uses int $blog_id
307
+ * @uses object $wpdb
308
+ * @uses object $wpua_functions
309
+ * @uses get_blog_prefix()
310
+ * @uses get_user_meta()
311
+ * @uses wpua_get_attachment_image()
312
+ * @return string $value
313
+ */
314
+ public function wpua_show_column($value, $column_name, $user_id) {
315
+ global $blog_id, $wpdb, $wpua_functions;
316
+ $wpua = get_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', true);
317
+ $wpua_image = $wpua_functions->wpua_get_attachment_image($wpua, array(32,32));
318
+ if($column_name == 'wp-user-avatar') {
319
+ $value = $wpua_image;
320
+ }
321
+ return $value;
322
+ }
323
+
324
+ /**
325
+ * Get list table
326
+ * @param string $class
327
+ * @param array $args
328
+ * @return object
329
+ */
330
+ public function _wpua_get_list_table($class, $args = array()) {
331
+ require_once(WPUA_INC.'class-wp-user-avatar-list-table.php');
332
+ $args['screen'] = 'wp-user-avatar';
333
+ return new $class($args);
334
+ }
335
+
336
+ /**
337
+ * Add media states
338
+ * @param array $states
339
+ * @uses object $post
340
+ * @uses int $wpua_avatar_default
341
+ * @uses apply_filters()
342
+ * @uses get_post_custom_values()
343
+ * @return array
344
+ */
345
+ public function wpua_add_media_state($states) {
346
+ global $post, $wpua_avatar_default;
347
+ $is_wpua = get_post_custom_values('_wp_attachment_wp_user_avatar', $post->ID);
348
+ if(!empty($is_wpua)) {
349
+ $states[] = __('Avatar');
350
+ }
351
+ if(!empty($wpua_avatar_default) && ($wpua_avatar_default == $post->ID)) {
352
+ $states[] = __('Default Avatar');
353
+ }
354
+ /**
355
+ * Filter media states
356
+ * @param array $states
357
+ */
358
+ return apply_filters('wpua_add_media_state', $states);
359
+ }
360
+ }
361
+
362
+ /**
363
+ * Initialize
364
+ */
365
+ function wpua_admin_init() {
366
+ global $wpua_admin;
367
+ $wpua_admin = new WP_User_Avatar_Admin();
368
+ }
369
+ add_action('init', 'wpua_admin_init');
includes/class-wp-user-avatar-functions.php ADDED
@@ -0,0 +1,423 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Core user functions.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.5
7
+ */
8
+
9
+ class WP_User_Avatar_Functions {
10
+ /**
11
+ * Constructor
12
+ * @uses add_filter()
13
+ */
14
+ public function __construct() {
15
+ add_filter('get_avatar', array($this, 'wpua_get_avatar_filter'), 10, 5);
16
+ }
17
+
18
+ /**
19
+ * Returns true if user has Gravatar-hosted image
20
+ * @param int|string $id_or_email
21
+ * @param bool $has_gravatar
22
+ * @param int|string $user
23
+ * @param string $email
24
+ * @uses get_user_by()
25
+ * @uses is_wp_error()
26
+ * @uses wp_cache_get()
27
+ * @uses wp_cache_set()
28
+ * @uses wp_remote_head()
29
+ * @return bool $has_gravatar
30
+ */
31
+ public function wpua_has_gravatar($id_or_email="", $has_gravatar=0, $user="", $email="") {
32
+ if(!is_object($id_or_email) && !empty($id_or_email)) {
33
+ // Find user by ID or e-mail address
34
+ $user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
35
+ // Get registered user e-mail address
36
+ $email = !empty($user) ? $user->user_email : "";
37
+ }
38
+ // Check if Gravatar image returns 200 (OK) or 404 (Not Found)
39
+ $hash = md5(strtolower(trim($email)));
40
+ $gravatar = 'http://www.gravatar.com/avatar/'.$hash.'?d=404';
41
+ $data = wp_cache_get($hash);
42
+ if(false === $data) {
43
+ $response = wp_remote_head($gravatar);
44
+ $data = is_wp_error($response) ? 'not200' : $response['response']['code'];
45
+ wp_cache_set($hash, $data, $group="", $expire=60*5);
46
+ }
47
+ $has_gravatar = ($data == '200') ? true : false;
48
+ return $has_gravatar;
49
+ }
50
+
51
+ /**
52
+ * Check if local image
53
+ * @param int $attachment_id
54
+ * @uses apply_filters()
55
+ * @uses wp_attachment_is_image()
56
+ * @return bool
57
+ */
58
+ public function wpua_attachment_is_image($attachment_id) {
59
+ $is_image = wp_attachment_is_image($attachment_id);
60
+ /**
61
+ * Filter local image check
62
+ * @param bool $is_image
63
+ * @param int $attachment_id
64
+ */
65
+ $is_image = apply_filters('wpua_attachment_is_image', $is_image, $attachment_id);
66
+ return $is_image;
67
+ }
68
+
69
+ /**
70
+ * Get local image tag
71
+ * @param int $attachment_id
72
+ * @param int|string $size
73
+ * @param bool $icon
74
+ * @param string $attr
75
+ * @uses apply_filters()
76
+ * @uses wp_get_attachment_image()
77
+ * @return string
78
+ */
79
+ public function wpua_get_attachment_image($attachment_id, $size='thumbnail', $icon=0, $attr='') {
80
+ $image = wp_get_attachment_image($attachment_id, $size, $icon, $attr);
81
+ /**
82
+ * Filter local image tag
83
+ * @param string $image
84
+ * @param int $attachment_id
85
+ * @param int|string $size
86
+ * @param bool $icon
87
+ * @param string $attr
88
+ */
89
+ return apply_filters('wpua_get_attachment_image', $image, $attachment_id, $size, $icon, $attr);
90
+ }
91
+
92
+ /**
93
+ * Get local image src
94
+ * @param int $attachment_id
95
+ * @param int|string $size
96
+ * @param bool $icon
97
+ * @uses apply_filters()
98
+ * @uses wp_get_attachment_image_src()
99
+ * @return array
100
+ */
101
+ public function wpua_get_attachment_image_src($attachment_id, $size='thumbnail', $icon=0) {
102
+ $image_src_array = wp_get_attachment_image_src($attachment_id, $size, $icon);
103
+ /**
104
+ * Filter local image src
105
+ * @param array $image_src_array
106
+ * @param int $attachment_id
107
+ * @param int|string $size
108
+ * @param bool $icon
109
+ */
110
+ return apply_filters('wpua_get_attachment_image_src', $image_src_array, $attachment_id, $size, $icon);
111
+ }
112
+
113
+ /**
114
+ * Returns true if user has wp_user_avatar
115
+ * @param int|string $id_or_email
116
+ * @param bool $has_wpua
117
+ * @param object $user
118
+ * @param int $user_id
119
+ * @uses int $blog_id
120
+ * @uses object $wpdb
121
+ * @uses int $wpua_avatar_default
122
+ * @uses object $wpua_functions
123
+ * @uses get_user_by()
124
+ * @uses get_user_meta()
125
+ * @uses get_blog_prefix()
126
+ * @uses wpua_attachment_is_image()
127
+ * @return bool
128
+ */
129
+ public function has_wp_user_avatar($id_or_email="", $has_wpua=0, $user="", $user_id="") {
130
+ global $blog_id, $wpdb, $wpua_avatar_default, $wpua_functions;
131
+ if(!is_object($id_or_email) && !empty($id_or_email)) {
132
+ // Find user by ID or e-mail address
133
+ $user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
134
+ // Get registered user ID
135
+ $user_id = !empty($user) ? $user->ID : "";
136
+ }
137
+ $wpua = get_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', true);
138
+ // Check if avatar is same as default avatar or on excluded list
139
+ $has_wpua = !empty($wpua) && ($wpua != $wpua_avatar_default) && $wpua_functions->wpua_attachment_is_image($wpua) ? true : false;
140
+ return $has_wpua;
141
+ }
142
+
143
+ /**
144
+ * Replace get_avatar only in get_wp_user_avatar
145
+ * @param string $avatar
146
+ * @param int|string $id_or_email
147
+ * @param int|string $size
148
+ * @param string $default
149
+ * @param string $alt
150
+ * @uses string $avatar_default
151
+ * @uses string $mustache_admin
152
+ * @uses string $mustache_avatar
153
+ * @uses string $mustache_medium
154
+ * @uses string $mustache_original
155
+ * @uses string $mustache_thumbnail
156
+ * @uses object $post
157
+ * @uses int $wpua_avatar_default
158
+ * @uses bool $wpua_disable_gravatar
159
+ * @uses object $wpua_functions
160
+ * @uses apply_filters()
161
+ * @uses get_wp_user_avatar()
162
+ * @uses has_wp_user_avatar()
163
+ * @uses wpua_has_gravatar()
164
+ * @uses wpua_attachment_is_image()
165
+ * @uses wpua_get_attachment_image_src()
166
+ * @uses get_option()
167
+ * @return string $avatar
168
+ */
169
+ public function wpua_get_avatar_filter($avatar, $id_or_email="", $size="", $default="", $alt="") {
170
+ global $avatar_default, $mustache_admin, $mustache_avatar, $mustache_medium, $mustache_original, $mustache_thumbnail, $post, $wpua_avatar_default, $wpua_disable_gravatar, $wpua_functions;
171
+ // User has WPUA
172
+ if(is_object($id_or_email)) {
173
+ if(!empty($id_or_email->comment_author_email)) {
174
+ $avatar = get_wp_user_avatar($id_or_email, $size, $default, $alt);
175
+ } else {
176
+ $avatar = get_wp_user_avatar('unknown@gravatar.com', $size, $default, $alt);
177
+ }
178
+ } else {
179
+ if(has_wp_user_avatar($id_or_email)) {
180
+ $avatar = get_wp_user_avatar($id_or_email, $size, $default, $alt);
181
+ // User has Gravatar and Gravatar is not disabled
182
+ } elseif((bool) $wpua_disable_gravatar != 1 && $wpua_functions->wpua_has_gravatar($id_or_email)) {
183
+ $avatar = $avatar;
184
+ // User doesn't have WPUA or Gravatar and Default Avatar is wp_user_avatar, show custom Default Avatar
185
+ } elseif($avatar_default == 'wp_user_avatar') {
186
+ // Show custom Default Avatar
187
+ if(!empty($wpua_avatar_default) && $wpua_functions->wpua_attachment_is_image($wpua_avatar_default)) {
188
+ // Get image
189
+ $wpua_avatar_default_image = $wpua_functions->wpua_get_attachment_image_src($wpua_avatar_default, array($size,$size));
190
+ // Image src
191
+ $default = $wpua_avatar_default_image[0];
192
+ // Add dimensions if numeric size
193
+ $dimensions = ' width="'.$wpua_avatar_default_image[1].'" height="'.$wpua_avatar_default_image[2].'"';
194
+ } else {
195
+ // Get mustache image based on numeric size comparison
196
+ if($size > get_option('medium_size_w')) {
197
+ $default = $mustache_original;
198
+ } elseif($size <= get_option('medium_size_w') && $size > get_option('thumbnail_size_w')) {
199
+ $default = $mustache_medium;
200
+ } elseif($size <= get_option('thumbnail_size_w') && $size > 96) {
201
+ $default = $mustache_thumbnail;
202
+ } elseif($size <= 96 && $size > 32) {
203
+ $default = $mustache_avatar;
204
+ } elseif($size <= 32) {
205
+ $default = $mustache_admin;
206
+ }
207
+ // Add dimensions if numeric size
208
+ $dimensions = ' width="'.$size.'" height="'.$size.'"';
209
+ }
210
+ // Construct the img tag
211
+ $avatar = '<img src="'.$default.'"'.$dimensions.' alt="'.$alt.'" class="avatar avatar-'.$size.' wp-user-avatar wp-user-avatar-'.$size.' photo avatar-default" />';
212
+ }
213
+ }
214
+ /**
215
+ * Filter get_avatar filter
216
+ * @param string $avatar
217
+ * @param int|string $id_or_email
218
+ * @param int|string $size
219
+ * @param string $default
220
+ * @param string $alt
221
+ */
222
+ return apply_filters('wpua_get_avatar_filter', $avatar, $id_or_email, $size, $default, $alt);
223
+ }
224
+
225
+ /**
226
+ * Get original avatar, for when user removes wp_user_avatar
227
+ * @param int|string $id_or_email
228
+ * @param int|string $size
229
+ * @param string $default
230
+ * @param string $alt
231
+ * @uses string $avatar_default
232
+ * @uses string $mustache_avatar
233
+ * @uses int $wpua_avatar_default
234
+ * @uses bool $wpua_disable_gravatar
235
+ * @uses object $wpua_functions
236
+ * @uses wpua_attachment_is_image()
237
+ * @uses wpua_get_attachment_image_src()
238
+ * @uses wpua_has_gravatar()
239
+ * @uses add_filter()
240
+ * @uses apply_filters()
241
+ * @uses get_avatar()
242
+ * @uses remove_filter()
243
+ * @return string $default
244
+ */
245
+ public function wpua_get_avatar_original($id_or_email="", $size="", $default="", $alt="") {
246
+ global $avatar_default, $mustache_avatar, $wpua_avatar_default, $wpua_disable_gravatar, $wpua_functions;
247
+ // Remove get_avatar filter
248
+ remove_filter('get_avatar', array($wpua_functions, 'wpua_get_avatar_filter'));
249
+ if((bool) $wpua_disable_gravatar != 1) {
250
+ // User doesn't have Gravatar and Default Avatar is wp_user_avatar, show custom Default Avatar
251
+ if(!$wpua_functions->wpua_has_gravatar($id_or_email) && $avatar_default == 'wp_user_avatar') {
252
+ // Show custom Default Avatar
253
+ if(!empty($wpua_avatar_default) && $wpua_functions->wpua_attachment_is_image($wpua_avatar_default)) {
254
+ $wpua_avatar_default_image = $wpua_functions->wpua_get_attachment_image_src($wpua_avatar_default, array($size,$size));
255
+ $default = $wpua_avatar_default_image[0];
256
+ } else {
257
+ $default = $mustache_avatar;
258
+ }
259
+ } else {
260
+ // Get image from Gravatar, whether it's the user's image or default image
261
+ $wpua_image = get_avatar($id_or_email, $size);
262
+ // Takes the img tag, extracts the src
263
+ $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $wpua_image, $matches, PREG_SET_ORDER);
264
+ $default = !empty($matches) ? $matches [0] [1] : "";
265
+ }
266
+ } else {
267
+ if(!empty($wpua_avatar_default) && $wpua_functions->wpua_attachment_is_image($wpua_avatar_default)) {
268
+ $wpua_avatar_default_image = $wpua_functions->wpua_get_attachment_image_src($wpua_avatar_default, array($size,$size));
269
+ $default = $wpua_avatar_default_image[0];
270
+ } else {
271
+ $default = $mustache_avatar;
272
+ }
273
+ }
274
+ // Enable get_avatar filter
275
+ add_filter('get_avatar', array($wpua_functions, 'wpua_get_avatar_filter'), 10, 5);
276
+ /**
277
+ * Filter original avatar src
278
+ * @param string $default
279
+ */
280
+ return apply_filters('wpua_get_avatar_original', $default);
281
+ }
282
+
283
+ /**
284
+ * Find WPUA, show get_avatar if empty
285
+ * @param int|string $id_or_email
286
+ * @param int|string $size
287
+ * @param string $align
288
+ * @param string $alt
289
+ * @uses array $_wp_additional_image_sizes
290
+ * @uses array $all_sizes
291
+ * @uses string $avatar_default
292
+ * @uses int $blog_id
293
+ * @uses object $post
294
+ * @uses object $wpdb
295
+ * @uses int $wpua_avatar_default
296
+ * @uses object $wpua_functions
297
+ * @uses apply_filters()
298
+ * @uses get_the_author_meta()
299
+ * @uses get_blog_prefix()
300
+ * @uses get_user_by()
301
+ * @uses get_query_var()
302
+ * @uses is_author()
303
+ * @uses wpua_attachment_is_image()
304
+ * @uses wpua_get_attachment_image_src()
305
+ * @uses get_option()
306
+ * @uses get_avatar()
307
+ * @return string $avatar
308
+ */
309
+ public function get_wp_user_avatar($id_or_email="", $size='96', $align="", $alt="") {
310
+ global $all_sizes, $avatar_default, $blog_id, $post, $wpdb, $wpua_avatar_default, $wpua_functions, $_wp_additional_image_sizes;
311
+ $email='unknown@gravatar.com';
312
+ // Checks if comment
313
+ if(is_object($id_or_email)) {
314
+ // Checks if comment author is registered user by user ID
315
+ if($id_or_email->user_id != 0) {
316
+ $email = $id_or_email->user_id;
317
+ // Checks that comment author isn't anonymous
318
+ } elseif(!empty($id_or_email->comment_author_email)) {
319
+ // Checks if comment author is registered user by e-mail address
320
+ $user = get_user_by('email', $id_or_email->comment_author_email);
321
+ // Get registered user info from profile, otherwise e-mail address should be value
322
+ $email = !empty($user) ? $user->ID : $id_or_email->comment_author_email;
323
+ }
324
+ $alt = $id_or_email->comment_author;
325
+ } else {
326
+ if(!empty($id_or_email)) {
327
+ // Find user by ID or e-mail address
328
+ $user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
329
+ } else {
330
+ // Find author's name if id_or_email is empty
331
+ $author_name = get_query_var('author_name');
332
+ if(is_author()) {
333
+ // On author page, get user by page slug
334
+ $user = get_user_by('slug', $author_name);
335
+ } else {
336
+ // On post, get user by author meta
337
+ $user_id = get_the_author_meta('ID');
338
+ $user = get_user_by('id', $user_id);
339
+ }
340
+ }
341
+ // Set user's ID and name
342
+ if(!empty($user)) {
343
+ $email = $user->ID;
344
+ $alt = $user->display_name;
345
+ }
346
+ }
347
+ // Checks if user has WPUA
348
+ $wpua_meta = get_the_author_meta($wpdb->get_blog_prefix($blog_id).'user_avatar', $email);
349
+ // Add alignment class
350
+ $alignclass = !empty($align) && ($align == 'left' || $align == 'right' || $align == 'center') ? ' align'.$align : ' alignnone';
351
+ // User has WPUA, check if on excluded list and bypass get_avatar
352
+ if(!empty($wpua_meta) && $wpua_functions->wpua_attachment_is_image($wpua_meta)) {
353
+ // Numeric size use size array
354
+ $get_size = is_numeric($size) ? array($size,$size) : $size;
355
+ // Get image src
356
+ $wpua_image = $wpua_functions->wpua_get_attachment_image_src($wpua_meta, $get_size);
357
+ // Add dimensions to img only if numeric size was specified
358
+ $dimensions = is_numeric($size) ? ' width="'.$wpua_image[1].'" height="'.$wpua_image[2].'"' : "";
359
+ // Construct the img tag
360
+ $avatar = '<img src="'.$wpua_image[0].'"'.$dimensions.' alt="'.$alt.'" class="avatar avatar-'.$size.' wp-user-avatar wp-user-avatar-'.$size.$alignclass.' photo" />';
361
+ } else {
362
+ // Check for custom image sizes
363
+ if(in_array($size, $all_sizes)) {
364
+ if(in_array($size, array('original', 'large', 'medium', 'thumbnail'))) {
365
+ $get_size = ($size == 'original') ? get_option('large_size_w') : get_option($size.'_size_w');
366
+ } else {
367
+ $get_size = $_wp_additional_image_sizes[$size]['width'];
368
+ }
369
+ } else {
370
+ // Numeric sizes leave as-is
371
+ $get_size = $size;
372
+ }
373
+ // User with no WPUA uses get_avatar
374
+ $avatar = get_avatar($email, $get_size, $default="", $alt="");
375
+ // Remove width and height for non-numeric sizes
376
+ if(in_array($size, array('original', 'large', 'medium', 'thumbnail'))) {
377
+ $avatar = preg_replace('/(width|height)=\"\d*\"\s/', "", $avatar);
378
+ $avatar = preg_replace("/(width|height)=\'\d*\'\s/", "", $avatar);
379
+ }
380
+ $replace = array('wp-user-avatar ', 'wp-user-avatar-'.$get_size.' ', 'wp-user-avatar-'.$size.' ', 'avatar-'.$get_size, 'photo');
381
+ $replacements = array("", "", "", 'avatar-'.$size, 'wp-user-avatar wp-user-avatar-'.$size.$alignclass.' photo');
382
+ $avatar = str_replace($replace, $replacements, $avatar);
383
+ }
384
+ /**
385
+ * Filter get_wp_user_avatar
386
+ * @param string $avatar
387
+ * @param int|string $id_or_email
388
+ * @param int|string $size
389
+ * @param string $align
390
+ * @param string $alt
391
+ */
392
+ return apply_filters('get_wp_user_avatar', $avatar, $id_or_email, $size, $align, $alt);
393
+ }
394
+
395
+ /**
396
+ * Return just the image src
397
+ * @param int|string $id_or_email
398
+ * @param int|string $size
399
+ * @param string $align
400
+ * @uses get_wp_user_avatar()
401
+ * @return string
402
+ */
403
+ public function get_wp_user_avatar_src($id_or_email="", $size="", $align="") {
404
+ $wpua_image_src = "";
405
+ // Gets the avatar img tag
406
+ $wpua_image = get_wp_user_avatar($id_or_email, $size, $align);
407
+ // Takes the img tag, extracts the src
408
+ if(!empty($wpua_image)) {
409
+ $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $wpua_image, $matches, PREG_SET_ORDER);
410
+ $wpua_image_src = !empty($matches) ? $matches [0] [1] : "";
411
+ }
412
+ return $wpua_image_src;
413
+ }
414
+ }
415
+
416
+ /**
417
+ * Initialize
418
+ */
419
+ function wpua_functions_init() {
420
+ global $wpua_functions;
421
+ $wpua_functions = new WP_User_Avatar_Functions();
422
+ }
423
+ add_action('plugins_loaded', 'wpua_functions_init');
includes/class-wp-user-avatar-list-table.php ADDED
@@ -0,0 +1,387 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Based on WP_Media_List_Table class.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.5
7
+ */
8
+
9
+ class WP_User_Avatar_List_Table extends WP_List_Table {
10
+ /**
11
+ * Constructor
12
+ * @param array $args
13
+ * @uses array $avatars
14
+ * @uses object $post
15
+ * @uses int $wpua_avatar_default
16
+ * @uses get_query_var()
17
+ * @uses have_posts()
18
+ * @uses the_post()
19
+ * @uses wp_edit_attachments_query
20
+ * @uses WP_Query()
21
+ * @uses wp_reset_query()
22
+ */
23
+ public function __construct($args = array()) {
24
+ global $avatars, $post, $wpua_avatar_default;
25
+ $paged = (get_query_var('page')) ? get_query_var('page') : 1;
26
+ $q = array(
27
+ 'paged' => $paged,
28
+ 'post_type' => 'attachment',
29
+ 'post_status' => 'inherit',
30
+ 'posts_per_page' => '-1',
31
+ 'meta_query' => array(
32
+ array(
33
+ 'key' => '_wp_attachment_wp_user_avatar',
34
+ 'value' => "",
35
+ 'compare' => '!='
36
+ )
37
+ )
38
+ );
39
+ $avatars_wp_query = new WP_Query($q);
40
+ $avatars = array();
41
+ while($avatars_wp_query->have_posts()) : $avatars_wp_query->the_post();
42
+ $avatars[] = $post->ID;
43
+ endwhile;
44
+ wp_reset_query();
45
+ // Include default avatar
46
+ $avatars[] = $wpua_avatar_default;
47
+ parent::__construct(array(
48
+ 'plural' => 'media',
49
+ 'screen' => isset($args['screen']) ? $args['screen'] : null
50
+ ));
51
+ }
52
+
53
+ /**
54
+ * Only users with edit_users capability can use this section
55
+ * @uses current_user_can()
56
+ */
57
+ public function ajax_user_can() {
58
+ return current_user_can('edit_users');
59
+ }
60
+
61
+ /**
62
+ * Search form
63
+ * @param string $text
64
+ * @param int $input_id
65
+ * @uses _admin_search_query()
66
+ * @uses has_items()
67
+ * @uses submit_button()
68
+ */
69
+ public function search_box($text, $input_id) {
70
+ if(empty($_REQUEST['s']) && !$this->has_items()) {
71
+ return;
72
+ }
73
+ $input_id = $input_id.'-search-input';
74
+ if(!empty($_REQUEST['orderby'])) {
75
+ echo '<input type="hidden" name="orderby" value="'.esc_attr($_REQUEST['orderby']).'" />';
76
+ }
77
+ if(!empty($_REQUEST['order'])) {
78
+ echo '<input type="hidden" name="order" value="'.esc_attr($_REQUEST['order']).'" />';
79
+ }
80
+ if(!empty($_REQUEST['post_mime_type'])) {
81
+ echo '<input type="hidden" name="post_mime_type" value="'.esc_attr($_REQUEST['post_mime_type']).'" />';
82
+ }
83
+ if(!empty($_REQUEST['detached'])) {
84
+ echo '<input type="hidden" name="detached" value="'.esc_attr($_REQUEST['detached']).'" />';
85
+ }
86
+ ?>
87
+ <p class="search-box">
88
+ <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
89
+ <input type="hidden" id="page" name="page" value="wp-user-avatar-library" />
90
+ <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" />
91
+ <?php submit_button($text, 'button', false, false, array('id' => 'search-submit')); ?>
92
+ </p>
93
+ <?php
94
+ }
95
+
96
+ /**
97
+ * Return only avatars and paginate results
98
+ * @uses array $avatars
99
+ * @uses wp_edit_attachments_query()
100
+ */
101
+ public function prepare_items() {
102
+ global $avail_post_mime_types, $avatars, $lost, $post, $post_mime_types, $wp_query, $wpdb;
103
+ $q = $_REQUEST;
104
+ $q['post__in'] = $avatars;
105
+ list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query($q);
106
+ $this->is_trash = isset($_REQUEST['status']) && $_REQUEST['status'] == 'trash';
107
+ $this->set_pagination_args(array(
108
+ 'total_items' => $wp_query->found_posts,
109
+ 'total_pages' => $wp_query->max_num_pages,
110
+ 'per_page' => $wp_query->query_vars['posts_per_page'],
111
+ ));
112
+ }
113
+
114
+ /**
115
+ * Links to available table views
116
+ * @uses array $avatars
117
+ * @uses add_query_arg()
118
+ * @uses number_format_i18n()
119
+ * @return array
120
+ */
121
+ public function get_views() {
122
+ global $avatars;
123
+ $type_links = array();
124
+ $_total_posts = count(array_filter($avatars));
125
+ $class = (empty($_GET['post_mime_type']) && !isset($_GET['status'])) ? ' class="current"' : "";
126
+ $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>';
127
+ return $type_links;
128
+ }
129
+
130
+ /**
131
+ * Bulk action available with this table
132
+ * @return array
133
+ */
134
+ public function get_bulk_actions() {
135
+ $actions = array();
136
+ $actions['delete'] = __('Delete Permanently');
137
+ return $actions;
138
+ }
139
+
140
+ /**
141
+ * Current action from bulk actions list
142
+ * @uses current_action()
143
+ * @return string|bool
144
+ */
145
+ public function current_action() {
146
+ return parent::current_action();
147
+ }
148
+
149
+ /**
150
+ * Checks whether table has items
151
+ * @uses have_posts()
152
+ * @return bool
153
+ */
154
+ public function has_items() {
155
+ return have_posts();
156
+ }
157
+
158
+ /**
159
+ * Message displayed when no items
160
+ */
161
+ public function no_items() {
162
+ _e('No media attachments found.');
163
+ }
164
+
165
+ /**
166
+ * Columns in this table
167
+ * @return array
168
+ */
169
+ public function get_columns() {
170
+ $columns = array();
171
+ $columns['cb'] = '<input type="checkbox" />';
172
+ $columns['icon'] = "";
173
+ $columns['title'] = _x('File', 'column name');
174
+ $columns['author'] = __('Author');
175
+ $columns['parent'] = _x('Uploaded to', 'column name');
176
+ $columns['date'] = _x('Date', 'column name');
177
+ return $columns;
178
+ }
179
+
180
+ /**
181
+ * Sortable columns in this table
182
+ * @return array
183
+ */
184
+ public function get_sortable_columns() {
185
+ return array(
186
+ 'title' => 'title',
187
+ 'author' => 'author',
188
+ 'date' => array('date', true)
189
+ );
190
+ }
191
+
192
+ /**
193
+ * Display for rows in table
194
+ * @uses object $post
195
+ * @uses object $wpdb
196
+ * @uses object $wpua_functions
197
+ * @uses add_filter()
198
+ * @uses _draft_or_post_title()
199
+ * @uses _media_states()
200
+ * @uses current_user_can()
201
+ * @uses get_attached_file()
202
+ * @uses get_current_user_id()
203
+ * @uses get_edit_post_link()
204
+ * @uses get_edit_user_link()
205
+ * @uses get_post_mime_type()
206
+ * @uses get_the_author()
207
+ * @uses get_the_author_meta()
208
+ * @uses get_userdata()
209
+ * @uses have_posts()
210
+ * @uses the_post()
211
+ * @uses wpua_get_attachment_image()
212
+ */
213
+ public function display_rows() {
214
+ global $post, $wpdb, $wpua_functions;
215
+ add_filter('the_title','esc_html');
216
+ $alt = "";
217
+ while (have_posts()) : the_post();
218
+ $user_can_edit = current_user_can('edit_post', $post->ID);
219
+ if($this->is_trash && $post->post_status != 'trash' || !$this->is_trash && $post->post_status == 'trash') {
220
+ continue;
221
+ }
222
+ $alt = ('alternate' == $alt) ? "" : 'alternate';
223
+ $post_owner = (get_current_user_id() == $post->post_author) ? 'self' : 'other';
224
+ $att_title = _draft_or_post_title();
225
+ ?>
226
+ <tr id='post-<?php echo $post->ID; ?>' class='<?php echo trim($alt.' author-'.$post_owner.' status-'.$post->post_status); ?>' valign="top">
227
+ <?php
228
+ list($columns, $hidden) = $this->get_column_info();
229
+ foreach($columns as $column_name => $column_display_name) {
230
+ $class = "class='$column_name column-$column_name'";
231
+ $style = "";
232
+ if(in_array($column_name, $hidden)) {
233
+ $style = ' style="display:none;"';
234
+ }
235
+ $attributes = $class.$style;
236
+ switch($column_name) {
237
+ case 'cb':
238
+ ?>
239
+ <th scope="row" class="check-column">
240
+ <?php if($user_can_edit) { ?>
241
+ <label class="screen-reader-text" for="cb-select-<?php the_ID(); ?>"><?php echo sprintf(__('Select %s'), $att_title);?></label>
242
+ <input type="checkbox" name="media[]" id="cb-select-<?php the_ID(); ?>" value="<?php the_ID(); ?>" />
243
+ <?php } ?>
244
+ </th>
245
+ <?php
246
+ break;
247
+ case 'icon':
248
+ $attributes = 'class="column-icon media-icon"'.$style;
249
+ ?>
250
+ <td <?php echo $attributes ?>><?php
251
+ if($thumb = $wpua_functions->wpua_get_attachment_image($post->ID, array(80, 60), true)) {
252
+ if($this->is_trash || !$user_can_edit) {
253
+ echo $thumb;
254
+ } else {
255
+ ?>
256
+ <a href="<?php echo get_edit_post_link($post->ID, true); ?>" title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $att_title)); ?>">
257
+ <?php echo $thumb; ?>
258
+ </a>
259
+ <?php } }
260
+ ?>
261
+ </td>
262
+ <?php
263
+ break;
264
+ case 'title':
265
+ ?>
266
+ <td <?php echo $attributes ?>><strong>
267
+ <?php if($this->is_trash || !$user_can_edit) {
268
+ echo $att_title;
269
+ } else { ?>
270
+ <a href="<?php echo get_edit_post_link($post->ID, true); ?>"
271
+ title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $att_title)); ?>">
272
+ <?php echo $att_title; ?></a>
273
+ <?php };
274
+ _media_states($post); ?></strong>
275
+ <p>
276
+ <?php
277
+ if(preg_match('/^.*?\.(\w+)$/', get_attached_file($post->ID), $matches)) {
278
+ echo esc_html(strtoupper($matches[1]));
279
+ } else {
280
+ echo strtoupper(str_replace('image/', "", get_post_mime_type()));
281
+ }
282
+ ?>
283
+ </p>
284
+ <?php echo $this->row_actions($this->_get_row_actions($post, $att_title)); ?>
285
+ </td>
286
+ <?php
287
+ break;
288
+ case 'author':
289
+ ?>
290
+ <td <?php echo $attributes ?>>
291
+ <?php
292
+ printf('<a href="%s">%s</a>',
293
+ esc_url(add_query_arg(array('author' => get_the_author_meta('ID')), 'upload.php')),
294
+ get_the_author()
295
+ ); ?>
296
+ </td>
297
+ <?php
298
+ break;
299
+ case 'date':
300
+ if('0000-00-00 00:00:00' == $post->post_date) {
301
+ $h_time = __('Unpublished');
302
+ } else {
303
+ $m_time = $post->post_date;
304
+ $time = get_post_time('G', true, $post, false);
305
+ if ((abs($t_diff = time() - $time)) < DAY_IN_SECONDS) {
306
+ if ($t_diff < 0)
307
+ $h_time = sprintf(__('%s from now'), human_time_diff($time));
308
+ else
309
+ $h_time = sprintf(__('%s ago'), human_time_diff($time));
310
+ } else {
311
+ $h_time = mysql2date(__('Y/m/d'), $m_time);
312
+ }
313
+ }
314
+ ?>
315
+ <td <?php echo $attributes ?>><?php echo $h_time ?></td>
316
+ <?php
317
+ break;
318
+ case 'parent':
319
+ global $blog_id, $wpdb;
320
+ // Find all users with this WPUA
321
+ $wpua_metakey = $wpdb->get_blog_prefix($blog_id).'user_avatar';
322
+ $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));
323
+ // Find users without WPUA
324
+ $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, ""));
325
+ $user_array = array();
326
+ ?>
327
+ <td <?php echo $attributes ?>>
328
+ <strong>
329
+ <?php
330
+ if(!empty($wpuas)) {
331
+ foreach($wpuas as $usermeta) {
332
+ $user = get_userdata($usermeta->user_id);
333
+ $user_array[] = '<a href="'.get_edit_user_link($user->ID).'">'.$user->user_login.'</a>';
334
+ }
335
+ } else {
336
+ foreach($nowpuas as $usermeta) {
337
+ $user = get_userdata($usermeta->ID);
338
+ $user_array[] = '<a href="'.get_edit_user_link($user->ID).'">'.$user->user_login.'</a>';
339
+ }
340
+ }
341
+ ?>
342
+ <?php echo implode(', ', array_filter($user_array)); ?>
343
+ </strong>
344
+ </td>
345
+ <?php
346
+ break;
347
+ }
348
+ }
349
+ ?>
350
+ </tr>
351
+ <?php endwhile;
352
+ }
353
+
354
+ /**
355
+ * Actions for rows in table
356
+ * @uses object $post
357
+ * @uses string $att_title
358
+ * @uses _draft_or_post_title()
359
+ * @uses current_user_can()
360
+ * @uses get_edit_post_link()
361
+ * @uses get_permalink()
362
+ * @uses wp_nonce_url()
363
+ * @return array
364
+ */
365
+ public function _get_row_actions($post, $att_title) {
366
+ $actions = array();
367
+ if(current_user_can('edit_post', $post->ID) && !$this->is_trash) {
368
+ $actions['edit'] = '<a href="'.get_edit_post_link($post->ID, true).'">'.__('Edit').'</a>';
369
+ }
370
+ if(current_user_can('delete_post', $post->ID)) {
371
+ if($this->is_trash) {
372
+ $actions['untrash'] = "<a class='submitdelete' href='".wp_nonce_url("post.php?action=untrash&amp;post=$post->ID", 'untrash-post_'.$post->ID)."'>".__('Restore')."</a>";
373
+ } elseif (EMPTY_TRASH_DAYS && MEDIA_TRASH) {
374
+ $actions['trash'] = "<a class='submitdelete' href='".wp_nonce_url("post.php?action=trash&amp;post=$post->ID", 'trash-post_'.$post->ID)."'>".__('Trash')."</a>";
375
+ }
376
+ if($this->is_trash || !EMPTY_TRASH_DAYS || !MEDIA_TRASH) {
377
+ $delete_ays = (!$this->is_trash && !MEDIA_TRASH) ? " onclick='return showNotice.warn();'" : "";
378
+ $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>";
379
+ }
380
+ }
381
+ if(!$this->is_trash) {
382
+ $title = _draft_or_post_title($post->post_parent);
383
+ $actions['view'] = '<a href="'.get_permalink($post->ID).'" title="'.esc_attr(sprintf(__('View &#8220;%s&#8221;'), $title)).'" rel="permalink">'.__('View').'</a>';
384
+ }
385
+ return $actions;
386
+ }
387
+ }
includes/class-wp-user-avatar-resource-manager.php ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Move body CSS to head.
4
+ * Borrowed from NextGen Gallery C_Photocrati_Resource_Manager class.
5
+ *
6
+ * @package WP User Avatar
7
+ * @version 1.9.5
8
+ */
9
+
10
+ class WP_User_Avatar_Resource_Manager {
11
+ static $instance = NULL;
12
+
13
+ var $buffer = '';
14
+ var $styles = '';
15
+ var $other_output = '';
16
+ var $wrote_footer = FALSE;
17
+ var $run_shutdown = FALSE;
18
+ var $valid_request = TRUE;
19
+
20
+ /**
21
+ * Start buffering all generated output. We'll then do two things with the buffer
22
+ * 1) Find stylesheets lately enqueued and move them to the header
23
+ * 2) Ensure that wp_print_footer_scripts() is called
24
+ */
25
+ function __construct() {
26
+ // Validate the request
27
+ $this->validate_request();
28
+ add_action('init', array(&$this, 'start_buffer'), 1);
29
+ }
30
+
31
+ /**
32
+ * Determines if the resource manager should perform it's routines for this request
33
+ * @return bool
34
+ */
35
+ function validate_request() {
36
+ $retval = FALSE;
37
+ if(!is_admin()) {
38
+ $retval = TRUE;
39
+ }
40
+ $this->valid_request = $retval;
41
+ }
42
+
43
+ // Start the output buffers
44
+ function start_buffer() {
45
+ ob_start(array(&$this, 'output_buffer_handler'));
46
+ ob_start(array(&$this, 'get_buffer'));
47
+ add_action('wp_print_footer_scripts', array(&$this, 'get_resources'), 1);
48
+ add_action('shutdown', array(&$this, 'shutdown'));
49
+ }
50
+
51
+ function get_resources() {
52
+ ob_start();
53
+ wp_print_styles();
54
+ print_admin_styles();
55
+ $this->styles = ob_get_clean();
56
+ $this->wrote_footer = TRUE;
57
+ }
58
+
59
+ /**
60
+ * Output the buffer after PHP execution has ended (but before shutdown)
61
+ * @param string $content
62
+ * @return string
63
+ */
64
+ function output_buffer_handler($content) {
65
+ return $this->output_buffer();
66
+ }
67
+
68
+ /**
69
+ * Removes the closing </html> tag from the output buffer. We'll then write our own closing tag
70
+ * in the shutdown function after running wp_print_footer_scripts()
71
+ * @param string $content
72
+ * @return mixed
73
+ */
74
+ function get_buffer($content) {
75
+ $this->buffer = $content;
76
+ return '';
77
+ }
78
+
79
+
80
+ // Moves resources to their appropriate place
81
+ function move_resources() {
82
+ if($this->valid_request) {
83
+ // Move stylesheets to head
84
+ if($this->styles) {
85
+ $this->buffer = str_ireplace('</head>', $this->styles.'</head>', $this->buffer);
86
+ }
87
+ }
88
+ }
89
+
90
+ // When PHP has finished, we output the footer scripts and closing tags
91
+ function output_buffer($in_shutdown=FALSE) {
92
+ // If the footer scripts haven't been outputted, then
93
+ // we need to take action - as they're required
94
+ if(!$this->wrote_footer) {
95
+ // We don't want to manipulate the buffer if it doesn't contain HTML
96
+ if(strpos($this->buffer, '</body>') === FALSE) {
97
+ $this->valid_request = FALSE;
98
+ }
99
+ // The output_buffer() function has been called in the PHP shutdown callback
100
+ // This will allow us to print the scripts ourselves and manipulate the buffer
101
+ if($in_shutdown === TRUE) {
102
+ ob_start();
103
+ if(!did_action('wp_footer')) {
104
+ wp_footer();
105
+ } else {
106
+ wp_print_footer_scripts();
107
+ }
108
+ $this->other_output = ob_get_clean();
109
+ }
110
+ // W3TC isn't activated and we're not in the shutdown callback.
111
+ // We'll therefore add a shutdown callback to print the scripts
112
+ else {
113
+ $this->run_shutdown = TRUE;
114
+ return '';
115
+ }
116
+ }
117
+ // Once we have the footer scripts, we can modify the buffer and
118
+ // move the resources around
119
+ if ($this->wrote_footer) $this->move_resources();
120
+ return $this->buffer;
121
+ }
122
+
123
+ // PHP shutdown callback. Manipulate and output the buffer
124
+ function shutdown() {
125
+ if($this->run_shutdown) echo $this->output_buffer(TRUE);
126
+ }
127
+
128
+ public static function init() {
129
+ $klass = get_class();
130
+ return self::$instance = new $klass;
131
+ }
132
+ }
includes/class-wp-user-avatar-shortcode.php ADDED
@@ -0,0 +1,217 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Defines shortcodes.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.5
7
+ */
8
+
9
+ class WP_User_Avatar_Shortcode {
10
+ /**
11
+ * Constructor
12
+ * @uses object $wp_user_avatar
13
+ * @uses add_action()
14
+ * @uses add_shortcode()
15
+ */
16
+ public function __construct() {
17
+ global $wp_user_avatar;
18
+ add_shortcode('avatar', array($this, 'wpua_shortcode'));
19
+ add_shortcode('avatar_upload', array($this, 'wpua_edit_shortcode'));
20
+ // Add avatar and scripts to avatar_upload
21
+ add_action('wpua_show_profile', array($wp_user_avatar, 'wpua_action_show_user_profile'));
22
+ add_action('wpua_show_profile', array($wp_user_avatar, 'wpua_media_upload_scripts'));
23
+ add_action('wpua_update', array($wp_user_avatar, 'wpua_action_process_option_update'));
24
+ // Add error messages to avatar_upload
25
+ add_action('wpua_update_errors', array($wp_user_avatar, 'wpua_upload_errors'), 10, 3);
26
+ }
27
+
28
+ /**
29
+ * Display shortcode
30
+ * @since 1.1
31
+ * @param array $atts
32
+ * @param string $content
33
+ * @uses array $_wp_additional_image_sizes
34
+ * @uses array $all_sizes
35
+ * @uses int $blog_id
36
+ * @uses object $post
37
+ * @uses object $wpdb
38
+ * @uses do_shortcode()
39
+ * @uses get_attachment_link()
40
+ * @uses get_blog_prefix()
41
+ * @uses get_option()
42
+ * @uses get_user_by()
43
+ * @uses get_query_var()
44
+ * @uses get_the_author_meta()
45
+ * @uses get_user_meta()
46
+ * @uses get_wp_user_avatar_src()
47
+ * @uses get_wp_user_avatar()
48
+ * @uses image_add_caption()
49
+ * @uses is_author()
50
+ * @uses shortcode_atts()
51
+ * @return string
52
+ */
53
+ public function wpua_shortcode($atts, $content=null) {
54
+ global $all_sizes, $blog_id, $post, $wpdb;
55
+ // Set shortcode attributes
56
+ extract(shortcode_atts(array('user' => "", 'size' => '96', 'align' => "", 'link' => "", 'target' => ""), $atts));
57
+ // Find user by ID, login, slug, or e-mail address
58
+ if(!empty($user)) {
59
+ $user = is_numeric($user) ? get_user_by('id', $user) : get_user_by('login', $user);
60
+ $user = empty($user) ? get_user_by('slug', $user) : $user;
61
+ $user = empty($user) ? get_user_by('email', $user) : $user;
62
+ } else {
63
+ // Find author's name if id_or_email is empty
64
+ $author_name = get_query_var('author_name');
65
+ if(is_author()) {
66
+ // On author page, get user by page slug
67
+ $user = get_user_by('slug', $author_name);
68
+ } else {
69
+ // On post, get user by author meta
70
+ $user_id = get_the_author_meta('ID');
71
+ $user = get_user_by('id', $user_id);
72
+ }
73
+ }
74
+ // Numeric sizes leave as-is
75
+ $get_size = $size;
76
+ // Check for custom image sizes if there are captions
77
+ if(!empty($content)) {
78
+ if(in_array($size, $all_sizes)) {
79
+ if(in_array($size, array('original', 'large', 'medium', 'thumbnail'))) {
80
+ $get_size = ($size == 'original') ? get_option('large_size_w') : get_option($size.'_size_w');
81
+ } else {
82
+ $get_size = $_wp_additional_image_sizes[$size]['width'];
83
+ }
84
+ }
85
+ }
86
+ // Get user ID
87
+ $id_or_email = !empty($user) ? $user->ID : 'unknown@gravatar.com';
88
+ // Check if link is set
89
+ if(!empty($link)) {
90
+ // CSS class is same as link type, except for URL
91
+ $link_class = $link;
92
+ if($link == 'file') {
93
+ // Get image src
94
+ $link = get_wp_user_avatar_src($id_or_email, 'original');
95
+ } elseif($link == 'attachment') {
96
+ // Get attachment URL
97
+ $link = get_attachment_link(get_the_author_meta($wpdb->get_blog_prefix($blog_id).'user_avatar', $id_or_email));
98
+ } else {
99
+ // URL
100
+ $link_class = 'custom';
101
+ }
102
+ // Open in new window
103
+ $target_link = !empty($target) ? ' target="'.$target.'"' : "";
104
+ // Wrap the avatar inside the link
105
+ $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>';
106
+ } else {
107
+ $html = get_wp_user_avatar($id_or_email, $get_size, $align);
108
+ }
109
+ // Check if caption is set
110
+ if(!empty($content)) {
111
+ // Get attachment ID
112
+ $wpua = get_user_meta($id_or_email, $wpdb->get_blog_prefix($blog_id).'user_avatar', true);
113
+ // Clean up caption
114
+ $content = trim($content);
115
+ $content = preg_replace('/\r|\n/', "", $content);
116
+ $content = preg_replace('/<\/p><p>/', "", $content, 1);
117
+ $content = preg_replace('/<\/p><p>$/', "", $content);
118
+ $content = str_replace('</p><p>', "<br /><br />", $content);
119
+ $avatar = do_shortcode(image_add_caption($html, $wpua, $content, $title="", $align, $link, $get_size, $alt=""));
120
+ } else {
121
+ $avatar = $html;
122
+ }
123
+ return $avatar;
124
+ }
125
+
126
+ /**
127
+ * Update user
128
+ * @since 1.8
129
+ * @param bool $user_id
130
+ * @uses add_query_arg()
131
+ * @uses do_action_ref_array()
132
+ * @uses wp_safe_redirect()
133
+ */
134
+ private function wpua_edit_user($user_id=0) {
135
+ global $post, $wp_http_referer;
136
+ $user = new stdClass;
137
+ $update = $user_id ? true : false;
138
+ $errors = new WP_Error();
139
+ do_action_ref_array('wpua_update_errors', array(&$errors, $update, &$user));
140
+ if($errors->get_error_codes()) {
141
+ // Return with errors
142
+ return $errors;
143
+ }
144
+ if($update) {
145
+ // Redirect with updated variable
146
+ wp_safe_redirect(add_query_arg(array('updated' => '1'), $_POST['_wp_http_referer']));
147
+ }
148
+ }
149
+
150
+ /**
151
+ * Edit shortcode
152
+ * @since 1.8
153
+ * @param array $atts
154
+ * @uses do_action()
155
+ * @uses get_error_messages()
156
+ * @uses is_user_logged_in()
157
+ * @uses is_wp_error()
158
+ * @uses wpua_edit_form()
159
+ * @uses wpua_edit_user()
160
+ * @return string
161
+ */
162
+ public function wpua_edit_shortcode($atts) {
163
+ global $current_user, $errors;
164
+ // Shortcode only works with logged-in user
165
+ if(is_user_logged_in()) {
166
+ // Save
167
+ if(isset($_POST['submit']) && $_POST['submit'] && $_POST['action'] == 'update') {
168
+ do_action('wpua_update', $current_user->ID);
169
+ // Check for errors
170
+ $errors = $this->wpua_edit_user($current_user->ID);
171
+ }
172
+ // Errors
173
+ if(isset($errors) && is_wp_error($errors)) {
174
+ echo '<div class="error"><p>'.implode("</p>\n<p>", $errors->get_error_messages()).'</p></div>';
175
+ } elseif(isset($_GET['updated']) && $_GET['updated'] == '1') {
176
+ echo '<div class="updated"><p><strong>'.__('Profile updated.').'</strong></p></div>';
177
+ }
178
+ // Edit form
179
+ return $this->wpua_edit_form();
180
+ }
181
+ }
182
+
183
+ /**
184
+ * Edit form
185
+ * @since 1.8
186
+ * @uses object $current_user
187
+ * @uses object $post
188
+ * @uses do_action()
189
+ * @uses submit_button()
190
+ * @uses wp_nonce_field()
191
+ * @uses wp_reset_query()
192
+ */
193
+ private function wpua_edit_form() {
194
+ global $current_user, $post;
195
+ wp_reset_query();
196
+ ob_start();
197
+ ?>
198
+ <form id="wpua-edit-<?php echo $current_user->ID; ?>" class="wpua-edit" action="" method="post" enctype="multipart/form-data">
199
+ <?php do_action('wpua_show_profile', $current_user); ?>
200
+ <input type="hidden" name="action" value="update" />
201
+ <input type="hidden" name="user_id" id="user_id" value="<?php echo esc_attr($current_user->ID); ?>" />
202
+ <?php wp_nonce_field('update-user_'.$current_user->ID); ?>
203
+ <?php submit_button(__('Update Profile')); ?>
204
+ </form>
205
+ <?php
206
+ return ob_get_clean();
207
+ }
208
+ }
209
+
210
+ /**
211
+ * Initialize
212
+ */
213
+ function wpua_shortcode_init() {
214
+ global $wpua_shortcode;
215
+ $wpua_shortcode = new WP_User_Avatar_Shortcode();
216
+ }
217
+ add_action('init', 'wpua_shortcode_init');
includes/class-wp-user-avatar-subscriber.php ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Settings only for subscribers and contributors.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.5
7
+ */
8
+
9
+ class WP_User_Avatar_Subscriber {
10
+ /**
11
+ * Constructor
12
+ * @uses object $wp_user_avatar
13
+ * @uses bool $wpua_allow_upload
14
+ * @uses add_action()
15
+ * @uses current_user_can()
16
+ * @uses wpua_is_author_or_above()
17
+ */
18
+ public function __construct() {
19
+ global $wp_user_avatar, $wpua_allow_upload;
20
+ if((bool) $wpua_allow_upload == 1) {
21
+ add_action('user_edit_form_tag', array($this, 'wpua_add_edit_form_multipart_encoding'));
22
+ // Only Subscribers lack delete_posts capability
23
+ if(!current_user_can('delete_posts') && !$wp_user_avatar->wpua_is_author_or_above()) {
24
+ add_action('admin_menu', array($this, 'wpua_subscriber_remove_menu_pages'));
25
+ add_action('wp_before_admin_bar_render', array($this, 'wpua_subscriber_remove_menu_bar_items'));
26
+ add_action('wp_dashboard_setup', array($this, 'wpua_subscriber_remove_dashboard_widgets'));
27
+ add_action('admin_init', array($this, 'wpua_subscriber_offlimits'));
28
+ }
29
+ }
30
+ add_action('admin_init', array($this, 'wpua_subscriber_capability'));
31
+ }
32
+
33
+ /**
34
+ * Allow multipart data in form
35
+ */
36
+ public function wpua_add_edit_form_multipart_encoding() {
37
+ echo ' enctype="multipart/form-data"';
38
+ }
39
+
40
+ /**
41
+ * Remove menu items
42
+ * @uses remove_menu_page()
43
+ */
44
+ public function wpua_subscriber_remove_menu_pages() {
45
+ remove_menu_page('edit.php');
46
+ remove_menu_page('edit-comments.php');
47
+ remove_menu_page('tools.php');
48
+ }
49
+
50
+ /**
51
+ * Remove menu bar items
52
+ * @uses object $wp_admin_bar
53
+ * @uses remove_menu()
54
+ */
55
+ public function wpua_subscriber_remove_menu_bar_items() {
56
+ global $wp_admin_bar;
57
+ $wp_admin_bar->remove_menu('comments');
58
+ $wp_admin_bar->remove_menu('new-content');
59
+ }
60
+
61
+ /**
62
+ * Remove dashboard items
63
+ * @uses remove_meta_box()
64
+ */
65
+ public function wpua_subscriber_remove_dashboard_widgets() {
66
+ remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
67
+ remove_meta_box('dashboard_recent_drafts', 'dashboard', 'side');
68
+ remove_meta_box('dashboard_right_now', 'dashboard', 'normal');
69
+ }
70
+
71
+ /**
72
+ * Restrict access to pages
73
+ * @uses string $pagenow
74
+ * @uses bool $wpua_edit_avatar
75
+ * @uses apply_filters()
76
+ * @uses do_action()
77
+ * @uses wp_die()
78
+ */
79
+ public function wpua_subscriber_offlimits() {
80
+ global $pagenow, $wpua_edit_avatar;
81
+ $offlimits = array('edit.php', 'edit-comments.php', 'post-new.php', 'tools.php');
82
+ if((bool) $wpua_edit_avatar != 1) {
83
+ array_push($offlimits, 'post.php');
84
+ }
85
+ /**
86
+ * Filter restricted pages
87
+ * @param array $offlimits
88
+ */
89
+ $offlimits = apply_filters('wpua_subscriber_offlimits', $offlimits);
90
+ if(in_array($pagenow, $offlimits)) {
91
+ do_action('admin_page_access_denied');
92
+ wp_die(__('You do not have sufficient permissions to access this page.'));
93
+ }
94
+ }
95
+
96
+ /**
97
+ * Give subscribers edit_posts capability
98
+ * @uses int $blog_id
99
+ * @uses object $wpdb
100
+ * @uses bool $wpua_allow_upload
101
+ * @uses bool $wpua_edit_avatar
102
+ * @uses get_blog_prefix()
103
+ * @uses get_option()
104
+ * @uses update_option()
105
+ */
106
+ public function wpua_subscriber_capability() {
107
+ global $blog_id, $wpdb, $wpua_allow_upload, $wpua_edit_avatar;
108
+ $wp_user_roles = $wpdb->get_blog_prefix($blog_id).'user_roles';
109
+ $user_roles = get_option($wp_user_roles);
110
+ if((bool) $wpua_allow_upload == 1 && (bool) $wpua_edit_avatar == 1) {
111
+ $user_roles['subscriber']['capabilities']['edit_posts'] = true;
112
+ } else {
113
+ unset($user_roles['subscriber']['capabilities']['edit_posts']);
114
+ }
115
+ update_option($wp_user_roles, $user_roles);
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Initialize
121
+ */
122
+ function wpua_subscriber_init() {
123
+ global $wpua_subscriber;
124
+ $wpua_subscriber = new WP_User_Avatar_Subscriber();
125
+ }
126
+ add_action('init', 'wpua_subscriber_init');
includes/class-wp-user-avatar-update.php ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Updates for legacy settings.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.5
7
+ */
8
+
9
+ class WP_User_Avatar_Update {
10
+ /**
11
+ * Constructor
12
+ * @uses bool $wpua_default_avatar_updated
13
+ * @uses bool $wpua_media_updated
14
+ * @uses bool $wpua_users_updated
15
+ * @uses add_action()
16
+ */
17
+ public function __construct() {
18
+ global $wpua_default_avatar_updated, $wpua_media_updated, $wpua_users_updated;
19
+ if(empty($wpua_default_avatar_updated)) {
20
+ add_action('admin_init', array($this, 'wpua_default_avatar'));
21
+ }
22
+ if(empty($wpua_users_updated)) {
23
+ add_action('admin_init', array($this, 'wpua_user_meta'));
24
+ }
25
+ if(empty($wpua_media_updated)) {
26
+ add_action('admin_init', array($this, 'wpua_media_state'));
27
+ }
28
+ }
29
+
30
+ /**
31
+ * Update default avatar to new format
32
+ * @uses string $avatar_default
33
+ * @uses string $mustache_original
34
+ * @uses int $wpua_avatar_default
35
+ * @uses update_option()
36
+ * @uses wp_get_attachment_image_src()
37
+ */
38
+ public function wpua_default_avatar() {
39
+ global $avatar_default, $mustache_original, $wpua_avatar_default;
40
+ // If default avatar is the old mustache URL, update it
41
+ if($avatar_default == $mustache_original) {
42
+ update_option('avatar_default', 'wp_user_avatar');
43
+ }
44
+ // If user had an image URL as the default avatar, replace with ID instead
45
+ if(!empty($wpua_avatar_default)) {
46
+ $wpua_avatar_default_image = wp_get_attachment_image_src($wpua_avatar_default, 'medium');
47
+ if($avatar_default == $wpua_avatar_default_image[0]) {
48
+ update_option('avatar_default', 'wp_user_avatar');
49
+ }
50
+ }
51
+ update_option('wp_user_avatar_default_avatar_updated', '1');
52
+ }
53
+
54
+ /**
55
+ * Rename user meta to match database settings
56
+ * @uses int $blog_id
57
+ * @uses object $wpdb
58
+ * @uses delete_user_meta()
59
+ * @uses get_blog_prefix()
60
+ * @uses get_user_meta()
61
+ * @uses get_users()
62
+ * @uses update_option()
63
+ * @uses update_user_meta()
64
+ */
65
+ public function wpua_user_meta() {
66
+ global $blog_id, $wpdb;
67
+ $wpua_metakey = $wpdb->get_blog_prefix($blog_id).'user_avatar';
68
+ // If database tables start with something other than wp_
69
+ if($wpua_metakey != 'wp_user_avatar') {
70
+ $users = get_users();
71
+ // Move current user metakeys to new metakeys
72
+ foreach($users as $user) {
73
+ $wpua = get_user_meta($user->ID, 'wp_user_avatar', true);
74
+ if(!empty($wpua)) {
75
+ update_user_meta($user->ID, $wpua_metakey, $wpua);
76
+ delete_user_meta($user->ID, 'wp_user_avatar');
77
+ }
78
+ }
79
+ }
80
+ update_option('wp_user_avatar_users_updated', '1');
81
+ }
82
+
83
+ /**
84
+ * Add media state to existing avatars
85
+ * @uses int $blog_id
86
+ * @uses object $wpdb
87
+ * @uses add_post_meta()
88
+ * @uses get_blog_prefix()
89
+ * @uses get_results()
90
+ * @uses update_option()
91
+ */
92
+ public function wpua_media_state() {
93
+ global $blog_id, $wpdb;
94
+ // Find all users with WPUA
95
+ $wpua_metakey = $wpdb->get_blog_prefix($blog_id).'user_avatar';
96
+ $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, ""));
97
+ foreach($wpuas as $usermeta) {
98
+ add_post_meta($usermeta->meta_value, '_wp_attachment_wp_user_avatar', $usermeta->user_id);
99
+ }
100
+ update_option('wp_user_avatar_media_updated', '1');
101
+ }
102
+ }
103
+
104
+ /**
105
+ * Initialize
106
+ */
107
+ function wpua_update_init() {
108
+ global $wpua_update;
109
+ $wpua_update = new WP_User_Avatar_Update();
110
+ }
111
+ add_action('init', 'wpua_update_init');
includes/class-wp-user-avatar-widget.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Defines widgets.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.5
7
+ */
8
+
9
+ class WP_User_Avatar_Profile_Widget extends WP_Widget {
10
+ /**
11
+ * Constructor
12
+ */
13
+ public function __construct() {
14
+ $widget_ops = array('classname' => 'widget_wp_user_avatar', 'description' => __('Insert').' '.__('[avatar_upload]', 'wp-user-avatar').'.');
15
+ parent::__construct('wp_user_avatar_profile', __('WP User Avatar', 'wp-user-avatar'), $widget_ops);
16
+ }
17
+
18
+ /**
19
+ * Add [avatar_upload] to widget
20
+ * @since 1.9.4
21
+ * @param array $args
22
+ * @param array $instance
23
+ * @uses object $wpua_shortcode
24
+ * @uses add_filter()
25
+ * @uses apply_filters()
26
+ * @uses is_user_logged_in()
27
+ * @uses remove_filter()
28
+ * @uses wpua_edit_shortcode()
29
+ */
30
+ public function widget($args, $instance) {
31
+ global $wpua_shortcode;
32
+ extract($args);
33
+ $instance = apply_filters('wpua_widget_instance', $instance);
34
+ $title = apply_filters('widget_title', empty($instance['title']) ? "" : $instance['title'], $instance, $this->id_base);
35
+ // Show widget only for logged-in users
36
+ if(is_user_logged_in()) {
37
+ echo $before_widget;
38
+ if($title){
39
+ echo $before_title.$title.$after_title;
40
+ }
41
+ // Remove profile title
42
+ add_filter('wpua_profile_title', '__return_null');
43
+ // Get [avatar_upload] shortcode
44
+ echo $wpua_shortcode->wpua_edit_shortcode("");
45
+ remove_filter('wpua_profile_title', '__return_null');
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Set title
51
+ * @param array $instance
52
+ * @uses wp_parse_args()
53
+ */
54
+ public function form($instance) {
55
+ $instance = wp_parse_args((array) $instance, array('title' => ""));
56
+ $title = isset($instance['title']) ? esc_attr($instance['title']) : "";
57
+ ?>
58
+ <p>
59
+ <label for="<?php echo $this->get_field_id('title'); ?>">
60
+ <?php _e('Title:'); ?>
61
+ <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); ?>" />
62
+ </label>
63
+ </p>
64
+ <?php
65
+ }
66
+
67
+ /**
68
+ * Update widget
69
+ * @param array $new_instance
70
+ * @param array $old_instance
71
+ * @uses wp_parse_args()
72
+ * @return array
73
+ */
74
+ public function update($new_instance, $old_instance) {
75
+ $instance = $old_instance;
76
+ $new_instance = wp_parse_args((array) $new_instance, array('title' => ""));
77
+ $instance['title'] = strip_tags($new_instance['title']);
78
+ return $instance;
79
+ }
80
+ }
includes/class-wp-user-avatar.php ADDED
@@ -0,0 +1,437 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Defines all profile and upload settings.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.5
7
+ */
8
+
9
+ class WP_User_Avatar {
10
+ /**
11
+ * Constructor
12
+ * @uses string $pagenow
13
+ * @uses bool $show_avatars
14
+ * @uses object $wpua_admin
15
+ * @uses bool $wpua_allow_upload
16
+ * @uses add_action()
17
+ * @uses add_filterI]()
18
+ * @uses is_admin()
19
+ * @uses is_user_logged_in()
20
+ * @uses wpua_is_author_or_above()
21
+ * @uses wpua_is_menu_page()
22
+ */
23
+ public function __construct() {
24
+ global $pagenow, $show_avatars, $wpua_admin, $wpua_allow_upload;
25
+ // Add WPUA to profile
26
+ if($this->wpua_is_author_or_above() || ((bool) $wpua_allow_upload == 1 && is_user_logged_in())) {
27
+ // Profile functions and scripts
28
+ add_action('show_user_profile', array('wp_user_avatar', 'wpua_action_show_user_profile'));
29
+ add_action('personal_options_update', array($this, 'wpua_action_process_option_update'));
30
+ add_action('edit_user_profile', array('wp_user_avatar', 'wpua_action_show_user_profile'));
31
+ add_action('edit_user_profile_update', array($this, 'wpua_action_process_option_update'));
32
+ add_action('user_new_form', array($this, 'wpua_action_show_user_profile'));
33
+ add_action('user_register', array($this, 'wpua_action_process_option_update'));
34
+ // Admin scripts
35
+ $pages = array('profile.php', 'options-discussion.php', 'user-edit.php', 'user-new.php');
36
+ if(in_array($pagenow, $pages) || $wpua_admin->wpua_is_menu_page()) {
37
+ add_action('admin_enqueue_scripts', array($this, 'wpua_media_upload_scripts'));
38
+ }
39
+ // Front pages
40
+ if(!is_admin()) {
41
+ add_action('show_user_profile', array('wp_user_avatar', 'wpua_media_upload_scripts'));
42
+ add_action('edit_user_profile', array('wp_user_avatar', 'wpua_media_upload_scripts'));
43
+ }
44
+ if(!$this->wpua_is_author_or_above()) {
45
+ // Upload errors
46
+ add_action('user_profile_update_errors', array($this, 'wpua_upload_errors'), 10, 3);
47
+ // Prefilter upload size
48
+ add_filter('wp_handle_upload_prefilter', array($this, 'wpua_handle_upload_prefilter'));
49
+ }
50
+ }
51
+ add_filter('media_view_settings', array($this, 'wpua_media_view_settings'), 10, 1);
52
+ }
53
+
54
+ /**
55
+ * Avatars have no parent posts
56
+ * @param array $settings
57
+ * @uses object $post
58
+ * @uses bool $wpua_is_profile
59
+ * @uses is_admin()
60
+ * @return array $settings
61
+ */
62
+ public function wpua_media_view_settings($settings) {
63
+ global $post, $wpua_is_profile;
64
+ // Get post ID so not to interfere with media uploads
65
+ $post_id = is_object($post) ? $post->ID : 0;
66
+ // Don't use post ID on front pages if there's a WPUA uploader
67
+ $settings['post']['id'] = (!is_admin() && $wpua_is_profile == 1) ? 0 : $post_id;
68
+ return $settings;
69
+ }
70
+
71
+ /**
72
+ * Media Uploader
73
+ * @param object $user
74
+ * @uses object $current_user
75
+ * @uses string $mustache_admin
76
+ * @uses string $pagenow
77
+ * @uses object $post
78
+ * @uses bool $show_avatars
79
+ * @uses object $wp_user_avatar
80
+ * @uses object $wpua_admin
81
+ * @uses object $wpua_functions
82
+ * @uses bool $wpua_is_profile
83
+ * @uses int $wpua_upload_size_limit
84
+ * @uses get_user_by()
85
+ * @uses wp_enqueue_script()
86
+ * @uses wp_enqueue_media()
87
+ * @uses wp_enqueue_style()
88
+ * @uses wp_localize_script()
89
+ * @uses wp_max_upload_size()
90
+ * @uses wpua_get_avatar_original()
91
+ * @uses wpua_is_author_or_above()
92
+ * @uses wpua_is_menu_page()
93
+ */
94
+ public static function wpua_media_upload_scripts($user="") {
95
+ global $current_user, $mustache_admin, $pagenow, $post, $show_avatars, $wp_user_avatar, $wpua_admin, $wpua_functions, $wpua_is_profile, $wpua_upload_size_limit;
96
+ // This is a profile page
97
+ $wpua_is_profile = 1;
98
+ $user = ($pagenow == 'user-edit.php' && isset($_GET['user_id'])) ? get_user_by('id', $_GET['user_id']) : $current_user;
99
+ wp_enqueue_script('jquery');
100
+ if($wp_user_avatar->wpua_is_author_or_above()) {
101
+ wp_enqueue_script('admin-bar');
102
+ wp_enqueue_media(array('post' => $post));
103
+ wp_enqueue_script('wp-user-avatar', WPUA_URL.'js/wp-user-avatar.js', array('jquery', 'media-editor'), WPUA_VERSION, true);
104
+ } else {
105
+ wp_enqueue_script('wp-user-avatar', WPUA_URL.'js/wp-user-avatar-user.js', array('jquery'), WPUA_VERSION, true);
106
+ }
107
+ wp_enqueue_style('wp-user-avatar', WPUA_URL.'css/wp-user-avatar.css', "", WPUA_VERSION);
108
+ // Admin scripts
109
+ if($pagenow == 'options-discussion.php' || $wpua_admin->wpua_is_menu_page()) {
110
+ // Size limit slider
111
+ wp_enqueue_script('jquery-ui-slider');
112
+ wp_enqueue_style('wp-user-avatar-jqueryui', WPUA_URL.'css/jquery.ui.slider.css', "", null);
113
+ // Default avatar
114
+ wp_localize_script('wp-user-avatar', 'wpua_custom', array('avatar_thumb' => $mustache_admin));
115
+ // Settings control
116
+ wp_enqueue_script('wp-user-avatar-admin', WPUA_URL.'js/wp-user-avatar-admin.js', array('wp-user-avatar'), WPUA_VERSION, true);
117
+ wp_localize_script('wp-user-avatar-admin', 'wpua_admin', array('upload_size_limit' => $wpua_upload_size_limit, 'max_upload_size' => wp_max_upload_size()));
118
+ } else {
119
+ // Original user avatar
120
+ $avatar_medium_src = (bool) $show_avatars == 1 ? $wpua_functions->wpua_get_avatar_original($user->user_email, 'medium') : includes_url().'images/blank.gif';
121
+ wp_localize_script('wp-user-avatar', 'wpua_custom', array('avatar_thumb' => $avatar_medium_src));
122
+ }
123
+ }
124
+
125
+ /**
126
+ * Add to edit user profile
127
+ * @param object $user
128
+ * @uses int $blog_id
129
+ * @uses object $current_user
130
+ * @uses bool $show_avatars
131
+ * @uses object $wpdb
132
+ * @uses object $wp_user_avatar
133
+ * @uses bool $wpua_allow_upload
134
+ * @uses bool $wpua_edit_avatar
135
+ * @uses object $wpua_functions
136
+ * @uses string $wpua_upload_size_limit_with_units
137
+ * @uses add_query_arg()
138
+ * @uses admin_url()
139
+ * @uses do_action()
140
+ * @uses get_blog_prefix()
141
+ * @uses get_user_meta()
142
+ * @uses get_wp_user_avatar_src()
143
+ * @uses has_wp_user_avatar()
144
+ * @uses is_admin()
145
+ * @uses wpua_author()
146
+ * @uses wpua_get_avatar_original()
147
+ * @uses wpua_is_author_or_above()
148
+ */
149
+ public static function wpua_action_show_user_profile($user) {
150
+ 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;
151
+ // Get WPUA attachment ID
152
+ $wpua = get_user_meta($user->ID, $wpdb->get_blog_prefix($blog_id).'user_avatar', true);
153
+ // Show remove button if WPUA is set
154
+ $hide_remove = !has_wp_user_avatar($user->ID) ? 'wpua-hide' : "";
155
+ // Hide image tags if show avatars is off
156
+ $hide_images = !has_wp_user_avatar($user->ID) && (bool) $show_avatars == 0 ? 'wpua-no-avatars' : "";
157
+ // If avatars are enabled, get original avatar image or show blank
158
+ $avatar_medium_src = (bool) $show_avatars == 1 ? $wpua_functions->wpua_get_avatar_original($user->user_email, 'medium') : includes_url().'images/blank.gif';
159
+ // Check if user has wp_user_avatar, if not show image from above
160
+ $avatar_medium = has_wp_user_avatar($user->ID) ? get_wp_user_avatar_src($user->ID, 'medium') : $avatar_medium_src;
161
+ // Check if user has wp_user_avatar, if not show image from above
162
+ $avatar_thumbnail = has_wp_user_avatar($user->ID) ? get_wp_user_avatar_src($user->ID, 96) : $avatar_medium_src;
163
+ $edit_attachment_link = add_query_arg(array('post' => $wpua, 'action' => 'edit'), admin_url('post.php'));
164
+ // Chck if admin page
165
+ $is_admin = is_admin() ? '_admin' : "";
166
+ ?>
167
+ <?php do_action('wpua_before_avatar'.$is_admin); ?>
168
+ <input type="hidden" name="wp-user-avatar" id="wp-user-avatar" value="<?php echo $wpua; ?>" />
169
+ <?php if($wp_user_avatar->wpua_is_author_or_above()) : // Button to launch Media Uploader ?>
170
+ <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>
171
+ <?php elseif(!$wp_user_avatar->wpua_is_author_or_above()) : // Upload button ?>
172
+ <p id="wpua-upload-button">
173
+ <input name="wpua-file" id="wpua-file" type="file" />
174
+ <button type="submit" class="button" id="wpua-upload" name="submit" value="<?php _e('Upload'); ?>"><?php _e('Upload'); ?></button>
175
+ </p>
176
+ <p id="wpua-upload-messages">
177
+ <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>
178
+ <span id="wpua-allowed-files" class="description"><?php _e('Allowed Files'); ?>: <?php _e('<code>jpg jpeg png gif</code>'); ?></span>
179
+ </p>
180
+ <?php endif; ?>
181
+ <div id="wpua-images" class="<?php echo $hide_images; ?>">
182
+ <p id="wpua-preview">
183
+ <img src="<?php echo $avatar_medium; ?>" alt="" />
184
+ <span class="description"><?php _e('Original Size'); ?></span>
185
+ </p>
186
+ <p id="wpua-thumbnail">
187
+ <img src="<?php echo $avatar_thumbnail; ?>" alt="" />
188
+ <span class="description"><?php _e('Thumbnail'); ?></span>
189
+ </p>
190
+ <p id="wpua-remove-button" class="<?php echo $hide_remove; ?>">
191
+ <button type="button" class="button" id="wpua-remove" name="wpua-remove"><?php _e('Remove Image'); ?></button>
192
+ <?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 ?>
193
+ <span id="wpua-edit-attachment"><a href="<?php echo $edit_attachment_link; ?>" class="edit-attachment" target="_blank"><?php _e('Edit Image'); ?></a></span>
194
+ <?php endif; ?>
195
+ </p>
196
+ <p id="wpua-undo-button"><button type="button" class="button" id="wpua-undo" name="wpua-undo"><?php _e('Undo'); ?></button></p>
197
+ </div>
198
+ <?php do_action('wpua_after_avatar'.$is_admin); ?>
199
+ <?php
200
+ }
201
+
202
+ /**
203
+ * Add upload error messages
204
+ * @param array $errors
205
+ * @param bool $update
206
+ * @param object $user
207
+ * @uses int $wpua_upload_size_limit
208
+ * @uses add()
209
+ * @uses wp_upload_dir()
210
+ */
211
+ public static function wpua_upload_errors($errors, $update, $user) {
212
+ global $wpua_upload_size_limit;
213
+ if($update && !empty($_FILES['wpua-file'])) {
214
+ $size = $_FILES['wpua-file']['size'];
215
+ $type = $_FILES['wpua-file']['type'];
216
+ $upload_dir = wp_upload_dir();
217
+ // Allow only JPG, GIF, PNG
218
+ if(!empty($type) && !preg_match('/(jpe?g|gif|png)$/i', $type)) {
219
+ $errors->add('wpua_file_type', __('This file is not an image. Please try another.'));
220
+ }
221
+ // Upload size limit
222
+ if(!empty($size) && $size > $wpua_upload_size_limit) {
223
+ $errors->add('wpua_file_size', __('Memory exceeded. Please try another smaller file.'));
224
+ }
225
+ // Check if directory is writeable
226
+ if(!is_writeable($upload_dir['path'])) {
227
+ $errors->add('wpua_file_directory', sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), $upload_dir['path']));
228
+ }
229
+ }
230
+ }
231
+
232
+ /**
233
+ * Set upload size limit
234
+ * @param object $file
235
+ * @uses int $wpua_upload_size_limit
236
+ * @uses add_action()
237
+ * @return object $file
238
+ */
239
+ public function wpua_handle_upload_prefilter($file) {
240
+ global $wpua_upload_size_limit;
241
+ $size = $file['size'];
242
+ if(!empty($size) && $size > $wpua_upload_size_limit) {
243
+ function wpua_file_size_error($errors, $update, $user) {
244
+ $errors->add('wpua_file_size', __('Memory exceeded. Please try another smaller file.'));
245
+ }
246
+ add_action('user_profile_update_errors', 'wpua_file_size_error', 10, 3);
247
+ return;
248
+ }
249
+ return $file;
250
+ }
251
+
252
+ /**
253
+ * Update user meta
254
+ * @param int $user_id
255
+ * @uses int $blog_id
256
+ * @uses object $post
257
+ * @uses object $wpdb
258
+ * @uses object $wp_user_avatar
259
+ * @uses bool $wpua_resize_crop
260
+ * @uses int $wpua_resize_h
261
+ * @uses bool $wpua_resize_upload
262
+ * @uses int $wpua_resize_w
263
+ * @uses add_post_meta()
264
+ * @uses delete_metadata()
265
+ * @uses get_blog_prefix()
266
+ * @uses is_wp_error()
267
+ * @uses update_post_meta()
268
+ * @uses update_user_meta()
269
+ * @uses wp_delete_attachment()
270
+ * @uses wp_generate_attachment_metadata()
271
+ * @uses wp_get_image_editor()
272
+ * @uses wp_handle_upload()
273
+ * @uses wp_insert_attachment()
274
+ * @uses WP_Query()
275
+ * @uses wp_read_image_metadata()
276
+ * @uses wp_reset_query()
277
+ * @uses wp_update_attachment_metadata()
278
+ * @uses wp_upload_dir()
279
+ * @uses wpua_is_author_or_above()
280
+ */
281
+ public static function wpua_action_process_option_update($user_id) {
282
+ global $blog_id, $post, $wpdb, $wp_user_avatar, $wpua_resize_crop, $wpua_resize_h, $wpua_resize_upload, $wpua_resize_w;
283
+ // Check if user has publish_posts capability
284
+ if($wp_user_avatar->wpua_is_author_or_above()) {
285
+ $wpua_id = isset($_POST['wp-user-avatar']) ? strip_tags($_POST['wp-user-avatar']) : "";
286
+ // Remove old attachment postmeta
287
+ delete_metadata('post', null, '_wp_attachment_wp_user_avatar', $user_id, true);
288
+ // Create new attachment postmeta
289
+ add_post_meta($wpua_id, '_wp_attachment_wp_user_avatar', $user_id);
290
+ // Update usermeta
291
+ update_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', $wpua_id);
292
+ } else {
293
+ // Remove attachment info if avatar is blank
294
+ if(isset($_POST['wp-user-avatar']) && empty($_POST['wp-user-avatar'])) {
295
+ // Delete other uploads by user
296
+ $q = array(
297
+ 'author' => $user_id,
298
+ 'post_type' => 'attachment',
299
+ 'post_status' => 'inherit',
300
+ 'posts_per_page' => '-1',
301
+ 'meta_query' => array(
302
+ array(
303
+ 'key' => '_wp_attachment_wp_user_avatar',
304
+ 'value' => "",
305
+ 'compare' => '!='
306
+ )
307
+ )
308
+ );
309
+ $avatars_wp_query = new WP_Query($q);
310
+ while($avatars_wp_query->have_posts()) : $avatars_wp_query->the_post();
311
+ wp_delete_attachment($post->ID);
312
+ endwhile;
313
+ wp_reset_query();
314
+ // Remove attachment postmeta
315
+ delete_metadata('post', null, '_wp_attachment_wp_user_avatar', $user_id, true);
316
+ // Remove usermeta
317
+ update_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', "");
318
+ }
319
+ // Create attachment from upload
320
+ if(isset($_POST['submit']) && $_POST['submit'] && !empty($_FILES['wpua-file'])) {
321
+ $name = $_FILES['wpua-file']['name'];
322
+ $file = wp_handle_upload($_FILES['wpua-file'], array('test_form' => false));
323
+ $type = $_FILES['wpua-file']['type'];
324
+ $upload_dir = wp_upload_dir();
325
+ if(is_writeable($upload_dir['path'])) {
326
+ if(!empty($type) && preg_match('/(jpe?g|gif|png)$/i', $type)) {
327
+ // Resize uploaded image
328
+ if((bool) $wpua_resize_upload == 1) {
329
+ // Original image
330
+ $uploaded_image = wp_get_image_editor($file['file']);
331
+ // Check for errors
332
+ if(!is_wp_error($uploaded_image)) {
333
+ // Resize image
334
+ $uploaded_image->resize($wpua_resize_w, $wpua_resize_h, $wpua_resize_crop);
335
+ // Save image
336
+ $resized_image = $uploaded_image->save($file['file']);
337
+ }
338
+ }
339
+ // Break out file info
340
+ $name_parts = pathinfo($name);
341
+ $name = trim(substr($name, 0, -(1 + strlen($name_parts['extension']))));
342
+ $url = $file['url'];
343
+ $file = $file['file'];
344
+ $title = $name;
345
+ // Use image exif/iptc data for title if possible
346
+ if($image_meta = @wp_read_image_metadata($file)) {
347
+ if(trim($image_meta['title']) && !is_numeric(sanitize_title($image_meta['title']))) {
348
+ $title = $image_meta['title'];
349
+ }
350
+ }
351
+ // Construct the attachment array
352
+ $attachment = array(
353
+ 'guid' => $url,
354
+ 'post_mime_type' => $type,
355
+ 'post_title' => $title,
356
+ 'post_content' => ""
357
+ );
358
+ // This should never be set as it would then overwrite an existing attachment
359
+ if(isset($attachment['ID'])) {
360
+ unset($attachment['ID']);
361
+ }
362
+ // Save the attachment metadata
363
+ $attachment_id = wp_insert_attachment($attachment, $file);
364
+ if(!is_wp_error($attachment_id)) {
365
+ // Delete other uploads by user
366
+ $q = array(
367
+ 'author' => $user_id,
368
+ 'post_type' => 'attachment',
369
+ 'post_status' => 'inherit',
370
+ 'posts_per_page' => '-1',
371
+ 'meta_query' => array(
372
+ array(
373
+ 'key' => '_wp_attachment_wp_user_avatar',
374
+ 'value' => "",
375
+ 'compare' => '!='
376
+ )
377
+ )
378
+ );
379
+ $avatars_wp_query = new WP_Query($q);
380
+ while($avatars_wp_query->have_posts()) : $avatars_wp_query->the_post();
381
+ wp_delete_attachment($post->ID);
382
+ endwhile;
383
+ wp_reset_query();
384
+ wp_update_attachment_metadata($attachment_id, wp_generate_attachment_metadata($attachment_id, $file));
385
+ // Remove old attachment postmeta
386
+ delete_metadata('post', null, '_wp_attachment_wp_user_avatar', $user_id, true);
387
+ // Create new attachment postmeta
388
+ update_post_meta($attachment_id, '_wp_attachment_wp_user_avatar', $user_id);
389
+ // Update usermeta
390
+ update_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', $attachment_id);
391
+ }
392
+ }
393
+ }
394
+ }
395
+ }
396
+ }
397
+
398
+ /**
399
+ * Check attachment is owned by user
400
+ * @param int $attachment_id
401
+ * @param int $user_id
402
+ * @param bool $wpua_author
403
+ * @uses get_post()
404
+ * @return bool
405
+ */
406
+ private function wpua_author($attachment_id, $user_id, $wpua_author=0) {
407
+ $attachment = get_post($attachment_id);
408
+ if(!empty($attachment) && $attachment->post_author == $user_id) {
409
+ $wpua_author = true;
410
+ }
411
+ return $wpua_author;
412
+ }
413
+
414
+ /**
415
+ * Check if current user has at least Author privileges
416
+ * @uses current_user_can()
417
+ * @uses apply_filters()
418
+ * @return bool
419
+ */
420
+ public function wpua_is_author_or_above() {
421
+ $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;
422
+ /**
423
+ * Filter Author privilege check
424
+ * @param bool $is_author_or_above
425
+ */
426
+ return apply_filters('wpua_is_author_or_above', $is_author_or_above);
427
+ }
428
+ }
429
+
430
+ /**
431
+ * Initialize WP_User_Avatar
432
+ */
433
+ function wpua_init() {
434
+ global $wp_user_avatar;
435
+ $wp_user_avatar = new WP_User_Avatar();
436
+ }
437
+ add_action('init', 'wpua_init');
includes/tinymce.php DELETED
@@ -1,47 +0,0 @@
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
- function wpua_myplugin_addbuttons(){
13
- // Don't bother doing this stuff if the current user lacks permissions
14
- if(!current_user_can('edit_posts') && !current_user_can('edit_pages')){
15
- return;
16
- }
17
- // Add only in Rich Editor mode
18
- if(get_user_option('rich_editing') == 'true'){
19
- add_filter('mce_external_plugins', 'wpua_add_myplugin_tinymce_plugin');
20
- add_filter('mce_buttons', 'wpua_register_myplugin_button');
21
- }
22
- }
23
- // init process for button control
24
- add_action('init', 'wpua_myplugin_addbuttons');
25
-
26
-
27
- function wpua_register_myplugin_button($buttons){
28
- array_push($buttons, 'separator', 'wpUserAvatar');
29
- return $buttons;
30
- }
31
-
32
- // Load the TinyMCE plugin : editor_plugin.js (wp2.5)
33
- function wpua_add_myplugin_tinymce_plugin($plugin_array){
34
- $plugin_array['wpUserAvatar'] = WPUA_URLPATH.'includes/tinymce/editor_plugin.js';
35
- return $plugin_array;
36
- }
37
-
38
- // Call TinyMCE window content via admin-ajax
39
- function wpua_ajax_tinymce(){
40
- if(!current_user_can('edit_posts') && !current_user_can('edit_pages')){
41
- die('You are not allowed to call this page directly.');
42
- }
43
- include_once(WPUA_ABSPATH.'includes/tinymce/window.php');
44
- die();
45
- }
46
- add_action('wp_ajax_wp_user_avatar_tinymce', 'wpua_ajax_tinymce');
47
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/tinymce/editor_plugin.js 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.5"}}});tinymce.PluginManager.add('wpUserAvatar',tinymce.plugins.wpUserAvatar)})();
includes/tinymce/window.php CHANGED
@@ -1,129 +1,184 @@
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;
27
- var align = document.getElementById('wp_user_avatar_align').value;
28
- var link = document.getElementById('wp_user_avatar_link').value;
29
- var link_external = document.getElementById('wp_user_avatar_link_external').value;
30
- var target = document.getElementById('wp_user_avatar_target').value;
 
31
 
32
  // Add tag to shortcode only if not blank
33
  var user_tag = (user != "") ? ' user="' + user + '"' : "";
34
  var size_tag = (size != "" && size_number == "") ? ' size="' + size + '"' : "";
35
- size_tag = (size_number != "") ? ' size="' + size_number + '"' : size_tag;
36
  var align_tag = (align != "") ? ' align="' + align + '"' : "";
37
  var link_tag = (link != "" && link != '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.5
7
  */
8
 
9
+ /**
10
+ * @uses get_users()
11
+ */
12
+
13
+ if(!defined('ABSPATH')) {
14
+ die('You are not allowed to call this page directly.');
15
  }
16
  ?>
17
+ <!DOCTYPE html>
18
+ <html>
19
  <head>
20
  <title><?php _e('WP User Avatar', 'wp-user-avatar'); ?></title>
21
  <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
22
  <base target="_self" />
23
  <script type="text/javascript" src="<?php echo site_url(); ?>/wp-includes/js/jquery/jquery.js"></script>
24
+ <script type="text/javascript" src="<?php echo site_url(); ?>/wp-includes/js/jquery/ui/jquery.ui.core.min.js"></script>
25
+ <script type="text/javascript" src="<?php echo site_url(); ?>/wp-includes/js/jquery/ui/jquery.ui.widget.min.js"></script>
26
+ <script type="text/javascript" src="<?php echo site_url(); ?>/wp-includes/js/jquery/ui/jquery.ui.tabs.min.js"></script>
27
  <script type="text/javascript" src="<?php echo site_url(); ?>/wp-includes/js/tinymce/tiny_mce_popup.js"></script>
28
  <script type="text/javascript" src="<?php echo site_url(); ?>/wp-includes/js/tinymce/utils/form_utils.js"></script>
29
  <script type="text/javascript">
30
+ function wpuaInsertAvatar() {
31
  // Custom shortcode values
32
+ var shortcode, closing_tag,
33
+ user = document.getElementById('wp_user_avatar_user').value,
34
+ size = document.getElementById('wp_user_avatar_size').value,
35
+ size_number = document.getElementById('wp_user_avatar_size_number').value,
36
+ align = document.getElementById('wp_user_avatar_align').value,
37
+ link = document.getElementById('wp_user_avatar_link').value,
38
+ link_external = document.getElementById('wp_user_avatar_link_external').value,
39
+ target = document.getElementById('wp_user_avatar_target').value,
40
+ caption = document.getElementById('wp_user_avatar_caption').value;
41
 
42
  // Add tag to shortcode only if not blank
43
  var user_tag = (user != "") ? ' user="' + user + '"' : "";
44
  var size_tag = (size != "" && size_number == "") ? ' size="' + size + '"' : "";
45
+ size_tag = (size_number != "") ? ' size="' + size_number + '"' : size_tag;
46
  var align_tag = (align != "") ? ' align="' + align + '"' : "";
47
  var link_tag = (link != "" && link != 'custom-url' && link_external == "") ? ' link="' + link + '"' : "";
48
+ link_tag = (link_external != "") ? ' link="' + link_external + '"' : link_tag;
49
  var target_tag = document.getElementById('wp_user_avatar_target').checked && (link_tag != "") ? ' target="' + target + '"' : "";
 
 
50
 
51
+ // Assemble the shortcode
52
+ closing_tag = (caption != "") ? "]" + caption + "[/avatar]" : " /]";
53
+ shortcode = "<p>[avatar" + user_tag + size_tag + align_tag + link_tag + target_tag + closing_tag + "</p>";
54
+
55
+ if(window.tinyMCE) {
56
  window.tinyMCE.execInstanceCommand(window.tinyMCE.activeEditor.id, 'mceInsertContent', false, shortcode);
57
  tinyMCEPopup.editor.execCommand('mceRepaint');
58
  tinyMCEPopup.close();
59
  }
60
  return;
61
  }
62
+ function wpuaInsertAvatarUpload() {
63
+ // Upload shortcode
64
+ var shortcode = "<p>[avatar_upload]</p>";
65
+
66
+ if(window.tinyMCE) {
67
+ window.tinyMCE.execInstanceCommand(window.tinyMCE.activeEditor.id, 'mceInsertContent', false, shortcode);
68
+ tinyMCEPopup.editor.execCommand('mceRepaint');
69
+ tinyMCEPopup.close();
70
+ }
71
+ return;
72
+ }
73
+ jQuery(function($) {
74
+ $('#wp_user_avatar_link').change(function() {
75
+ $('#wp_user_avatar_link_external_section').toggle($('#wp_user_avatar_link').val() == 'custom-url');
76
  });
77
+ $('#wp_user_avatar_size').change(function() {
78
+ $('#wp_user_avatar_size_number_section').toggle($('#wp_user_avatar_size').val() == 'custom');
79
  });
80
+ $('#wpua-tabs').tabs();
81
  });
82
  </script>
83
  <style type="text/css">
84
+ ul { margin: 0; padding: 0; list-style: none; }
85
+ ul li { float: left; }
86
+ 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; }
87
+ ul li.ui-tabs-active a { background: #fff; }
88
+ form { clear: both; background: #fff; border: 1px solid #eee; }
89
  p, h4 { margin: 0; padding: 12px 0 0; }
90
  h4.center { text-align: center; }
91
+ label { width: 150px; margin-right: 3px; display: inline-block; text-align: right; vertical-align: top; }
92
  .mceActionPanel { padding: 7px 0 12px; text-align: center; }
93
  .mceActionPanel #insert { float: none; width: 180px; margin: 0 auto; }
94
  #wp_user_avatar_size_number_section, #wp_user_avatar_link_external_section { display: none; }
95
  </style>
96
  </head>
97
+ <body id="link" class="wp-core-ui" onload="document.body.style.display='';" style="display:none;">
98
+ <div id="wpua-tabs">
99
+ <ul>
100
+ <li><a href="#wpua"><?php _e('Avatar'); ?></a></li>
101
+ <li><a href="#wpua-upload"><?php _e('Upload'); ?></a></li>
102
+ </ul>
103
+ <form name="wpUserAvatar" action="#">
104
+ <div id="wpua">
105
+ <p>
106
+ <label for="<?php esc_attr_e('wp_user_avatar_user'); ?>"><strong><?php _e('User Name'); ?>:</strong></label>
107
+ <select id="<?php esc_attr_e('wp_user_avatar_user'); ?>" name="<?php esc_attr_e('wp_user_avatar_user'); ?>">
108
+ <option value=""></option>
109
+ <?php $users = get_users(); foreach($users as $user) : ?>
110
+ <option value="<?php echo $user->user_login; ?>"><?php echo $user->display_name; ?></option>
111
+ <?php endforeach; ?>
112
+ </select>
113
+ </p>
114
+
115
+ <p>
116
+ <label for="<?php esc_attr_e('wp_user_avatar_size'); ?>"><strong><?php _e('Size'); ?>:</strong></label>
117
+ <select id="<?php esc_attr_e('wp_user_avatar_size'); ?>" name="<?php esc_attr_e('wp_user_avatar_size'); ?>">
118
+ <option value=""></option>
119
+ <option value="original"><?php _e('Original Size'); ?></option>
120
+ <option value="large"><?php _e('Large'); ?></option>
121
+ <option value="medium"><?php _e('Medium'); ?></option>
122
+ <option value="thumbnail"><?php _e('Thumbnail'); ?></option>
123
+ <option value="custom"><?php _e('Custom'); ?></option>
124
+ </select>
125
+ </p>
126
+
127
+ <p id="<?php esc_attr_e('wp_user_avatar_size_number_section'); ?>">
128
+ <label for="<?php esc_attr_e('wp_user_avatar_size_number'); ?>"><?php _e('Size'); ?>:</label>
129
+ <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="" />
130
+ </p>
131
 
132
+ <p>
133
+ <label for="<?php esc_attr_e('wp_user_avatar_align'); ?>"><strong><?php _e('Alignment'); ?>:</strong></label>
134
+ <select id="<?php esc_attr_e('wp_user_avatar_align'); ?>" name="<?php esc_attr_e('wp_user_avatar_align'); ?>">
135
+ <option value=""></option>
136
+ <option value="center"><?php _e('Center'); ?></option>
137
+ <option value="left"><?php _e('Left'); ?></option>
138
+ <option value="right"><?php _e('Right'); ?></option>
139
+ </select>
140
+ </p>
 
 
141
 
142
+ <p>
143
+ <label for="<?php esc_attr_e('wp_user_avatar_link'); ?>"><strong><?php _e('Link To'); ?>:</strong></label>
144
+ <select id="<?php esc_attr_e('wp_user_avatar_link'); ?>" name="<?php esc_attr_e('wp_user_avatar_link'); ?>">
145
+ <option value=""></option>
146
+ <option value="file"><?php _e('Image File'); ?></option>
147
+ <option value="attachment"><?php _e('Attachment Page'); ?></option>
148
+ <option value="custom-url"><?php _e('Custom URL'); ?></option>
149
+ </select>
150
+ </p>
151
 
152
+ <p id="<?php esc_attr_e('wp_user_avatar_link_external_section'); ?>">
153
+ <label for="<?php esc_attr_e('wp_user_avatar_link_external'); ?>"><?php _e('URL'); ?>:</label>
154
+ <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="" />
155
+ </p>
 
 
 
156
 
157
+ <p>
158
+ <label for="<?php esc_attr_e('wp_user_avatar_target'); ?>"></label>
159
+ <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>
160
+ </p>
 
 
 
 
 
161
 
162
+ <p>
163
+ <label for="<?php esc_attr_e('wp_user_avatar_caption'); ?>"><strong><?php _e('Caption'); ?>:</strong></label>
164
+ <textarea cols="36" rows="2" id="<?php esc_attr_e('wp_user_avatar_caption'); ?>" name="<?php esc_attr_e('wp_user_avatar_size'); ?>"></textarea>
165
+ </p>
166
 
167
+ <div class="mceActionPanel">
168
+ <input type="submit" id="insert" class="button-primary" name="insert" value="<?php _e('Insert into Post'); ?>" onclick="wpuaInsertAvatar();" />
169
+ </div>
170
+ </div>
171
+ <div id="wpua-upload">
172
+ <p id="<?php esc_attr_e('wp_user_avatar_upload'); ?>">
173
+ <label for="<?php esc_attr_e('wp_user_avatar_upload'); ?>"><strong><?php _e('Upload'); ?>:</strong></label>
174
+ <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" />
175
+ </p>
176
 
177
+ <div class="mceActionPanel">
178
+ <input type="submit" id="insert" class="button-primary" name="insert" value="<?php _e('Insert into Post'); ?>" onclick="wpuaInsertAvatarUpload();" />
179
+ </div>
180
+ </div>
181
+ </form>
182
+ </div>
183
  </body>
184
  </html>
includes/wpua-functions.php ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Public user functions.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.5
7
+ */
8
+
9
+ /**
10
+ * Returns true if user has wp_user_avatar
11
+ * @param int|string $id_or_email
12
+ * @param bool $has_wpua
13
+ * @param object $user
14
+ * @param int $user_id
15
+ * @uses object $wpua_functions
16
+ * @return object has_wp_user_avatar()
17
+ */
18
+ function has_wp_user_avatar($id_or_email="", $has_wpua="", $user="", $user_id="") {
19
+ global $wpua_functions;
20
+ return $wpua_functions->has_wp_user_avatar($id_or_email, $has_wpua, $user, $user_id);
21
+ }
22
+
23
+ /**
24
+ * Find WPUA, show get_avatar if empty
25
+ * @param int|string $id_or_email
26
+ * @param int|string $size
27
+ * @param string $align
28
+ * @param string $alt
29
+ * @uses object $wpua_functions
30
+ * @return object get_wp_user_avatar()
31
+ */
32
+ function get_wp_user_avatar($id_or_email="", $size="", $align="", $alt="") {
33
+ global $wpua_functions;
34
+ return $wpua_functions->get_wp_user_avatar($id_or_email, $size, $align, $alt);
35
+ }
36
+
37
+ /**
38
+ * Return just the image src
39
+ * @param int|string $id_or_email
40
+ * @param int|string $size
41
+ * @param string $align
42
+ * @uses object $wpua_functions
43
+ * @return object get_wp_user_avatar_src()
44
+ */
45
+ function get_wp_user_avatar_src($id_or_email="", $size="", $align="") {
46
+ global $wpua_functions;
47
+ return $wpua_functions->get_wp_user_avatar_src($id_or_email, $size, $align);
48
+ }
49
+
50
+ /**
51
+ * Before wrapper for profile
52
+ * @uses do_action()
53
+ */
54
+ function wpua_before_avatar() {
55
+ do_action('wpua_before_avatar');
56
+ }
57
+
58
+ /**
59
+ * After wrapper for profile
60
+ * @uses do_action()
61
+ */
62
+ function wpua_after_avatar() {
63
+ do_action('wpua_after_avatar');
64
+ }
65
+
66
+ /**
67
+ * Before avatar container
68
+ * @uses apply_filters()
69
+ * @uses bbp_is_edit()
70
+ * @uses wpuf_has_shortcode()
71
+ */
72
+ function wpua_do_before_avatar() {
73
+ $wpua_profile_title = '<h3>'.__('Avatar').'</h3>';
74
+ /**
75
+ * Filter profile title
76
+ * @param string $wpua_profile_title
77
+ */
78
+ $wpua_profile_title = apply_filters('wpua_profile_title', $wpua_profile_title);
79
+ ?>
80
+ <?php if(class_exists('bbPress') && bbp_is_edit()) : // Add to bbPress profile with same style ?>
81
+ <h2 class="entry-title"><?php _e('Avatar'); ?></h2>
82
+ <fieldset class="bbp-form">
83
+ <legend><?php _e('Image'); ?></legend>
84
+ <?php elseif(class_exists('WPUF_Main') && wpuf_has_shortcode('wpuf_editprofile')) : // Add to WP User Frontend profile with same style ?>
85
+ <fieldset>
86
+ <legend><?php _e('Avatar') ?></legend>
87
+ <table class="wpuf-table">
88
+ <tr>
89
+ <th><label for="wp_user_avatar"><?php _e('Image'); ?></label></th>
90
+ <td>
91
+ <?php else : // Add to profile without table ?>
92
+ <div class="wpua-edit-container">
93
+ <?php echo $wpua_profile_title; ?>
94
+ <?php endif; ?>
95
+ <?php
96
+ }
97
+ add_action('wpua_before_avatar', 'wpua_do_before_avatar');
98
+
99
+ /**
100
+ * After avatar container
101
+ * @uses bbp_is_edit()
102
+ * @uses wpuf_has_shortcode()
103
+ */
104
+ function wpua_do_after_avatar() {
105
+ ?>
106
+ <?php if(class_exists('bbPress') && bbp_is_edit()) : // Add to bbPress profile with same style ?>
107
+ </fieldset>
108
+ <?php elseif(class_exists('WPUF_Main') && wpuf_has_shortcode('wpuf_editprofile')) : // Add to WP User Frontend profile with same style ?>
109
+ </td>
110
+ </tr>
111
+ </table>
112
+ </fieldset>
113
+ <?php else : // Add to profile without table ?>
114
+ </div>
115
+ <?php endif; ?>
116
+ <?php
117
+ }
118
+ add_action('wpua_after_avatar', 'wpua_do_after_avatar');
119
+
120
+ /**
121
+ * Before wrapper for profile
122
+ * @uses do_action()
123
+ */
124
+ function wpua_before_avatar_admin() {
125
+ do_action('wpua_before_avatar_admin');
126
+ }
127
+
128
+ /**
129
+ * After wrapper for profile
130
+ * @uses do_action()
131
+ */
132
+ function wpua_after_avatar_admin() {
133
+ do_action('wpua_after_avatar_admin');
134
+ }
135
+
136
+ /**
137
+ * Before avatar container
138
+ */
139
+ function wpua_do_before_avatar_admin() {
140
+ ?>
141
+ <h3><?php _e('Avatar') ?></h3>
142
+ <table class="form-table">
143
+ <tr>
144
+ <th><label for="wp_user_avatar"><?php _e('Image'); ?></label></th>
145
+ <td>
146
+ <?php
147
+ }
148
+ add_action('wpua_before_avatar_admin', 'wpua_do_before_avatar_admin');
149
+
150
+ /**
151
+ * After avatar container
152
+ */
153
+ function wpua_do_after_avatar_admin() {
154
+ ?>
155
+ </td>
156
+ </tr>
157
+ </table>
158
+ <?php
159
+ }
160
+ add_action('wpua_after_avatar_admin', 'wpua_do_after_avatar_admin');
161
+
162
+ /**
163
+ * Filter for the inevitable complaints about the donation message :(
164
+ * @uses do_action()
165
+ */
166
+ function wpua_donation_message() {
167
+ do_action('wpua_donation_message');
168
+ }
169
+
170
+ /**
171
+ * Donation message
172
+ */
173
+ function wpua_do_donation_message() { ?>
174
+ <div class="updated">
175
+ <p><?php _e('Do you like WP User Avatar?', 'wp-user-avatar'); ?> <a href="http://siboliban.org/donate" target="_blank"><?php _e('Make a donation.', 'wp-user-avatar'); ?></a></p>
176
+ </div>
177
+ <?php
178
+ }
179
+ add_action('wpua_donation_message', 'wpua_do_donation_message');
180
+
181
+ /**
182
+ * Register widget
183
+ * @uses register_widget()
184
+ */
185
+ function wpua_widgets_init() {
186
+ register_widget('WP_User_Avatar_Profile_Widget');
187
+ }
188
+ add_action('widgets_init', 'wpua_widgets_init');
includes/wpua-globals.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Global variables used in plugin.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.5
7
+ */
8
+
9
+ // Define global variables
10
+ global $avatar_default,
11
+ $show_avatars,
12
+ $wpua_allow_upload,
13
+ $wpua_avatar_default,
14
+ $wpua_disable_gravatar,
15
+ $wpua_edit_avatar,
16
+ $wpua_resize_crop,
17
+ $wpua_resize_h,
18
+ $wpua_resize_upload,
19
+ $wpua_resize_w,
20
+ $wpua_tinymce,
21
+ $mustache_original,
22
+ $mustache_medium,
23
+ $mustache_thumbnail,
24
+ $mustache_avatar,
25
+ $mustache_admin,
26
+ $wpua_default_avatar_updated,
27
+ $wpua_users_updated,
28
+ $wpua_media_updated,
29
+ $upload_size_limit,
30
+ $upload_size_limit_with_units,
31
+ $wpua_user_upload_size_limit,
32
+ $wpua_upload_size_limit,
33
+ $wpua_upload_size_limit_with_units,
34
+ $all_sizes;
35
+
36
+ // Default avatar name
37
+ $avatar_default = get_option('avatar_default');
38
+ // Attachment ID of default avatar
39
+ $wpua_avatar_default = get_option('avatar_default_wp_user_avatar');
40
+
41
+ // Booleans
42
+ $show_avatars = get_option('show_avatars');
43
+ $wpua_allow_upload = get_option('wp_user_avatar_allow_upload');
44
+ $wpua_disable_gravatar = get_option('wp_user_avatar_disable_gravatar');
45
+ $wpua_edit_avatar = get_option('wp_user_avatar_edit_avatar');
46
+ $wpua_resize_crop = get_option('wp_user_avatar_resize_crop');
47
+ $wpua_resize_upload = get_option('wp_user_avatar_resize_upload');
48
+ $wpua_tinymce = get_option('wp_user_avatar_tinymce');
49
+
50
+ // Resize dimensions
51
+ $wpua_resize_h = get_option('wp_user_avatar_resize_h');
52
+ $wpua_resize_w = get_option('wp_user_avatar_resize_w');
53
+
54
+ // Default avatar 512x512
55
+ $mustache_original = WPUA_URL.'images/wpua.png';
56
+ // Default avatar 300x300
57
+ $mustache_medium = WPUA_URL.'images/wpua-300x300.png';
58
+ // Default avatar 150x150
59
+ $mustache_thumbnail = WPUA_URL.'images/wpua-150x150.png';
60
+ // Default avatar 96x96
61
+ $mustache_avatar = WPUA_URL.'images/wpua-96x96.png';
62
+ // Default avatar 32x32
63
+ $mustache_admin = WPUA_URL.'images/wpua-32x32.png';
64
+
65
+ // Check for updates
66
+ $wpua_default_avatar_updated = get_option('wp_user_avatar_default_avatar_updated');
67
+ $wpua_users_updated = get_option('wp_user_avatar_users_updated');
68
+ $wpua_media_updated = get_option('wp_user_avatar_media_updated');
69
+
70
+ // Server upload size limit
71
+ $upload_size_limit = wp_max_upload_size();
72
+ // Convert to KB
73
+ if($upload_size_limit > 1024) {
74
+ $upload_size_limit /= 1024;
75
+ }
76
+ $upload_size_limit_with_units = (int) $upload_size_limit.'KB';
77
+
78
+ // User upload size limit
79
+ $wpua_user_upload_size_limit = get_option('wp_user_avatar_upload_size_limit');
80
+ if($wpua_user_upload_size_limit == 0 || $wpua_user_upload_size_limit > wp_max_upload_size()) {
81
+ $wpua_user_upload_size_limit = wp_max_upload_size();
82
+ }
83
+ // Value in bytes
84
+ $wpua_upload_size_limit = $wpua_user_upload_size_limit;
85
+ // Convert to KB
86
+ if($wpua_user_upload_size_limit > 1024) {
87
+ $wpua_user_upload_size_limit /= 1024;
88
+ }
89
+ $wpua_upload_size_limit_with_units = (int) $wpua_user_upload_size_limit.'KB';
90
+
91
+ // Check for custom image sizes
92
+ $all_sizes = array_merge(get_intermediate_image_sizes(), array('original'));
includes/wpua-media-page.php ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Media Library view of all avatars in use.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.5
7
+ */
8
+
9
+ /**
10
+ * @uses object $wpua_admin
11
+ * @uses _wpua_get_list_table()
12
+ * @uses add_query_arg()
13
+ * @uses check_admin_referer()
14
+ * @uses current_action()
15
+ * @uses current_user_can()
16
+ * @uses display()
17
+ * @uses esc_url()
18
+ * @uses find_posts_div()
19
+ * @uses get_pagenum()
20
+ * @uses get_search_query
21
+ * @uses number_format_i18n()
22
+ * @uses prepare_items()
23
+ * @uses remove_query_arg()
24
+ * @uses search_box()
25
+ * @uses views()
26
+ * @uses wp_delete_attachment()
27
+ * @uses wp_die()
28
+ * @uses wp_enqueue_script()
29
+ * @uses wp_get_referer()
30
+ * @uses wp_redirect()
31
+ * @uses wp_unslash()
32
+ */
33
+
34
+ /** WordPress Administration Bootstrap */
35
+ require_once(ABSPATH.'wp-admin/admin.php');
36
+
37
+ if(!current_user_can('upload_files'))
38
+ wp_die(__('You do not have permission to upload files.'));
39
+
40
+ global $wpua_admin;
41
+
42
+ $wp_list_table = $wpua_admin->_wpua_get_list_table('WP_User_Avatar_List_Table');
43
+ $pagenum = $wp_list_table->get_pagenum();
44
+
45
+ // Handle bulk actions
46
+ $doaction = $wp_list_table->current_action();
47
+
48
+ if($doaction) {
49
+ check_admin_referer('bulk-media');
50
+
51
+ if(isset($_REQUEST['media'])) {
52
+ $post_ids = $_REQUEST['media'];
53
+ } elseif(isset($_REQUEST['ids'])) {
54
+ $post_ids = explode(',', $_REQUEST['ids']);
55
+ }
56
+
57
+ $location = esc_url(add_query_arg(array('page' => 'wp-user-avatar-library'), 'admin.php'));
58
+ if($referer = wp_get_referer()) {
59
+ if(false !== strpos($referer, 'admin.php')) {
60
+ $location = remove_query_arg(array('trashed', 'untrashed', 'deleted', 'message', 'ids', 'posted'), $referer);
61
+ }
62
+ }
63
+ switch($doaction) {
64
+ case 'delete':
65
+ if(!isset($post_ids)) {
66
+ break;
67
+ }
68
+ foreach((array) $post_ids as $post_id_del) {
69
+ if(!current_user_can('delete_post', $post_id_del)) {
70
+ wp_die(__('You are not allowed to delete this post.'));
71
+ }
72
+ if(!wp_delete_attachment($post_id_del)) {
73
+ wp_die(__('Error in deleting.'));
74
+ }
75
+ }
76
+ $location = add_query_arg('deleted', count($post_ids), $location);
77
+ break;
78
+ }
79
+ wp_redirect($location);
80
+ exit;
81
+ } elseif(!empty($_GET['_wp_http_referer'])) {
82
+ wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), wp_unslash($_SERVER['REQUEST_URI'])));
83
+ exit;
84
+ }
85
+ $wp_list_table->prepare_items();
86
+ wp_enqueue_script('wp-ajax-response');
87
+ wp_enqueue_script('jquery-ui-draggable');
88
+ wp_enqueue_script('media');
89
+ ?>
90
+ <div class="wrap">
91
+ <h2>
92
+ <?php _e('Avatars');
93
+ if(!empty($_REQUEST['s'])) {
94
+ printf('<span class="subtitle">'.__('Search results for &#8220;%s&#8221;').'</span>', get_search_query());
95
+ }
96
+ ?>
97
+ </h2>
98
+ <?php
99
+ $message = "";
100
+ if(!empty($_GET['deleted']) && $deleted = absint($_GET['deleted'])) {
101
+ $message = sprintf(_n('Media attachment permanently deleted.', '%d media attachments permanently deleted.', $deleted), number_format_i18n($_GET['deleted']));
102
+ $_SERVER['REQUEST_URI'] = remove_query_arg(array('deleted'), $_SERVER['REQUEST_URI']);
103
+ }
104
+ if(!empty($message)) : ?>
105
+ <div id="message" class="updated"><p><?php echo $message; ?></p></div>
106
+ <?php endif; ?>
107
+ <?php $wp_list_table->views(); ?>
108
+ <form id="posts-filter" action="" method="get">
109
+ <?php $wp_list_table->search_box(__('Search'), 'media'); ?>
110
+ <?php $wp_list_table->display(); ?>
111
+ <div id="ajax-response"></div>
112
+ <?php find_posts_div(); ?>
113
+ <br class="clear" />
114
+ </form>
115
+ </div>
includes/wpua-options-page.php ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Admin page to change plugin options.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.5
7
+ */
8
+
9
+ /**
10
+ * @uses bool $show_avatars
11
+ * @uses string $upload_size_limit_with_units
12
+ * @uses object $wpua_admin
13
+ * @uses bool $wpua_allow_upload
14
+ * @uses bool $wpua_disable_gravatar
15
+ * @uses bool $wpua_edit_avatar
16
+ * @uses bool $wpua_resize_crop
17
+ * @uses int int $wpua_resize_h
18
+ * @uses bool $wpua_resize_upload
19
+ * @uses int $wpua_resize_w
20
+ * @uses object $wpua_subscriber
21
+ * @uses bool $wpua_tinymce
22
+ * @uses int $wpua_upload_size_limit
23
+ * @uses string $wpua_upload_size_limit_with_units
24
+ * @uses admin_url()
25
+ * @uses apply_filters()
26
+ * @uses checked()
27
+ * @uses do_action()
28
+ * @uses do_settings_fields()
29
+ * @uses get_option()
30
+ * @uses settings_fields()
31
+ * @uses submit_button()
32
+ * @uses wpua_add_default_avatar()
33
+ */
34
+
35
+ global $show_avatars, $upload_size_limit_with_units, $wpua_admin, $wpua_allow_upload, $wpua_disable_gravatar, $wpua_edit_avatar, $wpua_resize_crop, $wpua_resize_h, $wpua_resize_upload, $wpua_resize_w, $wpua_subscriber, $wpua_tinymce, $wpua_upload_size_limit, $wpua_upload_size_limit_with_units;
36
+ $updated = false;
37
+ if(isset($_GET['settings-updated']) && $_GET['settings-updated'] == 'true') {
38
+ $updated = true;
39
+ }
40
+ $hide_size = (bool) $wpua_allow_upload != 1 ? ' style="display:none;"' : "";
41
+ $hide_resize = (bool) $wpua_resize_upload != 1 ? ' style="display:none;"' : "";
42
+ $wpua_options_page_title = __('WP User Avatar', 'wp-user-avatar');
43
+ /**
44
+ * Filter admin page title
45
+ * @param string $wpua_options_page_title
46
+ */
47
+ $wpua_options_page_title = apply_filters('wpua_options_page_title', $wpua_options_page_title);
48
+ ?>
49
+
50
+ <?php if($updated) : ?>
51
+ <div id="message" class="updated"><p><strong><?php _e('Settings saved.'); ?></strong></p></div>
52
+ <?php endif; ?>
53
+
54
+ <div class="wrap">
55
+ <h2><?php echo $wpua_options_page_title; ?></h2>
56
+ <form method="post" action="<?php echo admin_url('options.php'); ?>">
57
+ <?php settings_fields('wpua-settings-group'); ?>
58
+ <?php do_settings_fields('wpua-settings-group', ""); ?>
59
+ <?php do_action('wpua_donation_message'); ?>
60
+ <table class="form-table">
61
+ <?php
62
+ // Format settings in table rows
63
+ $wpua_before_settings = array();
64
+ /**
65
+ * Filter settings at beginning of table
66
+ * @param array $wpua_before_settings
67
+ */
68
+ $wpua_before_settings = apply_filters('wpua_before_settings', $wpua_before_settings);
69
+ echo implode("", $wpua_before_settings);
70
+ ?>
71
+ <tr valign="top">
72
+ <th scope="row"><?php _e('Settings'); ?></th>
73
+ <td>
74
+ <?php
75
+ // Format settings in fieldsets
76
+ $wpua_settings = array();
77
+ $wpua_settings['tinymce'] = '<fieldset>
78
+ <label for="wp_user_avatar_tinymce">
79
+ <input name="wp_user_avatar_tinymce" type="checkbox" id="wp_user_avatar_tinymce" value="1" '.checked($wpua_tinymce, 1, 0).' />'
80
+ .__('Add avatar button to Visual Editor', 'wp-user-avatar').'
81
+ </label>
82
+ </fieldset>';
83
+ $wpua_settings['upload'] ='<fieldset>
84
+ <label for="wp_user_avatar_allow_upload">
85
+ <input name="wp_user_avatar_allow_upload" type="checkbox" id="wp_user_avatar_allow_upload" value="1" '.checked($wpua_allow_upload, 1, 0).' />'
86
+ .__('Allow Contributors & Subscribers to upload avatars', 'wp-user-avatar').'
87
+ </label>
88
+ </fieldset>';
89
+ $wpua_settings['gravatar'] ='<fieldset>
90
+ <label for="wp_user_avatar_disable_gravatar">
91
+ <input name="wp_user_avatar_disable_gravatar" type="checkbox" id="wp_user_avatar_disable_gravatar" value="1" '.checked($wpua_disable_gravatar, 1, 0).' />'
92
+ .__('Disable Gravatar and use only local avatars', 'wp-user-avatar').'
93
+ </label>
94
+ </fieldset>';
95
+ /**
96
+ * Filter main settings
97
+ * @param array $wpua_settings
98
+ */
99
+ $wpua_settings = apply_filters('wpua_settings', $wpua_settings);
100
+ echo implode("", $wpua_settings);
101
+ ?>
102
+ </td>
103
+ </tr>
104
+ </table>
105
+ <?php
106
+ // Format settings in table
107
+ $wpua_subscriber_settings = array();
108
+ $wpua_subscriber_settings['subscriber-settings'] = '<div id="wpua-contributors-subscribers"'.$hide_size.'>
109
+ <table class="form-table">
110
+ <tr valign="top">
111
+ <th scope="row">
112
+ <label for="wp_user_avatar_upload_size_limit">'
113
+ .__('Upload Size Limit', 'wp-user-avatar').' '.__('(only for Contributors & Subscribers)', 'wp-user-avatar').'
114
+ </label>
115
+ </th>
116
+ <td>
117
+ <fieldset>
118
+ <legend class="screen-reader-text"><span>'.__('Upload Size Limit', 'wp-user-avatar').' '. __('(only for Contributors & Subscribers)', 'wp-user-avatar').'</span></legend>
119
+ <input name="wp_user_avatar_upload_size_limit" type="text" id="wp_user_avatar_upload_size_limit" value="'.$wpua_upload_size_limit.'" class="regular-text" />
120
+ <span id="wpua-readable-size">'.$wpua_upload_size_limit_with_units.'</span>
121
+ <span id="wpua-readable-size-error">'.sprintf(__('%s exceeds the maximum upload size for this site.'), "").'</span>
122
+ <div id="wpua-slider"></div>
123
+ <span class="description">'.sprintf(__('Maximum upload file size: %d%s.'), esc_html(wp_max_upload_size()), esc_html(' bytes ('.$upload_size_limit_with_units.')')).'</span>
124
+ </fieldset>
125
+ <fieldset>
126
+ <label for="wp_user_avatar_edit_avatar">
127
+ <input name="wp_user_avatar_edit_avatar" type="checkbox" id="wp_user_avatar_edit_avatar" value="1" '.checked($wpua_edit_avatar, 1, 0).' />'
128
+ .__('Allow users to edit avatars', 'wp-user-avatar').'
129
+ </label>
130
+ </fieldset>
131
+ <fieldset>
132
+ <label for="wp_user_avatar_resize_upload">
133
+ <input name="wp_user_avatar_resize_upload" type="checkbox" id="wp_user_avatar_resize_upload" value="1" '.checked($wpua_resize_upload, 1, 0).' />'
134
+ .__('Resize avatars on upload', 'wp-user-avatar').'
135
+ </label>
136
+ </fieldset>
137
+ <fieldset id="wpua-resize-sizes"'.$hide_resize.'>
138
+ <label for="wp_user_avatar_resize_w">'.__('Width').'</label>
139
+ <input name="wp_user_avatar_resize_w" type="number" step="1" min="0" id="wp_user_avatar_resize_w" value="'.get_option('wp_user_avatar_resize_w').'" class="small-text" />
140
+ <label for="wp_user_avatar_resize_h">'.__('Height').'</label>
141
+ <input name="wp_user_avatar_resize_h" type="number" step="1" min="0" id="wp_user_avatar_resize_h" value="'.get_option('wp_user_avatar_resize_h').'" class="small-text" />
142
+ <br />
143
+ <input name="wp_user_avatar_resize_crop" type="checkbox" id="wp_user_avatar_resize_crop" value="1" '.checked('1', $wpua_resize_crop, 0).' />
144
+ <label for="wp_user_avatar_resize_crop">'.__('Crop avatars to exact dimensions', 'wp-user-avatar').'</label>
145
+ </fieldset>
146
+ </td>
147
+ </tr>
148
+ </table>
149
+ </div>';
150
+ /**
151
+ * Filter Subscriber settings
152
+ * @param array $wpua_subscriber_settings
153
+ */
154
+ $wpua_subscriber_settings = apply_filters('wpua_subscriber_settings', $wpua_subscriber_settings);
155
+ echo implode("", $wpua_subscriber_settings);
156
+ ?>
157
+ <table class="form-table">
158
+ <tr valign="top">
159
+ <th scope="row"><?php _e('Avatar Display'); ?></th>
160
+ <td>
161
+ <fieldset>
162
+ <legend class="screen-reader-text"><span><?php _e('Avatar Display'); ?></span></legend>
163
+ <label for="show_avatars">
164
+ <input type="checkbox" id="show_avatars" name="show_avatars" value="1" <?php checked($show_avatars, 1); ?> />
165
+ <?php _e('Show Avatars'); ?>
166
+ </label>
167
+ </fieldset>
168
+ </td>
169
+ </tr>
170
+ <?php if((bool) $wpua_disable_gravatar != 1) : ?>
171
+ <tr valign="top" id="avatar-rating">
172
+ <th scope="row"><?php _e('Maximum Rating'); ?></th>
173
+ <td>
174
+ <fieldset>
175
+ <legend class="screen-reader-text"><span><?php _e('Maximum Rating'); ?></span></legend>
176
+ <?php
177
+ $ratings = array(
178
+ 'G' => __('G &#8212; Suitable for all audiences'),
179
+ 'PG' => __('PG &#8212; Possibly offensive, usually for audiences 13 and above'),
180
+ 'R' => __('R &#8212; Intended for adult audiences above 17'),
181
+ 'X' => __('X &#8212; Even more mature than above')
182
+ );
183
+ foreach ($ratings as $key => $rating) :
184
+ $selected = (get_option('avatar_rating') == $key) ? 'checked="checked"' : "";
185
+ echo "\n\t<label><input type='radio' name='avatar_rating' value='".esc_attr($key)."' $selected/> $rating</label><br />";
186
+ endforeach;
187
+ ?>
188
+ </fieldset>
189
+ </td>
190
+ </tr>
191
+ <?php else : ?>
192
+ <input type="hidden" id="avatar_rating" name="avatar_rating" value="<?php echo get_option('avatar_rating'); ?>" />
193
+ <?php endif; ?>
194
+ <tr valign="top">
195
+ <th scope="row"><?php _e('Default Avatar') ?></th>
196
+ <td class="defaultavatarpicker">
197
+ <fieldset>
198
+ <legend class="screen-reader-text"><span><?php _e('Default Avatar'); ?></span></legend>
199
+ <?php _e('For users without a custom avatar of their own, you can either display a generic logo or a generated one based on their e-mail address.'); ?><br />
200
+ <?php echo $wpua_admin->wpua_add_default_avatar(); ?>
201
+ </fieldset>
202
+ </td>
203
+ </tr>
204
+ </table>
205
+ <?php submit_button(); ?>
206
+ </form>
207
+ </div>
includes/wpua-tinymce.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * TinyMCE button for Visual Editor.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.5
7
+ */
8
+
9
+ /**
10
+ * Add TinyMCE button
11
+ * @uses add_filter()
12
+ * @uses get_user_option()
13
+ */
14
+ function wpua_add_buttons() {
15
+ // Add only in Rich Editor mode
16
+ if(get_user_option('rich_editing') == 'true') {
17
+ add_filter('mce_external_plugins', 'wpua_add_tinymce_plugin');
18
+ add_filter('mce_buttons', 'wpua_register_button');
19
+ }
20
+ }
21
+ add_action('init', 'wpua_add_buttons');
22
+
23
+ /**
24
+ * Register TinyMCE button
25
+ * @param array $buttons
26
+ * @return array
27
+ */
28
+ function wpua_register_button($buttons) {
29
+ array_push($buttons, 'separator', 'wpUserAvatar');
30
+ return $buttons;
31
+ }
32
+
33
+ /**
34
+ * Load TinyMCE plugin
35
+ * @param array $plugin_array
36
+ * @return array
37
+ */
38
+ function wpua_add_tinymce_plugin($plugins) {
39
+ $plugins['wpUserAvatar'] = WPUA_INC_URL.'tinymce/editor_plugin.js';
40
+ return $plugins;
41
+ }
42
+
43
+ /**
44
+ * Call TinyMCE window content via admin-ajax
45
+ */
46
+ function wpua_ajax_tinymce() {
47
+ include_once(WPUA_INC.'tinymce/window.php');
48
+ die();
49
+ }
50
+ add_action('wp_ajax_wp_user_avatar_tinymce', 'wpua_ajax_tinymce');
js/wp-user-avatar-admin.js CHANGED
@@ -1,37 +1,40 @@
1
- jQuery(function(){
2
  // Show size info only if allow uploads is checked
3
- jQuery('#wp_user_avatar_allow_upload').change(function(){
4
- jQuery('#wpua-size-limit').removeClass('wpua-hide').toggle(jQuery('#wp_user_avatar_allow_upload').is(':checked'));
 
 
 
 
5
  });
6
  // Hide Gravatars if disable Gravatars is checked
7
- jQuery('#wp_user_avatar_disable_gravatar').change(function(){
8
- if(jQuery('#wp-avatars').length){
9
- jQuery('#wp-avatars').toggle(!jQuery('#wp_user_avatar_disable_gravatar').is(':checked'));
10
- jQuery('#wp_user_avatar_radio').trigger('click');
11
  }
12
- jQuery('#wpua-message').show();
13
  });
14
  // Add size slider
15
- jQuery('#wpua-slider').slider({
16
  value: parseInt(wpua_admin.upload_size_limit),
17
  min: 0,
18
  max: parseInt(wpua_admin.max_upload_size),
19
  step: 1,
20
- slide: function(event, ui){
21
- jQuery('#wp_user_avatar_upload_size_limit').val(ui.value);
22
- jQuery('#wpua-readable-size').html(Math.floor(ui.value / 1024) + 'KB');
23
- jQuery('#wpua-readable-size-error').hide();
24
- jQuery('#wpua-readable-size').removeClass('wpua-error');
25
  }
26
  });
27
  // Update readable size on keyup
28
- jQuery('#wp_user_avatar_upload_size_limit').keyup(function(){
29
- var wpua_upload_size_limit = jQuery(this).val();
30
- wpua_upload_size_limit = wpua_upload_size_limit.replace(/\D/g, '');
31
- jQuery(this).val(wpua_upload_size_limit);
32
- jQuery('#wpua-readable-size').html(Math.floor(wpua_upload_size_limit / 1024) + 'KB');
33
- jQuery('#wpua-readable-size-error').toggle(wpua_upload_size_limit > parseInt(wpua_admin.max_upload_size));
34
- jQuery('#wpua-readable-size').toggleClass('wpua-error', wpua_upload_size_limit > parseInt(wpua_admin.max_upload_size));
35
  });
36
- jQuery('#wp_user_avatar_upload_size_limit').val(jQuery('#wpua-slider').slider('value'));
37
  });
1
+ jQuery(function($) {
2
  // Show size info only if allow uploads is checked
3
+ $('#wp_user_avatar_allow_upload').change(function() {
4
+ $('#wpua-contributors-subscribers').slideToggle($('#wp_user_avatar_allow_upload').is(':checked'));
5
+ });
6
+ // Show resize info only if resize uploads is checked
7
+ $('#wp_user_avatar_resize_upload').change(function() {
8
+ $('#wpua-resize-sizes').slideToggle($('#wp_user_avatar_resize_upload').is(':checked'));
9
  });
10
  // Hide Gravatars if disable Gravatars is checked
11
+ $('#wp_user_avatar_disable_gravatar').change(function() {
12
+ if($('#wp-avatars').length) {
13
+ $('#wp-avatars, #avatar-rating').slideToggle(!$('#wp_user_avatar_disable_gravatar').is(':checked'));
14
+ $('#wp_user_avatar_radio').trigger('click');
15
  }
 
16
  });
17
  // Add size slider
18
+ $('#wpua-slider').slider({
19
  value: parseInt(wpua_admin.upload_size_limit),
20
  min: 0,
21
  max: parseInt(wpua_admin.max_upload_size),
22
  step: 1,
23
+ slide: function(event, ui) {
24
+ $('#wp_user_avatar_upload_size_limit').val(ui.value);
25
+ $('#wpua-readable-size').html(Math.floor(ui.value / 1024) + 'KB');
26
+ $('#wpua-readable-size-error').hide();
27
+ $('#wpua-readable-size').removeClass('wpua-error');
28
  }
29
  });
30
  // Update readable size on keyup
31
+ $('#wp_user_avatar_upload_size_limit').keyup(function() {
32
+ var wpuaUploadSizeLimit = $(this).val();
33
+ wpuaUploadSizeLimit = wpuaUploadSizeLimit.replace(/\D/g, "");
34
+ $(this).val(wpuaUploadSizeLimit);
35
+ $('#wpua-readable-size').html(Math.floor(wpuaUploadSizeLimit / 1024) + 'KB');
36
+ $('#wpua-readable-size-error').toggle(wpuaUploadSizeLimit > parseInt(wpua_admin.max_upload_size));
37
+ $('#wpua-readable-size').toggleClass('wpua-error', wpuaUploadSizeLimit > parseInt(wpua_admin.max_upload_size));
38
  });
39
+ $('#wp_user_avatar_upload_size_limit').val($('#wpua-slider').slider('value'));
40
  });
js/wp-user-avatar-user.js ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(function($) {
2
+ // Add enctype to form with JavaScript as backup
3
+ $('#your-profile').attr('enctype', 'multipart/form-data');
4
+ // Store WP User Avatar ID
5
+ var wpuaID = $('#wp-user-avatar').val();
6
+ // Store WP User Avatar src
7
+ var wpuaSrc = $('#wpua-preview').find('img').attr('src');
8
+ // Remove WP User Avatar
9
+ $('body').on('click', '#wpua-remove', function(e) {
10
+ e.preventDefault();
11
+ $('#wpua-original').remove();
12
+ $('#wpua-remove-button, #wpua-thumbnail').hide();
13
+ $('#wpua-preview').find('img:first').hide();
14
+ $('#wpua-preview').prepend('<img id="wpua-original" />');
15
+ $('#wpua-original').attr('src', wpua_custom.avatar_thumb);
16
+ $('#wp-user-avatar').val("");
17
+ $('#wpua-original, #wpua-undo-button').show();
18
+ $('#wp_user_avatar_radio').trigger('click');
19
+ });
20
+ // Undo WP User Avatar
21
+ $('body').on('click', '#wpua-undo', function(e) {
22
+ e.preventDefault();
23
+ $('#wpua-original').remove();
24
+ $('#wpua-images').removeAttr('style');
25
+ $('#wpua-undo-button').hide();
26
+ $('#wpua-remove-button, #wpua-thumbnail').show();
27
+ $('#wpua-preview').find('img:first').attr('src', wpuaSrc).show();
28
+ $('#wp-user-avatar').val(wpuaID);
29
+ $('#wp_user_avatar_radio').trigger('click');
30
+ });
31
+ });
js/wp-user-avatar.js CHANGED
@@ -1 +1 @@
1
- function wpuaMediaUploader(c,d,f){wp.media.wpUserAvatar={get:function(){return wp.media.view.settings.post.wpUserAvatarId},set:function(a){var b=wp.media.view.settings;b.post.wpUserAvatarId=a;b.post.wpUserAvatarSrc=jQuery('div.attachment-info').find('img').attr('src');if(b.post.wpUserAvatarId){wpuaSetAvatar(b.post.wpUserAvatarId,b.post.wpUserAvatarSrc);jQuery('#wp_user_avatar_radio').trigger('click')}},frame:function(){if(this._frame){return this._frame}this._frame=wp.media({state:'library',states:[new wp.media.controller.Library({title:d+": "+c})]});this._frame.on('open',function(){var a=this.state().get('selection');id=jQuery('#wp-user-avatar').val();attachment=wp.media.attachment(id);attachment.fetch();a.add(attachment?[attachment]:[])},this._frame);this._frame.on('toolbar:create:select',function(a){this.createSelectToolbar(a,{text:f})},this._frame);this._frame.state('library').on('select',this.select);return this._frame},select:function(a){var b=wp.media.view.settings,selection=this.get('selection').single();wp.media.wpUserAvatar.set(selection?selection.id:-1)},init:function(){jQuery('body').on('click','#wpua-add',function(e){e.preventDefault();e.stopPropagation();wp.media.wpUserAvatar.frame().open()})}};jQuery(wp.media.wpUserAvatar.init)}function wpuaSetAvatar(a,b){jQuery('#wp-user-avatar',window.parent.document).val(a);jQuery('#wpua-preview',window.parent.document).find('img').attr('src',b).removeAttr('width',"").removeAttr('height',"");jQuery('#wpua-message',window.parent.document).show();jQuery('#wpua-remove',window.parent.document).removeClass('wpua-hide').show();jQuery('#wpua-thumbnail',window.parent.document).hide();jQuery('#wp_user_avatar_radio',window.parent.document).trigger('click');wp.media.wpUserAvatar.frame().close()}function wpuaRemoveAvatar(a){jQuery('body').on('click','#wpua-remove',function(e){e.preventDefault();jQuery(this).hide();jQuery('#wpua-edit, #wpua-thumbnail').hide();jQuery('#wpua-preview').find('img').attr('src',a).removeAttr('width',"").removeAttr('height',"");jQuery('#wp-user-avatar').val("");jQuery('#wpua-message').show();jQuery('#wp_user_avatar_radio').trigger('click')})}jQuery(function(){jQuery('#your-profile').attr('enctype','multipart/form-data');if(typeof(wp)!='undefined'){wpuaMediaUploader(wpua_custom.section,wpua_custom.edit_image,wpua_custom.select_image)}wpuaRemoveAvatar(wpua_custom.avatar_thumb)});
1
+ eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(3($){2.5.p={H:3(){E 2.5.W.P.8.v},M:3(a){q b=2.5.W.P;b.8.v=a;b.8.D=$(\'K.f-Z\').9(\'c\').d(\'k\');u(b.8.v&&b.8.D){$(\'#2-m-n\').o(b.8.v);$(\'#0-T, #0-s-h\').t();$(\'#0-r\').9(\'c\').d(\'k\',b.8.D).O(\'X\',"");$(\'#0-g-h, #0-z\').x();$(\'#C\').w(\'6\')}2.5.p.A().1j()},A:3(){u(4.7){E 4.7}4.7=2.5({S:{12:\'13\'},15:1f,U:$(\'#0-B\').J(\'U\')});4.7.l(\'L\',3(){q a=$(\'#2-m-n\').o();u(a==""){$(\'K.5-14\').9(\'a:y\').w(\'6\')}17{q b=4.N().H(\'j\');f=2.5.f(a);f.Y();b.B(f?[f]:[])}},4.7);4.7.N(\'S\').l(\'F\',4.F);E 4.7},F:3(a){j=4.H(\'j\').10();2.5.p.M(j?j.Q:-1)},R:3(){$(\'G\').l(\'6\',\'#0-B\',3(e){e.I();e.16();2.5.p.A().L()})}}})(V);V(3($){u(18(2)!=\'19\'){2.5.p.R()}$(\'#1a-1b\').d(\'1c\',\'1d/1e-J\');q a=$(\'#2-m-n\').o();q b=$(\'#0-r\').9(\'c\').d(\'k\');$(\'G\').l(\'6\',\'#0-g\',3(e){e.I();$(\'#0-i\').g();$(\'#0-g-h, #0-z\').x();$(\'#0-r\').9(\'c:y\').x();$(\'#0-r\').1g(\'<c Q="0-i" />\');$(\'#0-i\').d(\'k\',1h.1i);$(\'#2-m-n\').o("");$(\'#0-i, #0-s-h\').t();$(\'#C\').w(\'6\')});$(\'G\').l(\'6\',\'#0-s\',3(e){e.I();$(\'#0-i\').g();$(\'#0-T\').O(\'11\');$(\'#0-s-h\').x();$(\'#0-g-h, #0-z\').t();$(\'#0-r\').9(\'c:y\').d(\'k\',b).t();$(\'#2-m-n\').o(a);$(\'#C\').w(\'6\')})});',62,82,'wpua||wp|function|this|media|click|_frame|post|find|||img|attr||attachment|remove|button|original|selection|src|on|user|avatar|val|wpUserAvatar|var|preview|undo|show|if|wpUserAvatarId|trigger|hide|first|thumbnail|frame|add|wp_user_avatar_radio|wpUserAvatarSrc|return|select|body|get|preventDefault|data|div|open|set|state|removeAttr|settings|id|init|library|images|title|jQuery|view|height|fetch|info|single|style|type|image|router|multiple|stopPropagation|else|typeof|undefined|your|profile|enctype|multipart|form|false|prepend|wpua_custom|avatar_thumb|close'.split('|'),0,{}))
lang/wp-user-avatar-de_DE.mo CHANGED
Binary file
lang/wp-user-avatar-de_DE.po CHANGED
@@ -1,12 +1,12 @@
1
  # German (de_DE) translation for WP User Avatar.
2
- # Copyright (C) 2013 Bangbay Siboliban.
3
  # This file is distributed under the same license as the WP User Avatar package.
4
  #
5
  msgid ""
6
  msgstr ""
7
- "Project-Id-Version: WP User Avatar 1.5.4\n"
8
  "Report-Msgid-Bugs-To: http://wordpress.org/plugins/wp-user-avatar/\n"
9
- "PO-Revision-Date: 2013-07-31 00:00-0000\n"
10
  "Language: de_DE\n"
11
  "Last-Translator: WP User Avatar\n"
12
  "Language-Team: WP User Avatar\n"
@@ -14,32 +14,52 @@ msgstr ""
14
  "Content-Type: text/plain; charset=UTF-8\n"
15
  "Content-Transfer-Encoding: 8bit\n"
16
 
17
- #: wp-user-avatar.php:341
18
- #: wp-user-avatar.php:798
19
- msgid "Click %s to save your changes"
20
- msgstr "Klicken Sie %s, um Ihre Änderungen zu speichern"
21
 
22
- #: wp-user-avatar.php:870
 
 
 
 
 
 
 
 
23
  msgid "Add avatar button to Visual Editor"
24
  msgstr "Einen Avatar-Knopf zum WYSIWYG-Editor hinzufügen"
25
 
26
- #: wp-user-avatar.php:875
27
  msgid "Allow Contributors & Subscribers to upload avatars"
28
  msgstr "Mitarbeiter und Abonnenten erlauben, Avatare hochzuladen"
29
 
30
- #: wp-user-avatar.php:880
31
  msgid "Disable Gravatar and use only local avatars"
32
  msgstr "Gravatar deaktivieren und nur lokale Avatare verwenden"
33
 
34
- #: wp-user-avatar.php:888
35
- #: wp-user-avatar.php:893
36
- msgid "Upload Size Limit (only for Contributors & Subscribers)"
37
- msgstr "Dateigrößenbeschränkung (nur für Mitarbeiter und Abonnenten)"
 
 
 
 
 
38
 
39
- #: wp-user-avatar.php:902
40
  msgid "Allow users to edit avatars"
41
  msgstr "Benutzer erlauben, Avatare bearbeiten"
42
 
 
 
 
 
 
 
 
 
43
  #. Plugin Name of the plugin/theme
44
  msgid "WP User Avatar"
45
  msgstr "WP-Benutzer-Avatar"
1
  # German (de_DE) translation for WP User Avatar.
2
+ # Copyright (C) 2014 Bangbay Siboliban.
3
  # This file is distributed under the same license as the WP User Avatar package.
4
  #
5
  msgid ""
6
  msgstr ""
7
+ "Project-Id-Version: WP User Avatar 1.9.5\n"
8
  "Report-Msgid-Bugs-To: http://wordpress.org/plugins/wp-user-avatar/\n"
9
+ "PO-Revision-Date: 2014-04-24 00:00-0000\n"
10
  "Language: de_DE\n"
11
  "Last-Translator: WP User Avatar\n"
12
  "Language-Team: WP User Avatar\n"
14
  "Content-Type: text/plain; charset=UTF-8\n"
15
  "Content-Transfer-Encoding: 8bit\n"
16
 
17
+ #: includes/class-wp-user-avatar-admin.php:209
18
+ msgid "Donate"
19
+ msgstr "Spenden"
 
20
 
21
+ #: includes/wpua-functions.php:175
22
+ msgid "Do you like WP User Avatar?"
23
+ msgstr "Bist Du mit WP-Benutzer-Avatar zufrieden?"
24
+
25
+ #: includes/wpua-functions.php:175
26
+ msgid "Make a donation."
27
+ msgstr "Spenden"
28
+
29
+ #: includes/wpua-options-page.php:80
30
  msgid "Add avatar button to Visual Editor"
31
  msgstr "Einen Avatar-Knopf zum WYSIWYG-Editor hinzufügen"
32
 
33
+ #: includes/wpua-options-page.php:86
34
  msgid "Allow Contributors & Subscribers to upload avatars"
35
  msgstr "Mitarbeiter und Abonnenten erlauben, Avatare hochzuladen"
36
 
37
+ #: includes/wpua-options-page.php:92
38
  msgid "Disable Gravatar and use only local avatars"
39
  msgstr "Gravatar deaktivieren und nur lokale Avatare verwenden"
40
 
41
+ #: includes/wpua-options-page.php:113
42
+ #: includes/wpua-options-page.php:118
43
+ msgid "Upload Size Limit"
44
+ msgstr "Dateigrößenbeschränkung"
45
+
46
+ #: includes/wpua-options-page.php:113
47
+ #: includes/wpua-options-page.php:118
48
+ msgid "(only for Contributors & Subscribers)"
49
+ msgstr "(nur für Mitarbeiter und Abonnenten)"
50
 
51
+ #: includes/wpua-options-page.php:128
52
  msgid "Allow users to edit avatars"
53
  msgstr "Benutzer erlauben, Avatare bearbeiten"
54
 
55
+ #: includes/wpua-options-page.php:134
56
+ msgid "Resize avatars on upload"
57
+ msgstr "Resize Avatare beim Upload"
58
+
59
+ #: includes/wpua-options-page.php:144
60
+ msgid "Crop avatars to exact dimensions"
61
+ msgstr "Avatare auf exakte Größe beschneiden"
62
+
63
  #. Plugin Name of the plugin/theme
64
  msgid "WP User Avatar"
65
  msgstr "WP-Benutzer-Avatar"
lang/wp-user-avatar-es_ES.mo CHANGED
Binary file
lang/wp-user-avatar-es_ES.po CHANGED
@@ -1,12 +1,12 @@
1
  # Spanish (es_ES) translation for WP User Avatar.
2
- # Copyright (C) 2013 Bangbay Siboliban.
3
  # This file is distributed under the same license as the WP User Avatar package.
4
  #
5
  msgid ""
6
  msgstr ""
7
- "Project-Id-Version: WP User Avatar 1.5.4\n"
8
  "Report-Msgid-Bugs-To: http://wordpress.org/plugins/wp-user-avatar/\n"
9
- "PO-Revision-Date: 2013-07-31 00:00-0000\n"
10
  "Language: es_ES\n"
11
  "Last-Translator: WP User Avatar\n"
12
  "Language-Team: WP User Avatar\n"
@@ -14,32 +14,52 @@ msgstr ""
14
  "Content-Type: text/plain; charset=UTF-8\n"
15
  "Content-Transfer-Encoding: 8bit\n"
16
 
17
- #: wp-user-avatar.php:341
18
- #: wp-user-avatar.php:798
19
- msgid "Click %s to save your changes"
20
- msgstr "Haz clic %s para guardar los cambios"
21
 
22
- #: wp-user-avatar.php:870
 
 
 
 
 
 
 
 
23
  msgid "Add avatar button to Visual Editor"
24
  msgstr "Añadir botón avatar al editor visual"
25
 
26
- #: wp-user-avatar.php:875
27
  msgid "Allow Contributors & Subscribers to upload avatars"
28
  msgstr "Permitir los colaboradores y los suscriptores subir avatares"
29
 
30
- #: wp-user-avatar.php:880
31
  msgid "Disable Gravatar and use only local avatars"
32
  msgstr "Desactivar Gravatar y utilizar sólo los avatares locales"
33
 
34
- #: wp-user-avatar.php:888
35
- #: wp-user-avatar.php:893
36
- msgid "Upload Size Limit (only for Contributors & Subscribers)"
37
- msgstr "Sube límite de tamaño (para colaboradores y suscriptores)"
 
 
 
 
 
38
 
39
- #: wp-user-avatar.php:902
40
  msgid "Allow users to edit avatars"
41
  msgstr "Permitir a los usuarios editar avatar"
42
 
 
 
 
 
 
 
 
 
43
  #. Plugin Name of the plugin/theme
44
  msgid "WP User Avatar"
45
  msgstr "WP-Usuario-Avatar"
1
  # Spanish (es_ES) translation for WP User Avatar.
2
+ # Copyright (C) 2014 Bangbay Siboliban.
3
  # This file is distributed under the same license as the WP User Avatar package.
4
  #
5
  msgid ""
6
  msgstr ""
7
+ "Project-Id-Version: WP User Avatar 1.9.5\n"
8
  "Report-Msgid-Bugs-To: http://wordpress.org/plugins/wp-user-avatar/\n"
9
+ "PO-Revision-Date: 2014-04-24 00:00-0000\n"
10
  "Language: es_ES\n"
11
  "Last-Translator: WP User Avatar\n"
12
  "Language-Team: WP User Avatar\n"
14
  "Content-Type: text/plain; charset=UTF-8\n"
15
  "Content-Transfer-Encoding: 8bit\n"
16
 
17
+ #: includes/class-wp-user-avatar-admin.php:209
18
+ msgid "Donate"
19
+ msgstr "Donar"
 
20
 
21
+ #: includes/wpua-functions.php:175
22
+ msgid "Do you like WP User Avatar?"
23
+ msgstr "¿Está satisfecho con WP-Usuario-Avatar?"
24
+
25
+ #: includes/wpua-functions.php:175
26
+ msgid "Make a donation."
27
+ msgstr "Donar"
28
+
29
+ #: includes/wpua-options-page.php:80
30
  msgid "Add avatar button to Visual Editor"
31
  msgstr "Añadir botón avatar al editor visual"
32
 
33
+ #: includes/wpua-options-page.php:86
34
  msgid "Allow Contributors & Subscribers to upload avatars"
35
  msgstr "Permitir los colaboradores y los suscriptores subir avatares"
36
 
37
+ #: includes/wpua-options-page.php:92
38
  msgid "Disable Gravatar and use only local avatars"
39
  msgstr "Desactivar Gravatar y utilizar sólo los avatares locales"
40
 
41
+ #: includes/wpua-options-page.php:113
42
+ #: includes/wpua-options-page.php:118
43
+ msgid "Upload Size Limit"
44
+ msgstr "Sube límite de tamaño"
45
+
46
+ #: includes/wpua-options-page.php:113
47
+ #: includes/wpua-options-page.php:118
48
+ msgid "(only for Contributors & Subscribers)"
49
+ msgstr "(para colaboradores y suscriptores)"
50
 
51
+ #: includes/wpua-options-page.php:128
52
  msgid "Allow users to edit avatars"
53
  msgstr "Permitir a los usuarios editar avatar"
54
 
55
+ #: includes/wpua-options-page.php:134
56
+ msgid "Resize avatars on upload"
57
+ msgstr "Cambiar el tamaño de avatares en carga"
58
+
59
+ #: includes/wpua-options-page.php:144
60
+ msgid "Crop avatars to exact dimensions"
61
+ msgstr "Recortar los avatares a sus dimensiones exactas"
62
+
63
  #. Plugin Name of the plugin/theme
64
  msgid "WP User Avatar"
65
  msgstr "WP-Usuario-Avatar"
lang/wp-user-avatar-fr_FR.mo CHANGED
Binary file
lang/wp-user-avatar-fr_FR.po CHANGED
@@ -1,12 +1,12 @@
1
  # French (fr_FR) translation for WP User Avatar.
2
- # Copyright (C) 2013 Bangbay Siboliban.
3
  # This file is distributed under the same license as the WP User Avatar package.
4
  #
5
  msgid ""
6
  msgstr ""
7
- "Project-Id-Version: WP User Avatar 1.5.4\n"
8
  "Report-Msgid-Bugs-To: http://wordpress.org/plugins/wp-user-avatar/\n"
9
- "PO-Revision-Date: 2013-07-31 00:00-0000\n"
10
  "Language: fr_FR\n"
11
  "Last-Translator: WP User Avatar\n"
12
  "Language-Team: WP User Avatar\n"
@@ -14,32 +14,52 @@ msgstr ""
14
  "Content-Type: text/plain; charset=UTF-8\n"
15
  "Content-Transfer-Encoding: 8bit\n"
16
 
17
- #: wp-user-avatar.php:341
18
- #: wp-user-avatar.php:798
19
- msgid "Click %s to save your changes"
20
- msgstr "Cliquez sur %s pour enregistrer vos modifications"
21
 
22
- #: wp-user-avatar.php:870
 
 
 
 
 
 
 
 
23
  msgid "Add avatar button to Visual Editor"
24
  msgstr "Ajouter le bouton avatar sur l'éditeur visuel"
25
 
26
- #: wp-user-avatar.php:875
27
  msgid "Allow Contributors & Subscribers to upload avatars"
28
  msgstr "Permettre aux contributeurs et aux abonnés d'envoyer des avatars"
29
 
30
- #: wp-user-avatar.php:880
31
  msgid "Disable Gravatar and use only local avatars"
32
  msgstr "Désactiver Gravatar et utiliser les avatars fournis"
33
 
34
- #: wp-user-avatar.php:888
35
- #: wp-user-avatar.php:893
36
- msgid "Upload Size Limit (only for Contributors & Subscribers)"
37
- msgstr "Taille limite d'envoi de fichiers (pour contributeurs et abonnés)"
 
 
 
 
 
38
 
39
- #: wp-user-avatar.php:902
40
  msgid "Allow users to edit avatars"
41
  msgstr "Permettre aux utilisateurs de modifier avatar"
42
 
 
 
 
 
 
 
 
 
43
  #. Plugin Name of the plugin/theme
44
  msgid "WP User Avatar"
45
  msgstr "WP-Utilisateur-Avatar"
1
  # French (fr_FR) translation for WP User Avatar.
2
+ # Copyright (C) 2014 Bangbay Siboliban.
3
  # This file is distributed under the same license as the WP User Avatar package.
4
  #
5
  msgid ""
6
  msgstr ""
7
+ "Project-Id-Version: WP User Avatar 1.9.5\n"
8
  "Report-Msgid-Bugs-To: http://wordpress.org/plugins/wp-user-avatar/\n"
9
+ "PO-Revision-Date: 2014-04-24 00:00-0000\n"
10
  "Language: fr_FR\n"
11
  "Last-Translator: WP User Avatar\n"
12
  "Language-Team: WP User Avatar\n"
14
  "Content-Type: text/plain; charset=UTF-8\n"
15
  "Content-Transfer-Encoding: 8bit\n"
16
 
17
+ #: includes/class-wp-user-avatar-admin.php:209
18
+ msgid "Donate"
19
+ msgstr "Faites un don"
 
20
 
21
+ #: includes/wpua-functions.php:175
22
+ msgid "Do you like WP User Avatar?"
23
+ msgstr "Etes-vous satisfait avec WP-Utilisateur-Avatar?"
24
+
25
+ #: includes/wpua-functions.php:175
26
+ msgid "Make a donation."
27
+ msgstr "Faites un don"
28
+
29
+ #: includes/wpua-options-page.php:80
30
  msgid "Add avatar button to Visual Editor"
31
  msgstr "Ajouter le bouton avatar sur l'éditeur visuel"
32
 
33
+ #: includes/wpua-options-page.php:86
34
  msgid "Allow Contributors & Subscribers to upload avatars"
35
  msgstr "Permettre aux contributeurs et aux abonnés d'envoyer des avatars"
36
 
37
+ #: includes/wpua-options-page.php:92
38
  msgid "Disable Gravatar and use only local avatars"
39
  msgstr "Désactiver Gravatar et utiliser les avatars fournis"
40
 
41
+ #: includes/wpua-options-page.php:113
42
+ #: includes/wpua-options-page.php:118
43
+ msgid "Upload Size Limit"
44
+ msgstr "Taille limite d'envoi de fichiers"
45
+
46
+ #: includes/wpua-options-page.php:113
47
+ #: includes/wpua-options-page.php:118
48
+ msgid "(only for Contributors & Subscribers)"
49
+ msgstr "(pour contributeurs et abonnés)"
50
 
51
+ #: includes/wpua-options-page.php:128
52
  msgid "Allow users to edit avatars"
53
  msgstr "Permettre aux utilisateurs de modifier avatar"
54
 
55
+ #: includes/wpua-options-page.php:134
56
+ msgid "Resize avatars on upload"
57
+ msgstr "Redimensionner avatars lors du téléchargement"
58
+
59
+ #: includes/wpua-options-page.php:144
60
+ msgid "Crop avatars to exact dimensions"
61
+ msgstr "Recadrer les avatars pour parvenir aux dimensions exactes"
62
+
63
  #. Plugin Name of the plugin/theme
64
  msgid "WP User Avatar"
65
  msgstr "WP-Utilisateur-Avatar"
lang/wp-user-avatar-pl_PL.mo ADDED
Binary file
lang/wp-user-avatar-pl_PL.po ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Polish (pl_PL) translation for WP User Avatar.
2
+ # Copyright (C) 2014 Bangbay Siboliban.
3
+ # This file is distributed under the same license as the WP User Avatar package.
4
+ #
5
+ msgid ""
6
+ msgstr ""
7
+ "Project-Id-Version: WP User Avatar 1.9.5\n"
8
+ "Report-Msgid-Bugs-To: http://wordpress.org/plugins/wp-user-avatar/\n"
9
+ "PO-Revision-Date: 2014-04-24 00:00-0000\n"
10
+ "Language: de_DE\n"
11
+ "Last-Translator: WP User Avatar\n"
12
+ "Language-Team: WP User Avatar\n"
13
+ "MIME-Version: 1.0\n"
14
+ "Content-Type: text/plain; charset=UTF-8\n"
15
+ "Content-Transfer-Encoding: 8bit\n"
16
+
17
+ #: includes/class-wp-user-avatar-admin.php:209
18
+ msgid "Donate"
19
+ msgstr "Dotuj"
20
+
21
+ #: includes/wpua-functions.php:175
22
+ msgid "Do you like WP User Avatar?"
23
+ msgstr "Jesteś zadowolony z Wp User Avatar"
24
+
25
+ #: includes/wpua-functions.php:175
26
+ msgid "Make a donation."
27
+ msgstr "Dokonaj dotacji"
28
+
29
+ #: includes/wpua-options-page.php:80
30
+ msgid "Add avatar button to Visual Editor"
31
+ msgstr "Dodaj przycisk avatara do edytora wizualnego"
32
+
33
+ #: includes/wpua-options-page.php:86
34
+ msgid "Allow Contributors & Subscribers to upload avatars"
35
+ msgstr "Pozwalaj kontrybutorom oraz subskrynentom przesyłać awatary"
36
+
37
+ #: includes/wpua-options-page.php:92
38
+ msgid "Disable Gravatar and use only local avatars"
39
+ msgstr "Wyłącz gravatary i używaj tylko lokalnych awatarów"
40
+
41
+ #: includes/wpua-options-page.php:113
42
+ #: includes/wpua-options-page.php:118
43
+ msgid "Upload Size Limit"
44
+ msgstr "Limit wielkości pliku"
45
+
46
+ #: includes/wpua-options-page.php:113
47
+ #: includes/wpua-options-page.php:118
48
+ msgid "(only for Contributors & Subscribers)"
49
+ msgstr "(tylko dla subskrynentów i kontrybutorów)"
50
+
51
+ #: includes/wpua-options-page.php:128
52
+ msgid "Allow users to edit avatars"
53
+ msgstr "Pozwalaj użytkownikom edytować awatary"
54
+
55
+ #: includes/wpua-options-page.php:134
56
+ msgid "Resize avatars on upload"
57
+ msgstr "Zmieniaj rozmiar po przesłaniu"
58
+
59
+ #: includes/wpua-options-page.php:144
60
+ msgid "Crop avatars to exact dimensions"
61
+ msgstr "Przytnij awatar do dokładnych rozmiarów"
62
+
63
+ #. Plugin Name of the plugin/theme
64
+ msgid "WP User Avatar"
65
+ msgstr "WP Awatar Użytkownika"
66
+
67
+ #. Plugin URI of the plugin/theme
68
+ msgid "http://wordpress.org/plugins/wp-user-avatar/"
69
+ msgstr "http://wordpress.org/plugins/wp-user-avatar/"
70
+
71
+ #. Description of the plugin/theme
72
+ msgid "Use any image from your WordPress Media Library as a custom user avatar. Add your own Default Avatar."
73
+ msgstr "Użyj dowolnego obrazka z biblioteki mediów jako awatar użytkownika. Dodaj swój własny domyślny awatar."
74
+
75
+ #. Author of the plugin/theme
76
+ msgid "Bangbay Siboliban"
77
+ msgstr "Bangbay Siboliban"
78
+
79
+ #. Author URI of the plugin/theme
80
+ msgid "http://siboliban.org/"
81
+ msgstr "http://siboliban.org/"
lang/wp-user-avatar-sv_SE.mo CHANGED
Binary file
lang/wp-user-avatar-sv_SE.po CHANGED
@@ -1,12 +1,12 @@
1
  # Swedish (sv_SE) translation for WP User Avatar.
2
- # Copyright (C) 2013 Bangbay Siboliban.
3
  # This file is distributed under the same license as the WP User Avatar package.
4
  #
5
  msgid ""
6
  msgstr ""
7
- "Project-Id-Version: WP User Avatar 1.5.4\n"
8
  "Report-Msgid-Bugs-To: http://wordpress.org/plugins/wp-user-avatar/\n"
9
- "PO-Revision-Date: 2013-07-31 00:00-0000\n"
10
  "Language: sv_SE\n"
11
  "Last-Translator: Mattias Tengblad <mst@eyesx.com>\n"
12
  "Language-Team: WordPress Sverige <info@wpsv.se>\n"
@@ -14,32 +14,52 @@ msgstr ""
14
  "Content-Type: text/plain; charset=UTF-8\n"
15
  "Content-Transfer-Encoding: 8bit\n"
16
 
17
- #: wp-user-avatar.php:341
18
- #: wp-user-avatar.php:798
19
- msgid "Click %s to save your changes"
20
- msgstr "Klicka på %s för att spara dina ändringar"
21
 
22
- #: wp-user-avatar.php:870
 
 
 
 
 
 
 
 
23
  msgid "Add avatar button to Visual Editor"
24
  msgstr "Lägg till knapp för avatarer i den visuella redigeraren"
25
 
26
- #: wp-user-avatar.php:875
27
  msgid "Allow Contributors & Subscribers to upload avatars"
28
  msgstr "Tillåt medarbetare & prenumeranter att ladda upp avatarer"
29
 
30
- #: wp-user-avatar.php:880
31
  msgid "Disable Gravatar and use only local avatars"
32
  msgstr "Inaktivera Gravatar och använd endast lokala avatarer"
33
 
34
- #: wp-user-avatar.php:888
35
- #: wp-user-avatar.php:893
36
- msgid "Upload Size Limit (only for Contributors & Subscribers)"
37
- msgstr "Storleksgräns för uppladdningar (endast för medarbetare & prenumeranter)"
 
 
 
 
 
38
 
39
- #: wp-user-avatar.php:902
40
  msgid "Allow users to edit avatars"
41
  msgstr "Tillåt användare att redigera avatarer"
42
 
 
 
 
 
 
 
 
 
43
  #. Plugin Name of the plugin/theme
44
  msgid "WP User Avatar"
45
  msgstr "Visningsbild (avatar)"
1
  # Swedish (sv_SE) translation for WP User Avatar.
2
+ # Copyright (C) 2014 Bangbay Siboliban.
3
  # This file is distributed under the same license as the WP User Avatar package.
4
  #
5
  msgid ""
6
  msgstr ""
7
+ "Project-Id-Version: WP User Avatar 1.9.5\n"
8
  "Report-Msgid-Bugs-To: http://wordpress.org/plugins/wp-user-avatar/\n"
9
+ "PO-Revision-Date: 2014-04-24 00:00-0000\n"
10
  "Language: sv_SE\n"
11
  "Last-Translator: Mattias Tengblad <mst@eyesx.com>\n"
12
  "Language-Team: WordPress Sverige <info@wpsv.se>\n"
14
  "Content-Type: text/plain; charset=UTF-8\n"
15
  "Content-Transfer-Encoding: 8bit\n"
16
 
17
+ #: includes/class-wp-user-avatar-admin.php:209
18
+ msgid "Donate"
19
+ msgstr "Donera"
 
20
 
21
+ #: includes/wpua-functions.php:175
22
+ msgid "Do you like WP User Avatar?"
23
+ msgstr "Är du nöjd med Visningsbild (avatar)?"
24
+
25
+ #: includes/wpua-functions.php:175
26
+ msgid "Make a donation."
27
+ msgstr "Donera"
28
+
29
+ #: includes/wpua-options-page.php:80
30
  msgid "Add avatar button to Visual Editor"
31
  msgstr "Lägg till knapp för avatarer i den visuella redigeraren"
32
 
33
+ #: includes/wpua-options-page.php:86
34
  msgid "Allow Contributors & Subscribers to upload avatars"
35
  msgstr "Tillåt medarbetare & prenumeranter att ladda upp avatarer"
36
 
37
+ #: includes/wpua-options-page.php:92
38
  msgid "Disable Gravatar and use only local avatars"
39
  msgstr "Inaktivera Gravatar och använd endast lokala avatarer"
40
 
41
+ #: includes/wpua-options-page.php:113
42
+ #: includes/wpua-options-page.php:118
43
+ msgid "Upload Size Limit"
44
+ msgstr "Storleksgräns för uppladdningar"
45
+
46
+ #: includes/wpua-options-page.php:113
47
+ #: includes/wpua-options-page.php:118
48
+ msgid "(only for Contributors & Subscribers)"
49
+ msgstr "(endast för medarbetare & prenumeranter)"
50
 
51
+ #: includes/wpua-options-page.php:128
52
  msgid "Allow users to edit avatars"
53
  msgstr "Tillåt användare att redigera avatarer"
54
 
55
+ #: includes/wpua-options-page.php:134
56
+ msgid "Resize avatars on upload"
57
+ msgstr "Ändra storlek på avatarer på uppladdning"
58
+
59
+ #: includes/wpua-options-page.php:144
60
+ msgid "Crop avatars to exact dimensions"
61
+ msgstr "Beskär avatarer till exakta dimensioner"
62
+
63
  #. Plugin Name of the plugin/theme
64
  msgid "WP User Avatar"
65
  msgstr "Visningsbild (avatar)"
readme.txt CHANGED
@@ -2,10 +2,10 @@
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.5
7
- Tested up to: 3.7-alpha-24927
8
- Stable tag: 1.5.4
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -13,26 +13,31 @@ Use any image from your WordPress Media Library as a custom user avatar. Add you
13
 
14
  == Description ==
15
 
16
- WordPress currently only allows you to use custom avatars that are uploaded through [Gravatar](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 WP User Avatar settings.
21
  * Show the user's [Gravatar](http://gravatar.com/) avatar or Default Avatar if the user doesn't have a WP User Avatar image.
22
  * Disable [Gravatar](http://gravatar.com/) avatars and use only local avatars.
23
- * Use the <code>[avatar]</code> shortcode in your posts. The shortcode will work with any theme, whether it has avatar support or not.
 
24
  * Allow Contributors and Subscribers to upload their own avatars.
25
- * Limit upload file size for Contributors and Subscribers.
 
 
26
 
27
  == Installation ==
28
 
 
 
29
  1. Download, install, and activate the WP User Avatar plugin.
30
  2. On your profile edit page, click "Edit Image".
31
  3. Choose an image, then click "Select Image".
32
  4. Click "Update Profile".
33
  5. Upload your own Default Avatar in your WP User Avatar settings (optional). You can also allow Contributors & Subscribers to upload avatars and disable Gravatar.
34
  6. Choose a theme that has avatar support. In your theme, manually replace <code>get_avatar</code> with <code>get_wp_user_avatar</code> or leave <code>get_avatar</code> as-is. [Read about the differences here](http://wordpress.org/extend/plugins/wp-user-avatar/faq/).
35
- 7. You can also use the <code>[avatar]</code> shortcode in your posts. The shortcode will work with any theme, whether it has avatar support or not.
36
 
37
  **Example Usage**
38
 
@@ -90,11 +95,21 @@ For comments, you must specify the $comment variable.
90
 
91
  **Other Available Functions**
92
 
 
 
 
 
93
  = [avatar] shortcode =
94
 
95
  You can use the <code>[avatar]</code> shortcode in your posts. It will detect the author of the post or you can specify an author by username. You can specify a size, alignment, and link, but they are optional. For links, you can link to the original image file, attachment page, or a custom URL.
96
 
97
- `[avatar user="admin" size="medium" align="left" link="file"]`
 
 
 
 
 
 
98
 
99
  = get_wp_user_avatar_src =
100
 
@@ -118,6 +133,8 @@ Returns true if the user has a WP User Avatar image. You must specify the user I
118
 
119
  == Frequently Asked Questions ==
120
 
 
 
121
  = How do I use WP User Avatar? =
122
 
123
  First, choose a theme that has avatar support. In your theme, you have a choice of manually replacing <code>get_avatar</code> with <code>get_wp_user_avatar</code>, or leaving <code>get_avatar</code> as-is. Here are the differences:
@@ -126,9 +143,10 @@ First, choose a theme that has avatar support. In your theme, you have a choice
126
 
127
  1. Allows you to use the values "original", "large", "medium", or "thumbnail" for your avatar size.
128
  2. Doesn't add a fixed width and height to the image if you use the aforementioned values. This will give you more flexibility to resize the image with CSS.
129
- 3. Optionally adds CSS classes "alignleft", "alignright", or "aligncenter" to position your avatar.
130
- 4. Shows nothing if the user has no WP User Avatar image.
131
- 5. Shows the user's [Gravatar](http://gravatar.com/) avatar or Default Avatar only if "Show Avatars" is enabled in your WP User Avatar settings.
 
132
 
133
  = get_avatar =
134
 
@@ -143,17 +161,9 @@ First, choose a theme that has avatar support. In your theme, you have a choice
143
  = Can I create a custom Default Avatar? =
144
  In your WP User Avatar settings, you can upload your own Default Avatar.
145
 
146
- = Can I insert WP User Avatar directly into a post? =
147
-
148
- You can use the <code>[avatar]</code> shortcode in your posts. It will detect the author of the post or you can specify an author by username. You can specify a size, alignment, and link, but they are optional. For links, you can link to the original image file, attachment page, or a custom URL.
149
-
150
- `[avatar user="admin" size="96" align="left" link="file"]`
151
-
152
- Outputs:
153
 
154
- `<a href="{fileURL}" class="wp-user-avatar-link wp-user-avatar-file">
155
- <img src="{imageURL}" width="96" height="96" class="wp-user-avatar wp-user-avatar-96 alignleft" />
156
- </a>`
157
 
158
  = Can Contributors or Subscribers choose their own WP User Avatar image? =
159
  Yes, if you enable "Allow Contributors & Subscribers to upload avatars" in the WP User Avatar settings. These users will see a slightly different interface because they are allowed only one image upload.
@@ -162,14 +172,14 @@ Yes, if you enable "Allow Contributors & Subscribers to upload avatars" in the W
162
 
163
  Yes, for registered users. Non-registered comment authors will show their [Gravatar](http://gravatar.com/) avatars or Default Avatar.
164
 
165
- = Can I disable all Gravatar avatars? =
166
-
167
- In your WP User Avatar settings, you can select "Disable Gravatar — Use only local avatars" to disable all [Gravatar](http://gravatar.com/) avatars on your site and replace them with your Default Avatar. This will affect your registered users and non-registered comment authors.
168
-
169
  = Will WP User Avatar work with bbPress? =
170
 
171
  Yes!
172
 
 
 
 
 
173
  = Will WP User Avatar work with WordPress Multisite? =
174
 
175
  Yes, however, each site has its own avatar settings. If you set a WP User Avatar image on one site, you have to set it again for different sites in your network.
@@ -178,6 +188,37 @@ Yes, however, each site has its own avatar settings. If you set a WP User Avatar
178
 
179
  For Administrators, WP User Avatar adds a column with avatar thumbnails to your Users list table. If "Show Avatars" is enabled in your WP User Avatar settings, you will see avatars to the left of each username instead of in a new column.
180
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
  = What CSS can I use with WP User Avatar? =
182
 
183
  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:
@@ -206,7 +247,7 @@ If you use the <code>[avatar]</code> shortcode, WP User Avatar will add the CSS
206
  * Attachment: wp-user-avatar-attachment
207
  * Custom URL: wp-user-avatar-custom
208
 
209
- `[avatar user="admin" size="96" align="left" link="attachment"]`
210
 
211
  Outputs:
212
 
@@ -219,19 +260,264 @@ Outputs:
219
  * <code>has_wp_user_avatar</code>: checks if the user has a WP User Avatar image
220
  * [See example usage here](http://wordpress.org/extend/plugins/wp-user-avatar/installation/)
221
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222
  == Screenshots ==
223
 
224
  1. WP User Avatar admin settings.
225
  2. WP User Avatar lets you upload your own Default Avatar.
226
  3. WP User Avatar adds a field to your profile edit page.
227
  4. After you've chosen a WP User Avatar image, you will see the option to remove it.
228
- 5. WP User Avatar adds a button to insert the [avatar] shortcode in the Visual Editor.
229
- 6. Options for the [avatar] shortcode.
230
 
231
  == Changelog ==
232
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
  = 1.5.4 =
234
- * Add: Option to enable avatar editing privilege for Subscribers
235
  * Add: Swedish translation
236
  * Update: Move inline JavaScript to wp-user-avatar.js and wp-user-avatar-admin.js
237
  * Update: Load JavaScript in footer
@@ -263,7 +549,7 @@ Outputs:
263
  * Bug Fix: Use wp_die for errors
264
 
265
  = 1.4 =
266
- * Add: Uploader for Subscribers and Contributors
267
  * Add: Media states for avatar images
268
  * Add: Plugin admin settings
269
  * Update: Change support only to WP 3.4+
@@ -323,7 +609,7 @@ Outputs:
323
  = 1.2 =
324
  * Add: Default Avatar setting
325
 
326
- = 1.1.7 =
327
  * Bug Fix: Change update_usermeta to update_user_meta
328
 
329
  = 1.1.6 =
@@ -367,6 +653,10 @@ Outputs:
367
 
368
  == Upgrade Notice ==
369
 
 
 
 
 
370
  = 1.5.3 =
371
  * Notice: WP User Avatar 1.5.3 only supports WordPress 3.5 and above. If you are using an older version of WordPress, please upgrade your version of WordPress first.
372
 
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, widget
6
+ Requires at least: 3.6
7
+ Tested up to: 3.9
8
+ Stable tag: 1.9.5
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
13
 
14
  == Description ==
15
 
16
+ WordPress currently only allows you to use custom avatars that are uploaded through [Gravatar](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 WP User Avatar settings.
21
  * Show the user's [Gravatar](http://gravatar.com/) avatar or Default Avatar if the user doesn't have a WP User Avatar image.
22
  * Disable [Gravatar](http://gravatar.com/) avatars and use only local avatars.
23
+ * Use the <code>[avatar_upload]</code> shortcode to add a standalone uploader to a front page or widget. This uploader is only visible to logged-in users.
24
+ * Use the <code>[avatar]</code> shortcode in your posts. These shortcodes will work with any theme, whether it has avatar support or not.
25
  * Allow Contributors and Subscribers to upload their own avatars.
26
+ * Limit upload file size and image dimensions for Contributors and Subscribers.
27
+
28
+ Visit [WP User Avatar](http://wpuseravatar.com/) for more information and documentation.
29
 
30
  == Installation ==
31
 
32
+ Visit [WP User Avatar](http://wpuseravatar.com/) for more information and documentation.
33
+
34
  1. Download, install, and activate the WP User Avatar plugin.
35
  2. On your profile edit page, click "Edit Image".
36
  3. Choose an image, then click "Select Image".
37
  4. Click "Update Profile".
38
  5. Upload your own Default Avatar in your WP User Avatar settings (optional). You can also allow Contributors & Subscribers to upload avatars and disable Gravatar.
39
  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/).
40
+ 7. You can also use the <code>[avatar_upload]</code> and <code>[avatar]</code> shortcodes in your posts. These shortcodes will work with any theme, whether it has avatar support or not.
41
 
42
  **Example Usage**
43
 
95
 
96
  **Other Available Functions**
97
 
98
+ = [avatar_upload] shortcode =
99
+
100
+ You can use the <code>[avatar_upload]</code> shortcode to add a standalone uploader to a front page or widget. This uploader is only visible to logged-in users. If you want to integrate the uploader into a profile edit page, see [Other Notes](http://wordpress.org/plugins/wp-user-avatar/other_notes/).
101
+
102
  = [avatar] shortcode =
103
 
104
  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.
105
 
106
+ `[avatar user="admin" size="medium" align="left" link="file" /]`
107
+
108
+ You can also add a caption to the shortcode:
109
+
110
+ `[avatar user="admin" size="medium" align="left" link="file"]Photo Credit: Your Name[/avatar]`
111
+
112
+ **Note:** If you are using one shortcode without a caption and another shortcode with a caption on the same page, you must close the caption-less shortcode with a forward slash before the closing bracket: <code>[avatar /]</code> instead of <code>[avatar]</code>
113
 
114
  = get_wp_user_avatar_src =
115
 
133
 
134
  == Frequently Asked Questions ==
135
 
136
+ Visit [WP User Avatar](http://wpuseravatar.com/) for more information and documentation.
137
+
138
  = How do I use WP User Avatar? =
139
 
140
  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:
143
 
144
  1. Allows you to use the values "original", "large", "medium", or "thumbnail" for your avatar size.
145
  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.
146
+ 3. Allows you to use custom image sizes registered with [<code>add_image_size</code>](http://codex.wordpress.org/Function_Reference/add_image_size) (fixed width and height are added to the image).
147
+ 4. Optionally adds CSS classes "alignleft", "alignright", or "aligncenter" to position your avatar.
148
+ 5. Shows nothing if the user has no WP User Avatar image.
149
+ 6. Shows the user's [Gravatar](http://gravatar.com/) avatar or Default Avatar only if "Show Avatars" is enabled in your WP User Avatar settings.
150
 
151
  = get_avatar =
152
 
161
  = Can I create a custom Default Avatar? =
162
  In your WP User Avatar settings, you can upload your own Default Avatar.
163
 
164
+ = Can I disable all Gravatar avatars? =
 
 
 
 
 
 
165
 
166
+ In your WP User Avatar settings, you can select "Disable Gravatar — Use only local avatars" to disable all [Gravatar](http://gravatar.com/) avatars on your site and replace them with your Default Avatar. This will affect your registered users and non-registered comment authors.
 
 
167
 
168
  = Can Contributors or Subscribers choose their own WP User Avatar image? =
169
  Yes, if you enable "Allow Contributors & Subscribers to upload avatars" in the WP User Avatar settings. These users will see a slightly different interface because they are allowed only one image upload.
172
 
173
  Yes, for registered users. Non-registered comment authors will show their [Gravatar](http://gravatar.com/) avatars or Default Avatar.
174
 
 
 
 
 
175
  = Will WP User Avatar work with bbPress? =
176
 
177
  Yes!
178
 
179
+ = Will WP User Avatar work with BuddyPress? =
180
+
181
+ No, BuddyPress has its own custom avatar functions and WP User Avatar will override only some of them. It's best to use BuddyPress without WP User Avatar.
182
+
183
  = Will WP User Avatar work with WordPress Multisite? =
184
 
185
  Yes, however, each site has its own avatar settings. If you set a WP User Avatar image on one site, you have to set it again for different sites in your network.
188
 
189
  For Administrators, WP User Avatar adds a column with avatar thumbnails to your Users list table. If "Show Avatars" is enabled in your WP User Avatar settings, you will see avatars to the left of each username instead of in a new column.
190
 
191
+ = Can I use the WP User Avatar uploader in a front page or widget? =
192
+
193
+ Yes, you can use the <code>[avatar_upload]</code> shortcode to put a standalone uploader in a front page or widget. This uploader is only visible to logged-in users. If you want to integrate the uploader into a profile edit page, see [Other Notes](http://wordpress.org/plugins/wp-user-avatar/other_notes/).
194
+
195
+ = Can I insert WP User Avatar directly into a post? =
196
+
197
+ 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.
198
+
199
+ `[avatar user="admin" size="96" align="left" link="file" /]`
200
+
201
+ Outputs:
202
+
203
+ `<a href="{fileURL}" class="wp-user-avatar-link wp-user-avatar-file">
204
+ <img src="{imageURL}" width="96" height="96" class="wp-user-avatar wp-user-avatar-96 alignleft" />
205
+ </a>`
206
+
207
+ If you have a caption, the output will be similar to how WordPress adds captions to other images.
208
+
209
+ `[avatar user="admin" size="96" align="left" link="file"]Photo Credit: Your Name[/avatar]`
210
+
211
+ Outputs:
212
+
213
+ `<div style="width: 106px" class="wp-caption alignleft">
214
+ <a href="{fileURL}" class="wp-user-avatar-link wp-user-avatar-file">
215
+ <img src="{imageURL}" width="96" height="96" class="wp-user-avatar wp-user-avatar-96" />
216
+ </a>
217
+ <p class="wp-caption-text">Photo Credit: Your Name</p>
218
+ </div>`
219
+
220
+ **Note:** If you are using one shortcode without a caption and another shortcode with a caption on the same page, you must close the caption-less shortcode with a forward slash before the closing bracket: <code>[avatar /]</code> instead of <code>[avatar]</code>
221
+
222
  = What CSS can I use with WP User Avatar? =
223
 
224
  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:
247
  * Attachment: wp-user-avatar-attachment
248
  * Custom URL: wp-user-avatar-custom
249
 
250
+ `[avatar user="admin" size="96" align="left" link="attachment" /]`
251
 
252
  Outputs:
253
 
260
  * <code>has_wp_user_avatar</code>: checks if the user has a WP User Avatar image
261
  * [See example usage here](http://wordpress.org/extend/plugins/wp-user-avatar/installation/)
262
 
263
+ = There's a call for donations in the WP User Avatar settings. How can I remove it? =
264
+ I've spent countless hours developing this plugin for free. If you're able to give a donation I'd appreciate it, but it's by no means a requirement. You can remove the message by adding this to the <code>functions.php</code> file of your theme:
265
+
266
+ `remove_action('wpua_donation_message', 'wpua_do_donation_message');`
267
+
268
+ == Advanced Settings ==
269
+
270
+ Visit [WP User Avatar](http://wpuseravatar.com/) for more information and documentation.
271
+
272
+ = Add WP User Avatar to your own profile edit page =
273
+
274
+ You can use the [avatar_upload] shortcode to add a standalone uploader to any page. It's best to use this uploader by itself and without other profile fields.
275
+
276
+ If you're building your own profile edit page with other fields, WP User Avatar is automatically added to the [show_user_profile](http://codex.wordpress.org/Plugin_API/Action_Reference/show_user_profile) and [edit_user_profile](http://codex.wordpress.org/Plugin_API/Action_Reference/show_user_profile) hooks. If you'd rather have WP User Avatar in its own section, you could add another hook:
277
+
278
+ `do_action('edit_user_avatar', $current_user);`
279
+
280
+ Then, to add WP User Avatar to that hook and remove it from the other hooks outside of the administration panel, you would add this code to the <code>functions.php</code> file of your theme:
281
+
282
+ `function my_avatar_filter() {
283
+ // Remove from show_user_profile hook
284
+ remove_action('show_user_profile', array('wp_user_avatar', 'wpua_action_show_user_profile'));
285
+ remove_action('show_user_profile', array('wp_user_avatar', 'wpua_media_upload_scripts'));
286
+
287
+ // Remove from edit_user_profile hook
288
+ remove_action('edit_user_profile', array('wp_user_avatar', 'wpua_action_show_user_profile'));
289
+ remove_action('edit_user_profile', array('wp_user_avatar', 'wpua_media_upload_scripts'));
290
+
291
+ // Add to edit_user_avatar hook
292
+ add_action('edit_user_avatar', array('wp_user_avatar', 'wpua_action_show_user_profile'));
293
+ add_action('edit_user_avatar', array('wp_user_avatar', 'wpua_media_upload_scripts'));
294
+ }
295
+
296
+ // Loads only outside of administration panel
297
+ if(!is_admin()) {
298
+ add_action('init','my_avatar_filter');
299
+ }`
300
+
301
+ = HTML Wrapper =
302
+
303
+ You can change the HTML wrapper of the WP User Avatar section by using the functions <code>wpua_before_avatar</code> and <code>wpua_after_avatar</code>. By default, the avatar code is structured like this:
304
+
305
+ `<div class="wpua-edit-container">
306
+ <h3>Avatar</h3>
307
+ <input type="hidden" name="wp-user-avatar" id="wp-user-avatar" value="{attachmentID}" />
308
+ <p id="wpua-add-button">
309
+ <button type="button" class="button" id="wpua-add" name="wpua-add">Edit Image</button>
310
+ </p>
311
+ <p id="wpua-preview">
312
+ <img src="{imageURL}" alt="" />
313
+ Original Size
314
+ </p>
315
+ <p id="wpua-thumbnail">
316
+ <img src="{imageURL}" alt="" />
317
+ Thumbnail
318
+ </p>
319
+ <p id="wpua-remove-button">
320
+ <button type="button" class="button" id="wpua-remove" name="wpua-remove">Default Avatar</button>
321
+ </p>
322
+ <p id="wpua-undo-button">
323
+ <button type="button" class="button" id="wpua-undo" name="wpua-undo">Undo</button>
324
+ </p>
325
+ </div>`
326
+
327
+ To strip out the div container and h3 heading, you would add the following filters to the <code>functions.php</code> file in your theme:
328
+
329
+ `remove_action('wpua_before_avatar', 'wpua_do_before_avatar');
330
+ remove_action('wpua_after_avatar', 'wpua_do_after_avatar');`
331
+
332
+ To add your own wrapper, you could create something like this:
333
+
334
+ `function my_before_avatar() {
335
+ echo '<div id="my-avatar">';
336
+ }
337
+ add_action('wpua_before_avatar', 'my_before_avatar');
338
+
339
+ function my_after_avatar() {
340
+ echo '</div>';
341
+ }
342
+ add_action('wpua_after_avatar', 'my_after_avatar');`
343
+
344
+ This would output:
345
+
346
+ `<div id="my-avatar">
347
+ <input type="hidden" name="wp-user-avatar" id="wp-user-avatar" value="{attachmentID}" />
348
+ <p id="wpua-add-button">
349
+ <button type="button" class="button" id="wpua-add" name="wpua-add">Edit Image</button>
350
+ </p>
351
+ <p id="wpua-preview">
352
+ <img src="{imageURL}" alt="" />
353
+ <span class="description">Original Size</span>
354
+ </p>
355
+ <p id="wpua-thumbnail">
356
+ <img src="{imageURL}" alt="" />
357
+ <span class="description">Thumbnail</span>
358
+ </p>
359
+ <p id="wpua-remove-button">
360
+ <button type="button" class="button" id="wpua-remove" name="wpua-remove">Default Avatar</button>
361
+ </p>
362
+ <p id="wpua-undo-button">
363
+ <button type="button" class="button" id="wpua-undo" name="wpua-undo">Undo</button>
364
+ </p>
365
+ </div>`
366
+
367
  == Screenshots ==
368
 
369
  1. WP User Avatar admin settings.
370
  2. WP User Avatar lets you upload your own Default Avatar.
371
  3. WP User Avatar adds a field to your profile edit page.
372
  4. After you've chosen a WP User Avatar image, you will see the option to remove it.
 
 
373
 
374
  == Changelog ==
375
 
376
+ = 1.9.5 =
377
+ * Add: Start documentation of functions
378
+ * Bug Fix: [avatar_upload] permalink and redirect
379
+
380
+ = 1.9.4 =
381
+ * Add: Widget for [avatar_upload]
382
+ * Add: wpua_before_avatar_admin and wpua_after_avatar_admin for admin pages
383
+ * Bug Fix: Load functions class on plugins_loaded
384
+ * Update: Allow non-numeric WPUA value
385
+
386
+ = 1.9.3 =
387
+ * Bug Fix: Missing php
388
+
389
+ = 1.9.2 =
390
+ * Add: Setup class
391
+ * Bug Fix: Give wpua_attachment_is_image filter two variables
392
+ * Bug Fix: Return [avatar_upload] instead of echo
393
+ * Remove: Unneccessary filters
394
+ * Update: Allow upload to overwrite avatar for Contributors & Subscribers
395
+ * Update: Move Edit Image link for Contributors & Subscribers
396
+ * Update: Move text from localize script to data attribute
397
+ * Update: Shorten variable names
398
+ * Update: Wrap all classes in init
399
+
400
+ = 1.9.1 =
401
+ * Bug Fix: Double underscore for options page title
402
+ * Bug Fix: Remove TinyMCE language pack
403
+ * Bug Fix: Wrong variables in get_wp_user_avatar filter
404
+
405
+ = 1.9 =
406
+ * Add: Filters throughout plugin
407
+ * Bug Fix: Die messages
408
+ * Update: Move public functions to class
409
+
410
+ = 1.8.10 =
411
+ * Add: Search and screen option in Media Library view
412
+ * Bug Fix: Bulk delete in Media Library view
413
+ * Bug Fix: Hide captions if "Show Avatars" is off
414
+ * Bug Fix: Update avatar metadata on removal
415
+ * Update: Choose Image text
416
+ * Update: Show only images in Media Library modal
417
+ * Update: Show upload tab if no WP User Avatar image has been selected yet
418
+
419
+ = 1.8.9 =
420
+ * Bug Fix: Check for post object
421
+
422
+ = 1.8.8 =
423
+ * Bug Fix: Media upload scripts
424
+
425
+ = 1.8.7 =
426
+ * Bug Fix: Bad reference to wpua_is_author_or_above
427
+
428
+ = 1.8.6 =
429
+ * Bug Fix: Check for media upload scripts before setting post parent
430
+
431
+ = 1.8.5 =
432
+ * Add: Capability check in one function
433
+
434
+ = 1.8.4 =
435
+ * Bug Fix: Set avatar post parent to 0
436
+
437
+ = 1.8.3 =
438
+ * Bug Fix: Prevent attachment insert without image
439
+ * Update: Check for delete_posts capability instead of user role for Subscribers
440
+ * Update: Refactor and clean up
441
+
442
+ = 1.8.2 =
443
+ * Bug Fix: Edit avatar setting
444
+
445
+ = 1.8.1 =
446
+ * Bug Fix: Reattach scripts to profile action
447
+
448
+ = 1.8 =
449
+ * Add: Front page uploader
450
+ * Add: Media Library view of all avatars
451
+ * Bug Fix: Identify public static functions
452
+ * Update: Refactor code into separate classes
453
+ * Update: Translations
454
+
455
+ = 1.7.2 =
456
+ * Bug Fix: Files not committed properly in previous release
457
+
458
+ = 1.7.1 =
459
+ * Update: Error message handling for front pages
460
+
461
+ = 1.7 =
462
+ * Add: Caption for avatar
463
+ * Add: Polish translation
464
+ * Update: Error message handling
465
+
466
+ = 1.6.8 =
467
+ * Bug Fix: Shortcode without user
468
+
469
+ = 1.6.7 =
470
+ * Add: Undo button
471
+ * Bug Fix: Get original avatar
472
+
473
+ = 1.6.6 =
474
+ * Add: Donation message
475
+ * Bug Fix: Die page when image is too large
476
+ * Bug Fix: Resize images uploaded through plugin only
477
+ * Remove: Unused function
478
+ * Update: Refactor JavaScript
479
+
480
+ = 1.6.5 =
481
+ * Bug Fix: Use entire comment object instead of just e-mail address
482
+
483
+ = 1.6.4 =
484
+ * Bug Fix: Correct avatar not showing in widget
485
+ * Update: Check compatibility to 3.7.1
486
+
487
+ = 1.6.3 =
488
+ * Bug Fix: Checkbox value for "Crop avatars to exact dimensions"
489
+
490
+ = 1.6.2 =
491
+ * Bug Fix: Show Default Avatar if attachment doesn't exist
492
+ * Bug Fix: manage_users_custom_column not returning values
493
+
494
+ = 1.6.1 =
495
+ * Bug Fix: Profile not saving without an avatar for Contributors & Subscribers
496
+
497
+ = 1.6.0 =
498
+ * Add: Filters to change profile HTML structure
499
+ * Add: Recognition of sizes registered with add_image_size
500
+ * Add: Resize image options for Contributors & Subscribers
501
+ * Bug Fix: Rerrange CSS class names
502
+
503
+ = 1.5.8 =
504
+ * Bug Fix: Add function exists checks to prevent redeclare errors
505
+ * Bug Fix: Page die if file upload is too big
506
+ * Bug Fix: Upload file with submit
507
+
508
+ = 1.5.7 =
509
+ * Bug Fix: Separate out JavaScript for Contributors & Subscribers
510
+ * Bug Fix: Subscriber uploader not finding error type
511
+
512
+ = 1.5.6 =
513
+ * Update: Use cache for wpua_has_gravatar
514
+
515
+ = 1.5.5 =
516
+ * Bug Fix: Hide "Edit Image" button if Contributors & Subscribers can't edit avatar
517
+ * Bug Fix: Remove edit_posts capability if Subscribers can't edit avatar
518
+
519
  = 1.5.4 =
520
+ * Add: Option to enable avatar editing privilege for Contributors & Subscribers
521
  * Add: Swedish translation
522
  * Update: Move inline JavaScript to wp-user-avatar.js and wp-user-avatar-admin.js
523
  * Update: Load JavaScript in footer
549
  * Bug Fix: Use wp_die for errors
550
 
551
  = 1.4 =
552
+ * Add: Uploader for Contributors & Subscribers
553
  * Add: Media states for avatar images
554
  * Add: Plugin admin settings
555
  * Update: Change support only to WP 3.4+
609
  = 1.2 =
610
  * Add: Default Avatar setting
611
 
612
+ = 1.1.8 =
613
  * Bug Fix: Change update_usermeta to update_user_meta
614
 
615
  = 1.1.6 =
653
 
654
  == Upgrade Notice ==
655
 
656
+ = 1.8 =
657
+ * New Feature: Front page uploader
658
+ * New Feature: Media Library view of all avatars
659
+
660
  = 1.5.3 =
661
  * Notice: WP User Avatar 1.5.3 only supports WordPress 3.5 and above. If you are using an older version of WordPress, please upgrade your version of WordPress first.
662
 
uninstall.php CHANGED
@@ -1,31 +1,37 @@
1
  <?php
2
  /**
 
 
3
  * @package WP User Avatar
4
- * @version 1.5.4
5
  */
6
 
7
- // Remove user metadata and options on plugin delete
8
- if(!defined('WP_UNINSTALL_PLUGIN')){
9
- die(__('You are not allowed to call this page directly.'));
10
  }
11
 
12
  global $wpdb, $blog_id, $switched;
13
  $users = get_users();
 
14
  // Remove settings for all sites in multisite
15
- if(is_multisite()){
16
- $blogs = $wpdb->get_results("SELECT * FROM $wpdb->blogs");
17
- foreach($users as $user){
18
- foreach($blogs as $blog){
19
  delete_user_meta($user->ID, $wpdb->get_blog_prefix($blog->blog_id).'user_avatar');
20
  }
21
  }
22
- foreach($blogs as $blog){
23
  switch_to_blog($blog->blog_id);
24
  delete_option('avatar_default_wp_user_avatar');
25
  delete_option('wp_user_avatar_allow_upload');
26
  delete_option('wp_user_avatar_disable_gravatar');
27
  delete_option('wp_user_avatar_edit_avatar');
28
  delete_option('wp_user_avatar_load_scripts');
 
 
 
 
29
  delete_option('wp_user_avatar_tinymce');
30
  delete_option('wp_user_avatar_upload_size_limit');
31
  delete_option('wp_user_avatar_default_avatar_updated');
@@ -33,7 +39,7 @@ if(is_multisite()){
33
  delete_option('wp_user_avatar_users_updated');
34
  }
35
  } else {
36
- foreach($users as $user){
37
  delete_user_meta($user->ID, $wpdb->get_blog_prefix($blog_id).'user_avatar');
38
  }
39
  delete_option('avatar_default_wp_user_avatar');
@@ -41,14 +47,19 @@ if(is_multisite()){
41
  delete_option('wp_user_avatar_disable_gravatar');
42
  delete_option('wp_user_avatar_edit_avatar');
43
  delete_option('wp_user_avatar_load_scripts');
 
 
 
 
44
  delete_option('wp_user_avatar_tinymce');
45
  delete_option('wp_user_avatar_upload_size_limit');
46
  delete_option('wp_user_avatar_default_avatar_updated');
47
  delete_option('wp_user_avatar_media_updated');
48
  delete_option('wp_user_avatar_users_updated');
49
  }
 
50
  // Delete post meta
51
  delete_post_meta_by_key('_wp_attachment_wp_user_avatar');
 
52
  // Reset all default avatars to Mystery Man
53
  update_option('avatar_default', 'mystery');
54
- ?>
1
  <?php
2
  /**
3
+ * Remove user metadata and options on plugin delete.
4
+ *
5
  * @package WP User Avatar
6
+ * @version 1.9.5
7
  */
8
 
9
+ if(!defined('WP_UNINSTALL_PLUGIN')) {
10
+ die('You are not allowed to call this page directly.');
 
11
  }
12
 
13
  global $wpdb, $blog_id, $switched;
14
  $users = get_users();
15
+
16
  // Remove settings for all sites in multisite
17
+ if(is_multisite()) {
18
+ $blogs = wp_get_sites();
19
+ foreach($users as $user) {
20
+ foreach($blogs as $blog) {
21
  delete_user_meta($user->ID, $wpdb->get_blog_prefix($blog->blog_id).'user_avatar');
22
  }
23
  }
24
+ foreach($blogs as $blog) {
25
  switch_to_blog($blog->blog_id);
26
  delete_option('avatar_default_wp_user_avatar');
27
  delete_option('wp_user_avatar_allow_upload');
28
  delete_option('wp_user_avatar_disable_gravatar');
29
  delete_option('wp_user_avatar_edit_avatar');
30
  delete_option('wp_user_avatar_load_scripts');
31
+ delete_option('wp_user_avatar_resize_crop');
32
+ delete_option('wp_user_avatar_resize_h');
33
+ delete_option('wp_user_avatar_resize_upload');
34
+ delete_option('wp_user_avatar_resize_w');
35
  delete_option('wp_user_avatar_tinymce');
36
  delete_option('wp_user_avatar_upload_size_limit');
37
  delete_option('wp_user_avatar_default_avatar_updated');
39
  delete_option('wp_user_avatar_users_updated');
40
  }
41
  } else {
42
+ foreach($users as $user) {
43
  delete_user_meta($user->ID, $wpdb->get_blog_prefix($blog_id).'user_avatar');
44
  }
45
  delete_option('avatar_default_wp_user_avatar');
47
  delete_option('wp_user_avatar_disable_gravatar');
48
  delete_option('wp_user_avatar_edit_avatar');
49
  delete_option('wp_user_avatar_load_scripts');
50
+ delete_option('wp_user_avatar_resize_crop');
51
+ delete_option('wp_user_avatar_resize_h');
52
+ delete_option('wp_user_avatar_resize_upload');
53
+ delete_option('wp_user_avatar_resize_w');
54
  delete_option('wp_user_avatar_tinymce');
55
  delete_option('wp_user_avatar_upload_size_limit');
56
  delete_option('wp_user_avatar_default_avatar_updated');
57
  delete_option('wp_user_avatar_media_updated');
58
  delete_option('wp_user_avatar_users_updated');
59
  }
60
+
61
  // Delete post meta
62
  delete_post_meta_by_key('_wp_attachment_wp_user_avatar');
63
+
64
  // Reset all default avatars to Mystery Man
65
  update_option('avatar_default', 'mystery');
 
wp-user-avatar.php CHANGED
@@ -1,986 +1,79 @@
1
  <?php
2
  /**
3
  * @package WP User Avatar
4
- * @version 1.5.4
5
  */
 
6
  /*
7
  Plugin Name: WP User Avatar
8
  Plugin URI: http://wordpress.org/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
  Author: Bangbay Siboliban
11
  Author URI: http://siboliban.org/
12
- Version: 1.5.4
13
  Text Domain: wp-user-avatar
14
  Domain Path: /lang/
15
  */
16
 
17
- if(!defined('ABSPATH')){
18
- die(__('You are not allowed to call this page directly.'));
19
- @header('Content-Type:'.get_option('html_type').';charset='.get_option('blog_charset'));
20
- }
21
-
22
- // Define paths and variables
23
- define('WPUA_VERSION', ' 1.5.4');
24
- define('WPUA_FOLDER', basename(dirname(__FILE__)));
25
- define('WPUA_ABSPATH', trailingslashit(str_replace('\\', '/', WP_PLUGIN_DIR.'/'.WPUA_FOLDER)));
26
- define('WPUA_URLPATH', trailingslashit(plugins_url(WPUA_FOLDER)));
27
-
28
- // Define global variables
29
- $avatar_default = get_option('avatar_default');
30
- $show_avatars = get_option('show_avatars');
31
- $wpua_allow_upload = get_option('wp_user_avatar_allow_upload');
32
- $wpua_avatar_default = get_option('avatar_default_wp_user_avatar');
33
- $wpua_disable_gravatar = get_option('wp_user_avatar_disable_gravatar');
34
- $wpua_edit_avatar = get_option('wp_user_avatar_edit_avatar');
35
- $wpua_tinymce = get_option('wp_user_avatar_tinymce');
36
- $mustache_original = WPUA_URLPATH.'images/wp-user-avatar.png';
37
- $mustache_medium = WPUA_URLPATH.'images/wp-user-avatar-300x300.png';
38
- $mustache_thumbnail = WPUA_URLPATH.'images/wp-user-avatar-150x150.png';
39
- $mustache_avatar = WPUA_URLPATH.'images/wp-user-avatar-96x96.png';
40
- $mustache_admin = WPUA_URLPATH.'images/wp-user-avatar-32x32.png';
41
- $ssl = is_ssl() ? 's' : "";
42
-
43
- // Check for updates
44
- $wpua_default_avatar_updated = get_option('wp_user_avatar_default_avatar_updated');
45
- $wpua_users_updated = get_option('wp_user_avatar_users_updated');
46
- $wpua_media_updated = get_option('wp_user_avatar_media_updated');
47
-
48
- // Max upload size
49
- if(!function_exists('wp_max_upload_size')){
50
- require_once(ABSPATH.'wp-admin/includes/template.php');
51
  }
52
 
53
- // Server upload size limit
54
- $upload_size_limit = wp_max_upload_size();
55
- // Convert to KB
56
- if($upload_size_limit > 1024){
57
- $upload_size_limit /= 1024;
58
- }
59
- $upload_size_limit_with_units = (int) $upload_size_limit.'KB';
60
-
61
- // User upload size limit
62
- $wpua_user_upload_size_limit = get_option('wp_user_avatar_upload_size_limit');
63
- if($wpua_user_upload_size_limit == 0 || $wpua_user_upload_size_limit > wp_max_upload_size()){
64
- $wpua_user_upload_size_limit = wp_max_upload_size();
65
- }
66
- // Value in bytes
67
- $wpua_upload_size_limit = $wpua_user_upload_size_limit;
68
- // Convert to KB
69
- if($wpua_user_upload_size_limit > 1024){
70
- $wpua_user_upload_size_limit /= 1024;
71
- }
72
- $wpua_upload_size_limit_with_units = (int) $wpua_user_upload_size_limit.'KB';
73
-
74
- // Load add-ons
75
- if((bool) $wpua_tinymce == 1){
76
- include_once(WPUA_ABSPATH.'includes/tinymce.php');
77
- }
78
-
79
- // Load translations
80
- load_plugin_textdomain('wp-user-avatar', "", WPUA_FOLDER.'/lang');
81
-
82
- // Initialize default settings
83
- register_activation_hook(WPUA_ABSPATH.'wp-user-avatar.php', 'wpua_options');
84
-
85
- // Remove subscribers edit_posts capability
86
- register_deactivation_hook(WPUA_ABSPATH.'wp-user-avatar.php', 'wpua_deactivate');
87
-
88
- // Settings saved to wp_options
89
- function wpua_options(){
90
- add_option('avatar_default_wp_user_avatar', "");
91
- add_option('wp_user_avatar_allow_upload', '0');
92
- add_option('wp_user_avatar_disable_gravatar', '0');
93
- add_option('wp_user_avatar_edit_avatar', '1');
94
- add_option('wp_user_avatar_tinymce', '1');
95
- add_option('wp_user_avatar_upload_size_limit', '0');
96
- }
97
- add_action('admin_init', 'wpua_options');
98
-
99
- // Update default avatar to new format
100
- if(empty($wpua_default_avatar_updated)){
101
- function wpua_default_avatar(){
102
- global $avatar_default, $mustache_original, $wpua_avatar_default;
103
- // If default avatar is the old mustache URL, update it
104
- if($avatar_default == $mustache_original){
105
- update_option('avatar_default', 'wp_user_avatar');
106
- }
107
- // If user had an image URL as the default avatar, replace with ID instead
108
- if(!empty($wpua_avatar_default)){
109
- $wpua_avatar_default_image = wp_get_attachment_image_src($wpua_avatar_default, 'medium');
110
- if($avatar_default == $wpua_avatar_default_image[0]){
111
- update_option('avatar_default', 'wp_user_avatar');
112
- }
113
- }
114
- update_option('wp_user_avatar_default_avatar_updated', '1');
115
- }
116
- add_action('admin_init', 'wpua_default_avatar');
117
- }
118
-
119
- // Rename user meta to match database settings
120
- if(empty($wpua_users_updated)){
121
- function wpua_user_meta(){
122
- global $blog_id, $wpdb;
123
- $wpua_metakey = $wpdb->get_blog_prefix($blog_id).'user_avatar';
124
- // If database tables start with something other than wp_
125
- if($wpua_metakey != 'wp_user_avatar'){
126
- $users = get_users();
127
- // Move current user metakeys to new metakeys
128
- foreach($users as $user){
129
- $wpua = get_user_meta($user->ID, 'wp_user_avatar', true);
130
- if(!empty($wpua)){
131
- update_user_meta($user->ID, $wpua_metakey, $wpua);
132
- delete_user_meta($user->ID, 'wp_user_avatar');
133
- }
134
- }
135
- }
136
- update_option('wp_user_avatar_users_updated', '1');
137
- }
138
- add_action('admin_init', 'wpua_user_meta');
139
- }
140
-
141
- // Add media state to existing avatars
142
- if(empty($wpua_media_updated)){
143
- function wpua_media_state(){
144
- global $blog_id, $wpdb;
145
- // Find all users with WPUA
146
- $wpua_metakey = $wpdb->get_blog_prefix($blog_id).'user_avatar';
147
- $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, ""));
148
- foreach($wpuas as $usermeta){
149
- add_post_meta($usermeta->meta_value, '_wp_attachment_wp_user_avatar', $usermeta->user_id);
150
- }
151
- update_option('wp_user_avatar_media_updated', '1');
152
- }
153
- add_action('admin_init', 'wpua_media_state');
154
- }
155
-
156
- // Settings for Subscribers
157
- if((bool) $wpua_allow_upload == 1){
158
- // Allow multipart data in form
159
- function wpua_add_edit_form_multipart_encoding(){
160
- echo ' enctype="multipart/form-data"';
161
- }
162
- add_action('user_edit_form_tag', 'wpua_add_edit_form_multipart_encoding');
163
-
164
- // Check user role
165
- function check_user_role($role, $user_id=null){
166
- global $current_user;
167
- $user = is_numeric($user_id) ? get_userdata($user_id) : $current_user->ID;
168
- if(empty($user)){
169
- return false;
170
- }
171
- return in_array($role, (array) $user->roles);
172
- }
173
-
174
- // Remove menu items
175
- function wpua_subscriber_remove_menu_pages(){
176
- global $current_user;
177
- if(check_user_role('subscriber', $current_user->ID)){
178
- remove_menu_page('edit.php');
179
- remove_menu_page('edit-comments.php');
180
- remove_menu_page('tools.php');
181
- }
182
- }
183
- add_action('admin_menu', 'wpua_subscriber_remove_menu_pages');
184
-
185
- // Remove menu bar items
186
- function wpua_subscriber_remove_menu_bar_items(){
187
- global $current_user, $wp_admin_bar;
188
- if(check_user_role('subscriber', $current_user->ID)){
189
- $wp_admin_bar->remove_menu('comments');
190
- $wp_admin_bar->remove_menu('new-content');
191
- }
192
- }
193
- add_action('wp_before_admin_bar_render', 'wpua_subscriber_remove_menu_bar_items');
194
-
195
- // Remove dashboard items
196
- function wpua_subscriber_remove_dashboard_widgets(){
197
- global $current_user;
198
- if(check_user_role('subscriber', $current_user->ID)){
199
- remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
200
- remove_meta_box('dashboard_recent_drafts', 'dashboard', 'side');
201
- remove_meta_box('dashboard_right_now', 'dashboard', 'normal');
202
- }
203
- }
204
- add_action('wp_dashboard_setup', 'wpua_subscriber_remove_dashboard_widgets');
205
-
206
- // Restrict access to pages
207
- function wpua_subscriber_offlimits(){
208
- global $current_user, $pagenow, $wpua_edit_avatar;
209
- if((bool) $wpua_edit_avatar == 1){
210
- $offlimits = array('edit.php', 'edit-comments.php', 'post-new.php', 'tools.php');
211
- } else {
212
- $offlimits = array('edit.php', 'edit-comments.php', 'post.php', 'post-new.php', 'tools.php');
213
- }
214
- if(check_user_role('subscriber', $current_user->ID)){
215
- if(in_array($pagenow, $offlimits)){
216
- do_action('admin_page_access_denied');
217
- wp_die(__('You do not have sufficient permissions to access this page.'));
218
- }
219
- }
220
- }
221
- add_action('admin_init', 'wpua_subscriber_offlimits');
222
- }
223
-
224
- if((bool) $wpua_allow_upload == 1 && (bool) $wpua_edit_avatar == 1){
225
- // Give subscribers edit_posts capability
226
- function wpua_subscriber_add_cap(){
227
- global $blog_id, $wpdb;
228
- $wp_user_roles = $wpdb->get_blog_prefix($blog_id).'user_roles';
229
- $user_roles = get_option($wp_user_roles);
230
- $user_roles['subscriber']['capabilities']['edit_posts'] = true;
231
- update_option($wp_user_roles, $user_roles);
232
  }
233
- add_action('admin_init', 'wpua_subscriber_add_cap');
234
- }
235
-
236
- // Remove subscribers edit_posts capability
237
- function wpua_subscriber_remove_cap(){
238
- global $blog_id, $wpdb;
239
- $wp_user_roles = $wpdb->get_blog_prefix($blog_id).'user_roles';
240
- $user_roles = get_option($wp_user_roles);
241
- unset($user_roles['subscriber']['capabilities']['edit_posts']);
242
- update_option($wp_user_roles, $user_roles);
243
- }
244
-
245
- // On deactivation
246
- function wpua_deactivate(){
247
- // Remove subscribers edit_posts capability
248
- wpua_subscriber_remove_cap();
249
- // Reset all default avatar to Mystery Man
250
- update_option('avatar_default', 'mystery');
251
  }
252
 
253
- // WP User Avatar
254
- if(!class_exists('wp_user_avatar')){
255
- class wp_user_avatar{
256
- function wp_user_avatar(){
257
- global $current_screen, $current_user, $pagenow, $show_avatars, $wpua_allow_upload, $wpua_upload_size_limit;
258
- // Add WPUA to profile
259
- if(current_user_can('upload_files') || ((bool) $wpua_allow_upload == 1 && is_user_logged_in())){
260
- // For themes that use this function
261
- if(!function_exists('get_current_screen')){
262
- require_once(ABSPATH.'wp-admin/includes/screen.php');
263
- }
264
- // Profile functions and scripts
265
- add_action('show_user_profile', array('wp_user_avatar', 'wpua_action_show_user_profile'));
266
- add_action('edit_user_profile', array($this, 'wpua_action_show_user_profile'));
267
- add_action('personal_options_update', array($this, 'wpua_action_process_option_update'));
268
- add_action('edit_user_profile_update', array($this, 'wpua_action_process_option_update'));
269
- add_action('show_user_profile', array($this, 'wpua_media_upload_scripts'));
270
- add_action('edit_user_profile', array($this, 'wpua_media_upload_scripts'));
271
- // Admin scripts
272
- if($pagenow == 'options-discussion.php' || ($pagenow == 'options-general.php' && isset($_GET['page']) && $_GET['page'] == 'wp-user-avatar')){
273
- add_action('admin_enqueue_scripts', array($this, 'wpua_media_upload_scripts'));
274
- }
275
- // Prefilter upload size
276
- if(!current_user_can('upload_files')){
277
- add_filter('wp_handle_upload_prefilter', array($this, 'wpua_handle_upload_prefilter'), 10, 1);
278
- }
279
- // Admin menu settings
280
- add_action('admin_menu', 'wpua_admin');
281
- add_filter('plugin_action_links', array($this, 'wpua_plugin_settings_links'), 10, 2);
282
- // Hide column in Users table if default avatars are enabled
283
- if((bool) $show_avatars == 0 && is_admin()){
284
- add_filter('manage_users_columns', array($this, 'wpua_add_column'), 10, 1);
285
- add_filter('manage_users_custom_column', array($this, 'wpua_show_column'), 10, 3);
286
- }
287
- }
288
- }
289
-
290
- // Add to edit user profile
291
- function wpua_action_show_user_profile($user){
292
- global $blog_id, $current_user, $post, $show_avatars, $wpdb, $wpua_allow_upload, $wpua_edit_avatar, $wpua_upload_size_limit_with_units;
293
- // Get WPUA attachment ID
294
- $wpua = get_user_meta($user->ID, $wpdb->get_blog_prefix($blog_id).'user_avatar', true);
295
- // Show remove button if WPUA is set
296
- $hide_remove = !has_wp_user_avatar($user->ID) ? ' wpua-hide' : "";
297
- // If avatars are enabled, get original avatar image or show blank
298
- $avatar_medium_src = (bool) $show_avatars == 1 ? wpua_get_avatar_original($user->user_email, 96) : includes_url().'images/blank.gif';
299
- // Check if user has wp_user_avatar, if not show image from above
300
- $avatar_medium = has_wp_user_avatar($user->ID) ? get_wp_user_avatar_src($user->ID, 'medium') : $avatar_medium_src;
301
- // Check if user has wp_user_avatar, if not show image from above
302
- $avatar_thumbnail = has_wp_user_avatar($user->ID) ? get_wp_user_avatar_src($user->ID, 96) : $avatar_medium_src;
303
- // Change text on message based on current user
304
- $profile = ($current_user->ID == $user->ID) ? '&ldquo;'.__('Update Profile').'&rdquo;' : '&ldquo;'.__('Update User').'&rdquo;';
305
- ?>
306
- <?php if(class_exists('bbPress') && bbp_is_edit()) : // Add to bbPress profile with same style ?>
307
- <h2 class="entry-title"><?php _e('Avatar'); ?></h2>
308
- <fieldset class="bbp-form">
309
- <legend><?php _e('Image'); ?></legend>
310
- <?php else : // Add to profile with admin style ?>
311
- <h3><?php _e('Avatar') ?></h3>
312
- <table class="form-table">
313
- <tr>
314
- <th><label for="wp_user_avatar"><?php _e('Image'); ?></label></th>
315
- <td>
316
- <?php endif; ?>
317
- <input type="hidden" name="wp-user-avatar" id="wp-user-avatar" value="<?php echo $wpua; ?>" />
318
- <?php if(current_user_can('upload_files')) : // Button to launch Media uploader ?>
319
- <p><button type="button" class="button" id="wpua-add" name="wpua-add"><?php _e('Edit Image'); ?></button></p>
320
- <?php elseif(!current_user_can('upload_files') && !has_wp_user_avatar($current_user->ID)) : // Upload button ?>
321
- <input name="wp-user-avatar-file" id="wpua-file" type="file" />
322
- <button type="submit" class="button" id="upload-wp-user-avatar" name="upload-wp-user-avatar" value="<?php _e('Upload'); ?>"><?php _e('Upload'); ?></button>
323
- <p>
324
- <?php printf(__('Maximum upload file size: %d%s.'), esc_html($wpua_upload_size_limit_with_units), esc_html('KB')); ?>
325
- <br />
326
- <?php _e('Allowed Files'); ?>: <?php _e('<code>jpg jpeg png gif</code>'); ?>
327
- </p>
328
- <?php elseif((bool) $wpua_edit_avatar == 1 && !current_user_can('upload_files') && has_wp_user_avatar($current_user->ID) && wpua_author($wpua, $current_user->ID)) : // Edit button ?>
329
- <?php $edit_attachment_link = add_query_arg(array('post' => $wpua, 'action' => 'edit'), admin_url('post.php')); ?>
330
- <p><button type="button" class="button" id="wpua-edit" name="wpua-edit" onclick="window.open('<?php echo $edit_attachment_link; ?>', '_self');"><?php _e('Edit Image'); ?></button></p>
331
- <?php endif; ?>
332
- <p id="wpua-preview">
333
- <img src="<?php echo $avatar_medium; ?>" alt="" />
334
- <?php _e('Original Size'); ?>
335
- </p>
336
- <p id="wpua-thumbnail">
337
- <img src="<?php echo $avatar_thumbnail; ?>" alt="" />
338
- <?php _e('Thumbnail'); ?>
339
- </p>
340
- <p><button type="button" class="button<?php echo $hide_remove; ?>" id="wpua-remove" name="wpua-remove"><?php _e('Remove'); ?></button></p>
341
- <p id="wpua-message"><?php printf(__('Click %s to save your changes', 'wp-user-avatar'), $profile); ?></p>
342
- <?php if(class_exists('bbPress') && bbp_is_edit()) : // Add to bbPress profile with same style ?>
343
- </fieldset>
344
- <?php else : // Add to profile with admin style ?>
345
- </td>
346
- </tr>
347
- </table>
348
- <?php endif; ?>
349
- <?php
350
- }
351
-
352
- // Set upload size limit for users without upload_files capability
353
- function wpua_handle_upload_prefilter($file){
354
- global $wpua_upload_size_limit;
355
- $size = $file['size'];
356
- if($size > $wpua_upload_size_limit){
357
- $file['error'] = __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.');
358
- }
359
- return $file;
360
- }
361
-
362
- // Update user meta
363
- function wpua_action_process_option_update($user_id){
364
- global $blog_id, $wpdb;
365
- // Check if user has upload_files capability
366
- if(current_user_can('upload_files')){
367
- $wpua_id = isset($_POST['wp-user-avatar']) ? intval($_POST['wp-user-avatar']) : "";
368
- $wpdb->query($wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %d", '_wp_attachment_wp_user_avatar', $user_id));
369
- add_post_meta($wpua_id, '_wp_attachment_wp_user_avatar', $user_id);
370
- update_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', $wpua_id);
371
- } else {
372
- if(isset($_POST['wp-user-avatar']) && empty($_POST['wp-user-avatar'])){
373
- // Uploads by user
374
- $attachments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE post_author = %d AND post_type = %s", $user_id, 'attachment'));
375
- foreach($attachments as $attachment){
376
- // Delete attachment if not used by another user
377
- if(!wpua_image($attachment->ID, $user_id)){
378
- wp_delete_post($attachment->ID);
379
- }
380
- }
381
- update_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', "");
382
- }
383
- // Create attachment from upload
384
- if(isset($_POST['upload-wp-user-avatar']) && $_POST['upload-wp-user-avatar']){
385
- if(!function_exists('wp_handle_upload')){
386
- require_once(ABSPATH.'wp-admin/includes/admin.php');
387
- require_once(ABSPATH.'wp-admin/includes/file.php');
388
- }
389
- $name = $_FILES['wp-user-avatar-file']['name'];
390
- $file = wp_handle_upload($_FILES['wp-user-avatar-file'], array('test_form' => false));
391
- $type = $file['type'];
392
- // Allow only JPG, GIF, PNG
393
- if($file['error'] || !preg_match('/(jpe?g|gif|png)$/i', $type)){
394
- if($file['error']){
395
- wp_die($file['error']);
396
- } else {
397
- wp_die(__('Sorry, this file type is not permitted for security reasons.'));
398
- }
399
- }
400
- // Break out file info
401
- $name_parts = pathinfo($name);
402
- $name = trim(substr($name, 0, -(1 + strlen($name_parts['extension']))));
403
- $url = $file['url'];
404
- $file = $file['file'];
405
- $title = $name;
406
- // Use image exif/iptc data for title if possible
407
- if($image_meta = @wp_read_image_metadata($file)){
408
- if(trim($image_meta['title']) && !is_numeric(sanitize_title($image_meta['title']))){
409
- $title = $image_meta['title'];
410
- }
411
- }
412
- // Construct the attachment array
413
- $attachment = array(
414
- 'guid' => $url,
415
- 'post_mime_type' => $type,
416
- 'post_title' => $title
417
- );
418
- // This should never be set as it would then overwrite an existing attachment
419
- if(isset($attachment['ID'])){
420
- unset($attachment['ID']);
421
- }
422
- // Save the attachment metadata
423
- $attachment_id = wp_insert_attachment($attachment, $file);
424
- if(!is_wp_error($attachment_id)){
425
- require_once(ABSPATH.'wp-admin/includes/image.php');
426
- wp_update_attachment_metadata($attachment_id, wp_generate_attachment_metadata($attachment_id, $file));
427
- $wpdb->query($wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %d", '_wp_attachment_wp_user_avatar', $user_id));
428
- add_post_meta($attachment_id, '_wp_attachment_wp_user_avatar', $user_id);
429
- update_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', $attachment_id);
430
- }
431
- }
432
- }
433
- }
434
-
435
- // Add button to attach image for WP 3.4 and older
436
- function wpua_add_attachment_field_to_edit($fields, $post){
437
- $image = wp_get_attachment_image_src($post->ID, "medium");
438
- $button = '<button type="button" class="button" id="set-wp-user-avatar-image" name="set-wp-user-avatar-image" onclick="wpuaSetAvatar(\''.$post->ID.'\', \''.$image[0].'\')">'.__('Select Image').'</button>';
439
- $fields['wp-user-avatar'] = array(
440
- 'label' => __('WP User Avatar', 'wp-user-avatar'),
441
- 'input' => 'html',
442
- 'html' => $button
443
- );
444
- return $fields;
445
- }
446
-
447
- // Add settings link on plugin page
448
- function wpua_plugin_settings_links($links, $file){
449
- if(basename($file) == basename(plugin_basename(__FILE__))){
450
- $settings_link = '<a href="'.add_query_arg(array('page' => 'wp-user-avatar'), admin_url('options-general.php')).'">'.__('Settings').'</a>';
451
- $links = array_merge($links, array($settings_link));
452
- }
453
- return $links;
454
- }
455
-
456
- // Add column to Users table
457
- function wpua_add_column($columns){
458
- return $columns + array('wp-user-avatar' => __('WP User Avatar', 'wp-user-avatar'));
459
- }
460
-
461
- // Show thumbnail in Users table
462
- function wpua_show_column($value, $column_name, $user_id){
463
- global $blog_id, $wpdb;
464
- $wpua = get_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', true);
465
- $wpua_image = wp_get_attachment_image($wpua, array(32,32));
466
- if($column_name == 'wp-user-avatar'){
467
- return $wpua_image;
468
- }
469
- }
470
-
471
- // Media uploader
472
- function wpua_media_upload_scripts($user=""){
473
- global $mustache_admin, $pagenow, $show_avatars, $wpua_upload_size_limit;
474
- wp_enqueue_script('jquery');
475
- if(current_user_can('upload_files')){
476
- wp_enqueue_script('admin-bar');
477
- wp_enqueue_media();
478
- }
479
- wp_enqueue_script('wp-user-avatar', WPUA_URLPATH.'js/wp-user-avatar.js', array('jquery'), WPUA_VERSION, true);
480
- wp_enqueue_style('wp-user-avatar', WPUA_URLPATH.'css/wp-user-avatar.css', "", WPUA_VERSION);
481
- // Admin scripts
482
- if($pagenow == 'options-discussion.php' || ($pagenow == 'options-general.php' && isset($_GET['page']) && $_GET['page'] == 'wp-user-avatar')){
483
- // Size limit slider
484
- wp_enqueue_script('jquery-ui-slider');
485
- wp_enqueue_style('wp-user-avatar-jqueryui', WPUA_URLPATH.'css/jquery.ui.slider.css', "", null);
486
- // Remove/edit settings
487
- $wpua_custom_scripts = array('section' => __('Default Avatar'), 'edit_image' => __('Edit Image'), 'select_image' => __('Select Image'), 'avatar_thumb' => $mustache_admin);
488
- wp_localize_script('wp-user-avatar', 'wpua_custom', $wpua_custom_scripts);
489
- // Settings control
490
- wp_enqueue_script('wp-user-avatar-admin', WPUA_URLPATH.'js/wp-user-avatar-admin.js', array('wp-user-avatar'), WPUA_VERSION, true);
491
- $wpua_admin_scripts = array('upload_size_limit' => $wpua_upload_size_limit, 'max_upload_size' => wp_max_upload_size());
492
- wp_localize_script('wp-user-avatar-admin', 'wpua_admin', $wpua_admin_scripts);
493
- } else {
494
- // User remove/edit settings
495
- $avatar_medium_src = (bool) $show_avatars == 1 ? wpua_get_avatar_original($user->user_email, 96) : includes_url().'images/blank.gif';
496
- $wpua_custom_scripts = array('section' => $user->display_name, 'edit_image' => __('Edit Image'), 'select_image' => __('Select Image'), 'avatar_thumb' => $avatar_medium_src);
497
- wp_localize_script('wp-user-avatar', 'wpua_custom', $wpua_custom_scripts);
498
- }
499
- }
500
- }
501
-
502
- // Returns true if user has Gravatar-hosted image
503
- function wpua_has_gravatar($id_or_email, $has_gravatar=false, $user="", $email=""){
504
- global $ssl;
505
- if(!is_object($id_or_email) && !empty($id_or_email)){
506
- // Find user by ID or e-mail address
507
- $user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
508
- // Get registered user e-mail address
509
- $email = !empty($user) ? $user->user_email : "";
510
- }
511
- // Check if Gravatar image returns 200 (OK) or 404 (Not Found)
512
- if(!empty($email)){
513
- $hash = md5(strtolower(trim($email)));
514
- $gravatar = 'http'.$ssl.'://www.gravatar.com/avatar/'.$hash.'?d=404';
515
- $headers = @get_headers($gravatar);
516
- $has_gravatar = !preg_match("|200|", $headers[0]) ? false : true;
517
- }
518
- return $has_gravatar;
519
- }
520
-
521
- // Returns true if user has wp_user_avatar
522
- function has_wp_user_avatar($id_or_email="", $has_wpua=false, $user="", $user_id=""){
523
- global $blog_id, $wpdb;
524
- if(!is_object($id_or_email) && !empty($id_or_email)){
525
- // Find user by ID or e-mail address
526
- $user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
527
- // Get registered user ID
528
- $user_id = !empty($user) ? $user->ID : "";
529
- }
530
- $wpua = get_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', true);
531
- $has_wpua = !empty($wpua) ? true : false;
532
- return $has_wpua;
533
- }
534
-
535
- // Replace get_avatar only in get_wp_user_avatar
536
- function wpua_get_avatar_filter($avatar, $id_or_email="", $size="", $default="", $alt=""){
537
- global $avatar_default, $comment, $mustache_admin, $mustache_avatar, $mustache_medium, $mustache_original, $mustache_thumbnail, $post, $wpua_avatar_default, $wpua_disable_gravatar;
538
- // User has WPUA
539
- if(is_object($id_or_email)){
540
- if(!empty($comment->comment_author_email)){
541
- $avatar = get_wp_user_avatar($comment, $size, $default, $alt);
542
- } else {
543
- $avatar = get_wp_user_avatar('unknown@gravatar.com', $size, $default, $alt);
544
- }
545
- } else {
546
- if(has_wp_user_avatar($id_or_email)){
547
- $avatar = get_wp_user_avatar($id_or_email, $size, $default, $alt);
548
- // User has Gravatar and Gravatar is not disabled
549
- } elseif((bool) $wpua_disable_gravatar != 1 && wpua_has_gravatar($id_or_email)){
550
- $avatar = $avatar;
551
- // User doesn't have WPUA or Gravatar and Default Avatar is wp_user_avatar, show custom Default Avatar
552
- } elseif($avatar_default == 'wp_user_avatar'){
553
- // Show custom Default Avatar
554
- if(!empty($wpua_avatar_default)){
555
- // Get image
556
- $wpua_avatar_default_image = wp_get_attachment_image_src($wpua_avatar_default, array($size,$size));
557
- // Image src
558
- $default = $wpua_avatar_default_image[0];
559
- // Add dimensions if numeric size
560
- $dimensions = ' width="'.$wpua_avatar_default_image[1].'" height="'.$wpua_avatar_default_image[2].'"';
561
- $defaultcss = "";
562
- } else {
563
- // Get mustache image based on numeric size comparison
564
- if($size > get_option('medium_size_w')){
565
- $default = $mustache_original;
566
- } elseif($size <= get_option('medium_size_w') && $size > get_option('thumbnail_size_w')){
567
- $default = $mustache_medium;
568
- } elseif($size <= get_option('thumbnail_size_w') && $size > 96){
569
- $default = $mustache_thumbnail;
570
- } elseif($size <= 96 && $size > 32){
571
- $default = $mustache_avatar;
572
- } elseif($size <= 32){
573
- $default = $mustache_admin;
574
- }
575
- // Add dimensions if numeric size
576
- $dimensions = ' width="'.$size.'" height="'.$size.'"';
577
- $defaultcss = ' avatar-default';
578
- }
579
- // Construct the img tag
580
- $avatar = "<img src='".$default."'".$dimensions." alt='".$alt."' class='wp-user-avatar wp-user-avatar-".$size." avatar avatar-".$size." photo'".$defaultcss." />";
581
- }
582
- }
583
- return $avatar;
584
- }
585
- add_filter('get_avatar', 'wpua_get_avatar_filter', 10, 6);
586
-
587
- // Get original avatar, for when user removes wp_user_avatar
588
- function wpua_get_avatar_original($id_or_email, $size="", $default="", $alt=""){
589
- global $avatar_default, $mustache_avatar, $wpua_avatar_default, $wpua_disable_gravatar;
590
- // Remove get_avatar filter only in admin
591
- if(is_admin()){
592
- remove_filter('get_avatar', 'wpua_get_avatar_filter');
593
- }
594
- if((bool) $wpua_disable_gravatar != 1){
595
- // User doesn't have Gravatar and Default Avatar is wp_user_avatar, show custom Default Avatar
596
- if(!wpua_has_gravatar($id_or_email) && $avatar_default == 'wp_user_avatar'){
597
- // Show custom Default Avatar
598
- if(!empty($wpua_avatar_default)){
599
- $wpua_avatar_default_image = wp_get_attachment_image_src($wpua_avatar_default, array($size,$size));
600
- $default = $wpua_avatar_default_image[0];
601
- } else {
602
- $default = $mustache_avatar;
603
- }
604
- } else {
605
- // Get image from Gravatar, whether it's the user's image or default image
606
- $wpua_image = get_avatar($id_or_email, $size);
607
- // Takes the img tag, extracts the src
608
- $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $wpua_image, $matches, PREG_SET_ORDER);
609
- $default = $matches [0] [1];
610
- }
611
- } else {
612
- if(!empty($wpua_avatar_default)){
613
- $wpua_avatar_default_image = wp_get_attachment_image_src($wpua_avatar_default, array($size,$size));
614
- $default = $wpua_avatar_default_image[0];
615
- } else {
616
- $default = $mustache_avatar;
617
- }
618
- }
619
- return $default;
620
- }
621
-
622
- // Find WPUA, show get_avatar if empty
623
- function get_wp_user_avatar($id_or_email="", $size='96', $align="", $alt=""){
624
- global $avatar_default, $blog_id, $comment, $post, $wpdb;
625
- // Checks if comment
626
- if(is_object($id_or_email)){
627
- // Checks if comment author is registered user by user ID
628
- if($comment->user_id != 0){
629
- $id_or_email = $comment->user_id;
630
- // Checks that comment author isn't anonymous
631
- } elseif(!empty($comment->comment_author_email)){
632
- // Checks if comment author is registered user by e-mail address
633
- $user = get_user_by('email', $comment->comment_author_email);
634
- // Get registered user info from profile, otherwise e-mail address should be value
635
- $id_or_email = !empty($user) ? $user->ID : $comment->comment_author_email;
636
- }
637
- $alt = $comment->comment_author;
638
- } else {
639
- if(!empty($id_or_email)){
640
- // Find user by ID or e-mail address
641
- $user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
642
- } else {
643
- // Find author's name if id_or_email is empty
644
- $author_name = get_query_var('author_name');
645
- if(is_author()){
646
- // On author page, get user by page slug
647
- $user = get_user_by('slug', $author_name);
648
- } else {
649
- // On post, get user by author meta
650
- $user_id = get_the_author_meta('ID');
651
- $user = get_user_by('id', $user_id);
652
- }
653
- }
654
- // Set user's ID and name
655
- if(!empty($user)){
656
- $id_or_email = $user->ID;
657
- $alt = $user->display_name;
658
- }
659
- }
660
- // Checks if user has WPUA
661
- $wpua_meta = !empty($id_or_email) ? get_the_author_meta($wpdb->get_blog_prefix($blog_id).'user_avatar', $id_or_email) : "";
662
- // Add alignment class
663
- $alignclass = !empty($align) ? ' align'.$align : "";
664
- // User has WPUA, bypass get_avatar
665
- if(!empty($wpua_meta)){
666
- // Numeric size use size array
667
- $get_size = is_numeric($size) ? array($size,$size) : $size;
668
- // Get image src
669
- $wpua_image = wp_get_attachment_image_src($wpua_meta, $get_size);
670
- // Add dimensions to img only if numeric size was specified
671
- $dimensions = is_numeric($size) ? ' width="'.$wpua_image[1].'" height="'.$wpua_image[2].'"' : "";
672
- // Construct the img tag
673
- $avatar = '<img src="'.$wpua_image[0].'"'.$dimensions.' alt="'.$alt.'" class="wp-user-avatar wp-user-avatar-'.$size.$alignclass.' avatar avatar avatar-'.$size.' photo" />';
674
- } else {
675
- // Get numeric sizes for non-numeric sizes based on media options
676
- if($size == 'original' || $size == 'large' || $size == 'medium' || $size == 'thumbnail'){
677
- $get_size = ($size == 'original') ? get_option('large_size_w') : get_option($size.'_size_w');
678
- } else {
679
- // Numeric sizes leave as-is
680
- $get_size = $size;
681
- }
682
- // User with no WPUA uses get_avatar
683
- $avatar = get_avatar($id_or_email, $get_size, $default="", $alt="");
684
- // Remove width and height for non-numeric sizes
685
- if(!is_numeric($size)){
686
- $avatar = preg_replace("/(width|height)=\'\d*\'\s/", "", $avatar);
687
- $avatar = preg_replace('/(width|height)=\"\d*\"\s/', "", $avatar);
688
- $avatar = str_replace('wp-user-avatar wp-user-avatar-'.$get_size.' ', "", $avatar);
689
- $avatar = str_replace("class='", "class='wp-user-avatar wp-user-avatar-".$size.$alignclass." ", $avatar);
690
- }
691
- }
692
- return $avatar;
693
- }
694
-
695
- // Return just the image src
696
- function get_wp_user_avatar_src($id_or_email, $size="", $align=""){
697
- $wpua_image_src = "";
698
- // Gets the avatar img tag
699
- $wpua_image = get_wp_user_avatar($id_or_email, $size, $align);
700
- // Takes the img tag, extracts the src
701
- if(!empty($wpua_image)){
702
- $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $wpua_image, $matches, PREG_SET_ORDER);
703
- $wpua_image_src = $matches [0] [1];
704
- }
705
- return $wpua_image_src;
706
- }
707
-
708
- // Shortcode
709
- function wpua_shortcode($atts, $content){
710
- global $blog_id, $wpdb;
711
- // Set shortcode attributes
712
- extract(shortcode_atts(array('user' => "", 'size' => '96', 'align' => "", 'link' => "", 'target' => ""), $atts));
713
- // Find user by ID, login, slug, or e-mail address
714
- if(!empty($user)){
715
- $user = is_numeric($user) ? get_user_by('id', $user) : get_user_by('login', $user);
716
- $user = empty($user) ? get_user_by('slug', $user) : $user;
717
- $user = empty($user) ? get_user_by('email', $user) : $user;
718
- }
719
- // Get user ID
720
- $id_or_email = !empty($user) ? $user->ID : "";
721
- // Check if link is set
722
- if(!empty($link)){
723
- // CSS class is same as link type, except for URL
724
- $link_class = $link;
725
- // Open in new window
726
- $target_link = !empty($target) ? ' target="'.$target.'"' : "";
727
- if($link == 'file'){
728
- // Get image src
729
- $image_link = get_wp_user_avatar_src($id_or_email, 'original', $align);
730
- } elseif($link == 'attachment'){
731
- // Get attachment URL
732
- $image_link = get_attachment_link(get_the_author_meta($wpdb->get_blog_prefix($blog_id).'user_avatar', $id_or_email));
733
- } else {
734
- // URL
735
- $image_link = $link;
736
- $link_class = 'custom';
737
- }
738
- // Wrap the avatar inside the link
739
- $avatar = '<a href="'.$image_link.'" class="wp-user-avatar-link wp-user-avatar-'.$link_class.'"'.$target_link.'>'.get_wp_user_avatar($id_or_email, $size, $align).'</a>';
740
- } else {
741
- // Get WPUA as normal
742
- $avatar = get_wp_user_avatar($id_or_email, $size, $align);
743
- }
744
- return $avatar;
745
- }
746
- add_shortcode('avatar', 'wpua_shortcode');
747
-
748
- // Add default avatar
749
- function wpua_add_default_avatar($avatar_list=null){
750
- global $avatar_default, $mustache_admin, $mustache_medium, $wpua_avatar_default, $wpua_disable_gravatar;
751
- // Remove get_avatar filter
752
- remove_filter('get_avatar', 'wpua_get_avatar_filter');
753
- // Set avatar_list variable
754
- $avatar_list = "";
755
- // Set avatar defaults
756
- $avatar_defaults = array(
757
- 'mystery' => __('Mystery Man'),
758
- 'blank' => __('Blank'),
759
- 'gravatar_default' => __('Gravatar Logo'),
760
- 'identicon' => __('Identicon (Generated)'),
761
- 'wavatar' => __('Wavatar (Generated)'),
762
- 'monsterid' => __('MonsterID (Generated)'),
763
- 'retro' => __('Retro (Generated)')
764
- );
765
- // No Default Avatar, set to Mystery Man
766
- if(empty($avatar_default)){
767
- $avatar_default = 'mystery';
768
- }
769
- // Take avatar_defaults and get examples for unknown@gravatar.com
770
- foreach($avatar_defaults as $default_key => $default_name){
771
- $avatar = get_avatar('unknown@gravatar.com', 32, $default_key);
772
- $selected = ($avatar_default == $default_key) ? 'checked="checked" ' : "";
773
- $avatar_list .= "\n\t<label><input type='radio' name='avatar_default' id='avatar_{$default_key}' value='".esc_attr($default_key)."' {$selected}/> ";
774
- $avatar_list .= preg_replace("/src='(.+?)'/", "src='\$1&amp;forcedefault=1'", $avatar);
775
- $avatar_list .= ' '.$default_name.'</label>';
776
- $avatar_list .= '<br />';
777
- }
778
- // Show remove link if custom Default Avatar is set
779
- if(!empty($wpua_avatar_default)){
780
- $avatar_thumb_src = wp_get_attachment_image_src($wpua_avatar_default, array(32,32));
781
- $avatar_thumb = $avatar_thumb_src[0];
782
- $hide_remove = "";
783
- } else {
784
- $avatar_thumb = $mustache_admin;
785
- $hide_remove = ' class="wpua-hide"';
786
- }
787
- // Default Avatar is wp_user_avatar, check the radio button next to it
788
- $selected_avatar = ((bool) $wpua_disable_gravatar == 1 || $avatar_default == 'wp_user_avatar') ? ' checked="checked" ' : "";
789
- // Wrap WPUA in div
790
- $avatar_thumb_img = '<div id="wpua-preview"><img src="'.$avatar_thumb.'" width="32" /></div>';
791
- // Add WPUA to list
792
- $wpua_list = "\n\t<label><input type='radio' name='avatar_default' id='wp_user_avatar_radio' value='wp_user_avatar'$selected_avatar /> ";
793
- $wpua_list .= preg_replace("/src='(.+?)'/", "src='\$1'", $avatar_thumb_img);
794
- $wpua_list .= ' '.__('WP User Avatar', 'wp-user-avatar').'</label>';
795
- $wpua_list .= '<p id="wpua-edit"><button type="button" class="button" id="wpua-add" name="wpua-add">'.__('Edit Image').'</button>';
796
- $wpua_list .= '<a href="#" id="wpua-remove"'.$hide_remove.'>'.__('Remove').'</a></p>';
797
- $wpua_list .= '<input type="hidden" id="wp-user-avatar" name="avatar_default_wp_user_avatar" value="'.$wpua_avatar_default.'">';
798
- $wpua_list .= '<p id="wpua-message">'.sprintf(__('Click %s to save your changes', 'wp-user-avatar'), '&ldquo;'.__('Save Changes').'&rdquo;').'</p>';
799
- if((bool) $wpua_disable_gravatar != 1){
800
- return $wpua_list.'<div id="wp-avatars">'.$avatar_list.'</div>';
801
- } else {
802
- return $wpua_list;
803
- }
804
- }
805
- add_filter('default_avatar_select', 'wpua_add_default_avatar', 10);
806
-
807
- // Add default avatar_default to whitelist
808
- function wpua_whitelist_options($whitelist_options){
809
- $whitelist_options['discussion'][] = 'avatar_default_wp_user_avatar';
810
- return $whitelist_options;
811
- }
812
- add_filter('whitelist_options', 'wpua_whitelist_options', 10);
813
-
814
- // Add media state
815
- function wpua_add_media_state($media_states){
816
- global $post, $wpua_avatar_default;
817
- $is_wpua = get_post_custom_values('_wp_attachment_wp_user_avatar', $post->ID);
818
- if(!empty($is_wpua)){
819
- $media_states[] = __('Avatar');
820
- }
821
- if(!empty($wpua_avatar_default) && ($wpua_avatar_default == $post->ID)){
822
- $media_states[] = __('Default Avatar');
823
- }
824
- return apply_filters('wpua_add_media_state', $media_states);
825
- }
826
- add_filter('display_media_states', 'wpua_add_media_state', 10, 1);
827
-
828
- // Check if image is used as WPUA
829
- function wpua_image($attachment_id, $user_id, $wpua_image=false){
830
- global $wpdb;
831
- $wpua = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s AND meta_value != %d", $attachment_id, '_wp_attachment_wp_user_avatar', $user_id));
832
- if(!empty($wpua)){
833
- $wpua_image = true;
834
- }
835
- return $wpua_image;
836
- }
837
-
838
- // Check who owns image
839
- function wpua_author($attachment_id, $user_id, $wpua_author=false){
840
- $attachment = get_post($attachment_id);
841
- if(!empty($attachment) && $attachment->post_author == $user_id){
842
- $wpua_author = true;
843
- }
844
- return $wpua_author;
845
- }
846
-
847
- // Admin page
848
- function wpua_options_page(){
849
- global $show_avatars, $upload_size_limit_with_units, $wpua_allow_upload, $wpua_disable_gravatar, $wpua_edit_avatar, $wpua_tinymce, $wpua_upload_size_limit, $wpua_upload_size_limit_with_units;
850
- // Give subscribers edit_posts capability
851
- if(isset($_GET['settings-updated']) && $_GET['settings-updated'] == 'true' && (empty($wpua_allow_upload) || empty($wpua_edit_avatar))){
852
- wpua_subscriber_remove_cap();
853
- }
854
- $hide_size = (bool) $wpua_allow_upload != 1 ? ' class="wpua-hide"' : "";
855
- ?>
856
- <div class="wrap">
857
- <?php screen_icon(); ?>
858
- <h2><?php _e('WP User Avatar', 'wp-user-avatar'); ?></h2>
859
- <form method="post" action="options.php">
860
- <?php settings_fields('wpua-settings-group'); ?>
861
- <?php do_settings_fields('wpua-settings-group', ""); ?>
862
- <table class="form-table">
863
- <tr valign="top">
864
- <th scope="row"><?php _e('Settings'); ?></th>
865
- <td>
866
- <fieldset>
867
- <legend class="screen-reader-text"><span><?php _e('Settings'); ?></span></legend>
868
- <label for="wp_user_avatar_tinymce">
869
- <input name="wp_user_avatar_tinymce" type="checkbox" id="wp_user_avatar_tinymce" value="1" <?php checked($wpua_tinymce, 1); ?> />
870
- <?php _e('Add avatar button to Visual Editor', 'wp-user-avatar'); ?>
871
- </label>
872
- <br />
873
- <label for="wp_user_avatar_allow_upload">
874
- <input name="wp_user_avatar_allow_upload" type="checkbox" id="wp_user_avatar_allow_upload" value="1" <?php checked($wpua_allow_upload, 1); ?> />
875
- <?php _e('Allow Contributors & Subscribers to upload avatars', 'wp-user-avatar'); ?>
876
- </label>
877
- <br />
878
- <label for="wp_user_avatar_disable_gravatar">
879
- <input name="wp_user_avatar_disable_gravatar" type="checkbox" id="wp_user_avatar_disable_gravatar" value="1" <?php checked($wpua_disable_gravatar, 1); ?> />
880
- <?php _e('Disable Gravatar and use only local avatars', 'wp-user-avatar'); ?>
881
- </label>
882
- </fieldset>
883
- </td>
884
- </tr>
885
- <tr id="wpua-size-limit" valign="top"<?php echo $hide_size; ?>>
886
- <th scope="row">
887
- <label for="wp_user_avatar_upload_size_limit">
888
- <?php _e('Upload Size Limit (only for Contributors & Subscribers)', 'wp-user-avatar'); ?>
889
- </label>
890
- </th>
891
- <td>
892
- <fieldset>
893
- <legend class="screen-reader-text"><span><?php _e('Upload Size Limit (only for Contributors & Subscribers)', 'wp-user-avatar'); ?></span></legend>
894
- <input name="wp_user_avatar_upload_size_limit" type="text" id="wp_user_avatar_upload_size_limit" value="<?php echo $wpua_upload_size_limit; ?>" class="regular-text" />
895
- <span id="wpua-readable-size"><?php echo $wpua_upload_size_limit_with_units; ?></span>
896
- <span id="wpua-readable-size-error"><?php printf(__('%s exceeds the maximum upload size for this site.'), ""); ?></span>
897
- <div id="wpua-slider"></div>
898
- <span class="description"><?php printf(__('Maximum upload file size: %d%s.'), esc_html(wp_max_upload_size()), esc_html(' bytes ('.$upload_size_limit_with_units.')')); ?></span>
899
- <br />
900
- <label for="wp_user_avatar_edit_avatar">
901
- <input name="wp_user_avatar_edit_avatar" type="checkbox" id="wp_user_avatar_edit_avatar" value="1" <?php checked($wpua_edit_avatar, 1); ?> />
902
- <?php _e('Allow users to edit avatars', 'wp-user-avatar'); ?>
903
- </label>
904
- </fieldset>
905
- </td>
906
- </tr>
907
- </table>
908
- <h3 class="title"><?php _e('Avatars'); ?></h3>
909
- <p><?php _e('An avatar is an image that follows you from weblog to weblog appearing beside your name when you comment on avatar enabled sites. Here you can enable the display of avatars for people who comment on your site.'); ?></p>
910
- <table class="form-table">
911
- <tr valign="top">
912
- <th scope="row"><?php _e('Avatar Display'); ?></th>
913
- <td>
914
- <fieldset>
915
- <legend class="screen-reader-text"><span><?php _e('Avatar Display'); ?></span></legend>
916
- <label for="show_avatars">
917
- <input type="checkbox" id="show_avatars" name="show_avatars" value="1" <?php checked($show_avatars, 1); ?> />
918
- <?php _e('Show Avatars'); ?>
919
- </label>
920
- </fieldset>
921
- </td>
922
- </tr>
923
- <tr valign="top">
924
- <th scope="row"><?php _e('Maximum Rating'); ?></th>
925
- <td>
926
- <fieldset>
927
- <legend class="screen-reader-text"><span><?php _e('Maximum Rating'); ?></span></legend>
928
- <?php
929
- $ratings = array(
930
- 'G' => __('G &#8212; Suitable for all audiences'),
931
- 'PG' => __('PG &#8212; Possibly offensive, usually for audiences 13 and above'),
932
- 'R' => __('R &#8212; Intended for adult audiences above 17'),
933
- 'X' => __('X &#8212; Even more mature than above')
934
- );
935
- foreach ($ratings as $key => $rating) :
936
- $selected = (get_option('avatar_rating') == $key) ? 'checked="checked"' : "";
937
- echo "\n\t<label><input type='radio' name='avatar_rating' value='" . esc_attr($key) . "' $selected/> $rating</label><br />";
938
- endforeach;
939
- ?>
940
- </fieldset>
941
- </td>
942
- </tr>
943
- <tr valign="top">
944
- <th scope="row"><?php _e('Default Avatar') ?></th>
945
- <td class="defaultavatarpicker">
946
- <fieldset>
947
- <legend class="screen-reader-text"><span><?php _e('Default Avatar'); ?></span></legend>
948
- <?php _e('For users without a custom avatar of their own, you can either display a generic logo or a generated one based on their e-mail address.'); ?><br />
949
- <?php echo wpua_add_default_avatar(); ?>
950
- </fieldset>
951
- </td>
952
- </tr>
953
- </table>
954
- <?php submit_button(); ?>
955
- </form>
956
- </div>
957
- <?php
958
- }
959
-
960
- // Whitelist settings
961
- function wpua_admin_settings(){
962
- register_setting('wpua-settings-group', 'avatar_rating');
963
- register_setting('wpua-settings-group', 'avatar_default');
964
- register_setting('wpua-settings-group', 'avatar_default_wp_user_avatar', 'intval');
965
- register_setting('wpua-settings-group', 'show_avatars', 'intval');
966
- register_setting('wpua-settings-group', 'wp_user_avatar_tinymce', 'intval');
967
- register_setting('wpua-settings-group', 'wp_user_avatar_allow_upload', 'intval');
968
- register_setting('wpua-settings-group', 'wp_user_avatar_disable_gravatar', 'intval');
969
- register_setting('wpua-settings-group', 'wp_user_avatar_edit_avatar', 'intval');
970
- register_setting('wpua-settings-group', 'wp_user_avatar_upload_size_limit', 'intval');
971
- }
972
-
973
- // Add options page and settings
974
- function wpua_admin(){
975
- add_options_page(__('WP User Avatar', 'wp-user-avatar'), __('WP User Avatar', 'wp-user-avatar'), 'manage_options', 'wp-user-avatar', 'wpua_options_page');
976
- add_action('admin_init', 'wpua_admin_settings');
977
- }
978
-
979
- // Initialize WPUA after other plugins are loaded
980
- function wpua_load(){
981
- global $wpua_instance;
982
- $wpua_instance = new wp_user_avatar();
983
- }
984
- add_action('plugins_loaded', 'wpua_load');
985
- }
986
- ?>
1
  <?php
2
  /**
3
  * @package WP User Avatar
4
+ * @version 1.9.5
5
  */
6
+
7
  /*
8
  Plugin Name: WP User Avatar
9
  Plugin URI: http://wordpress.org/plugins/wp-user-avatar/
10
  Description: Use any image from your WordPress Media Library as a custom user avatar. Add your own Default Avatar.
11
  Author: Bangbay Siboliban
12
  Author URI: http://siboliban.org/
13
+ Version: 1.9.5
14
  Text Domain: wp-user-avatar
15
  Domain Path: /lang/
16
  */
17
 
18
+ if(!defined('ABSPATH')) {
19
+ die('You are not allowed to call this page directly.');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  }
21
 
22
+ /**
23
+ * Let's get started!
24
+ */
25
+ class WP_User_Avatar_Setup {
26
+ /**
27
+ * Constructor
28
+ */
29
+ public function __construct() {
30
+ $this->_define_constants();
31
+ $this->_load_wp_includes();
32
+ $this->_load_wpua();
33
+ }
34
+
35
+ /**
36
+ * Define paths
37
+ */
38
+ private function _define_constants() {
39
+ define('WPUA_VERSION', '1.9.5');
40
+ define('WPUA_FOLDER', basename(dirname(__FILE__)));
41
+ define('WPUA_DIR', plugin_dir_path(__FILE__));
42
+ define('WPUA_INC', WPUA_DIR.'includes'.'/');
43
+ define('WPUA_URL', plugin_dir_url(WPUA_FOLDER).WPUA_FOLDER.'/');
44
+ define('WPUA_INC_URL', WPUA_URL.'includes'.'/');
45
+ }
46
+
47
+ /**
48
+ * WordPress includes used in plugin
49
+ */
50
+ private function _load_wp_includes() {
51
+ require_once(ABSPATH.'wp-admin/includes/file.php');
52
+ require_once(ABSPATH.'wp-admin/includes/image.php');
53
+ require_once(ABSPATH.'wp-admin/includes/media.php');
54
+ require_once(ABSPATH.'wp-admin/includes/screen.php');
55
+ require_once(ABSPATH.'wp-admin/includes/template.php');
56
+ }
57
+
58
+ /**
59
+ * Load WP User Avatar
60
+ */
61
+ private function _load_wpua() {
62
+ require_once(WPUA_INC.'wpua-globals.php');
63
+ require_once(WPUA_INC.'wpua-functions.php');
64
+ require_once(WPUA_INC.'class-wp-user-avatar-admin.php');
65
+ require_once(WPUA_INC.'class-wp-user-avatar.php');
66
+ require_once(WPUA_INC.'class-wp-user-avatar-functions.php');
67
+ require_once(WPUA_INC.'class-wp-user-avatar-resource-manager.php');
68
+ WP_User_Avatar_Resource_Manager::init();
69
+ require_once(WPUA_INC.'class-wp-user-avatar-shortcode.php');
70
+ require_once(WPUA_INC.'class-wp-user-avatar-subscriber.php');
71
+ require_once(WPUA_INC.'class-wp-user-avatar-update.php');
72
+ require_once(WPUA_INC.'class-wp-user-avatar-widget.php');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  }
75
 
76
+ /**
77
+ * Initialize
78
+ */
79
+ new WP_User_Avatar_Setup();