Version Description
- Bug Fix: Double underscore for options page title
- Bug Fix: Remove TinyMCE language pack
- Bug Fix: Wrong variables in get_wp_user_avatar filter
Download this release
Release Info
Developer | bangbay |
Plugin | ![]() |
Version | 1.9.1 |
Comparing to | |
See all releases |
Code changes from version 1.5.4 to 1.9.1
- css/wp-user-avatar.css +6 -5
- images/{wp-user-avatar-150x150.png → wpua-150x150.png} +0 -0
- images/wpua-20x20.png +0 -0
- images/{wp-user-avatar-300x300.png → wpua-300x300.png} +0 -0
- images/{wp-user-avatar-32x32.png → wpua-32x32.png} +0 -0
- images/{wp-user-avatar-96x96.png → wpua-96x96.png} +0 -0
- images/wpua-icon.png +0 -0
- images/{wp-user-avatar.png → wpua.png} +0 -0
- includes/class-wp-user-avatar-admin.php +249 -0
- includes/class-wp-user-avatar-functions.php +233 -0
- includes/class-wp-user-avatar-list-table.php +288 -0
- includes/class-wp-user-avatar-shortcode.php +144 -0
- includes/class-wp-user-avatar-subscriber.php +84 -0
- includes/class-wp-user-avatar-update.php +72 -0
- includes/class-wp-user-avatar.php +289 -0
- includes/tinymce/editor_plugin.js +1 -1
- includes/tinymce/window.php +122 -71
- includes/wpua-functions.php +96 -0
- includes/wpua-globals.php +54 -0
- includes/wpua-media-page.php +85 -0
- includes/wpua-options-page.php +162 -0
- includes/{tinymce.php → wpua-tinymce.php} +12 -17
- js/wp-user-avatar-admin.js +25 -22
- js/wp-user-avatar-user.js +31 -0
- js/wp-user-avatar.js +1 -1
- lang/wp-user-avatar-de_DE.mo +0 -0
- lang/wp-user-avatar-de_DE.po +35 -15
- lang/wp-user-avatar-es_ES.mo +0 -0
- lang/wp-user-avatar-es_ES.po +35 -15
- lang/wp-user-avatar-fr_FR.mo +0 -0
- lang/wp-user-avatar-fr_FR.po +35 -15
- lang/wp-user-avatar-pl_PL.mo +0 -0
- lang/wp-user-avatar-pl_PL.po +81 -0
- lang/wp-user-avatar-sv_SE.mo +0 -0
- lang/wp-user-avatar-sv_SE.po +35 -15
- readme.txt +293 -32
- uninstall.php +20 -10
- wp-user-avatar.php +26 -967
css/wp-user-avatar.css
CHANGED
@@ -1,11 +1,12 @@
|
|
1 |
-
#wpua-errors, #wpua-
|
2 |
-
#wpua-
|
|
|
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 {
|
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 |
.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 #wpua-remove, #wpua-edit #wpua-undo { margin-left: 10px !important; }
|
|
|
9 |
#wpua-slider { width: 22.75em; }
|
10 |
+
#wpua-upload-messages span { display: block; }
|
11 |
.wpua-hide { display: none !important; }
|
12 |
+
.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,249 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Defines all of administrative, activation, and deactivation settings.
|
4 |
+
*
|
5 |
+
* @package WP User Avatar
|
6 |
+
* @version 1.9.1
|
7 |
+
*/
|
8 |
+
|
9 |
+
class WP_User_Avatar_Admin {
|
10 |
+
public function __construct() {
|
11 |
+
global $show_avatars, $wpua_allow_upload, $wpua_tinymce;
|
12 |
+
// Initialize default settings
|
13 |
+
register_activation_hook(WPUA_DIR.'wp-user-avatar.php', array($this, 'wpua_options'));
|
14 |
+
// Settings saved to wp_options
|
15 |
+
add_action('admin_init', array($this, 'wpua_options'));
|
16 |
+
// Remove subscribers edit_posts capability
|
17 |
+
register_deactivation_hook(WPUA_DIR.'wp-user-avatar.php', array($this, 'wpua_deactivate'));
|
18 |
+
// Translations
|
19 |
+
load_plugin_textdomain('wp-user-avatar', "", WPUA_FOLDER.'/lang');
|
20 |
+
// Admin menu settings
|
21 |
+
add_action('admin_menu', array($this, 'wpua_admin'));
|
22 |
+
// Default avatar
|
23 |
+
add_filter('default_avatar_select', array($this, 'wpua_add_default_avatar'), 10);
|
24 |
+
add_filter('whitelist_options', array($this, 'wpua_whitelist_options'), 10);
|
25 |
+
// Additional plugin info
|
26 |
+
add_filter('plugin_action_links', array($this, 'wpua_action_links'), 10, 2);
|
27 |
+
add_filter('plugin_row_meta', array($this, 'wpua_row_meta'), 10, 2);
|
28 |
+
// Hide column in Users table if default avatars are enabled
|
29 |
+
if((bool) $show_avatars == 0 && is_admin()) {
|
30 |
+
add_filter('manage_users_columns', array($this, 'wpua_add_column'), 10, 1);
|
31 |
+
add_filter('manage_users_custom_column', array($this, 'wpua_show_column'), 10, 3);
|
32 |
+
}
|
33 |
+
// Media states
|
34 |
+
add_filter('display_media_states', array($this, 'wpua_add_media_state'), 10, 1);
|
35 |
+
// Load TinyMCE only if enabled
|
36 |
+
if((bool) $wpua_tinymce == 1) {
|
37 |
+
include_once(WPUA_INC.'wpua-tinymce.php');
|
38 |
+
}
|
39 |
+
}
|
40 |
+
|
41 |
+
// Settings saved to wp_options
|
42 |
+
public function wpua_options() {
|
43 |
+
add_option('avatar_default_wp_user_avatar', "");
|
44 |
+
add_option('wp_user_avatar_allow_upload', '0');
|
45 |
+
add_option('wp_user_avatar_disable_gravatar', '0');
|
46 |
+
add_option('wp_user_avatar_edit_avatar', '1');
|
47 |
+
add_option('wp_user_avatar_resize_crop', '0');
|
48 |
+
add_option('wp_user_avatar_resize_h', '96');
|
49 |
+
add_option('wp_user_avatar_resize_upload', '0');
|
50 |
+
add_option('wp_user_avatar_resize_w', '96');
|
51 |
+
add_option('wp_user_avatar_tinymce', '1');
|
52 |
+
add_option('wp_user_avatar_upload_size_limit', '0');
|
53 |
+
}
|
54 |
+
|
55 |
+
// On deactivation
|
56 |
+
public function wpua_deactivate() {
|
57 |
+
global $blog_id, $wpdb;
|
58 |
+
$wp_user_roles = $wpdb->get_blog_prefix($blog_id).'user_roles';
|
59 |
+
$user_roles = get_option($wp_user_roles);
|
60 |
+
// Remove subscribers edit_posts capability
|
61 |
+
unset($user_roles['subscriber']['capabilities']['edit_posts']);
|
62 |
+
update_option($wp_user_roles, $user_roles);
|
63 |
+
// Reset all default avatar to Mystery Man
|
64 |
+
update_option('avatar_default', 'mystery');
|
65 |
+
}
|
66 |
+
|
67 |
+
// Add options page and settings
|
68 |
+
public function wpua_admin() {
|
69 |
+
add_menu_page(__('WP User Avatar', 'wp-user-avatar'), __('WP User Avatar', 'wp-user-avatar'), 'manage_options', 'wp-user-avatar', array($this, 'wpua_options_page'), WPUA_URL.'images/wpua-icon.png');
|
70 |
+
add_submenu_page('wp-user-avatar', __('Settings'), __('Settings'), 'manage_options', 'wp-user-avatar', array($this, 'wpua_options_page'));
|
71 |
+
$hook = add_submenu_page('wp-user-avatar', __('Library'), __('Library'), 'manage_options', 'wp-user-avatar-library', array($this, 'wpua_media_page'));
|
72 |
+
add_action("load-$hook", array($this, 'wpua_media_screen_option'));
|
73 |
+
add_filter('set-screen-option', array($this, 'wpua_set_media_screen_option'), 10, 3);
|
74 |
+
add_action('admin_init', array($this, 'wpua_register_settings'));
|
75 |
+
}
|
76 |
+
|
77 |
+
// Checks if current page is settings page
|
78 |
+
public function wpua_is_menu_page() {
|
79 |
+
global $pagenow;
|
80 |
+
$is_menu_page = ($pagenow == 'admin.php' && isset($_GET['page']) && $_GET['page'] == 'wp-user-avatar') ? true : false;
|
81 |
+
return $is_menu_page;
|
82 |
+
}
|
83 |
+
|
84 |
+
// Media page
|
85 |
+
public function wpua_media_page() {
|
86 |
+
require_once(WPUA_INC.'wpua-media-page.php');
|
87 |
+
}
|
88 |
+
|
89 |
+
// Avatars per page
|
90 |
+
public function wpua_media_screen_option() {
|
91 |
+
$option = 'per_page';
|
92 |
+
$args = array(
|
93 |
+
'label' => __('Avatars'),
|
94 |
+
'default' => 10,
|
95 |
+
'option' => 'upload_per_page'
|
96 |
+
);
|
97 |
+
add_screen_option($option, $args);
|
98 |
+
}
|
99 |
+
|
100 |
+
// Save per page setting
|
101 |
+
public function wpua_set_media_screen_option($status, $option, $value) {
|
102 |
+
if($option == 'upload_per_page') {
|
103 |
+
return $value;
|
104 |
+
}
|
105 |
+
return $status;
|
106 |
+
}
|
107 |
+
|
108 |
+
// Options page
|
109 |
+
public function wpua_options_page() {
|
110 |
+
require_once(WPUA_INC.'wpua-options-page.php');
|
111 |
+
}
|
112 |
+
|
113 |
+
// Whitelist settings
|
114 |
+
public function wpua_register_settings() {
|
115 |
+
$wpua_register_settings = array();
|
116 |
+
$wpua_register_settings[] = register_setting('wpua-settings-group', 'avatar_rating');
|
117 |
+
$wpua_register_settings[] = register_setting('wpua-settings-group', 'avatar_default');
|
118 |
+
$wpua_register_settings[] = register_setting('wpua-settings-group', 'avatar_default_wp_user_avatar', 'intval');
|
119 |
+
$wpua_register_settings[] = register_setting('wpua-settings-group', 'show_avatars', 'intval');
|
120 |
+
$wpua_register_settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_tinymce', 'intval');
|
121 |
+
$wpua_register_settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_allow_upload', 'intval');
|
122 |
+
$wpua_register_settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_disable_gravatar', 'intval');
|
123 |
+
$wpua_register_settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_edit_avatar', 'intval');
|
124 |
+
$wpua_register_settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_resize_crop', 'intval');
|
125 |
+
$wpua_register_settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_resize_h', 'intval');
|
126 |
+
$wpua_register_settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_resize_upload', 'intval');
|
127 |
+
$wpua_register_settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_resize_w', 'intval');
|
128 |
+
$wpua_register_settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_upload_size_limit', 'intval');
|
129 |
+
return apply_filters('wpua_register_settings', $wpua_register_settings);
|
130 |
+
}
|
131 |
+
|
132 |
+
// Add default avatar
|
133 |
+
public function wpua_add_default_avatar($avatar_list=null) {
|
134 |
+
global $avatar_default, $mustache_admin, $mustache_medium, $wpua_avatar_default, $wpua_disable_gravatar, $wpua_functions;
|
135 |
+
// Remove get_avatar filter
|
136 |
+
remove_filter('get_avatar', array($wpua_functions, 'wpua_get_avatar_filter'));
|
137 |
+
// Set avatar_list variable
|
138 |
+
$avatar_list = "";
|
139 |
+
// Set avatar defaults
|
140 |
+
$avatar_defaults = array(
|
141 |
+
'mystery' => __('Mystery Man'),
|
142 |
+
'blank' => __('Blank'),
|
143 |
+
'gravatar_default' => __('Gravatar Logo'),
|
144 |
+
'identicon' => __('Identicon (Generated)'),
|
145 |
+
'wavatar' => __('Wavatar (Generated)'),
|
146 |
+
'monsterid' => __('MonsterID (Generated)'),
|
147 |
+
'retro' => __('Retro (Generated)')
|
148 |
+
);
|
149 |
+
// No Default Avatar, set to Mystery Man
|
150 |
+
if(empty($avatar_default)) {
|
151 |
+
$avatar_default = 'mystery';
|
152 |
+
}
|
153 |
+
// Take avatar_defaults and get examples for unknown@gravatar.com
|
154 |
+
foreach($avatar_defaults as $default_key => $default_name) {
|
155 |
+
$avatar = get_avatar('unknown@gravatar.com', 32, $default_key);
|
156 |
+
$selected = ($avatar_default == $default_key) ? 'checked="checked" ' : "";
|
157 |
+
$avatar_list .= "\n\t<label><input type='radio' name='avatar_default' id='avatar_{$default_key}' value='".esc_attr($default_key)."' {$selected}/> ";
|
158 |
+
$avatar_list .= preg_replace("/src='(.+?)'/", "src='\$1&forcedefault=1'", $avatar);
|
159 |
+
$avatar_list .= ' '.$default_name.'</label>';
|
160 |
+
$avatar_list .= '<br />';
|
161 |
+
}
|
162 |
+
// Show remove link if custom Default Avatar is set
|
163 |
+
if(!empty($wpua_avatar_default) && wp_attachment_is_image($wpua_avatar_default)) {
|
164 |
+
$avatar_thumb_src = wp_get_attachment_image_src($wpua_avatar_default, array(32,32));
|
165 |
+
$avatar_thumb = $avatar_thumb_src[0];
|
166 |
+
$hide_remove = "";
|
167 |
+
} else {
|
168 |
+
$avatar_thumb = $mustache_admin;
|
169 |
+
$hide_remove = ' class="wpua-hide"';
|
170 |
+
}
|
171 |
+
// Default Avatar is wp_user_avatar, check the radio button next to it
|
172 |
+
$selected_avatar = ((bool) $wpua_disable_gravatar == 1 || $avatar_default == 'wp_user_avatar') ? ' checked="checked" ' : "";
|
173 |
+
// Wrap WPUA in div
|
174 |
+
$avatar_thumb_img = '<div id="wpua-preview"><img src="'.$avatar_thumb.'" width="32" /></div>';
|
175 |
+
// Add WPUA to list
|
176 |
+
$wpua_list = "\n\t<label><input type='radio' name='avatar_default' id='wp_user_avatar_radio' value='wp_user_avatar'$selected_avatar /> ";
|
177 |
+
$wpua_list .= preg_replace("/src='(.+?)'/", "src='\$1'", $avatar_thumb_img);
|
178 |
+
$wpua_list .= ' '.__('WP User Avatar', 'wp-user-avatar').'</label>';
|
179 |
+
$wpua_list .= '<p id="wpua-edit"><button type="button" class="button" id="wpua-add" name="wpua-add">'.__('Choose Image').'</button>';
|
180 |
+
$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>';
|
181 |
+
$wpua_list .= '<input type="hidden" id="wp-user-avatar" name="avatar_default_wp_user_avatar" value="'.$wpua_avatar_default.'">';
|
182 |
+
if((bool) $wpua_disable_gravatar != 1) {
|
183 |
+
return $wpua_list.'<div id="wp-avatars">'.$avatar_list.'</div>';
|
184 |
+
} else {
|
185 |
+
return $wpua_list;
|
186 |
+
}
|
187 |
+
}
|
188 |
+
|
189 |
+
// Add default avatar_default to whitelist
|
190 |
+
public function wpua_whitelist_options($whitelist_options) {
|
191 |
+
$whitelist_options['discussion'][] = 'avatar_default_wp_user_avatar';
|
192 |
+
return $whitelist_options;
|
193 |
+
}
|
194 |
+
|
195 |
+
// Add actions links on plugin page
|
196 |
+
public function wpua_action_links($links, $file) {
|
197 |
+
if(basename(dirname($file)) == 'wp-user-avatar') {
|
198 |
+
$links[] = '<a href="'.add_query_arg(array('page' => 'wp-user-avatar'), admin_url('admin.php')).'">'.__('Settings').'</a>';
|
199 |
+
}
|
200 |
+
return $links;
|
201 |
+
}
|
202 |
+
|
203 |
+
// Add row meta on plugin page
|
204 |
+
public function wpua_row_meta($links, $file) {
|
205 |
+
if(basename(dirname($file)) == 'wp-user-avatar') {
|
206 |
+
$links[] = '<a href="http://wordpress.org/support/plugin/wp-user-avatar" target="_blank">'.__('Support Forums').'</a>';
|
207 |
+
$links[] = '<a href="http://siboliban.org/donate" target="_blank">'.__('Donate', 'wp-user-avatar').'</a>';
|
208 |
+
}
|
209 |
+
return $links;
|
210 |
+
}
|
211 |
+
|
212 |
+
// Add column to Users table
|
213 |
+
public function wpua_add_column($columns) {
|
214 |
+
return $columns + array('wp-user-avatar' => __('WP User Avatar', 'wp-user-avatar'));
|
215 |
+
}
|
216 |
+
|
217 |
+
// Show thumbnail in Users table
|
218 |
+
public function wpua_show_column($value, $column_name, $user_id) {
|
219 |
+
global $blog_id, $wpdb;
|
220 |
+
$wpua = get_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', true);
|
221 |
+
$wpua_image = wp_get_attachment_image($wpua, array(32,32));
|
222 |
+
if($column_name == 'wp-user-avatar') {
|
223 |
+
$value = $wpua_image;
|
224 |
+
}
|
225 |
+
return $value;
|
226 |
+
}
|
227 |
+
|
228 |
+
// Get list table
|
229 |
+
public function _wpua_get_list_table($class, $args = array()) {
|
230 |
+
require_once(WPUA_INC.'class-wp-user-avatar-list-table.php');
|
231 |
+
$args['screen'] = 'wp-user-avatar';
|
232 |
+
return new $class($args);
|
233 |
+
}
|
234 |
+
|
235 |
+
// Add media states
|
236 |
+
public function wpua_add_media_state($media_states) {
|
237 |
+
global $post, $wpua_avatar_default;
|
238 |
+
$is_wpua = get_post_custom_values('_wp_attachment_wp_user_avatar', $post->ID);
|
239 |
+
if(!empty($is_wpua)) {
|
240 |
+
$media_states[] = __('Avatar');
|
241 |
+
}
|
242 |
+
if(!empty($wpua_avatar_default) && ($wpua_avatar_default == $post->ID)) {
|
243 |
+
$media_states[] = __('Default Avatar');
|
244 |
+
}
|
245 |
+
return apply_filters('wpua_add_media_state', $media_states);
|
246 |
+
}
|
247 |
+
}
|
248 |
+
|
249 |
+
$wpua_admin = new WP_User_Avatar_Admin();
|
includes/class-wp-user-avatar-functions.php
ADDED
@@ -0,0 +1,233 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Core user functions.
|
4 |
+
*
|
5 |
+
* @package WP User Avatar
|
6 |
+
* @version 1.9.1
|
7 |
+
*/
|
8 |
+
|
9 |
+
class WP_User_Avatar_Functions {
|
10 |
+
public function __construct() {
|
11 |
+
add_filter('get_avatar', array($this, 'wpua_get_avatar_filter'), 10, 5);
|
12 |
+
}
|
13 |
+
|
14 |
+
// Returns true if user has Gravatar-hosted image
|
15 |
+
public function wpua_has_gravatar($id_or_email, $has_gravatar=false, $user="", $email="") {
|
16 |
+
if(!is_object($id_or_email) && !empty($id_or_email)) {
|
17 |
+
// Find user by ID or e-mail address
|
18 |
+
$user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
|
19 |
+
// Get registered user e-mail address
|
20 |
+
$email = !empty($user) ? $user->user_email : "";
|
21 |
+
}
|
22 |
+
// Check if Gravatar image returns 200 (OK) or 404 (Not Found)
|
23 |
+
$hash = md5(strtolower(trim($email)));
|
24 |
+
$gravatar = 'http://www.gravatar.com/avatar/'.$hash.'?d=404';
|
25 |
+
$data = wp_cache_get($hash);
|
26 |
+
if(false === $data) {
|
27 |
+
$response = wp_remote_head($gravatar);
|
28 |
+
$data = is_wp_error($response) ? 'not200' : $response['response']['code'];
|
29 |
+
wp_cache_set($hash, $data, $group="", $expire=60*5);
|
30 |
+
}
|
31 |
+
$has_gravatar = ($data == '200') ? true : false;
|
32 |
+
return apply_filters('wpua_has_gravatar', $has_gravatar);
|
33 |
+
}
|
34 |
+
|
35 |
+
// Returns true if user has wp_user_avatar
|
36 |
+
public function has_wp_user_avatar($id_or_email="", $has_wpua=false, $user="", $user_id="") {
|
37 |
+
global $blog_id, $wpdb;
|
38 |
+
if(!is_object($id_or_email) && !empty($id_or_email)) {
|
39 |
+
// Find user by ID or e-mail address
|
40 |
+
$user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
|
41 |
+
// Get registered user ID
|
42 |
+
$user_id = !empty($user) ? $user->ID : "";
|
43 |
+
}
|
44 |
+
$wpua = get_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', true);
|
45 |
+
$has_wpua = !empty($wpua) && wp_attachment_is_image($wpua) ? true : false;
|
46 |
+
return apply_filters('has_wp_user_avatar', $has_wpua);
|
47 |
+
}
|
48 |
+
|
49 |
+
// Replace get_avatar only in get_wp_user_avatar
|
50 |
+
public function wpua_get_avatar_filter($avatar, $id_or_email="", $size="", $default="", $alt="") {
|
51 |
+
global $avatar_default, $mustache_admin, $mustache_avatar, $mustache_medium, $mustache_original, $mustache_thumbnail, $post, $wpua_avatar_default, $wpua_disable_gravatar, $wpua_functions;
|
52 |
+
// User has WPUA
|
53 |
+
if(is_object($id_or_email)) {
|
54 |
+
if(!empty($id_or_email->comment_author_email)) {
|
55 |
+
$avatar = get_wp_user_avatar($id_or_email, $size, $default, $alt);
|
56 |
+
} else {
|
57 |
+
$avatar = get_wp_user_avatar('unknown@gravatar.com', $size, $default, $alt);
|
58 |
+
}
|
59 |
+
} else {
|
60 |
+
if(has_wp_user_avatar($id_or_email)) {
|
61 |
+
$avatar = get_wp_user_avatar($id_or_email, $size, $default, $alt);
|
62 |
+
// User has Gravatar and Gravatar is not disabled
|
63 |
+
} elseif((bool) $wpua_disable_gravatar != 1 && $wpua_functions->wpua_has_gravatar($id_or_email)) {
|
64 |
+
$avatar = $avatar;
|
65 |
+
// User doesn't have WPUA or Gravatar and Default Avatar is wp_user_avatar, show custom Default Avatar
|
66 |
+
} elseif($avatar_default == 'wp_user_avatar') {
|
67 |
+
// Show custom Default Avatar
|
68 |
+
if(!empty($wpua_avatar_default) && wp_attachment_is_image($wpua_avatar_default)) {
|
69 |
+
// Get image
|
70 |
+
$wpua_avatar_default_image = wp_get_attachment_image_src($wpua_avatar_default, array($size,$size));
|
71 |
+
// Image src
|
72 |
+
$default = $wpua_avatar_default_image[0];
|
73 |
+
// Add dimensions if numeric size
|
74 |
+
$dimensions = ' width="'.$wpua_avatar_default_image[1].'" height="'.$wpua_avatar_default_image[2].'"';
|
75 |
+
} else {
|
76 |
+
// Get mustache image based on numeric size comparison
|
77 |
+
if($size > get_option('medium_size_w')) {
|
78 |
+
$default = $mustache_original;
|
79 |
+
} elseif($size <= get_option('medium_size_w') && $size > get_option('thumbnail_size_w')) {
|
80 |
+
$default = $mustache_medium;
|
81 |
+
} elseif($size <= get_option('thumbnail_size_w') && $size > 96) {
|
82 |
+
$default = $mustache_thumbnail;
|
83 |
+
} elseif($size <= 96 && $size > 32) {
|
84 |
+
$default = $mustache_avatar;
|
85 |
+
} elseif($size <= 32) {
|
86 |
+
$default = $mustache_admin;
|
87 |
+
}
|
88 |
+
// Add dimensions if numeric size
|
89 |
+
$dimensions = ' width="'.$size.'" height="'.$size.'"';
|
90 |
+
}
|
91 |
+
// Construct the img tag
|
92 |
+
$avatar = '<img src="'.$default.'"'.$dimensions.' alt="'.$alt.'" class="avatar avatar-'.$size.' wp-user-avatar wp-user-avatar-'.$size.' photo avatar-default" />';
|
93 |
+
}
|
94 |
+
}
|
95 |
+
return apply_filters('wpua_get_avatar_filter', $avatar, $id_or_email, $size, $default, $alt);
|
96 |
+
}
|
97 |
+
|
98 |
+
// Get original avatar, for when user removes wp_user_avatar
|
99 |
+
public function wpua_get_avatar_original($id_or_email, $size="", $default="", $alt="") {
|
100 |
+
global $avatar_default, $mustache_avatar, $wpua_avatar_default, $wpua_disable_gravatar, $wpua_functions;
|
101 |
+
// Remove get_avatar filter
|
102 |
+
remove_filter('get_avatar', array($wpua_functions, 'wpua_get_avatar_filter'));
|
103 |
+
if((bool) $wpua_disable_gravatar != 1) {
|
104 |
+
// User doesn't have Gravatar and Default Avatar is wp_user_avatar, show custom Default Avatar
|
105 |
+
if(!$wpua_functions->wpua_has_gravatar($id_or_email) && $avatar_default == 'wp_user_avatar') {
|
106 |
+
// Show custom Default Avatar
|
107 |
+
if(!empty($wpua_avatar_default) && wp_attachment_is_image($wpua_avatar_default)) {
|
108 |
+
$wpua_avatar_default_image = wp_get_attachment_image_src($wpua_avatar_default, array($size,$size));
|
109 |
+
$default = $wpua_avatar_default_image[0];
|
110 |
+
} else {
|
111 |
+
$default = $mustache_avatar;
|
112 |
+
}
|
113 |
+
} else {
|
114 |
+
// Get image from Gravatar, whether it's the user's image or default image
|
115 |
+
$wpua_image = get_avatar($id_or_email, $size);
|
116 |
+
// Takes the img tag, extracts the src
|
117 |
+
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $wpua_image, $matches, PREG_SET_ORDER);
|
118 |
+
$default = !empty($matches) ? $matches [0] [1] : "";
|
119 |
+
}
|
120 |
+
} else {
|
121 |
+
if(!empty($wpua_avatar_default) && wp_attachment_is_image($wpua_avatar_default)) {
|
122 |
+
$wpua_avatar_default_image = wp_get_attachment_image_src($wpua_avatar_default, array($size,$size));
|
123 |
+
$default = $wpua_avatar_default_image[0];
|
124 |
+
} else {
|
125 |
+
$default = $mustache_avatar;
|
126 |
+
}
|
127 |
+
}
|
128 |
+
// Enable get_avatar filter
|
129 |
+
add_filter('get_avatar', array($wpua_functions, 'wpua_get_avatar_filter'), 10, 5);
|
130 |
+
return apply_filters('wpua_get_avatar_original', $default);
|
131 |
+
}
|
132 |
+
|
133 |
+
// Find WPUA, show get_avatar if empty
|
134 |
+
public function get_wp_user_avatar($id_or_email="", $size='96', $align="", $alt="", $email='unknown@gravatar.com') {
|
135 |
+
global $all_sizes, $avatar_default, $blog_id, $post, $wpdb, $_wp_additional_image_sizes;
|
136 |
+
// Checks if comment
|
137 |
+
if(is_object($id_or_email)) {
|
138 |
+
// Checks if comment author is registered user by user ID
|
139 |
+
if($id_or_email->user_id != 0) {
|
140 |
+
$email = $id_or_email->user_id;
|
141 |
+
// Checks that comment author isn't anonymous
|
142 |
+
} elseif(!empty($id_or_email->comment_author_email)) {
|
143 |
+
// Checks if comment author is registered user by e-mail address
|
144 |
+
$user = get_user_by('email', $id_or_email->comment_author_email);
|
145 |
+
// Get registered user info from profile, otherwise e-mail address should be value
|
146 |
+
$email = !empty($user) ? $user->ID : $id_or_email->comment_author_email;
|
147 |
+
}
|
148 |
+
$alt = $id_or_email->comment_author;
|
149 |
+
} else {
|
150 |
+
if(!empty($id_or_email)) {
|
151 |
+
// Find user by ID or e-mail address
|
152 |
+
$user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
|
153 |
+
} else {
|
154 |
+
// Find author's name if id_or_email is empty
|
155 |
+
$author_name = get_query_var('author_name');
|
156 |
+
if(is_author()) {
|
157 |
+
// On author page, get user by page slug
|
158 |
+
$user = get_user_by('slug', $author_name);
|
159 |
+
} else {
|
160 |
+
// On post, get user by author meta
|
161 |
+
$user_id = get_the_author_meta('ID');
|
162 |
+
$user = get_user_by('id', $user_id);
|
163 |
+
}
|
164 |
+
}
|
165 |
+
// Set user's ID and name
|
166 |
+
if(!empty($user)) {
|
167 |
+
$email = $user->ID;
|
168 |
+
$alt = $user->display_name;
|
169 |
+
}
|
170 |
+
}
|
171 |
+
// Checks if user has WPUA
|
172 |
+
$wpua_meta = get_the_author_meta($wpdb->get_blog_prefix($blog_id).'user_avatar', $email);
|
173 |
+
// Add alignment class
|
174 |
+
$alignclass = !empty($align) && ($align == 'left' || $align == 'right' || $align == 'center') ? ' align'.$align : ' alignnone';
|
175 |
+
// User has WPUA, bypass get_avatar
|
176 |
+
if(!empty($wpua_meta)) {
|
177 |
+
// Numeric size use size array
|
178 |
+
$get_size = is_numeric($size) ? array($size,$size) : $size;
|
179 |
+
// Get image src
|
180 |
+
$wpua_image = wp_get_attachment_image_src($wpua_meta, $get_size);
|
181 |
+
// Add dimensions to img only if numeric size was specified
|
182 |
+
$dimensions = is_numeric($size) ? ' width="'.$wpua_image[1].'" height="'.$wpua_image[2].'"' : "";
|
183 |
+
// Construct the img tag
|
184 |
+
$avatar = '<img src="'.$wpua_image[0].'"'.$dimensions.' alt="'.$alt.'" class="avatar avatar-'.$size.' wp-user-avatar wp-user-avatar-'.$size.$alignclass.' photo" />';
|
185 |
+
} else {
|
186 |
+
// Check for custom image sizes
|
187 |
+
if(in_array($size, $all_sizes)) {
|
188 |
+
if(in_array($size, array('original', 'large', 'medium', 'thumbnail'))) {
|
189 |
+
$get_size = ($size == 'original') ? get_option('large_size_w') : get_option($size.'_size_w');
|
190 |
+
} else {
|
191 |
+
$get_size = $_wp_additional_image_sizes[$size]['width'];
|
192 |
+
}
|
193 |
+
} else {
|
194 |
+
// Numeric sizes leave as-is
|
195 |
+
$get_size = $size;
|
196 |
+
}
|
197 |
+
// User with no WPUA uses get_avatar
|
198 |
+
$avatar = get_avatar($email, $get_size, $default="", $alt="");
|
199 |
+
// Remove width and height for non-numeric sizes
|
200 |
+
if(in_array($size, array('original', 'large', 'medium', 'thumbnail'))) {
|
201 |
+
$avatar = preg_replace('/(width|height)=\"\d*\"\s/', "", $avatar);
|
202 |
+
$avatar = preg_replace("/(width|height)=\'\d*\'\s/", "", $avatar);
|
203 |
+
}
|
204 |
+
$str_replacemes = array('wp-user-avatar ', 'wp-user-avatar-'.$get_size.' ', 'wp-user-avatar-'.$size.' ', 'avatar-'.$get_size, 'photo');
|
205 |
+
$str_replacements = array("", "", "", 'avatar-'.$size, 'wp-user-avatar wp-user-avatar-'.$size.$alignclass.' photo');
|
206 |
+
$avatar = str_replace($str_replacemes, $str_replacements, $avatar);
|
207 |
+
}
|
208 |
+
return apply_filters('get_wp_user_avatar', $avatar, $id_or_email, $size, $align, $alt, $email);
|
209 |
+
}
|
210 |
+
|
211 |
+
// Return just the image src
|
212 |
+
public function get_wp_user_avatar_src($id_or_email, $size="", $align="") {
|
213 |
+
$wpua_image_src = "";
|
214 |
+
// Gets the avatar img tag
|
215 |
+
$wpua_image = get_wp_user_avatar($id_or_email, $size, $align);
|
216 |
+
// Takes the img tag, extracts the src
|
217 |
+
if(!empty($wpua_image)) {
|
218 |
+
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $wpua_image, $matches, PREG_SET_ORDER);
|
219 |
+
$wpua_image_src = !empty($matches) ? $matches [0] [1] : "";
|
220 |
+
}
|
221 |
+
return apply_filters('get_wp_user_avatar_src', $wpua_image_src);
|
222 |
+
}
|
223 |
+
|
224 |
+
// Check if avatar_upload is in use
|
225 |
+
public function wpua_has_shortcode() {
|
226 |
+
global $post;
|
227 |
+
$content = !empty($post->post_content) ? $post->post_content : null;
|
228 |
+
$has_shortcode = has_shortcode($content, 'avatar_upload') ? true : false;
|
229 |
+
return $has_shortcode;
|
230 |
+
}
|
231 |
+
}
|
232 |
+
|
233 |
+
$wpua_functions = new WP_User_Avatar_Functions();
|
includes/class-wp-user-avatar-list-table.php
ADDED
@@ -0,0 +1,288 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Based on WP_Media_List_Table class.
|
4 |
+
*
|
5 |
+
* @package WP User Avatar
|
6 |
+
* @version 1.9.1
|
7 |
+
*/
|
8 |
+
|
9 |
+
class WP_User_Avatar_List_Table extends WP_List_Table {
|
10 |
+
function __construct($args = array()) {
|
11 |
+
global $avatars_array, $post, $wpua_avatar_default;
|
12 |
+
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
|
13 |
+
$q = array(
|
14 |
+
'paged' => $paged,
|
15 |
+
'post_type' => 'attachment',
|
16 |
+
'post_status' => 'inherit',
|
17 |
+
'posts_per_page' => '-1',
|
18 |
+
'meta_query' => array(
|
19 |
+
array(
|
20 |
+
'key' => '_wp_attachment_wp_user_avatar',
|
21 |
+
'value' => '',
|
22 |
+
'compare' => '!='
|
23 |
+
)
|
24 |
+
)
|
25 |
+
);
|
26 |
+
$avatars_wp_query = new WP_Query($q);
|
27 |
+
$avatars_array = array();
|
28 |
+
while($avatars_wp_query->have_posts()) : $avatars_wp_query->the_post();
|
29 |
+
$avatars_array[] = $post->ID;
|
30 |
+
endwhile;
|
31 |
+
wp_reset_query();
|
32 |
+
// Include default avatar
|
33 |
+
$avatars_array[] = $wpua_avatar_default;
|
34 |
+
parent::__construct(array(
|
35 |
+
'plural' => 'media',
|
36 |
+
'screen' => isset($args['screen']) ? $args['screen'] : null
|
37 |
+
));
|
38 |
+
}
|
39 |
+
|
40 |
+
function ajax_user_can() {
|
41 |
+
return current_user_can('upload_files');
|
42 |
+
}
|
43 |
+
|
44 |
+
function search_box($text, $input_id) {
|
45 |
+
if(empty($_REQUEST['s']) && !$this->has_items())
|
46 |
+
return;
|
47 |
+
$input_id = $input_id.'-search-input';
|
48 |
+
if(!empty($_REQUEST['orderby']))
|
49 |
+
echo '<input type="hidden" name="orderby" value="'.esc_attr($_REQUEST['orderby']).'" />';
|
50 |
+
if(!empty($_REQUEST['order']))
|
51 |
+
echo '<input type="hidden" name="order" value="'.esc_attr($_REQUEST['order']).'" />';
|
52 |
+
if(!empty($_REQUEST['post_mime_type']))
|
53 |
+
echo '<input type="hidden" name="post_mime_type" value="'.esc_attr($_REQUEST['post_mime_type']).'" />';
|
54 |
+
if(!empty( $_REQUEST['detached']))
|
55 |
+
echo '<input type="hidden" name="detached" value="'.esc_attr($_REQUEST['detached']).'" />';
|
56 |
+
?>
|
57 |
+
<p class="search-box">
|
58 |
+
<label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
|
59 |
+
<input type="hidden" id="page" name="page" value="wp-user-avatar-library" />
|
60 |
+
<input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" />
|
61 |
+
<?php submit_button($text, 'button', false, false, array('id' => 'search-submit')); ?>
|
62 |
+
</p>
|
63 |
+
<?php
|
64 |
+
}
|
65 |
+
|
66 |
+
function prepare_items() {
|
67 |
+
global $avatars_array, $lost, $wpdb, $wp_query, $post_mime_types, $avail_post_mime_types, $post;
|
68 |
+
$q = $_REQUEST;
|
69 |
+
$q['post__in'] = $avatars_array;
|
70 |
+
list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query($q);
|
71 |
+
$this->is_trash = isset($_REQUEST['status']) && 'trash' == $_REQUEST['status'];
|
72 |
+
$this->set_pagination_args(array(
|
73 |
+
'total_items' => $wp_query->found_posts,
|
74 |
+
'total_pages' => $wp_query->max_num_pages,
|
75 |
+
'per_page' => $wp_query->query_vars['posts_per_page'],
|
76 |
+
));
|
77 |
+
}
|
78 |
+
|
79 |
+
function get_views() {
|
80 |
+
global $avatars_array;
|
81 |
+
$type_links = array();
|
82 |
+
$_total_posts = count(array_filter($avatars_array));
|
83 |
+
$class = (empty($_GET['post_mime_type']) && !isset($_GET['status'])) ? ' class="current"' : '';
|
84 |
+
$type_links['all'] = sprintf('<a href="%s">',esc_url(add_query_arg(array('page' => 'wp-user-avatar-library'), 'admin.php'))).sprintf(_nx('All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $_total_posts, 'uploaded files'), number_format_i18n($_total_posts)).'</a>';
|
85 |
+
return $type_links;
|
86 |
+
}
|
87 |
+
|
88 |
+
function get_bulk_actions() {
|
89 |
+
$actions = array();
|
90 |
+
$actions['delete'] = __('Delete Permanently');
|
91 |
+
return $actions;
|
92 |
+
}
|
93 |
+
|
94 |
+
function current_action() {
|
95 |
+
return parent::current_action();
|
96 |
+
}
|
97 |
+
|
98 |
+
function has_items() {
|
99 |
+
return have_posts();
|
100 |
+
}
|
101 |
+
|
102 |
+
function no_items() {
|
103 |
+
_e('No media attachments found.');
|
104 |
+
}
|
105 |
+
|
106 |
+
function get_columns() {
|
107 |
+
$posts_columns = array();
|
108 |
+
$posts_columns['cb'] = '<input type="checkbox" />';
|
109 |
+
$posts_columns['icon'] = '';
|
110 |
+
$posts_columns['title'] = _x('File', 'column name');
|
111 |
+
$posts_columns['author'] = __('Author');
|
112 |
+
$posts_columns['parent'] = _x('Uploaded to', 'column name');
|
113 |
+
$posts_columns['date'] = _x('Date', 'column name');
|
114 |
+
return $posts_columns;
|
115 |
+
}
|
116 |
+
|
117 |
+
function get_sortable_columns() {
|
118 |
+
return array(
|
119 |
+
'title' => 'title',
|
120 |
+
'author' => 'author',
|
121 |
+
'date' => array('date', true),
|
122 |
+
);
|
123 |
+
}
|
124 |
+
|
125 |
+
function display_rows() {
|
126 |
+
global $post, $wpdb;
|
127 |
+
add_filter('the_title','esc_html');
|
128 |
+
$alt = '';
|
129 |
+
while (have_posts()) : the_post();
|
130 |
+
$user_can_edit = current_user_can('edit_post', $post->ID);
|
131 |
+
|
132 |
+
if($this->is_trash && $post->post_status != 'trash' || !$this->is_trash && $post->post_status == 'trash')
|
133 |
+
continue;
|
134 |
+
|
135 |
+
$alt = ('alternate' == $alt) ? '' : 'alternate';
|
136 |
+
$post_owner = (get_current_user_id() == $post->post_author) ? 'self' : 'other';
|
137 |
+
$att_title = _draft_or_post_title();
|
138 |
+
?>
|
139 |
+
<tr id='post-<?php echo $post->ID; ?>' class='<?php echo trim($alt.' author-'.$post_owner.' status-'.$post->post_status); ?>' valign="top">
|
140 |
+
<?php
|
141 |
+
list( $columns, $hidden ) = $this->get_column_info();
|
142 |
+
foreach($columns as $column_name => $column_display_name) {
|
143 |
+
$class = "class='$column_name column-$column_name'";
|
144 |
+
$style = '';
|
145 |
+
if(in_array($column_name, $hidden)) {
|
146 |
+
$style = ' style="display:none;"';
|
147 |
+
}
|
148 |
+
$attributes = $class.$style;
|
149 |
+
switch($column_name) {
|
150 |
+
case 'cb':
|
151 |
+
?>
|
152 |
+
<th scope="row" class="check-column">
|
153 |
+
<?php if ( $user_can_edit ) { ?>
|
154 |
+
<label class="screen-reader-text" for="cb-select-<?php the_ID(); ?>"><?php echo sprintf(__('Select %s'), $att_title);?></label>
|
155 |
+
<input type="checkbox" name="media[]" id="cb-select-<?php the_ID(); ?>" value="<?php the_ID(); ?>" />
|
156 |
+
<?php } ?>
|
157 |
+
</th>
|
158 |
+
<?php
|
159 |
+
break;
|
160 |
+
case 'icon':
|
161 |
+
$attributes = 'class="column-icon media-icon"'.$style;
|
162 |
+
?>
|
163 |
+
<td <?php echo $attributes ?>><?php
|
164 |
+
if ( $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true ) ) {
|
165 |
+
if ( $this->is_trash || ! $user_can_edit ) {
|
166 |
+
echo $thumb;
|
167 |
+
} else {
|
168 |
+
?>
|
169 |
+
<a href="<?php echo get_edit_post_link( $post->ID, true ); ?>" title="<?php echo esc_attr( sprintf( __( 'Edit “%s”' ), $att_title ) ); ?>">
|
170 |
+
<?php echo $thumb; ?>
|
171 |
+
</a>
|
172 |
+
<?php } }
|
173 |
+
?>
|
174 |
+
</td>
|
175 |
+
<?php
|
176 |
+
break;
|
177 |
+
case 'title':
|
178 |
+
?>
|
179 |
+
<td <?php echo $attributes ?>><strong>
|
180 |
+
<?php if ( $this->is_trash || ! $user_can_edit ) {
|
181 |
+
echo $att_title;
|
182 |
+
} else { ?>
|
183 |
+
<a href="<?php echo get_edit_post_link( $post->ID, true ); ?>"
|
184 |
+
title="<?php echo esc_attr( sprintf( __( 'Edit “%s”' ), $att_title ) ); ?>">
|
185 |
+
<?php echo $att_title; ?></a>
|
186 |
+
<?php };
|
187 |
+
_media_states( $post ); ?></strong>
|
188 |
+
<p>
|
189 |
+
<?php
|
190 |
+
if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) )
|
191 |
+
echo esc_html( strtoupper( $matches[1] ) );
|
192 |
+
else
|
193 |
+
echo strtoupper( str_replace( 'image/', '', get_post_mime_type() ) );
|
194 |
+
?>
|
195 |
+
</p>
|
196 |
+
<?php echo $this->row_actions( $this->_get_row_actions( $post, $att_title ) ); ?>
|
197 |
+
</td>
|
198 |
+
<?php
|
199 |
+
break;
|
200 |
+
case 'author':
|
201 |
+
?>
|
202 |
+
<td <?php echo $attributes ?>>
|
203 |
+
<?php
|
204 |
+
printf( '<a href="%s">%s</a>',
|
205 |
+
esc_url( add_query_arg( array( 'author' => get_the_author_meta('ID') ), 'upload.php' ) ),
|
206 |
+
get_the_author()
|
207 |
+
); ?>
|
208 |
+
</td>
|
209 |
+
<?php
|
210 |
+
break;
|
211 |
+
case 'date':
|
212 |
+
if ( '0000-00-00 00:00:00' == $post->post_date ) {
|
213 |
+
$h_time = __( 'Unpublished' );
|
214 |
+
} else {
|
215 |
+
$m_time = $post->post_date;
|
216 |
+
$time = get_post_time( 'G', true, $post, false );
|
217 |
+
if ( ( abs( $t_diff = time() - $time ) ) < DAY_IN_SECONDS ) {
|
218 |
+
if ( $t_diff < 0 )
|
219 |
+
$h_time = sprintf( __( '%s from now' ), human_time_diff( $time ) );
|
220 |
+
else
|
221 |
+
$h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
|
222 |
+
} else {
|
223 |
+
$h_time = mysql2date( __( 'Y/m/d' ), $m_time );
|
224 |
+
}
|
225 |
+
}
|
226 |
+
?>
|
227 |
+
<td <?php echo $attributes ?>><?php echo $h_time ?></td>
|
228 |
+
<?php
|
229 |
+
break;
|
230 |
+
case 'parent':
|
231 |
+
global $blog_id, $wpdb;
|
232 |
+
// Find all users with this WPUA
|
233 |
+
$wpua_metakey = $wpdb->get_blog_prefix($blog_id).'user_avatar';
|
234 |
+
$wpuas = $wpdb->get_results($wpdb->prepare("SELECT wpum.user_id FROM $wpdb->usermeta AS wpum, $wpdb->users AS wpu WHERE wpum.meta_key = %s AND wpum.meta_value = %d AND wpum.user_id = wpu.ID ORDER BY wpu.user_login", $wpua_metakey, $post->ID));
|
235 |
+
// Find users without WPUA
|
236 |
+
$nowpuas = $wpdb->get_results($wpdb->prepare("SELECT wpu.ID FROM $wpdb->users AS wpu, $wpdb->usermeta AS wpum WHERE wpum.meta_key = %s AND wpum.meta_value = %d AND wpum.user_id = wpu.ID ORDER BY wpu.user_login", $wpua_metakey, ""));
|
237 |
+
$user_array = array();
|
238 |
+
?>
|
239 |
+
<td <?php echo $attributes ?>>
|
240 |
+
<strong>
|
241 |
+
<?php
|
242 |
+
if(!empty($wpuas)) {
|
243 |
+
foreach($wpuas as $usermeta) {
|
244 |
+
$user = get_userdata($usermeta->user_id);
|
245 |
+
$user_array[] = '<a href="'.get_edit_user_link($user->ID).'">'.$user->user_login.'</a>';
|
246 |
+
}
|
247 |
+
} else {
|
248 |
+
foreach($nowpuas as $usermeta) {
|
249 |
+
$user = get_userdata($usermeta->ID);
|
250 |
+
$user_array[] = '<a href="'.get_edit_user_link($user->ID).'">'.$user->user_login.'</a>';
|
251 |
+
}
|
252 |
+
}
|
253 |
+
?>
|
254 |
+
<?php echo implode(', ', array_filter($user_array)); ?>
|
255 |
+
</strong>
|
256 |
+
</td>
|
257 |
+
<?php
|
258 |
+
break;
|
259 |
+
}
|
260 |
+
}
|
261 |
+
?>
|
262 |
+
</tr>
|
263 |
+
<?php endwhile;
|
264 |
+
}
|
265 |
+
|
266 |
+
function _get_row_actions($post, $att_title) {
|
267 |
+
$actions = array();
|
268 |
+
if(current_user_can('edit_post', $post->ID) && !$this->is_trash) {
|
269 |
+
$actions['edit'] = '<a href="'.get_edit_post_link($post->ID, true).'">'.__('Edit').'</a>';
|
270 |
+
}
|
271 |
+
if(current_user_can('delete_post', $post->ID)) {
|
272 |
+
if($this->is_trash) {
|
273 |
+
$actions['untrash'] = "<a class='submitdelete' href='".wp_nonce_url("post.php?action=untrash&post=$post->ID", 'untrash-post_'.$post->ID)."'>".__('Restore')."</a>";
|
274 |
+
} elseif (EMPTY_TRASH_DAYS && MEDIA_TRASH) {
|
275 |
+
$actions['trash'] = "<a class='submitdelete' href='".wp_nonce_url("post.php?action=trash&post=$post->ID", 'trash-post_'. $post->ID)."'>".__('Trash')."</a>";
|
276 |
+
}
|
277 |
+
if($this->is_trash || !EMPTY_TRASH_DAYS || !MEDIA_TRASH) {
|
278 |
+
$delete_ays = (!$this->is_trash && !MEDIA_TRASH) ? " onclick='return showNotice.warn();'" : '';
|
279 |
+
$actions['delete'] = "<a class='submitdelete'$delete_ays href='".wp_nonce_url("post.php?action=delete&post=$post->ID", 'delete-post_'.$post->ID)."'>".__('Delete Permanently')."</a>";
|
280 |
+
}
|
281 |
+
}
|
282 |
+
if(!$this->is_trash) {
|
283 |
+
$title =_draft_or_post_title($post->post_parent);
|
284 |
+
$actions['view'] = '<a href="'.get_permalink($post->ID).'" title="'.esc_attr(sprintf(__('View “%s”'), $title)).'" rel="permalink">'.__('View').'</a>';
|
285 |
+
}
|
286 |
+
return $actions;
|
287 |
+
}
|
288 |
+
}
|
includes/class-wp-user-avatar-shortcode.php
ADDED
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Defines shortcodes.
|
4 |
+
*
|
5 |
+
* @package WP User Avatar
|
6 |
+
* @version 1.9.1
|
7 |
+
*/
|
8 |
+
|
9 |
+
class WP_User_Avatar_Shortcode {
|
10 |
+
public function __construct() {
|
11 |
+
add_shortcode('avatar', array($this, 'wpua_shortcode'));
|
12 |
+
add_shortcode('avatar_upload', array($this, 'wpua_edit_shortcode'));
|
13 |
+
// Add avatar and scripts to avatar_upload
|
14 |
+
add_action('wpua_show_profile', array('wp_user_avatar', 'wpua_action_show_user_profile'));
|
15 |
+
add_action('wpua_show_profile', array('wp_user_avatar', 'wpua_media_upload_scripts'));
|
16 |
+
add_action('wpua_update', array('wp_user_avatar', 'wpua_action_process_option_update'));
|
17 |
+
// Add error messages to avatar_upload
|
18 |
+
add_action('wpua_update_errors', array('wp_user_avatar', 'wpua_upload_errors'), 10, 3);
|
19 |
+
}
|
20 |
+
|
21 |
+
// Display shortcode
|
22 |
+
public function wpua_shortcode($atts, $content=null) {
|
23 |
+
global $all_sizes, $blog_id, $post, $wpdb;
|
24 |
+
// Set shortcode attributes
|
25 |
+
extract(shortcode_atts(array('user' => "", 'size' => '96', 'align' => "", 'link' => "", 'target' => ""), $atts));
|
26 |
+
// Find user by ID, login, slug, or e-mail address
|
27 |
+
if(!empty($user)) {
|
28 |
+
$user = is_numeric($user) ? get_user_by('id', $user) : get_user_by('login', $user);
|
29 |
+
$user = empty($user) ? get_user_by('slug', $user) : $user;
|
30 |
+
$user = empty($user) ? get_user_by('email', $user) : $user;
|
31 |
+
} else {
|
32 |
+
// Find author's name if id_or_email is empty
|
33 |
+
$author_name = get_query_var('author_name');
|
34 |
+
if(is_author()) {
|
35 |
+
// On author page, get user by page slug
|
36 |
+
$user = get_user_by('slug', $author_name);
|
37 |
+
} else {
|
38 |
+
// On post, get user by author meta
|
39 |
+
$user_id = get_the_author_meta('ID');
|
40 |
+
$user = get_user_by('id', $user_id);
|
41 |
+
}
|
42 |
+
}
|
43 |
+
// Numeric sizes leave as-is
|
44 |
+
$get_size = $size;
|
45 |
+
// Check for custom image sizes if there are captions
|
46 |
+
if(!empty($content)) {
|
47 |
+
if(in_array($size, $all_sizes)) {
|
48 |
+
if(in_array($size, array('original', 'large', 'medium', 'thumbnail'))) {
|
49 |
+
$get_size = ($size == 'original') ? get_option('large_size_w') : get_option($size.'_size_w');
|
50 |
+
} else {
|
51 |
+
$get_size = $_wp_additional_image_sizes[$size]['width'];
|
52 |
+
}
|
53 |
+
}
|
54 |
+
}
|
55 |
+
// Get user ID
|
56 |
+
$id_or_email = !empty($user) ? $user->ID : 'unknown@gravatar.com';
|
57 |
+
// Check if link is set
|
58 |
+
if(!empty($link)) {
|
59 |
+
// CSS class is same as link type, except for URL
|
60 |
+
$link_class = $link;
|
61 |
+
if($link == 'file') {
|
62 |
+
// Get image src
|
63 |
+
$link = get_wp_user_avatar_src($id_or_email, 'original');
|
64 |
+
} elseif($link == 'attachment') {
|
65 |
+
// Get attachment URL
|
66 |
+
$link = get_attachment_link(get_the_author_meta($wpdb->get_blog_prefix($blog_id).'user_avatar', $id_or_email));
|
67 |
+
} else {
|
68 |
+
// URL
|
69 |
+
$link_class = 'custom';
|
70 |
+
}
|
71 |
+
// Open in new window
|
72 |
+
$target_link = !empty($target) ? ' target="'.$target.'"' : "";
|
73 |
+
// Wrap the avatar inside the link
|
74 |
+
$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>';
|
75 |
+
} else {
|
76 |
+
$html = get_wp_user_avatar($id_or_email, $get_size, $align);
|
77 |
+
}
|
78 |
+
// Check if caption is set
|
79 |
+
if(!empty($content)) {
|
80 |
+
// Get attachment ID
|
81 |
+
$wpua = get_user_meta($id_or_email, $wpdb->get_blog_prefix($blog_id).'user_avatar', true);
|
82 |
+
// Clean up caption
|
83 |
+
$content = trim($content);
|
84 |
+
$content = preg_replace('/\r|\n/', "", $content);
|
85 |
+
$content = preg_replace('/<\/p><p>/', "", $content, 1);
|
86 |
+
$content = preg_replace('/<\/p><p>$/', "", $content);
|
87 |
+
$content = str_replace('</p><p>', "<br /><br />", $content);
|
88 |
+
$avatar = do_shortcode(image_add_caption($html, $wpua, $content, $title="", $align, $link, $get_size, $alt=""));
|
89 |
+
} else {
|
90 |
+
$avatar = $html;
|
91 |
+
}
|
92 |
+
return $avatar;
|
93 |
+
}
|
94 |
+
|
95 |
+
// Update user
|
96 |
+
private function wpua_edit_user($user_id = 0) {
|
97 |
+
$user = new stdClass;
|
98 |
+
if($user_id) {
|
99 |
+
$update = true;
|
100 |
+
$user->ID = (int) $user_id;
|
101 |
+
} else {
|
102 |
+
$update = false;
|
103 |
+
}
|
104 |
+
$errors = new WP_Error();
|
105 |
+
do_action_ref_array('wpua_update_errors', array(&$errors, $update, &$user));
|
106 |
+
if($errors->get_error_codes()) {
|
107 |
+
return $errors;
|
108 |
+
}
|
109 |
+
if($update) {
|
110 |
+
$user_id = wp_update_user($user);
|
111 |
+
}
|
112 |
+
return $user_id;
|
113 |
+
}
|
114 |
+
|
115 |
+
// Edit shortcode
|
116 |
+
public function wpua_edit_shortcode($atts) {
|
117 |
+
global $current_user, $errors;
|
118 |
+
// Shortcode only works with logged in user
|
119 |
+
if(is_user_logged_in()) {
|
120 |
+
// Save
|
121 |
+
if(isset($_POST['submit']) && $_POST['submit'] && $_POST['action'] == 'update') {
|
122 |
+
do_action('wpua_update', $current_user->ID);
|
123 |
+
// Check for errors
|
124 |
+
$errors = $this->wpua_edit_user($current_user->ID);
|
125 |
+
}
|
126 |
+
// Errors
|
127 |
+
if(isset($errors) && is_wp_error($errors)) {
|
128 |
+
echo '<div class="error"><p>'.implode( "</p>\n<p>", $errors->get_error_messages()).'</p></div>';
|
129 |
+
} elseif(isset($errors) && !is_wp_error($errors)) {
|
130 |
+
echo '<div class="updated"><p><strong>'.__('Profile updated.').'</strong></p></div>';
|
131 |
+
}
|
132 |
+
// Form
|
133 |
+
echo '<form id="wpua-edit-'.$current_user->ID.'" class="wpua-edit" action="'.get_permalink().'" method="post" enctype="multipart/form-data">';
|
134 |
+
do_action('wpua_show_profile', $current_user);
|
135 |
+
echo '<input type="hidden" name="action" value="update" />';
|
136 |
+
echo '<input type="hidden" name="user_id" id="user_id" value="'.esc_attr($current_user->ID).'" />';
|
137 |
+
wp_nonce_field('update-user_'.$current_user->ID);
|
138 |
+
submit_button(__('Save'));
|
139 |
+
echo '</form>';
|
140 |
+
}
|
141 |
+
}
|
142 |
+
}
|
143 |
+
|
144 |
+
$wpua_shortcode = new WP_User_Avatar_Shortcode();
|
includes/class-wp-user-avatar-subscriber.php
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Settings only for subscribers and contributors.
|
4 |
+
*
|
5 |
+
* @package WP User Avatar
|
6 |
+
* @version 1.9.1
|
7 |
+
*/
|
8 |
+
|
9 |
+
class WP_User_Avatar_Subscriber {
|
10 |
+
public function __construct() {
|
11 |
+
global $wp_user_avatar, $wpua_allow_upload;
|
12 |
+
if((bool) $wpua_allow_upload == 1) {
|
13 |
+
add_action('user_edit_form_tag', array($this, 'wpua_add_edit_form_multipart_encoding'));
|
14 |
+
// Only Subscribers lack delete_posts capability
|
15 |
+
if(!current_user_can('delete_posts') && !$wp_user_avatar->wpua_is_author_or_above()) {
|
16 |
+
add_action('admin_menu', array($this, 'wpua_subscriber_remove_menu_pages'));
|
17 |
+
add_action('wp_before_admin_bar_render', array($this, 'wpua_subscriber_remove_menu_bar_items'));
|
18 |
+
add_action('wp_dashboard_setup', array($this, 'wpua_subscriber_remove_dashboard_widgets'));
|
19 |
+
add_action('admin_init', array($this, 'wpua_subscriber_offlimits'));
|
20 |
+
}
|
21 |
+
}
|
22 |
+
add_action('admin_init', array($this, 'wpua_subscriber_capability'));
|
23 |
+
}
|
24 |
+
|
25 |
+
// Allow multipart data in form
|
26 |
+
public function wpua_add_edit_form_multipart_encoding() {
|
27 |
+
echo ' enctype="multipart/form-data"';
|
28 |
+
}
|
29 |
+
|
30 |
+
// Remove menu items
|
31 |
+
public function wpua_subscriber_remove_menu_pages() {
|
32 |
+
remove_menu_page('edit.php');
|
33 |
+
remove_menu_page('edit-comments.php');
|
34 |
+
remove_menu_page('tools.php');
|
35 |
+
}
|
36 |
+
|
37 |
+
// Remove menu bar items
|
38 |
+
public function wpua_subscriber_remove_menu_bar_items() {
|
39 |
+
global $wp_admin_bar;
|
40 |
+
$wp_admin_bar->remove_menu('comments');
|
41 |
+
$wp_admin_bar->remove_menu('new-content');
|
42 |
+
}
|
43 |
+
|
44 |
+
// Remove dashboard items
|
45 |
+
public function wpua_subscriber_remove_dashboard_widgets() {
|
46 |
+
remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
|
47 |
+
remove_meta_box('dashboard_recent_drafts', 'dashboard', 'side');
|
48 |
+
remove_meta_box('dashboard_right_now', 'dashboard', 'normal');
|
49 |
+
}
|
50 |
+
|
51 |
+
// Restrict access to pages
|
52 |
+
public function wpua_subscriber_offlimits() {
|
53 |
+
global $pagenow, $wpua_edit_avatar;
|
54 |
+
$offlimits = array('edit.php', 'edit-comments.php', 'post-new.php', 'tools.php');
|
55 |
+
if((bool) $wpua_edit_avatar != 1) {
|
56 |
+
array_push($offlimits, 'post.php');
|
57 |
+
}
|
58 |
+
$offlimits = apply_filters('wpua_subscriber_offlimits', $offlimits);
|
59 |
+
if(in_array($pagenow, $offlimits)) {
|
60 |
+
do_action('admin_page_access_denied');
|
61 |
+
wp_die(__('You do not have sufficient permissions to access this page.'));
|
62 |
+
}
|
63 |
+
}
|
64 |
+
|
65 |
+
// Give subscribers edit_posts capability
|
66 |
+
public function wpua_subscriber_capability() {
|
67 |
+
global $blog_id, $wpdb, $wpua_allow_upload, $wpua_edit_avatar;;
|
68 |
+
$wp_user_roles = $wpdb->get_blog_prefix($blog_id).'user_roles';
|
69 |
+
$user_roles = get_option($wp_user_roles);
|
70 |
+
if((bool) $wpua_allow_upload == 1 && (bool) $wpua_edit_avatar == 1) {
|
71 |
+
$user_roles['subscriber']['capabilities']['edit_posts'] = true;
|
72 |
+
} else {
|
73 |
+
unset($user_roles['subscriber']['capabilities']['edit_posts']);
|
74 |
+
}
|
75 |
+
update_option($wp_user_roles, $user_roles);
|
76 |
+
}
|
77 |
+
}
|
78 |
+
|
79 |
+
// Initialize WP_User_Avatar_Subscriber
|
80 |
+
function wpua_subcriber_init() {
|
81 |
+
global $wpua_subscriber;
|
82 |
+
$wpua_subscriber = new WP_User_Avatar_Subscriber();
|
83 |
+
}
|
84 |
+
add_action('init', 'wpua_subcriber_init');
|
includes/class-wp-user-avatar-update.php
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Updates for legacy settings.
|
4 |
+
*
|
5 |
+
* @package WP User Avatar
|
6 |
+
* @version 1.9.1
|
7 |
+
*/
|
8 |
+
|
9 |
+
class WP_User_Avatar_Update {
|
10 |
+
public function __construct() {
|
11 |
+
global $wpua_default_avatar_updated, $wpua_media_updated, $wpua_users_updated;
|
12 |
+
if(empty($wpua_default_avatar_updated)) {
|
13 |
+
add_action('admin_init', array($this, 'wpua_default_avatar'));
|
14 |
+
}
|
15 |
+
if(empty($wpua_users_updated)) {
|
16 |
+
add_action('admin_init', array($this, 'wpua_user_meta'));
|
17 |
+
}
|
18 |
+
if(empty($wpua_media_updated)) {
|
19 |
+
add_action('admin_init', array($this, 'wpua_media_state'));
|
20 |
+
}
|
21 |
+
}
|
22 |
+
|
23 |
+
// Update default avatar to new format
|
24 |
+
public function wpua_default_avatar() {
|
25 |
+
global $avatar_default, $mustache_original, $wpua_avatar_default;
|
26 |
+
// If default avatar is the old mustache URL, update it
|
27 |
+
if($avatar_default == $mustache_original) {
|
28 |
+
update_option('avatar_default', 'wp_user_avatar');
|
29 |
+
}
|
30 |
+
// If user had an image URL as the default avatar, replace with ID instead
|
31 |
+
if(!empty($wpua_avatar_default)) {
|
32 |
+
$wpua_avatar_default_image = wp_get_attachment_image_src($wpua_avatar_default, 'medium');
|
33 |
+
if($avatar_default == $wpua_avatar_default_image[0]) {
|
34 |
+
update_option('avatar_default', 'wp_user_avatar');
|
35 |
+
}
|
36 |
+
}
|
37 |
+
update_option('wp_user_avatar_default_avatar_updated', '1');
|
38 |
+
}
|
39 |
+
|
40 |
+
// Rename user meta to match database settings
|
41 |
+
public function wpua_user_meta() {
|
42 |
+
global $blog_id, $wpdb;
|
43 |
+
$wpua_metakey = $wpdb->get_blog_prefix($blog_id).'user_avatar';
|
44 |
+
// If database tables start with something other than wp_
|
45 |
+
if($wpua_metakey != 'wp_user_avatar') {
|
46 |
+
$users = get_users();
|
47 |
+
// Move current user metakeys to new metakeys
|
48 |
+
foreach($users as $user) {
|
49 |
+
$wpua = get_user_meta($user->ID, 'wp_user_avatar', true);
|
50 |
+
if(!empty($wpua)) {
|
51 |
+
update_user_meta($user->ID, $wpua_metakey, $wpua);
|
52 |
+
delete_user_meta($user->ID, 'wp_user_avatar');
|
53 |
+
}
|
54 |
+
}
|
55 |
+
}
|
56 |
+
update_option('wp_user_avatar_users_updated', '1');
|
57 |
+
}
|
58 |
+
|
59 |
+
// Add media state to existing avatars
|
60 |
+
public function wpua_media_state() {
|
61 |
+
global $blog_id, $wpdb;
|
62 |
+
// Find all users with WPUA
|
63 |
+
$wpua_metakey = $wpdb->get_blog_prefix($blog_id).'user_avatar';
|
64 |
+
$wpuas = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->usermeta WHERE meta_key = %s AND meta_value != %d AND meta_value != %d", $wpua_metakey, 0, ""));
|
65 |
+
foreach($wpuas as $usermeta) {
|
66 |
+
add_post_meta($usermeta->meta_value, '_wp_attachment_wp_user_avatar', $usermeta->user_id);
|
67 |
+
}
|
68 |
+
update_option('wp_user_avatar_media_updated', '1');
|
69 |
+
}
|
70 |
+
}
|
71 |
+
|
72 |
+
$wpua_update = new WP_User_Avatar_Update();
|
includes/class-wp-user-avatar.php
ADDED
@@ -0,0 +1,289 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Defines all profile and upload settings.
|
4 |
+
*
|
5 |
+
* @package WP User Avatar
|
6 |
+
* @version 1.9.1
|
7 |
+
*/
|
8 |
+
|
9 |
+
class WP_User_Avatar {
|
10 |
+
public function __construct() {
|
11 |
+
global $pagenow, $show_avatars, $wpua_admin, $wpua_allow_upload;
|
12 |
+
// Add WPUA to profile
|
13 |
+
if($this->wpua_is_author_or_above() || ((bool) $wpua_allow_upload == 1 && is_user_logged_in())) {
|
14 |
+
// Profile functions and scripts
|
15 |
+
add_action('show_user_profile', array('wp_user_avatar', 'wpua_action_show_user_profile'));
|
16 |
+
add_action('edit_user_profile', array('wp_user_avatar', 'wpua_action_show_user_profile'));
|
17 |
+
add_action('personal_options_update', array($this, 'wpua_action_process_option_update'));
|
18 |
+
add_action('edit_user_profile_update', array($this, 'wpua_action_process_option_update'));
|
19 |
+
// Admin scripts
|
20 |
+
$pages = array('profile.php', 'options-discussion.php', 'user-edit.php');
|
21 |
+
if(in_array($pagenow, $pages) || $wpua_admin->wpua_is_menu_page()) {
|
22 |
+
add_action('admin_enqueue_scripts', array($this, 'wpua_media_upload_scripts'));
|
23 |
+
}
|
24 |
+
// Front pages
|
25 |
+
if(!is_admin()) {
|
26 |
+
add_action('show_user_profile', array('wp_user_avatar', 'wpua_media_upload_scripts'));
|
27 |
+
add_action('edit_user_profile', array('wp_user_avatar', 'wpua_media_upload_scripts'));
|
28 |
+
}
|
29 |
+
if(!$this->wpua_is_author_or_above()) {
|
30 |
+
// Upload errors
|
31 |
+
add_action('user_profile_update_errors', array($this, 'wpua_upload_errors'), 10, 3);
|
32 |
+
// Prefilter upload size
|
33 |
+
add_filter('wp_handle_upload_prefilter', array($this, 'wpua_handle_upload_prefilter'));
|
34 |
+
}
|
35 |
+
}
|
36 |
+
add_filter('media_view_settings', array($this, 'wpua_media_view_settings'), 10, 1);
|
37 |
+
}
|
38 |
+
|
39 |
+
// Avatars have no parent posts
|
40 |
+
public function wpua_media_view_settings($settings) {
|
41 |
+
global $post, $wpua_is_profile;
|
42 |
+
// Get post ID so not to interfere with media uploads
|
43 |
+
$post_id = is_object($post) ? $post->ID : 0;
|
44 |
+
// Don't use post ID on front pages if there's a WPUA uploader
|
45 |
+
$settings['post']['id'] = (!is_admin() && $wpua_is_profile == 1) ? 0 : $post_id;
|
46 |
+
return $settings;
|
47 |
+
}
|
48 |
+
|
49 |
+
// Media Uploader
|
50 |
+
public static function wpua_media_upload_scripts($user="") {
|
51 |
+
global $current_user, $mustache_admin, $pagenow, $post, $show_avatars, $wp_user_avatar, $wpua_admin, $wpua_functions, $wpua_is_profile, $wpua_upload_size_limit;
|
52 |
+
// This is a profile page
|
53 |
+
$wpua_is_profile = true;
|
54 |
+
$user = ($pagenow == 'user-edit.php' && isset($_GET['user_id'])) ? get_user_by('id', $_GET['user_id']) : $current_user;
|
55 |
+
wp_enqueue_script('jquery');
|
56 |
+
if($wp_user_avatar->wpua_is_author_or_above()) {
|
57 |
+
wp_enqueue_script('admin-bar');
|
58 |
+
wp_enqueue_media(array('post' => $post));
|
59 |
+
wp_enqueue_script('wp-user-avatar', WPUA_URL.'js/wp-user-avatar.js', array('jquery', 'media-editor'), WPUA_VERSION, true);
|
60 |
+
} else {
|
61 |
+
wp_enqueue_script('wp-user-avatar', WPUA_URL.'js/wp-user-avatar-user.js', array('jquery'), WPUA_VERSION, true);
|
62 |
+
}
|
63 |
+
wp_enqueue_style('wp-user-avatar', WPUA_URL.'css/wp-user-avatar.css', array('media-views'), WPUA_VERSION);
|
64 |
+
// Admin scripts
|
65 |
+
if($pagenow == 'options-discussion.php' || $wpua_admin->wpua_is_menu_page()) {
|
66 |
+
// Size limit slider
|
67 |
+
wp_enqueue_script('jquery-ui-slider');
|
68 |
+
wp_enqueue_style('wp-user-avatar-jqueryui', WPUA_URL.'css/jquery.ui.slider.css', "", null);
|
69 |
+
// Remove/edit settings
|
70 |
+
$wpua_custom_scripts = array('section' => __('Default Avatar'), 'edit_image' => __('Choose Image'), 'select_image' => __('Select Image'), 'avatar_thumb' => $mustache_admin);
|
71 |
+
wp_localize_script('wp-user-avatar', 'wpua_custom', $wpua_custom_scripts);
|
72 |
+
// Settings control
|
73 |
+
wp_enqueue_script('wp-user-avatar-admin', WPUA_URL.'js/wp-user-avatar-admin.js', array('wp-user-avatar'), WPUA_VERSION, true);
|
74 |
+
$wpua_admin_scripts = array('upload_size_limit' => $wpua_upload_size_limit, 'max_upload_size' => wp_max_upload_size());
|
75 |
+
wp_localize_script('wp-user-avatar-admin', 'wpua_admin', $wpua_admin_scripts);
|
76 |
+
} else {
|
77 |
+
// User remove/edit settings
|
78 |
+
$avatar_medium_src = (bool) $show_avatars == 1 ? $wpua_functions->wpua_get_avatar_original($user->user_email, 96) : includes_url().'images/blank.gif';
|
79 |
+
$wpua_custom_scripts = array('section' => $user->display_name, 'edit_image' => __('Choose Image'), 'select_image' => __('Select Image'), 'avatar_thumb' => $avatar_medium_src);
|
80 |
+
wp_localize_script('wp-user-avatar', 'wpua_custom', $wpua_custom_scripts);
|
81 |
+
}
|
82 |
+
}
|
83 |
+
|
84 |
+
// Add to edit user profile
|
85 |
+
public static function wpua_action_show_user_profile($user) {
|
86 |
+
global $blog_id, $current_user, $show_avatars, $wpdb, $wp_user_avatar, $wpua_allow_upload, $wpua_edit_avatar, $wpua_functions, $wpua_upload_size_limit_with_units;
|
87 |
+
// Get WPUA attachment ID
|
88 |
+
$wpua = get_user_meta($user->ID, $wpdb->get_blog_prefix($blog_id).'user_avatar', true);
|
89 |
+
// Show remove button if WPUA is set
|
90 |
+
$hide_remove = !has_wp_user_avatar($user->ID) ? 'wpua-hide' : "";
|
91 |
+
// Hide image tags if show avatars is off
|
92 |
+
$hide_images = !has_wp_user_avatar($user->ID) && (bool) $show_avatars == 0 ? 'wpua-no-avatars' : "";
|
93 |
+
// If avatars are enabled, get original avatar image or show blank
|
94 |
+
$avatar_medium_src = (bool) $show_avatars == 1 ? $wpua_functions->wpua_get_avatar_original($user->user_email, 96) : includes_url().'images/blank.gif';
|
95 |
+
// Check if user has wp_user_avatar, if not show image from above
|
96 |
+
$avatar_medium = has_wp_user_avatar($user->ID) ? get_wp_user_avatar_src($user->ID, 'medium') : $avatar_medium_src;
|
97 |
+
// Check if user has wp_user_avatar, if not show image from above
|
98 |
+
$avatar_thumbnail = has_wp_user_avatar($user->ID) ? get_wp_user_avatar_src($user->ID, 96) : $avatar_medium_src;
|
99 |
+
$edit_attachment_link = add_query_arg(array('post' => $wpua, 'action' => 'edit'), admin_url('post.php'));
|
100 |
+
?>
|
101 |
+
<?php do_action('wpua_before_avatar'); ?>
|
102 |
+
<input type="hidden" name="wp-user-avatar" id="wp-user-avatar" value="<?php echo $wpua; ?>" />
|
103 |
+
<?php if($wp_user_avatar->wpua_is_author_or_above()) : // Button to launch Media Uploader ?>
|
104 |
+
<p id="wpua-add-button"><button type="button" class="button" id="wpua-add" name="wpua-add"><?php _e('Choose Image'); ?></button></p>
|
105 |
+
<?php elseif(!$wp_user_avatar->wpua_is_author_or_above() && !has_wp_user_avatar($current_user->ID)) : // Upload button ?>
|
106 |
+
<p id="wpua-upload-button">
|
107 |
+
<input name="wpua-file" id="wpua-file" type="file" />
|
108 |
+
<button type="submit" class="button" id="wpua-upload" name="submit" value="<?php _e('Upload'); ?>"><?php _e('Upload'); ?></button>
|
109 |
+
</p>
|
110 |
+
<p id="wpua-upload-messages">
|
111 |
+
<span id="wpua-max-upload"><?php printf(__('Maximum upload file size: %d%s.'), esc_html($wpua_upload_size_limit_with_units), esc_html('KB')); ?></span>
|
112 |
+
<span id="wpua-allowed-files"><?php _e('Allowed Files'); ?>: <?php _e('<code>jpg jpeg png gif</code>'); ?></span>
|
113 |
+
</p>
|
114 |
+
<?php elseif((bool) $wpua_edit_avatar == 1 && !$wp_user_avatar->wpua_is_author_or_above() && has_wp_user_avatar($current_user->ID) && $wp_user_avatar->wpua_author($wpua, $current_user->ID)) : // Edit button ?>
|
115 |
+
<p id="wpua-edit-button"><button type="button" class="button" id="wpua-edit" name="wpua-edit" onclick="window.open('<?php echo $edit_attachment_link; ?>', '_self');"><?php _e('Edit Image'); ?></button></p>
|
116 |
+
<?php endif; ?>
|
117 |
+
<div id="wpua-images" class="<?php echo $hide_images; ?>">
|
118 |
+
<p id="wpua-preview">
|
119 |
+
<img src="<?php echo $avatar_medium; ?>" alt="" />
|
120 |
+
<span class="description"><?php _e('Original Size'); ?></span>
|
121 |
+
</p>
|
122 |
+
<p id="wpua-thumbnail">
|
123 |
+
<img src="<?php echo $avatar_thumbnail; ?>" alt="" />
|
124 |
+
<span class="description"><?php _e('Thumbnail'); ?></span>
|
125 |
+
</p>
|
126 |
+
<p id="wpua-remove-button" class="<?php echo $hide_remove; ?>"><button type="button" class="button" id="wpua-remove" name="wpua-remove"><?php _e('Remove Image'); ?></button></p>
|
127 |
+
<p id="wpua-undo-button"><button type="button" class="button" id="wpua-undo" name="wpua-undo"><?php _e('Undo'); ?></button></p>
|
128 |
+
</div>
|
129 |
+
<?php do_action('wpua_after_avatar'); ?>
|
130 |
+
<?php
|
131 |
+
}
|
132 |
+
|
133 |