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+)#x2F;', 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>#x2F;', "", $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 @@