WP User Avatar - Version 1.9.7

Version Description

  • Bug Fix: Remove resource manager
  • Bug Fix: User ID in shortcode
Download this release

Release Info

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

Code changes from version 1.5.4 to 1.9.7

Files changed (42) 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 +390 -0
  10. includes/class-wp-user-avatar-functions.php +440 -0
  11. includes/class-wp-user-avatar-list-table.php +400 -0
  12. includes/class-wp-user-avatar-resource-manager.php +136 -0
  13. includes/class-wp-user-avatar-shortcode.php +231 -0
  14. includes/class-wp-user-avatar-subscriber.php +135 -0
  15. includes/class-wp-user-avatar-update.php +116 -0
  16. includes/class-wp-user-avatar-widget.php +83 -0
  17. includes/class-wp-user-avatar.php +452 -0
  18. includes/tinymce.php +0 -47
  19. includes/tinymce/editor_plugin.js +1 -1
  20. includes/tinymce/window.php +134 -78
  21. includes/wpua-functions.php +203 -0
  22. includes/wpua-globals.php +99 -0
  23. includes/wpua-media-page.php +116 -0
  24. includes/wpua-options-page.php +212 -0
  25. includes/wpua-tinymce.php +54 -0
  26. index.html +1 -0
  27. js/wp-user-avatar-admin.js +25 -22
  28. js/wp-user-avatar-user.js +31 -0
  29. js/wp-user-avatar.js +1 -1
  30. lang/wp-user-avatar-de_DE.mo +0 -0
  31. lang/wp-user-avatar-de_DE.po +35 -15
  32. lang/wp-user-avatar-es_ES.mo +0 -0
  33. lang/wp-user-avatar-es_ES.po +35 -15
  34. lang/wp-user-avatar-fr_FR.mo +0 -0
  35. lang/wp-user-avatar-fr_FR.po +35 -15
  36. lang/wp-user-avatar-pl_PL.mo +0 -0
  37. lang/wp-user-avatar-pl_PL.po +81 -0
  38. lang/wp-user-avatar-sv_SE.mo +0 -0
  39. lang/wp-user-avatar-sv_SE.po +35 -15
  40. readme.txt +340 -33
  41. uninstall.php +38 -12
  42. wp-user-avatar.php +62 -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,390 @@
1
+ <?php
2
+ /**
3
+ * Defines all of administrative, activation, and deactivation settings.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.7
7
+ */
8
+
9
+ class WP_User_Avatar_Admin {
10
+ /**
11
+ * Constructor
12
+ * @since 1.8
13
+ * @uses bool $show_avatars
14
+ * @uses bool $wpua_allow_upload
15
+ * @uses bool $wpua_tinymce
16
+ * @uses add_action()
17
+ * @uses add_filter()
18
+ * @uses current_user_can()
19
+ * @uses is_admin()
20
+ * @uses load_plugin_textdomain()
21
+ * @uses register_activation_hook()
22
+ * @uses register_deactivation_hook()
23
+ */
24
+ public function __construct() {
25
+ global $show_avatars, $wpua_allow_upload, $wpua_tinymce;
26
+ // Initialize default settings
27
+ register_activation_hook(WPUA_DIR.'wp-user-avatar.php', array($this, 'wpua_options'));
28
+ // Settings saved to wp_options
29
+ add_action('admin_init', array($this, 'wpua_options'));
30
+ // Remove subscribers edit_posts capability
31
+ register_deactivation_hook(WPUA_DIR.'wp-user-avatar.php', array($this, 'wpua_deactivate'));
32
+ // Translations
33
+ load_plugin_textdomain('wp-user-avatar', "", WPUA_FOLDER.'/lang');
34
+ // Admin menu settings
35
+ add_action('admin_menu', array($this, 'wpua_admin'));
36
+ add_action('admin_init', array($this, 'wpua_register_settings'));
37
+ // Default avatar
38
+ add_filter('default_avatar_select', array($this, 'wpua_add_default_avatar'), 10);
39
+ add_filter('whitelist_options', array($this, 'wpua_whitelist_options'), 10);
40
+ // Additional plugin info
41
+ add_filter('plugin_action_links', array($this, 'wpua_action_links'), 10, 2);
42
+ add_filter('plugin_row_meta', array($this, 'wpua_row_meta'), 10, 2);
43
+ // Hide column in Users table if default avatars are enabled
44
+ if((bool) $show_avatars == 0 && is_admin()) {
45
+ add_filter('manage_users_columns', array($this, 'wpua_add_column'), 10, 1);
46
+ add_filter('manage_users_custom_column', array($this, 'wpua_show_column'), 10, 3);
47
+ }
48
+ // Media states
49
+ add_filter('display_media_states', array($this, 'wpua_add_media_state'), 10, 1);
50
+ // Load TinyMCE only if enabled and user has editing privileges
51
+ if((bool) $wpua_tinymce == 1 && current_user_can('edit_posts') && current_user_can('edit_pages')) {
52
+ include_once(WPUA_INC.'wpua-tinymce.php');
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Settings saved to wp_options
58
+ * @since 1.4
59
+ * @uses add_option()
60
+ */
61
+ public function wpua_options() {
62
+ add_option('avatar_default_wp_user_avatar', "");
63
+ add_option('wp_user_avatar_allow_upload', '0');
64
+ add_option('wp_user_avatar_disable_gravatar', '0');
65
+ add_option('wp_user_avatar_edit_avatar', '1');
66
+ add_option('wp_user_avatar_resize_crop', '0');
67
+ add_option('wp_user_avatar_resize_h', '96');
68
+ add_option('wp_user_avatar_resize_upload', '0');
69
+ add_option('wp_user_avatar_resize_w', '96');
70
+ add_option('wp_user_avatar_tinymce', '1');
71
+ add_option('wp_user_avatar_upload_size_limit', '0');
72
+ }
73
+
74
+ /**
75
+ * On deactivation
76
+ * @since 1.4
77
+ * @uses int $blog_id
78
+ * @uses object $wpdb
79
+ * @uses get_blog_prefix()
80
+ * @uses get_option()
81
+ * @uses update_option()
82
+ */
83
+ public function wpua_deactivate() {
84
+ global $blog_id, $wpdb;
85
+ $wp_user_roles = $wpdb->get_blog_prefix($blog_id).'user_roles';
86
+ // Get user roles and capabilities
87
+ $user_roles = get_option($wp_user_roles);
88
+ // Remove subscribers edit_posts capability
89
+ unset($user_roles['subscriber']['capabilities']['edit_posts']);
90
+ update_option($wp_user_roles, $user_roles);
91
+ // Reset all default avatars to Mystery Man
92
+ update_option('avatar_default', 'mystery');
93
+ }
94
+
95
+ /**
96
+ * Add options page and settings
97
+ * @since 1.4
98
+ * @uses add_menu_page()
99
+ * @uses add_submenu_page()
100
+ */
101
+ public function wpua_admin() {
102
+ 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');
103
+ add_submenu_page('wp-user-avatar', __('Settings'), __('Settings'), 'manage_options', 'wp-user-avatar', array($this, 'wpua_options_page'));
104
+ $hook = add_submenu_page('wp-user-avatar', __('Library'), __('Library'), 'manage_options', 'wp-user-avatar-library', array($this, 'wpua_media_page'));
105
+ add_action("load-$hook", array($this, 'wpua_media_screen_option'));
106
+ add_filter('set-screen-option', array($this, 'wpua_set_media_screen_option'), 10, 3);
107
+ }
108
+
109
+ /**
110
+ * Checks if current page is settings page
111
+ * @since 1.8.3
112
+ * @uses string $pagenow
113
+ * @return bool
114
+ */
115
+ public function wpua_is_menu_page() {
116
+ global $pagenow;
117
+ $is_menu_page = ($pagenow == 'admin.php' && isset($_GET['page']) && $_GET['page'] == 'wp-user-avatar') ? true : false;
118
+ return $is_menu_page;
119
+ }
120
+
121
+ /**
122
+ * Media page
123
+ * @since 1.8
124
+ */
125
+ public function wpua_media_page() {
126
+ require_once(WPUA_INC.'wpua-media-page.php');
127
+ }
128
+
129
+ /**
130
+ * Avatars per page
131
+ * @since 1.8.10
132
+ * @uses add_screen_option()
133
+ */
134
+ public function wpua_media_screen_option() {
135
+ $option = 'per_page';
136
+ $args = array(
137
+ 'label' => __('Avatars'),
138
+ 'default' => 10,
139
+ 'option' => 'upload_per_page'
140
+ );
141
+ add_screen_option($option, $args);
142
+ }
143
+
144
+ /**
145
+ * Save per page setting
146
+ * @since 1.8.10
147
+ * @param int $status
148
+ * @param string $option
149
+ * @param int $value
150
+ * @return int $status
151
+ */
152
+ public function wpua_set_media_screen_option($status, $option, $value) {
153
+ $status = ($option == 'upload_per_page') ? $value : $status;
154
+ return $status;
155
+ }
156
+
157
+ /**
158
+ * Options page
159
+ * @since 1.4
160
+ */
161
+ public function wpua_options_page() {
162
+ require_once(WPUA_INC.'wpua-options-page.php');
163
+ }
164
+
165
+ /**
166
+ * Whitelist settings
167
+ * @since 1.9
168
+ * @uses apply_filters()
169
+ * @uses register_setting()
170
+ * @return array
171
+ */
172
+ public function wpua_register_settings() {
173
+ $settings = array();
174
+ $settings[] = register_setting('wpua-settings-group', 'avatar_rating');
175
+ $settings[] = register_setting('wpua-settings-group', 'avatar_default');
176
+ $settings[] = register_setting('wpua-settings-group', 'avatar_default_wp_user_avatar');
177
+ $settings[] = register_setting('wpua-settings-group', 'show_avatars', 'intval');
178
+ $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_tinymce', 'intval');
179
+ $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_allow_upload', 'intval');
180
+ $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_disable_gravatar', 'intval');
181
+ $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_edit_avatar', 'intval');
182
+ $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_resize_crop', 'intval');
183
+ $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_resize_h', 'intval');
184
+ $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_resize_upload', 'intval');
185
+ $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_resize_w', 'intval');
186
+ $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_upload_size_limit', 'intval');
187
+ /**
188
+ * Filter admin whitelist settings
189
+ * @since 1.9
190
+ * @param array $settings
191
+ */
192
+ return apply_filters('wpua_register_settings', $settings);
193
+ }
194
+
195
+ /**
196
+ * Add default avatar
197
+ * @since 1.4
198
+ * @uses string $avatar_default
199
+ * @uses string $mustache_admin
200
+ * @uses string $mustache_medium
201
+ * @uses int $wpua_avatar_default
202
+ * @uses bool $wpua_disable_gravatar
203
+ * @uses object $wpua_functions
204
+ * @uses get_avatar()
205
+ * @uses remove_filter()
206
+ * @uses wpua_attachment_is_image()
207
+ * @uses wpua_get_attachment_image_src()
208
+ * @return string
209
+ */
210
+ public function wpua_add_default_avatar() {
211
+ global $avatar_default, $mustache_admin, $mustache_medium, $wpua_avatar_default, $wpua_disable_gravatar, $wpua_functions;
212
+ // Remove get_avatar filter
213
+ remove_filter('get_avatar', array($wpua_functions, 'wpua_get_avatar_filter'));
214
+ // Set avatar_list variable
215
+ $avatar_list = "";
216
+ // Set avatar defaults
217
+ $avatar_defaults = array(
218
+ 'mystery' => __('Mystery Man'),
219
+ 'blank' => __('Blank'),
220
+ 'gravatar_default' => __('Gravatar Logo'),
221
+ 'identicon' => __('Identicon (Generated)'),
222
+ 'wavatar' => __('Wavatar (Generated)'),
223
+ 'monsterid' => __('MonsterID (Generated)'),
224
+ 'retro' => __('Retro (Generated)')
225
+ );
226
+ // No Default Avatar, set to Mystery Man
227
+ if(empty($avatar_default)) {
228
+ $avatar_default = 'mystery';
229
+ }
230
+ // Take avatar_defaults and get examples for unknown@gravatar.com
231
+ foreach($avatar_defaults as $default_key => $default_name) {
232
+ $avatar = get_avatar('unknown@gravatar.com', 32, $default_key);
233
+ $selected = ($avatar_default == $default_key) ? 'checked="checked" ' : "";
234
+ $avatar_list .= "\n\t<label><input type='radio' name='avatar_default' id='avatar_{$default_key}' value='".esc_attr($default_key)."' {$selected}/> ";
235
+ $avatar_list .= preg_replace("/src='(.+?)'/", "src='\$1&amp;forcedefault=1'", $avatar);
236
+ $avatar_list .= ' '.$default_name.'</label>';
237
+ $avatar_list .= '<br />';
238
+ }
239
+ // Show remove link if custom Default Avatar is set
240
+ if(!empty($wpua_avatar_default) && $wpua_functions->wpua_attachment_is_image($wpua_avatar_default)) {
241
+ $avatar_thumb_src = $wpua_functions->wpua_get_attachment_image_src($wpua_avatar_default, array(32,32));
242
+ $avatar_thumb = $avatar_thumb_src[0];
243
+ $hide_remove = "";
244
+ } else {
245
+ $avatar_thumb = $mustache_admin;
246
+ $hide_remove = ' class="wpua-hide"';
247
+ }
248
+ // Default Avatar is wp_user_avatar, check the radio button next to it
249
+ $selected_avatar = ((bool) $wpua_disable_gravatar == 1 || $avatar_default == 'wp_user_avatar') ? ' checked="checked" ' : "";
250
+ // Wrap WPUA in div
251
+ $avatar_thumb_img = '<div id="wpua-preview"><img src="'.$avatar_thumb.'" width="32" /></div>';
252
+ // Add WPUA to list
253
+ $wpua_list = "\n\t<label><input type='radio' name='avatar_default' id='wp_user_avatar_radio' value='wp_user_avatar'$selected_avatar /> ";
254
+ $wpua_list .= preg_replace("/src='(.+?)'/", "src='\$1'", $avatar_thumb_img);
255
+ $wpua_list .= ' '.__('WP User Avatar', 'wp-user-avatar').'</label>';
256
+ $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>';
257
+ $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>';
258
+ $wpua_list .= '<input type="hidden" id="wp-user-avatar" name="avatar_default_wp_user_avatar" value="'.$wpua_avatar_default.'">';
259
+ $wpua_list .= '<div id="wpua-modal"></div>';
260
+ if((bool) $wpua_disable_gravatar != 1) {
261
+ return $wpua_list.'<div id="wp-avatars">'.$avatar_list.'</div>';
262
+ } else {
263
+ return $wpua_list;
264
+ }
265
+ }
266
+
267
+ /**
268
+ * Add default avatar_default to whitelist
269
+ * @since 1.4
270
+ * @param array $options
271
+ * @return array $options
272
+ */
273
+ public function wpua_whitelist_options($options) {
274
+ $options['discussion'][] = 'avatar_default_wp_user_avatar';
275
+ return $options;
276
+ }
277
+
278
+ /**
279
+ * Add actions links on plugin page
280
+ * @since 1.6.6
281
+ * @param array $links
282
+ * @param string $file
283
+ * @return array $links
284
+ */
285
+ public function wpua_action_links($links, $file) {
286
+ if(basename(dirname($file)) == 'wp-user-avatar') {
287
+ $links[] = '<a href="'.add_query_arg(array('page' => 'wp-user-avatar'), admin_url('admin.php')).'">'.__('Settings').'</a>';
288
+ }
289
+ return $links;
290
+ }
291
+
292
+ /**
293
+ * Add row meta on plugin page
294
+ * @since 1.6.6
295
+ * @param array $links
296
+ * @param string $file
297
+ * @return array $links
298
+ */
299
+ public function wpua_row_meta($links, $file) {
300
+ if(basename(dirname($file)) == 'wp-user-avatar') {
301
+ $links[] = '<a href="http://wordpress.org/support/plugin/wp-user-avatar" target="_blank">'.__('Support Forums').'</a>';
302
+ $links[] = '<a href="http://siboliban.org/donate" target="_blank">'.__('Donate', 'wp-user-avatar').'</a>';
303
+ }
304
+ return $links;
305
+ }
306
+
307
+ /**
308
+ * Add column to Users table
309
+ * @since 1.4
310
+ * @param array $columns
311
+ * @return array
312
+ */
313
+ public function wpua_add_column($columns) {
314
+ return $columns + array('wp-user-avatar' => __('Avatar'));
315
+ }
316
+
317
+ /**
318
+ * Show thumbnail in Users table
319
+ * @since 1.4
320
+ * @param string $value
321
+ * @param string $column_name
322
+ * @param int $user_id
323
+ * @uses int $blog_id
324
+ * @uses object $wpdb
325
+ * @uses object $wpua_functions
326
+ * @uses get_blog_prefix()
327
+ * @uses get_user_meta()
328
+ * @uses wpua_get_attachment_image()
329
+ * @return string $value
330
+ */
331
+ public function wpua_show_column($value, $column_name, $user_id) {
332
+ global $blog_id, $wpdb, $wpua_functions;
333
+ $wpua = get_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', true);
334
+ $wpua_image = $wpua_functions->wpua_get_attachment_image($wpua, array(32,32));
335
+ if($column_name == 'wp-user-avatar') {
336
+ $value = $wpua_image;
337
+ }
338
+ return $value;
339
+ }
340
+
341
+ /**
342
+ * Get list table
343
+ * @since 1.8
344
+ * @param string $class
345
+ * @param array $args
346
+ * @return object
347
+ */
348
+ public function _wpua_get_list_table($class, $args = array()) {
349
+ require_once(WPUA_INC.'class-wp-user-avatar-list-table.php');
350
+ $args['screen'] = 'wp-user-avatar';
351
+ return new $class($args);
352
+ }
353
+
354
+ /**
355
+ * Add media states
356
+ * @since 1.4
357
+ * @param array $states
358
+ * @uses object $post
359
+ * @uses int $wpua_avatar_default
360
+ * @uses apply_filters()
361
+ * @uses get_post_custom_values()
362
+ * @return array
363
+ */
364
+ public function wpua_add_media_state($states) {
365
+ global $post, $wpua_avatar_default;
366
+ $is_wpua = get_post_custom_values('_wp_attachment_wp_user_avatar', $post->ID);
367
+ if(!empty($is_wpua)) {
368
+ $states[] = __('Avatar');
369
+ }
370
+ if(!empty($wpua_avatar_default) && ($wpua_avatar_default == $post->ID)) {
371
+ $states[] = __('Default Avatar');
372
+ }
373
+ /**
374
+ * Filter media states
375
+ * @since 1.4
376
+ * @param array $states
377
+ */
378
+ return apply_filters('wpua_add_media_state', $states);
379
+ }
380
+ }
381
+
382
+ /**
383
+ * Initialize
384
+ * @since 1.9.2
385
+ */
386
+ function wpua_admin_init() {
387
+ global $wpua_admin;
388
+ $wpua_admin = new WP_User_Avatar_Admin();
389
+ }
390
+ add_action('init', 'wpua_admin_init');
includes/class-wp-user-avatar-functions.php ADDED
@@ -0,0 +1,440 @@
1
+ <?php
2
+ /**
3
+ * Core user functions.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.7
7
+ */
8
+
9
+ class WP_User_Avatar_Functions {
10
+ /**
11
+ * Constructor
12
+ * @since 1.8
13
+ * @uses add_filter()
14
+ */
15
+ public function __construct() {
16
+ add_filter('get_avatar', array($this, 'wpua_get_avatar_filter'), 10, 5);
17
+ }
18
+
19
+ /**
20
+ * Returns true if user has Gravatar-hosted image
21
+ * @since 1.4
22
+ * @param int|string $id_or_email
23
+ * @param bool $has_gravatar
24
+ * @param int|string $user
25
+ * @param string $email
26
+ * @uses get_user_by()
27
+ * @uses is_wp_error()
28
+ * @uses wp_cache_get()
29
+ * @uses wp_cache_set()
30
+ * @uses wp_remote_head()
31
+ * @return bool $has_gravatar
32
+ */
33
+ public function wpua_has_gravatar($id_or_email="", $has_gravatar=0, $user="", $email="") {
34
+ if(!is_object($id_or_email) && !empty($id_or_email)) {
35
+ // Find user by ID or e-mail address
36
+ $user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
37
+ // Get registered user e-mail address
38
+ $email = !empty($user) ? $user->user_email : "";
39
+ }
40
+ // Check if Gravatar image returns 200 (OK) or 404 (Not Found)
41
+ $hash = md5(strtolower(trim($email)));
42
+ $gravatar = 'http://www.gravatar.com/avatar/'.$hash.'?d=404';
43
+ $data = wp_cache_get($hash);
44
+ if(false === $data) {
45
+ $response = wp_remote_head($gravatar);
46
+ $data = is_wp_error($response) ? 'not200' : $response['response']['code'];
47
+ wp_cache_set($hash, $data, $group="", $expire=60*5);
48
+ }
49
+ $has_gravatar = ($data == '200') ? true : false;
50
+ return $has_gravatar;
51
+ }
52
+
53
+ /**
54
+ * Check if local image
55
+ * @since 1.9.2
56
+ * @param int $attachment_id
57
+ * @uses apply_filters()
58
+ * @uses wp_attachment_is_image()
59
+ * @return bool
60
+ */
61
+ public function wpua_attachment_is_image($attachment_id) {
62
+ $is_image = wp_attachment_is_image($attachment_id);
63
+ /**
64
+ * Filter local image check
65
+ * @since 1.9.2
66
+ * @param bool $is_image
67
+ * @param int $attachment_id
68
+ */
69
+ $is_image = apply_filters('wpua_attachment_is_image', $is_image, $attachment_id);
70
+ return $is_image;
71
+ }
72
+
73
+ /**
74
+ * Get local image tag
75
+ * @since 1.9.2
76
+ * @param int $attachment_id
77
+ * @param int|string $size
78
+ * @param bool $icon
79
+ * @param string $attr
80
+ * @uses apply_filters()
81
+ * @uses wp_get_attachment_image()
82
+ * @return string
83
+ */
84
+ public function wpua_get_attachment_image($attachment_id, $size='thumbnail', $icon=0, $attr='') {
85
+ $image = wp_get_attachment_image($attachment_id, $size, $icon, $attr);
86
+ /**
87
+ * Filter local image tag
88
+ * @since 1.9.2
89
+ * @param string $image
90
+ * @param int $attachment_id
91
+ * @param int|string $size
92
+ * @param bool $icon
93
+ * @param string $attr
94
+ */
95
+ return apply_filters('wpua_get_attachment_image', $image, $attachment_id, $size, $icon, $attr);
96
+ }
97
+
98
+ /**
99
+ * Get local image src
100
+ * @since 1.9.2
101
+ * @param int $attachment_id
102
+ * @param int|string $size
103
+ * @param bool $icon
104
+ * @uses apply_filters()
105
+ * @uses wp_get_attachment_image_src()
106
+ * @return array
107
+ */
108
+ public function wpua_get_attachment_image_src($attachment_id, $size='thumbnail', $icon=0) {
109
+ $image_src_array = wp_get_attachment_image_src($attachment_id, $size, $icon);
110
+ /**
111
+ * Filter local image src
112
+ * @since 1.9.2
113
+ * @param array $image_src_array
114
+ * @param int $attachment_id
115
+ * @param int|string $size
116
+ * @param bool $icon
117
+ */
118
+ return apply_filters('wpua_get_attachment_image_src', $image_src_array, $attachment_id, $size, $icon);
119
+ }
120
+
121
+ /**
122
+ * Returns true if user has wp_user_avatar
123
+ * @since 1.1
124
+ * @param int|string $id_or_email
125
+ * @param bool $has_wpua
126
+ * @param object $user
127
+ * @param int $user_id
128
+ * @uses int $blog_id
129
+ * @uses object $wpdb
130
+ * @uses int $wpua_avatar_default
131
+ * @uses object $wpua_functions
132
+ * @uses get_user_by()
133
+ * @uses get_user_meta()
134
+ * @uses get_blog_prefix()
135
+ * @uses wpua_attachment_is_image()
136
+ * @return bool
137
+ */
138
+ public function has_wp_user_avatar($id_or_email="", $has_wpua=0, $user="", $user_id="") {
139
+ global $blog_id, $wpdb, $wpua_avatar_default, $wpua_functions;
140
+ if(!is_object($id_or_email) && !empty($id_or_email)) {
141
+ // Find user by ID or e-mail address
142
+ $user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
143
+ // Get registered user ID
144
+ $user_id = !empty($user) ? $user->ID : "";
145
+ }
146
+ $wpua = get_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', true);
147
+ // Check if avatar is same as default avatar or on excluded list
148
+ $has_wpua = !empty($wpua) && ($wpua != $wpua_avatar_default) && $wpua_functions->wpua_attachment_is_image($wpua) ? true : false;
149
+ return $has_wpua;
150
+ }
151
+
152
+ /**
153
+ * Replace get_avatar only in get_wp_user_avatar
154
+ * @since 1.4
155
+ * @param string $avatar
156
+ * @param int|string $id_or_email
157
+ * @param int|string $size
158
+ * @param string $default
159
+ * @param string $alt
160
+ * @uses string $avatar_default
161
+ * @uses string $mustache_admin
162
+ * @uses string $mustache_avatar
163
+ * @uses string $mustache_medium
164
+ * @uses string $mustache_original
165
+ * @uses string $mustache_thumbnail
166
+ * @uses object $post
167
+ * @uses int $wpua_avatar_default
168
+ * @uses bool $wpua_disable_gravatar
169
+ * @uses object $wpua_functions
170
+ * @uses apply_filters()
171
+ * @uses get_wp_user_avatar()
172
+ * @uses has_wp_user_avatar()
173
+ * @uses wpua_has_gravatar()
174
+ * @uses wpua_attachment_is_image()
175
+ * @uses wpua_get_attachment_image_src()
176
+ * @uses get_option()
177
+ * @return string $avatar
178
+ */
179
+ public function wpua_get_avatar_filter($avatar, $id_or_email="", $size="", $default="", $alt="") {
180
+ global $avatar_default, $mustache_admin, $mustache_avatar, $mustache_medium, $mustache_original, $mustache_thumbnail, $post, $wpua_avatar_default, $wpua_disable_gravatar, $wpua_functions;
181
+ // User has WPUA
182
+ if(is_object($id_or_email)) {
183
+ if(!empty($id_or_email->comment_author_email)) {
184
+ $avatar = get_wp_user_avatar($id_or_email, $size, $default, $alt);
185
+ } else {
186
+ $avatar = get_wp_user_avatar('unknown@gravatar.com', $size, $default, $alt);
187
+ }
188
+ } else {
189
+ if(has_wp_user_avatar($id_or_email)) {
190
+ $avatar = get_wp_user_avatar($id_or_email, $size, $default, $alt);
191
+ // User has Gravatar and Gravatar is not disabled
192
+ } elseif((bool) $wpua_disable_gravatar != 1 && $wpua_functions->wpua_has_gravatar($id_or_email)) {
193
+ $avatar = $avatar;
194
+ // User doesn't have WPUA or Gravatar and Default Avatar is wp_user_avatar, show custom Default Avatar
195
+ } elseif($avatar_default == 'wp_user_avatar') {
196
+ // Show custom Default Avatar
197
+ if(!empty($wpua_avatar_default) && $wpua_functions->wpua_attachment_is_image($wpua_avatar_default)) {
198
+ // Get image
199
+ $wpua_avatar_default_image = $wpua_functions->wpua_get_attachment_image_src($wpua_avatar_default, array($size,$size));
200
+ // Image src
201
+ $default = $wpua_avatar_default_image[0];
202
+ // Add dimensions if numeric size
203
+ $dimensions = ' width="'.$wpua_avatar_default_image[1].'" height="'.$wpua_avatar_default_image[2].'"';
204
+ } else {
205
+ // Get mustache image based on numeric size comparison
206
+ if($size > get_option('medium_size_w')) {
207
+ $default = $mustache_original;
208
+ } elseif($size <= get_option('medium_size_w') && $size > get_option('thumbnail_size_w')) {
209
+ $default = $mustache_medium;
210
+ } elseif($size <= get_option('thumbnail_size_w') && $size > 96) {
211
+ $default = $mustache_thumbnail;
212
+ } elseif($size <= 96 && $size > 32) {
213
+ $default = $mustache_avatar;
214
+ } elseif($size <= 32) {
215
+ $default = $mustache_admin;
216
+ }
217
+ // Add dimensions if numeric size
218
+ $dimensions = ' width="'.$size.'" height="'.$size.'"';
219
+ }
220
+ // Construct the img tag
221
+ $avatar = '<img src="'.$default.'"'.$dimensions.' alt="'.$alt.'" class="avatar avatar-'.$size.' wp-user-avatar wp-user-avatar-'.$size.' photo avatar-default" />';
222
+ }
223
+ }
224
+ /**
225
+ * Filter get_avatar filter
226
+ * @since 1.9
227
+ * @param string $avatar
228
+ * @param int|string $id_or_email
229
+ * @param int|string $size
230
+ * @param string $default
231
+ * @param string $alt
232
+ */
233
+ return apply_filters('wpua_get_avatar_filter', $avatar, $id_or_email, $size, $default, $alt);
234
+ }
235
+
236
+ /**
237
+ * Get original avatar, for when user removes wp_user_avatar
238
+ * @since 1.4
239
+ * @param int|string $id_or_email
240
+ * @param int|string $size
241
+ * @param string $default
242
+ * @param string $alt
243
+ * @uses string $avatar_default
244
+ * @uses string $mustache_avatar
245
+ * @uses int $wpua_avatar_default
246
+ * @uses bool $wpua_disable_gravatar
247
+ * @uses object $wpua_functions
248
+ * @uses wpua_attachment_is_image()
249
+ * @uses wpua_get_attachment_image_src()
250
+ * @uses wpua_has_gravatar()
251
+ * @uses add_filter()
252
+ * @uses apply_filters()
253
+ * @uses get_avatar()
254
+ * @uses remove_filter()
255
+ * @return string $default
256
+ */
257
+ public function wpua_get_avatar_original($id_or_email="", $size="", $default="", $alt="") {
258
+ global $avatar_default, $mustache_avatar, $wpua_avatar_default, $wpua_disable_gravatar, $wpua_functions;
259
+ // Remove get_avatar filter
260
+ remove_filter('get_avatar', array($wpua_functions, 'wpua_get_avatar_filter'));
261
+ if((bool) $wpua_disable_gravatar != 1) {
262
+ // User doesn't have Gravatar and Default Avatar is wp_user_avatar, show custom Default Avatar
263
+ if(!$wpua_functions->wpua_has_gravatar($id_or_email) && $avatar_default == 'wp_user_avatar') {
264
+ // Show custom Default Avatar
265
+ if(!empty($wpua_avatar_default) && $wpua_functions->wpua_attachment_is_image($wpua_avatar_default)) {
266
+ $wpua_avatar_default_image = $wpua_functions->wpua_get_attachment_image_src($wpua_avatar_default, array($size,$size));
267
+ $default = $wpua_avatar_default_image[0];
268
+ } else {
269
+ $default = $mustache_avatar;
270
+ }
271
+ } else {
272
+ // Get image from Gravatar, whether it's the user's image or default image
273
+ $wpua_image = get_avatar($id_or_email, $size);
274
+ // Takes the img tag, extracts the src
275
+ $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $wpua_image, $matches, PREG_SET_ORDER);
276
+ $default = !empty($matches) ? $matches [0] [1] : "";
277
+ }
278
+ } else {
279
+ if(!empty($wpua_avatar_default) && $wpua_functions->wpua_attachment_is_image($wpua_avatar_default)) {
280
+ $wpua_avatar_default_image = $wpua_functions->wpua_get_attachment_image_src($wpua_avatar_default, array($size,$size));
281
+ $default = $wpua_avatar_default_image[0];
282
+ } else {
283
+ $default = $mustache_avatar;
284
+ }
285
+ }
286
+ // Enable get_avatar filter
287
+ add_filter('get_avatar', array($wpua_functions, 'wpua_get_avatar_filter'), 10, 5);
288
+ /**
289
+ * Filter original avatar src
290
+ * @since 1.9
291
+ * @param string $default
292
+ */
293
+ return apply_filters('wpua_get_avatar_original', $default);
294
+ }
295
+
296
+ /**
297
+ * Find WPUA, show get_avatar if empty
298
+ * @since 1.0
299
+ * @param int|string $id_or_email
300
+ * @param int|string $size
301
+ * @param string $align
302
+ * @param string $alt
303
+ * @uses array $_wp_additional_image_sizes
304
+ * @uses array $all_sizes
305
+ * @uses string $avatar_default
306
+ * @uses int $blog_id
307
+ * @uses object $post
308
+ * @uses object $wpdb
309
+ * @uses int $wpua_avatar_default
310
+ * @uses object $wpua_functions
311
+ * @uses apply_filters()
312
+ * @uses get_the_author_meta()
313
+ * @uses get_blog_prefix()
314
+ * @uses get_user_by()
315
+ * @uses get_query_var()
316
+ * @uses is_author()
317
+ * @uses wpua_attachment_is_image()
318
+ * @uses wpua_get_attachment_image_src()
319
+ * @uses get_option()
320
+ * @uses get_avatar()
321
+ * @return string $avatar
322
+ */
323
+ public function get_wp_user_avatar($id_or_email="", $size='96', $align="", $alt="") {
324
+ global $all_sizes, $avatar_default, $blog_id, $post, $wpdb, $wpua_avatar_default, $wpua_functions, $_wp_additional_image_sizes;
325
+ $email='unknown@gravatar.com';
326
+ // Checks if comment
327
+ if(is_object($id_or_email)) {
328
+ // Checks if comment author is registered user by user ID
329
+ if($id_or_email->user_id != 0) {
330
+ $email = $id_or_email->user_id;
331
+ // Checks that comment author isn't anonymous
332
+ } elseif(!empty($id_or_email->comment_author_email)) {
333
+ // Checks if comment author is registered user by e-mail address
334
+ $user = get_user_by('email', $id_or_email->comment_author_email);
335
+ // Get registered user info from profile, otherwise e-mail address should be value
336
+ $email = !empty($user) ? $user->ID : $id_or_email->comment_author_email;
337
+ }
338
+ $alt = $id_or_email->comment_author;
339
+ } else {
340
+ if(!empty($id_or_email)) {
341
+ // Find user by ID or e-mail address
342
+ $user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
343
+ } else {
344
+ // Find author's name if id_or_email is empty
345
+ $author_name = get_query_var('author_name');
346
+ if(is_author()) {
347
+ // On author page, get user by page slug
348
+ $user = get_user_by('slug', $author_name);
349
+ } else {
350
+ // On post, get user by author meta
351
+ $user_id = get_the_author_meta('ID');
352
+ $user = get_user_by('id', $user_id);
353
+ }
354
+ }
355
+ // Set user's ID and name
356
+ if(!empty($user)) {
357
+ $email = $user->ID;
358
+ $alt = $user->display_name;
359
+ }
360
+ }
361
+ // Checks if user has WPUA
362
+ $wpua_meta = get_the_author_meta($wpdb->get_blog_prefix($blog_id).'user_avatar', $email);
363
+ // Add alignment class
364
+ $alignclass = !empty($align) && ($align == 'left' || $align == 'right' || $align == 'center') ? ' align'.$align : ' alignnone';
365
+ // User has WPUA, check if on excluded list and bypass get_avatar
366
+ if(!empty($wpua_meta) && $wpua_functions->wpua_attachment_is_image($wpua_meta)) {
367
+ // Numeric size use size array
368
+ $get_size = is_numeric($size) ? array($size,$size) : $size;
369
+ // Get image src
370
+ $wpua_image = $wpua_functions->wpua_get_attachment_image_src($wpua_meta, $get_size);
371
+ // Add dimensions to img only if numeric size was specified
372
+ $dimensions = is_numeric($size) ? ' width="'.$wpua_image[1].'" height="'.$wpua_image[2].'"' : "";
373
+ // Construct the img tag
374
+ $avatar = '<img src="'.$wpua_image[0].'"'.$dimensions.' alt="'.$alt.'" class="avatar avatar-'.$size.' wp-user-avatar wp-user-avatar-'.$size.$alignclass.' photo" />';
375
+ } else {
376
+ // Check for custom image sizes
377
+ if(in_array($size, $all_sizes)) {
378
+ if(in_array($size, array('original', 'large', 'medium', 'thumbnail'))) {
379
+ $get_size = ($size == 'original') ? get_option('large_size_w') : get_option($size.'_size_w');
380
+ } else {
381
+ $get_size = $_wp_additional_image_sizes[$size]['width'];
382
+ }
383
+ } else {
384
+ // Numeric sizes leave as-is
385
+ $get_size = $size;
386
+ }
387
+ // User with no WPUA uses get_avatar
388
+ $avatar = get_avatar($email, $get_size, $default="", $alt="");
389
+ // Remove width and height for non-numeric sizes
390
+ if(in_array($size, array('original', 'large', 'medium', 'thumbnail'))) {
391
+ $avatar = preg_replace('/(width|height)=\"\d*\"\s/', "", $avatar);
392
+ $avatar = preg_replace("/(width|height)=\'\d*\'\s/", "", $avatar);
393
+ }
394
+ $replace = array('wp-user-avatar ', 'wp-user-avatar-'.$get_size.' ', 'wp-user-avatar-'.$size.' ', 'avatar-'.$get_size, 'photo');
395
+ $replacements = array("", "", "", 'avatar-'.$size, 'wp-user-avatar wp-user-avatar-'.$size.$alignclass.' photo');
396
+ $avatar = str_replace($replace, $replacements, $avatar);
397
+ }
398
+ /**
399
+ * Filter get_wp_user_avatar
400
+ * @since 1.9
401
+ * @param string $avatar
402
+ * @param int|string $id_or_email
403
+ * @param int|string $size
404
+ * @param string $align
405
+ * @param string $alt
406
+ */
407
+ return apply_filters('get_wp_user_avatar', $avatar, $id_or_email, $size, $align, $alt);
408
+ }
409
+
410
+ /**
411
+ * Return just the image src
412
+ * @since 1.1
413
+ * @param int|string $id_or_email
414
+ * @param int|string $size
415
+ * @param string $align
416
+ * @uses get_wp_user_avatar()
417
+ * @return string
418
+ */
419
+ public function get_wp_user_avatar_src($id_or_email="", $size="", $align="") {
420
+ $wpua_image_src = "";
421
+ // Gets the avatar img tag
422
+ $wpua_image = get_wp_user_avatar($id_or_email, $size, $align);
423
+ // Takes the img tag, extracts the src
424
+ if(!empty($wpua_image)) {
425
+ $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $wpua_image, $matches, PREG_SET_ORDER);
426
+ $wpua_image_src = !empty($matches) ? $matches [0] [1] : "";
427
+ }
428
+ return $wpua_image_src;
429
+ }
430
+ }
431
+
432
+ /**
433
+ * Initialize
434
+ * @since 1.9.2
435
+ */
436
+ function wpua_functions_init() {
437
+ global $wpua_functions;
438
+ $wpua_functions = new WP_User_Avatar_Functions();
439
+ }
440
+ add_action('plugins_loaded', 'wpua_functions_init');
includes/class-wp-user-avatar-list-table.php ADDED
@@ -0,0 +1,400 @@
1
+ <?php
2
+ /**
3
+ * Based on WP_Media_List_Table class.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.7
7
+ */
8
+
9
+ class WP_User_Avatar_List_Table extends WP_List_Table {
10
+ /**
11
+ * Constructor
12
+ * @since 1.8
13
+ * @param array $args
14
+ * @uses array $avatars
15
+ * @uses object $post
16
+ * @uses int $wpua_avatar_default
17
+ * @uses get_query_var()
18
+ * @uses have_posts()
19
+ * @uses the_post()
20
+ * @uses wp_edit_attachments_query
21
+ * @uses WP_Query()
22
+ * @uses wp_reset_query()
23
+ */
24
+ public function __construct($args = array()) {
25
+ global $avatars, $post, $wpua_avatar_default;
26
+ $paged = (get_query_var('page')) ? get_query_var('page') : 1;
27
+ $q = array(
28
+ 'paged' => $paged,
29
+ 'post_type' => 'attachment',
30
+ 'post_status' => 'inherit',
31
+ 'posts_per_page' => '-1',
32
+ 'meta_query' => array(
33
+ array(
34
+ 'key' => '_wp_attachment_wp_user_avatar',
35
+ 'value' => "",
36
+ 'compare' => '!='
37
+ )
38
+ )
39
+ );
40
+ $avatars_wp_query = new WP_Query($q);
41
+ $avatars = array();
42
+ while($avatars_wp_query->have_posts()) : $avatars_wp_query->the_post();
43
+ $avatars[] = $post->ID;
44
+ endwhile;
45
+ wp_reset_query();
46
+ // Include default avatar
47
+ $avatars[] = $wpua_avatar_default;
48
+ parent::__construct(array(
49
+ 'plural' => 'media',
50
+ 'screen' => isset($args['screen']) ? $args['screen'] : null
51
+ ));
52
+ }
53
+
54
+ /**
55
+ * Only users with edit_users capability can use this section
56
+ * @since 1.8
57
+ * @uses current_user_can()
58
+ */
59
+ public function ajax_user_can() {
60
+ return current_user_can('edit_users');
61
+ }
62
+
63
+ /**
64
+ * Search form
65
+ * @since 1.8
66
+ * @param string $text
67
+ * @param int $input_id
68
+ * @uses _admin_search_query()
69
+ * @uses has_items()
70
+ * @uses submit_button()
71
+ */
72
+ public function search_box($text, $input_id) {
73
+ if(empty($_REQUEST['s']) && !$this->has_items()) {
74
+ return;
75
+ }
76
+ $input_id = $input_id.'-search-input';
77
+ if(!empty($_REQUEST['orderby'])) {
78
+ echo '<input type="hidden" name="orderby" value="'.esc_attr($_REQUEST['orderby']).'" />';
79
+ }
80
+ if(!empty($_REQUEST['order'])) {
81
+ echo '<input type="hidden" name="order" value="'.esc_attr($_REQUEST['order']).'" />';
82
+ }
83
+ if(!empty($_REQUEST['post_mime_type'])) {
84
+ echo '<input type="hidden" name="post_mime_type" value="'.esc_attr($_REQUEST['post_mime_type']).'" />';
85
+ }
86
+ if(!empty($_REQUEST['detached'])) {
87
+ echo '<input type="hidden" name="detached" value="'.esc_attr($_REQUEST['detached']).'" />';
88
+ }
89
+ ?>
90
+ <p class="search-box">
91
+ <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
92
+ <input type="hidden" id="page" name="page" value="wp-user-avatar-library" />
93
+ <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" />
94
+ <?php submit_button($text, 'button', false, false, array('id' => 'search-submit')); ?>
95
+ </p>
96
+ <?php
97
+ }
98
+
99
+ /**
100
+ * Return only avatars and paginate results
101
+ * @since 1.8
102
+ * @uses array $avatars
103
+ * @uses wp_edit_attachments_query()
104
+ */
105
+ public function prepare_items() {
106
+ global $avail_post_mime_types, $avatars, $lost, $post, $post_mime_types, $wp_query, $wpdb;
107
+ $q = $_REQUEST;
108
+ $q['post__in'] = $avatars;
109
+ list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query($q);
110
+ $this->is_trash = isset($_REQUEST['status']) && $_REQUEST['status'] == 'trash';
111
+ $this->set_pagination_args(array(
112
+ 'total_items' => $wp_query->found_posts,
113
+ 'total_pages' => $wp_query->max_num_pages,
114
+ 'per_page' => $wp_query->query_vars['posts_per_page'],
115
+ ));
116
+ }
117
+
118
+ /**
119
+ * Links to available table views
120
+ * @since 1.8
121
+ * @uses array $avatars
122
+ * @uses add_query_arg()
123
+ * @uses number_format_i18n()
124
+ * @return array
125
+ */
126
+ public function get_views() {
127
+ global $avatars;
128
+ $type_links = array();
129
+ $_total_posts = count(array_filter($avatars));
130
+ $class = (empty($_GET['post_mime_type']) && !isset($_GET['status'])) ? ' class="current"' : "";
131
+ $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>';
132
+ return $type_links;
133
+ }
134
+
135
+ /**
136
+ * Bulk action available with this table
137
+ * @since 1.8
138
+ * @return array
139
+ */
140
+ public function get_bulk_actions() {
141
+ $actions = array();
142
+ $actions['delete'] = __('Delete Permanently');
143
+ return $actions;
144
+ }
145
+
146
+ /**
147
+ * Current action from bulk actions list
148
+ * @since 1.8
149
+ * @uses current_action()
150
+ * @return string|bool
151
+ */
152
+ public function current_action() {
153
+ return parent::current_action();
154
+ }
155
+
156
+ /**
157
+ * Checks whether table has items
158
+ * @since 1.8
159
+ * @uses have_posts()
160
+ * @return bool
161
+ */
162
+ public function has_items() {
163
+ return have_posts();
164
+ }
165
+
166
+ /**
167
+ * Message displayed when no items
168
+ * @since 1.8
169
+ */
170
+ public function no_items() {
171
+ _e('No media attachments found.');
172
+ }
173
+
174
+ /**
175
+ * Columns in this table
176
+ * @since 1.8
177
+ * @return array
178
+ */
179
+ public function get_columns() {
180
+ $columns = array();
181
+ $columns['cb'] = '<input type="checkbox" />';
182
+ $columns['icon'] = "";
183
+ $columns['title'] = _x('File', 'column name');
184
+ $columns['author'] = __('Author');
185
+ $columns['parent'] = _x('Uploaded to', 'column name');
186
+ $columns['date'] = _x('Date', 'column name');
187
+ return $columns;
188
+ }
189
+
190
+ /**
191
+ * Sortable columns in this table
192
+ * @since 1.8
193
+ * @return array
194
+ */
195
+ public function get_sortable_columns() {
196
+ return array(
197
+ 'title' => 'title',
198
+ 'author' => 'author',
199
+ 'date' => array('date', true)
200
+ );
201
+ }
202
+
203
+ /**
204
+ * Display for rows in table
205
+ * @since 1.8
206
+ * @uses object $post
207
+ * @uses object $wpdb
208
+ * @uses object $wpua_functions
209
+ * @uses add_filter()
210
+ * @uses _draft_or_post_title()
211
+ * @uses _media_states()
212
+ * @uses current_user_can()
213
+ * @uses get_attached_file()
214
+ * @uses get_current_user_id()
215
+ * @uses get_edit_post_link()
216
+ * @uses get_edit_user_link()
217
+ * @uses get_post_mime_type()
218
+ * @uses get_the_author()
219
+ * @uses get_the_author_meta()
220
+ * @uses get_userdata()
221
+ * @uses have_posts()
222
+ * @uses the_post()
223
+ * @uses wpua_get_attachment_image()
224
+ */
225
+ public function display_rows() {
226
+ global $post, $wpdb, $wpua_functions;
227
+ add_filter('the_title','esc_html');
228
+ $alt = "";
229
+ while (have_posts()) : the_post();
230
+ $user_can_edit = current_user_can('edit_post', $post->ID);
231
+ if($this->is_trash && $post->post_status != 'trash' || !$this->is_trash && $post->post_status == 'trash') {
232
+ continue;
233
+ }
234
+ $alt = ('alternate' == $alt) ? "" : 'alternate';
235
+ $post_owner = (get_current_user_id() == $post->post_author) ? 'self' : 'other';
236
+ $att_title = _draft_or_post_title();
237
+ ?>
238
+ <tr id='post-<?php echo $post->ID; ?>' class='<?php echo trim($alt.' author-'.$post_owner.' status-'.$post->post_status); ?>' valign="top">
239
+ <?php
240
+ list($columns, $hidden) = $this->get_column_info();
241
+ foreach($columns as $column_name => $column_display_name) {
242
+ $class = "class='$column_name column-$column_name'";
243
+ $style = "";
244
+ if(in_array($column_name, $hidden)) {
245
+ $style = ' style="display:none;"';
246
+ }
247
+ $attributes = $class.$style;
248
+ switch($column_name) {
249
+ case 'cb':
250
+ ?>
251
+ <th scope="row" class="check-column">
252
+ <?php if($user_can_edit) { ?>
253
+ <label class="screen-reader-text" for="cb-select-<?php the_ID(); ?>"><?php echo sprintf(__('Select %s'), $att_title);?></label>
254
+ <input type="checkbox" name="media[]" id="cb-select-<?php the_ID(); ?>" value="<?php the_ID(); ?>" />
255
+ <?php } ?>
256
+ </th>
257
+ <?php
258
+ break;
259
+ case 'icon':
260
+ $attributes = 'class="column-icon media-icon"'.$style;
261
+ ?>
262
+ <td <?php echo $attributes ?>><?php
263
+ if($thumb = $wpua_functions->wpua_get_attachment_image($post->ID, array(80, 60), true)) {
264
+ if($this->is_trash || !$user_can_edit) {
265
+ echo $thumb;
266
+ } else {
267
+ ?>
268
+ <a href="<?php echo get_edit_post_link($post->ID, true); ?>" title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $att_title)); ?>">
269
+ <?php echo $thumb; ?>
270
+ </a>
271
+ <?php } }
272
+ ?>
273
+ </td>
274
+ <?php
275
+ break;
276
+ case 'title':
277
+ ?>
278
+ <td <?php echo $attributes ?>><strong>
279
+ <?php if($this->is_trash || !$user_can_edit) {
280
+ echo $att_title;
281
+ } else { ?>
282
+ <a href="<?php echo get_edit_post_link($post->ID, true); ?>"
283
+ title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $att_title)); ?>">
284
+ <?php echo $att_title; ?></a>
285
+ <?php };
286
+ _media_states($post); ?></strong>
287
+ <p>
288
+ <?php
289
+ if(preg_match('/^.*?\.(\w+)#x2F;', get_attached_file($post->ID), $matches)) {
290
+ echo esc_html(strtoupper($matches[1]));
291
+ } else {
292
+ echo strtoupper(str_replace('image/', "", get_post_mime_type()));
293
+ }
294
+ ?>
295
+ </p>
296
+ <?php echo $this->row_actions($this->_get_row_actions($post, $att_title)); ?>
297
+ </td>
298
+ <?php
299
+ break;
300
+ case 'author':
301
+ ?>
302
+ <td <?php echo $attributes ?>>
303
+ <?php
304
+ printf('<a href="%s">%s</a>',
305
+ esc_url(add_query_arg(array('author' => get_the_author_meta('ID')), 'upload.php')),
306
+ get_the_author()
307
+ ); ?>
308
+ </td>
309
+ <?php
310
+ break;
311
+ case 'date':
312
+ if('0000-00-00 00:00:00' == $post->post_date) {
313
+ $h_time = __('Unpublished');
314
+ } else {
315
+ $m_time = $post->post_date;
316
+ $time = get_post_time('G', true, $post, false);
317
+ if ((abs($t_diff = time() - $time)) < DAY_IN_SECONDS) {
318
+ if ($t_diff < 0)
319
+ $h_time = sprintf(__('%s from now'), human_time_diff($time));
320
+ else
321
+ $h_time = sprintf(__('%s ago'), human_time_diff($time));
322
+ } else {
323
+ $h_time = mysql2date(__('Y/m/d'), $m_time);
324
+ }
325
+ }
326
+ ?>
327
+ <td <?php echo $attributes ?>><?php echo $h_time ?></td>
328
+ <?php
329
+ break;
330
+ case 'parent':
331
+ global $blog_id, $wpdb;
332
+ // Find all users with this WPUA
333
+ $wpua_metakey = $wpdb->get_blog_prefix($blog_id).'user_avatar';
334
+ $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));
335
+ // Find users without WPUA
336
+ $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, ""));
337
+ $user_array = array();
338
+ ?>
339
+ <td <?php echo $attributes ?>>
340
+ <strong>
341
+ <?php
342
+ if(!empty($wpuas)) {
343
+ foreach($wpuas as $usermeta) {
344
+ $user = get_userdata($usermeta->user_id);
345
+ $user_array[] = '<a href="'.get_edit_user_link($user->ID).'">'.$user->user_login.'</a>';
346
+ }
347
+ } else {
348
+ foreach($nowpuas as $usermeta) {
349
+ $user = get_userdata($usermeta->ID);
350
+ $user_array[] = '<a href="'.get_edit_user_link($user->ID).'">'.$user->user_login.'</a>';
351
+ }
352
+ }
353
+ ?>
354
+ <?php echo implode(', ', array_filter($user_array)); ?>
355
+ </strong>
356
+ </td>
357
+ <?php
358
+ break;
359
+ }
360
+ }
361
+ ?>
362
+ </tr>
363
+ <?php endwhile;
364
+ }
365
+
366
+ /**
367
+ * Actions for rows in table
368
+ * @since 1.8
369
+ * @uses object $post
370
+ * @uses string $att_title
371
+ * @uses _draft_or_post_title()
372
+ * @uses current_user_can()
373
+ * @uses get_edit_post_link()
374
+ * @uses get_permalink()
375
+ * @uses wp_nonce_url()
376
+ * @return array
377
+ */
378
+ public function _get_row_actions($post, $att_title) {
379
+ $actions = array();
380
+ if(current_user_can('edit_post', $post->ID) && !$this->is_trash) {
381
+ $actions['edit'] = '<a href="'.get_edit_post_link($post->ID, true).'">'.__('Edit').'</a>';
382
+ }
383
+ if(current_user_can('delete_post', $post->ID)) {
384
+ if($this->is_trash) {
385
+ $actions['untrash'] = "<a class='submitdelete' href='".wp_nonce_url("post.php?action=untrash&amp;post=$post->ID", 'untrash-post_'.$post->ID)."'>".__('Restore')."</a>";
386
+ } elseif (EMPTY_TRASH_DAYS && MEDIA_TRASH) {
387
+ $actions['trash'] = "<a class='submitdelete' href='".wp_nonce_url("post.php?action=trash&amp;post=$post->ID", 'trash-post_'.$post->ID)."'>".__('Trash')."</a>";
388
+ }
389
+ if($this->is_trash || !EMPTY_TRASH_DAYS || !MEDIA_TRASH) {
390
+ $delete_ays = (!$this->is_trash && !MEDIA_TRASH) ? " onclick='return showNotice.warn();'" : "";
391
+ $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>";
392
+ }
393
+ }
394
+ if(!$this->is_trash) {
395
+ $title = _draft_or_post_title($post->post_parent);
396
+ $actions['view'] = '<a href="'.get_permalink($post->ID).'" title="'.esc_attr(sprintf(__('View &#8220;%s&#8221;'), $title)).'" rel="permalink">'.__('View').'</a>';
397
+ }
398
+ return $actions;
399
+ }
400
+ }
includes/class-wp-user-avatar-resource-manager.php ADDED
@@ -0,0 +1,136 @@
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.7
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
+ * @since 1.9.5
25
+ */
26
+ function __construct() {
27
+ // Validate the request
28
+ $this->validate_request();
29
+ add_action('init', array(&$this, 'start_buffer'), 1);
30
+ }
31
+
32
+ /**
33
+ * Determines if the resource manager should perform it's routines for this request
34
+ * @since 1.9.5
35
+ * @return bool
36
+ */
37
+ function validate_request() {
38
+ $retval = FALSE;
39
+ if(!is_admin()) {
40
+ $retval = TRUE;
41
+ }
42
+ $this->valid_request = $retval;
43
+ }
44
+
45
+ // Start the output buffers
46
+ function start_buffer() {
47
+ ob_start(array(&$this, 'output_buffer_handler'));
48
+ ob_start(array(&$this, 'get_buffer'));
49
+ add_action('wp_print_footer_scripts', array(&$this, 'get_resources'), 1);
50
+ add_action('shutdown', array(&$this, 'shutdown'));
51
+ }
52
+
53
+ function get_resources() {
54
+ ob_start();
55
+ wp_print_styles();
56
+ print_admin_styles();
57
+ $this->styles = ob_get_clean();
58
+ $this->wrote_footer = TRUE;
59
+ }
60
+
61
+ /**
62
+ * Output the buffer after PHP execution has ended (but before shutdown)
63
+ * @since 1.9.5
64
+ * @param string $content
65
+ * @return string
66
+ */
67
+ function output_buffer_handler($content) {
68
+ return $this->output_buffer();
69
+ }
70
+
71
+ /**
72
+ * Removes the closing </html> tag from the output buffer. We'll then write our own closing tag
73
+ * in the shutdown function after running wp_print_footer_scripts()
74
+ * @since 1.9.5
75
+ * @param string $content
76
+ * @return mixed
77
+ */
78
+ function get_buffer($content) {
79
+ $this->buffer = $content;
80
+ return '';
81
+ }
82
+
83
+
84
+ // Moves resources to their appropriate place
85
+ function move_resources() {
86
+ if($this->valid_request) {
87
+ // Move stylesheets to head
88
+ if($this->styles) {
89
+ $this->buffer = str_ireplace('</head>', $this->styles.'</head>', $this->buffer);
90
+ }
91
+ }
92
+ }
93
+
94
+ // When PHP has finished, we output the footer scripts and closing tags
95
+ function output_buffer($in_shutdown=FALSE) {
96
+ // If the footer scripts haven't been outputted, then
97
+ // we need to take action - as they're required
98
+ if(!$this->wrote_footer) {
99
+ // We don't want to manipulate the buffer if it doesn't contain HTML
100
+ if(strpos($this->buffer, '</body>') === FALSE) {
101
+ $this->valid_request = FALSE;
102
+ }
103
+ // The output_buffer() function has been called in the PHP shutdown callback
104
+ // This will allow us to print the scripts ourselves and manipulate the buffer
105
+ if($in_shutdown === TRUE) {
106
+ ob_start();
107
+ if(!did_action('wp_footer')) {
108
+ wp_footer();
109
+ } else {
110
+ wp_print_footer_scripts();
111
+ }
112
+ $this->other_output = ob_get_clean();
113
+ }
114
+ // W3TC isn't activated and we're not in the shutdown callback.
115
+ // We'll therefore add a shutdown callback to print the scripts
116
+ else {
117
+ $this->run_shutdown = TRUE;
118
+ return '';
119
+ }
120
+ }
121
+ // Once we have the footer scripts, we can modify the buffer and
122
+ // move the resources around
123
+ if ($this->wrote_footer) $this->move_resources();
124
+ return $this->buffer;
125
+ }
126
+
127
+ // PHP shutdown callback. Manipulate and output the buffer
128
+ function shutdown() {
129
+ if($this->run_shutdown) echo $this->output_buffer(TRUE);
130
+ }
131
+
132
+ public static function init() {
133
+ $klass = get_class();
134
+ return self::$instance = new $klass;
135
+ }
136
+ }
includes/class-wp-user-avatar-shortcode.php ADDED
@@ -0,0 +1,231 @@
1
+ <?php
2
+ /**
3
+ * Defines shortcodes.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.7
7
+ */
8
+
9
+ class WP_User_Avatar_Shortcode {
10
+ /**
11
+ * Constructor
12
+ * @since 1.8
13
+ * @uses object $wp_user_avatar
14
+ * @uses add_action()
15
+ * @uses add_shortcode()
16
+ */
17
+ public function __construct() {
18
+ global $wp_user_avatar;
19
+ add_shortcode('avatar', array($this, 'wpua_shortcode'));
20
+ add_shortcode('avatar_upload', array($this, 'wpua_edit_shortcode'));
21
+ // Add avatar and scripts to avatar_upload
22
+ add_action('wpua_show_profile', array($wp_user_avatar, 'wpua_action_show_user_profile'));
23
+ add_action('wpua_show_profile', array($wp_user_avatar, 'wpua_media_upload_scripts'));
24
+ add_action('wpua_update', array($wp_user_avatar, 'wpua_action_process_option_update'));
25
+ // Add error messages to avatar_upload
26
+ add_action('wpua_update_errors', array($wp_user_avatar, 'wpua_upload_errors'), 10, 3);
27
+ }
28
+
29
+ /**
30
+ * Display shortcode
31
+ * @since 1.4
32
+ * @param array $atts
33
+ * @param string $content
34
+ * @uses array $_wp_additional_image_sizes
35
+ * @uses array $all_sizes
36
+ * @uses int $blog_id
37
+ * @uses object $post
38
+ * @uses object $wpdb
39
+ * @uses do_shortcode()
40
+ * @uses get_attachment_link()
41
+ * @uses get_blog_prefix()
42
+ * @uses get_option()
43
+ * @uses get_user_by()
44
+ * @uses get_query_var()
45
+ * @uses get_the_author_meta()
46
+ * @uses get_user_meta()
47
+ * @uses get_wp_user_avatar_src()
48
+ * @uses get_wp_user_avatar()
49
+ * @uses image_add_caption()
50
+ * @uses is_author()
51
+ * @uses shortcode_atts()
52
+ * @return string
53
+ */
54
+ public function wpua_shortcode($atts, $content=null) {
55
+ global $all_sizes, $blog_id, $post, $wpdb;
56
+ // Set shortcode attributes
57
+ extract(shortcode_atts(array('user' => "", 'size' => '96', 'align' => "", 'link' => "", 'target' => ""), $atts));
58
+ // Find user by ID, login, slug, or e-mail address
59
+ if(!empty($user)) {
60
+ $user = is_numeric($user) ? get_user_by('id', $user) : get_user_by('login', $user);
61
+ $user = empty($user) ? get_user_by('slug', $user) : $user;
62
+ $user = empty($user) ? get_user_by('email', $user) : $user;
63
+ } else {
64
+ // Find author's name if id_or_email is empty
65
+ $author_name = get_query_var('author_name');
66
+ if(is_author()) {
67
+ // On author page, get user by page slug
68
+ $user = get_user_by('slug', $author_name);
69
+ } else {
70
+ // On post, get user by author meta
71
+ $user_id = get_the_author_meta('ID');
72
+ $user = get_user_by('id', $user_id);
73
+ }
74
+ }
75
+ // Numeric sizes leave as-is
76
+ $get_size = $size;
77
+ // Check for custom image sizes if there are captions
78
+ if(!empty($content)) {
79
+ if(in_array($size, $all_sizes)) {
80
+ if(in_array($size, array('original', 'large', 'medium', 'thumbnail'))) {
81
+ $get_size = ($size == 'original') ? get_option('large_size_w') : get_option($size.'_size_w');
82
+ } else {
83
+ $get_size = $_wp_additional_image_sizes[$size]['width'];
84
+ }
85
+ }
86
+ }
87
+ // Get user ID
88
+ $id_or_email = !empty($user) ? $user->ID : 'unknown@gravatar.com';
89
+ // Check if link is set
90
+ if(!empty($link)) {
91
+ // CSS class is same as link type, except for URL
92
+ $link_class = $link;
93
+ if($link == 'file') {
94
+ // Get image src
95
+ $link = get_wp_user_avatar_src($id_or_email, 'original');
96
+ } elseif($link == 'attachment') {
97
+ // Get attachment URL
98
+ $link = get_attachment_link(get_the_author_meta($wpdb->get_blog_prefix($blog_id).'user_avatar', $id_or_email));
99
+ } else {
100
+ // URL
101
+ $link_class = 'custom';
102
+ }
103
+ // Open in new window
104
+ $target_link = !empty($target) ? ' target="'.$target.'"' : "";
105
+ // Wrap the avatar inside the link
106
+ $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>';
107
+ } else {
108
+ $html = get_wp_user_avatar($id_or_email, $get_size, $align);
109
+ }
110
+ // Check if caption is set
111
+ if(!empty($content)) {
112
+ // Get attachment ID
113
+ $wpua = get_user_meta($id_or_email, $wpdb->get_blog_prefix($blog_id).'user_avatar', true);
114
+ // Clean up caption
115
+ $content = trim($content);
116
+ $content = preg_replace('/\r|\n/', "", $content);
117
+ $content = preg_replace('/<\/p><p>/', "", $content, 1);
118
+ $content = preg_replace('/<\/p><p>#x2F;', "", $content);
119
+ $content = str_replace('</p><p>', "<br /><br />", $content);
120
+ $avatar = do_shortcode(image_add_caption($html, $wpua, $content, $title="", $align, $link, $get_size, $alt=""));
121
+ } else {
122
+ $avatar = $html;
123
+ }
124
+ return $avatar;
125
+ }
126
+
127
+ /**
128
+ * Update user
129
+ * @since 1.8
130
+ * @param bool $user_id
131
+ * @uses add_query_arg()
132
+ * @uses do_action_ref_array()
133
+ * @uses wp_safe_redirect()
134
+ */
135
+ private function wpua_edit_user($user_id=0) {
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 current_user_can()
155
+ * @uses do_action()
156
+ * @uses get_error_messages()
157
+ * @uses get_user_by()
158
+ * @uses is_user_logged_in()
159
+ * @uses is_wp_error()
160
+ * @uses shortcode_atts()
161
+ * @uses wpua_edit_form()
162
+ * @uses wpua_edit_user()
163
+ * @return string
164
+ */
165
+ public function wpua_edit_shortcode($atts) {
166
+ global $current_user, $errors;
167
+ // Shortcode only works with logged-in user
168
+ if(is_user_logged_in()) {
169
+ extract(shortcode_atts(array('user' => ""), $atts));
170
+ // Default user is current user
171
+ $valid_user = $current_user;
172
+ // Find user by ID, login, slug, or e-mail address
173
+ if(!empty($user)) {
174
+ $get_user = is_numeric($user) ? get_user_by('id', $user) : get_user_by('login', $user);
175
+ $get_user = empty($get_user) ? get_user_by('slug', $user) : $get_user;
176
+ $get_user = empty($get_user) ? get_user_by('email', $user) : $get_user;
177
+ // Check if current user can edit this user
178
+ $valid_user = current_user_can('edit_user', $get_user) ? $get_user : null;
179
+ }
180
+ // Show form only for valid user
181
+ if($valid_user) {
182
+ // Save
183
+ if(isset($_POST['submit']) && $_POST['submit'] && $_POST['action'] == 'update') {
184
+ do_action('wpua_update', $valid_user->ID);
185
+ // Check for errors
186
+ $errors = $this->wpua_edit_user($valid_user->ID);
187
+ }
188
+ // Errors
189
+ if(isset($errors) && is_wp_error($errors)) {
190
+ echo '<div class="error"><p>'.implode("</p>\n<p>", $errors->get_error_messages()).'</p></div>';
191
+ } elseif(isset($_GET['updated']) && $_GET['updated'] == '1') {
192
+ echo '<div class="updated"><p><strong>'.__('Profile updated.').'</strong></p></div>';
193
+ }
194
+ // Edit form
195
+ return $this->wpua_edit_form($valid_user);
196
+ }
197
+ }
198
+ }
199
+
200
+ /**
201
+ * Edit form
202
+ * @since 1.8
203
+ * @param object $user
204
+ * @uses do_action()
205
+ * @uses submit_button()
206
+ * @uses wp_nonce_field()
207
+ */
208
+ private function wpua_edit_form($user) {
209
+ ob_start();
210
+ ?>
211
+ <form id="wpua-edit-<?php echo $user->ID; ?>" class="wpua-edit" action="" method="post" enctype="multipart/form-data">
212
+ <?php do_action('wpua_show_profile', $user); ?>
213
+ <input type="hidden" name="action" value="update" />
214
+ <input type="hidden" name="user_id" id="user_id" value="<?php echo esc_attr($user->ID); ?>" />
215
+ <?php wp_nonce_field('update-user_'.$user->ID); ?>
216
+ <?php submit_button(__('Update Profile')); ?>
217
+ </form>
218
+ <?php
219
+ return ob_get_clean();
220
+ }
221
+ }
222
+
223
+ /**
224
+ * Initialize
225
+ * @since 1.9.2
226
+ */
227
+ function wpua_shortcode_init() {
228
+ global $wpua_shortcode;
229
+ $wpua_shortcode = new WP_User_Avatar_Shortcode();
230
+ }
231
+ add_action('init', 'wpua_shortcode_init');
includes/class-wp-user-avatar-subscriber.php ADDED
@@ -0,0 +1,135 @@
1
+ <?php
2
+ /**
3
+ * Settings only for subscribers and contributors.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.7
7
+ */
8
+
9
+ class WP_User_Avatar_Subscriber {
10
+ /**
11
+ * Constructor
12
+ * @since 1.8
13
+ * @uses object $wp_user_avatar
14
+ * @uses bool $wpua_allow_upload
15
+ * @uses add_action()
16
+ * @uses current_user_can()
17
+ * @uses wpua_is_author_or_above()
18
+ */
19
+ public function __construct() {
20
+ global $wp_user_avatar, $wpua_allow_upload;
21
+ if((bool) $wpua_allow_upload == 1) {
22
+ add_action('user_edit_form_tag', array($this, 'wpua_add_edit_form_multipart_encoding'));
23
+ // Only Subscribers lack delete_posts capability
24
+ if(!current_user_can('delete_posts') && !$wp_user_avatar->wpua_is_author_or_above()) {
25
+ add_action('admin_menu', array($this, 'wpua_subscriber_remove_menu_pages'));
26
+ add_action('wp_before_admin_bar_render', array($this, 'wpua_subscriber_remove_menu_bar_items'));
27
+ add_action('wp_dashboard_setup', array($this, 'wpua_subscriber_remove_dashboard_widgets'));
28
+ add_action('admin_init', array($this, 'wpua_subscriber_offlimits'));
29
+ }
30
+ }
31
+ add_action('admin_init', array($this, 'wpua_subscriber_capability'));
32
+ }
33
+
34
+ /**
35
+ * Allow multipart data in form
36
+ * @since 1.4.1
37
+ */
38
+ public function wpua_add_edit_form_multipart_encoding() {
39
+ echo ' enctype="multipart/form-data"';
40
+ }
41
+
42
+ /**
43
+ * Remove menu items
44
+ * @since 1.4
45
+ * @uses remove_menu_page()
46
+ */
47
+ public function wpua_subscriber_remove_menu_pages() {
48
+ remove_menu_page('edit.php');
49
+ remove_menu_page('edit-comments.php');
50
+ remove_menu_page('tools.php');
51
+ }
52
+
53
+ /**
54
+ * Remove menu bar items
55
+ * @since 1.5.1
56
+ * @uses object $wp_admin_bar
57
+ * @uses remove_menu()
58
+ */
59
+ public function wpua_subscriber_remove_menu_bar_items() {
60
+ global $wp_admin_bar;
61
+ $wp_admin_bar->remove_menu('comments');
62
+ $wp_admin_bar->remove_menu('new-content');
63
+ }
64
+
65
+ /**
66
+ * Remove dashboard items
67
+ * @since 1.4
68
+ * @uses remove_meta_box()
69
+ */
70
+ public function wpua_subscriber_remove_dashboard_widgets() {
71
+ remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
72
+ remove_meta_box('dashboard_recent_drafts', 'dashboard', 'side');
73
+ remove_meta_box('dashboard_right_now', 'dashboard', 'normal');
74
+ }
75
+
76
+ /**
77
+ * Restrict access to pages
78
+ * @since 1.4
79
+ * @uses string $pagenow
80
+ * @uses bool $wpua_edit_avatar
81
+ * @uses apply_filters()
82
+ * @uses do_action()
83
+ * @uses wp_die()
84
+ */
85
+ public function wpua_subscriber_offlimits() {
86
+ global $pagenow, $wpua_edit_avatar;
87
+ $offlimits = array('edit.php', 'edit-comments.php', 'post-new.php', 'tools.php');
88
+ if((bool) $wpua_edit_avatar != 1) {
89
+ array_push($offlimits, 'post.php');
90
+ }
91
+ /**
92
+ * Filter restricted pages
93
+ * @since 1.9
94
+ * @param array $offlimits
95
+ */
96
+ $offlimits = apply_filters('wpua_subscriber_offlimits', $offlimits);
97
+ if(in_array($pagenow, $offlimits)) {
98
+ do_action('admin_page_access_denied');
99
+ wp_die(__('You do not have sufficient permissions to access this page.'));
100
+ }
101
+ }
102
+
103
+ /**
104
+ * Give subscribers edit_posts capability
105
+ * @since 1.8.3
106
+ * @uses int $blog_id
107
+ * @uses object $wpdb
108
+ * @uses bool $wpua_allow_upload
109
+ * @uses bool $wpua_edit_avatar
110
+ * @uses get_blog_prefix()
111
+ * @uses get_option()
112
+ * @uses update_option()
113
+ */
114
+ public function wpua_subscriber_capability() {
115
+ global $blog_id, $wpdb, $wpua_allow_upload, $wpua_edit_avatar;
116
+ $wp_user_roles = $wpdb->get_blog_prefix($blog_id).'user_roles';
117
+ $user_roles = get_option($wp_user_roles);
118
+ if((bool) $wpua_allow_upload == 1 && (bool) $wpua_edit_avatar == 1) {
119
+ $user_roles['subscriber']['capabilities']['edit_posts'] = true;
120
+ } else {
121
+ unset($user_roles['subscriber']['capabilities']['edit_posts']);
122
+ }
123
+ update_option($wp_user_roles, $user_roles);
124
+ }
125
+ }
126
+
127
+ /**
128
+ * Initialize
129
+ * @since 1.9.5
130
+ */
131
+ function wpua_subscriber_init() {
132
+ global $wpua_subscriber;
133
+ $wpua_subscriber = new WP_User_Avatar_Subscriber();
134
+ }
135
+ add_action('init', 'wpua_subscriber_init');
includes/class-wp-user-avatar-update.php ADDED
@@ -0,0 +1,116 @@
1
+ <?php
2
+ /**
3
+ * Updates for legacy settings.
4
+ *
5
+ * @package WP User Avatar
6
+ * @version 1.9.7
7
+ */
8
+
9
+ class WP_User_Avatar_Update {
10
+ /**
11
+ * Constructor
12
+ * @since 1.8
13
+ * @uses bool $wpua_default_avatar_updated
14
+ * @uses bool $wpua_media_updated
15
+ * @uses bool $wpua_users_updated
16
+ * @uses add_action()
17
+ */
18
+ public function __construct() {
19
+ global $wpua_default_avatar_updated, $wpua_media_updated, $wpua_users_updated;
20
+ if(empty($wpua_default_avatar_updated)) {
21
+ add_action('admin_init', array($this, 'wpua_default_avatar'));
22
+ }
23
+ if(empty($wpua_users_updated)) {
24
+ add_action('admin_init', array($this, 'wpua_user_meta'));
25
+ }
26
+ if(empty($wpua_media_updated)) {
27
+ add_action('admin_init', array($this, 'wpua_media_state'));
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Update default avatar to new format
33
+ * @since 1.4
34
+ * @uses string $avatar_default
35
+ * @uses string $mustache_original
36
+ * @uses int $wpua_avatar_default
37
+ * @uses update_option()
38
+ * @uses wp_get_attachment_image_src()
39
+ */
40
+ public function wpua_default_avatar() {
41
+ global $avatar_default, $mustache_original, $wpua_avatar_default;
42
+ // If default avatar is the old mustache URL, update it
43
+ if($avatar_default == $mustache_original) {
44
+ update_option('avatar_default', 'wp_user_avatar');
45
+ }
46
+ // If user had an image URL as the default avatar, replace with ID instead
47
+ if(!empty($wpua_avatar_default)) {
48
+ $wpua_avatar_default_image = wp_get_attachment_image_src($wpua_avatar_default, 'medium');
49
+ if($avatar_default == $wpua_avatar_default_image[0]) {
50
+ update_option('avatar_default', 'wp_user_avatar');
51
+ }
52
+ }
53
+ update_option('wp_user_avatar_default_avatar_updated', '1');
54
+ }
55
+
56
+ /**
57
+ * Rename user meta to match database settings
58
+ * @since 1.4
59
+ * @uses int $blog_id
60
+ * @uses object $wpdb
61
+ * @uses delete_user_meta()
62
+ * @uses get_blog_prefix()
63
+ * @uses get_user_meta()
64
+ * @uses get_users()
65
+ * @uses update_option()
66
+ * @uses update_user_meta()
67
+ */
68
+ public function wpua_user_meta() {
69
+ global $blog_id, $wpdb;
70
+ $wpua_metakey = $wpdb->get_blog_prefix($blog_id).'user_avatar';
71
+ // If database tables start with something other than wp_
72
+ if($wpua_metakey != 'wp_user_avatar') {
73
+ $users = get_users();
74
+ // Move current user metakeys to new metakeys
75
+ foreach($users as $user) {
76
+ $wpua = get_user_meta($user->ID, 'wp_user_avatar', true);
77
+ if(!empty($wpua)) {
78
+ update_user_meta($user->ID, $wpua_metakey, $wpua);
79
+ delete_user_meta($user->ID, 'wp_user_avatar');
80
+ }
81
+ }
82
+ }
83
+ update_option('wp_user_avatar_users_updated', '1');
84
+ }
85
+
86
+ /**
87
+ * Add media state to existing avatars
88
+ * @since 1.4
89
+ * @uses int $blog_id
90
+ * @uses object $wpdb
91
+ * @uses add_post_meta()
92
+ * @uses get_blog_prefix()
93
+ * @uses get_results()
94
+ * @uses update_option()
95
+ */
96
+ public function wpua_media_state() {
97
+ global $blog_id, $wpdb;
98
+ // Find all users with WPUA
99
+ $wpua_metakey = $wpdb->get_blog_prefix($blog_id).'user_avatar';
100
+ $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, ""));
101
+ foreach($wpuas as $usermeta) {
102
+ add_post_meta($usermeta->meta_value, '_wp_attachment_wp_user_avatar', $usermeta->user_id);
103
+ }
104
+ update_option('wp_user_avatar_media_updated', '1');
105
+ }
106
+ }
107
+
108
+ /**
109
+ * Initialize
110
+ * @since 1.9.2
111
+ */
112
+ function wpua_update_init() {
113
+ global $wpua_update;
114
+ $wpua_update = new WP_User_Avatar_Update();
115
+ }
116
+ add_action('init', 'wpua_update_init');
includes/class-wp-user-avatar-widget.php ADDED
@@ -0,0 +1,83 @@