Custom User Profile Photo - Version 0.5

Version Description

  • Major Update - please be sure to backup your site and db.
  • Replaced update_user_meta with update_user_attribute per WordPress VIP Standards.
  • Replaced get_home_url with get_site_url for users where the edit image link was returning a 404. Credit: SOMTIJDS
  • Fixed textdomain loading issue.
  • Added Spanish translation. Credit: David Prez
  • Updated and formatted code per PHPCS. Credit: jmichaelward
  • Refactored multiple functions and variables for simplicity and compatibility. Credit: jmichaelward
Download this release

Release Info

Developer 3five
Plugin Icon wp plugin Custom User Profile Photo
Version 0.5
Comparing to
See all releases

Code changes from version 0.4 to 0.5

3five_cupp.php CHANGED
@@ -1,248 +1,304 @@
1
- <?php
2
- /*
3
- Plugin Name: Custom User Profile Photo
4
- Plugin URI: http://3five.com
5
- Description: A simple and effective custom WordPress user profile photo plugin. This plugin leverages the WordPress Media Uploader functionality. To use this plugin go to the users tab and select a user. The new field can be found below the password fields for that user.
6
- Author: 3five
7
- Author URI: http://3five.com
8
- Text Domain: custom-user-profile-photo
9
- Domain Path: /languages/
10
- Version: 0.4
11
- */
12
-
13
- /**
14
- * This program has been developed for use with the WordPress Software.
15
- *
16
- * It is distributed as free software with the intent that it will be
17
- * usefull and does not ship with any WARRANTY.
18
- *
19
- * USAGE
20
- * // Default:
21
- * This will override the WordPress get_avatar hook
22
- *
23
- * // Custom placement:
24
- * <?php $imgURL = get_cupp_meta( $user_id, $size ); ?>
25
- * or
26
- * <img src="<?php echo get_cupp_meta( $user_id, $size ); ?>">
27
- *
28
- * Beginner WordPress template editing skill required. Place the above tag in your template and provide the two parameters.
29
- * @param $user_id Default: $post->post_author. Will accept any valid user ID passed into this parameter.
30
- * @param $size Default: 'thumbnail'. Accepts all default WordPress sizes and any custom sizes made by the add_image_size() function.
31
- * @return {url} Use this inside the src attribute of an image tag or where you need to call the image url.
32
- *
33
- * Inquiries, suggestions and feedback can be sent to support@3five.com
34
- *
35
- * This is plugin is intented for Author, Editor and Admin role post/page authors. Thank you for downloading our plugin.
36
- * We hope this WordPress plugin meets your needs.
37
- *
38
- * Happy coding!
39
- * - 3five
40
- *
41
- * Resources:
42
- * Steven Slack - http://s2web.staging.wpengine.com/226/
43
- * • Pippin Williamson - https://gist.github.com/pippinsplugins/29bebb740e09e395dc06
44
- * Mike Jolley - https://gist.github.com/mikejolley/3a3b366cb62661727263#file-gistfile1-php
45
- *
46
- */
47
-
48
-
49
- // Enqueue scripts and styles
50
- add_action( 'admin_enqueue_scripts', 'cupp_enqueue_scripts_styles' );
51
- function cupp_enqueue_scripts_styles() {
52
- // Register
53
- wp_register_style( 'cupp_admin_css', plugins_url( 'custom-user-profile-photo/css/styles.css' ), false, '1.0.0', 'all' );
54
- wp_register_script( 'cupp_admin_js', plugins_url( 'custom-user-profile-photo/js/scripts.js' ), array('jquery'), '1.0.0', true );
55
-
56
- // Enqueue
57
- wp_enqueue_style( 'cupp_admin_css' );
58
- wp_enqueue_script( 'cupp_admin_js' );
59
- }
60
-
61
- // Show the new image field in the user profile page.
62
- add_action( 'show_user_profile', 'cupp_profile_img_fields' );
63
- add_action( 'edit_user_profile', 'cupp_profile_img_fields' );
64
-
65
- function cupp_profile_img_fields( $user ) {
66
- if(!current_user_can('upload_files'))
67
- return false;
68
-
69
- // vars
70
- $cupp_url = get_the_author_meta( 'cupp_meta', $user->ID );
71
- $cupp_upload_url = get_the_author_meta( 'cupp_upload_meta', $user->ID );
72
- $cupp_upload_edit_url = get_the_author_meta( 'cupp_upload_edit_meta', $user->ID );
73
-
74
- if(!$cupp_upload_url){
75
- $btn_text = 'Upload New Image';
76
- } else {
77
- $cupp_upload_edit_url = get_home_url().get_the_author_meta( 'cupp_upload_edit_meta', $user->ID );
78
- $btn_text = 'Change Current Image';
79
- }
80
- ?>
81
-
82
- <div id="cupp_container">
83
- <h3><?php _e( 'Custom User Profile Photo', 'custom-user-profile-photo' ); ?></h3>
84
-
85
- <table class="form-table">
86
-
87
- <tr>
88
- <th><label for="cupp_meta"><?php _e( 'Profile Photo', 'custom-user-profile-photo' ); ?></label></th>
89
- <td>
90
- <!-- Outputs the image after save -->
91
- <div id="current_img">
92
- <?php if($cupp_upload_url): ?>
93
- <img src="<?php echo esc_url( $cupp_upload_url ); ?>" class="cupp-current-img">
94
- <div class="edit_options uploaded">
95
- <a class="remove_img"><span>Remove</span></a>
96
- <a href="<?php echo $cupp_upload_edit_url; ?>" class="edit_img" target="_blank"><span>Edit</span></a>
97
- </div>
98
- <?php elseif($cupp_url) : ?>
99
- <img src="<?php echo esc_url( $cupp_url ); ?>" class="cupp-current-img">
100
- <div class="edit_options single">
101
- <a class="remove_img"><span>Remove</span></a>
102
- </div>
103
- <?php else : ?>
104
- <img src="<?php echo plugins_url( 'custom-user-profile-photo/img/placeholder.gif' ); ?>" class="cupp-current-img placeholder">
105
- <?php endif; ?>
106
- </div>
107
-
108
- <!-- Select an option: Upload to WPMU or External URL -->
109
- <div id="cupp_options">
110
- <input type="radio" id="upload_option" name="img_option" value="upload" class="tog" checked>
111
- <label for="upload_option">Upload New Image</label><br>
112
- <input type="radio" id="external_option" name="img_option" value="external" class="tog">
113
- <label for="external_option">Use External URL</label><br>
114
- </div>
115
-
116
- <!-- Hold the value here if this is a WPMU image -->
117
- <div id="cupp_upload">
118
- <input type="hidden" name="cupp_placeholder_meta" id="cupp_placeholder_meta" value="<?php echo plugins_url( 'custom-user-profile-photo/img/placeholder.gif' ); ?>" class="hidden" />
119
- <input type="hidden" name="cupp_upload_meta" id="cupp_upload_meta" value="<?php echo esc_url_raw( $cupp_upload_url ); ?>" class="hidden" />
120
- <input type="hidden" name="cupp_upload_edit_meta" id="cupp_upload_edit_meta" value="<?php echo esc_url_raw( $cupp_upload_edit_url ); ?>" class="hidden" />
121
- <input type='button' class="cupp_wpmu_button button-primary" value="<?php _e( $btn_text, 'custom-user-profile-photo' ); ?>" id="uploadimage"/><br />
122
- </div>
123
- <!-- Outputs the text field and displays the URL of the image retrieved by the media uploader -->
124
- <div id="cupp_external">
125
- <input type="text" name="cupp_meta" id="cupp_meta" value="<?php echo esc_url_raw( $cupp_url ); ?>" class="regular-text" />
126
- </div>
127
- <!-- Outputs the save button -->
128
- <span class="description"><?php _e( 'Upload a custom photo for your user profile or use a URL to a pre-existing photo.', 'custom-user-profile-photo' ); ?></span>
129
- <p class="description"><?php _e('Update Profile to save your changes.', 'custom-user-profile-photo'); ?></p>
130
- </td>
131
- </tr>
132
-
133
- </table><!-- end form-table -->
134
- </div> <!-- end #cupp_container -->
135
-
136
- <?php wp_enqueue_media(); // Enqueue the WordPress Media Uploader ?>
137
-
138
- <?php }
139
-
140
- // Save the new user CUPP url.
141
- add_action( 'personal_options_update', 'cupp_save_img_meta' );
142
- add_action( 'edit_user_profile_update', 'cupp_save_img_meta' );
143
-
144
- function cupp_save_img_meta( $user_id ) {
145
-
146
- if ( !current_user_can( 'upload_files', $user_id ) )
147
- return false;
148
-
149
- // If the current user can edit Users, allow this.
150
- update_user_meta( $user_id, 'cupp_meta', $_POST['cupp_meta'] );
151
- update_user_meta( $user_id, 'cupp_upload_meta', $_POST['cupp_upload_meta'] );
152
- update_user_meta( $user_id, 'cupp_upload_edit_meta', $_POST['cupp_upload_edit_meta'] );
153
- }
154
-
155
- /**
156
- * Retrieve the appropriate image size
157
- *
158
- * @param $user_id Default: $post->post_author. Will accept any valid user ID passed into this parameter.
159
- * @param $size Default: 'thumbnail'. Accepts all default WordPress sizes and any custom sizes made by the add_image_size() function.
160
- * @return {url} Use this inside the src attribute of an image tag or where you need to call the image url.
161
- */
162
- function get_cupp_meta( $user_id, $size ) {
163
- global $post;
164
-
165
- //allow the user to specify the image size
166
- if (!$size){
167
- $size = 'thumbnail'; // Default image size if not specified.
168
- }
169
- if(!$user_id || !is_numeric( $user_id ) ){
170
- // Here we're assuming that the avatar being called is the author of the post.
171
- // The theory is that when a number is not supplied, this function is being used to
172
- // get the avatar of a post author using get_avatar() and an email address is supplied
173
- // for the $id_or_email parameter. We need an integer to get the custom image so we force that here.
174
- // Also, many themes use get_avatar on the single post pages and pass it the author email address so this
175
- // acts as a fall back.
176
- $user_id = $post->post_author;
177
- }
178
-
179
- // get the custom uploaded image
180
- $attachment_upload_url = esc_url( get_the_author_meta( 'cupp_upload_meta', $user_id ) );
181
-
182
- // get the external image
183
- $attachment_ext_url = esc_url( get_the_author_meta( 'cupp_meta', $user_id ) );
184
- $attachment_url = '';
185
- $image_url = '';
186
- if($attachment_upload_url){
187
- $attachment_url = $attachment_upload_url;
188
-
189
- // grabs the id from the URL using the WordPress function attachment_url_to_postid @since 4.0.0
190
- $attachment_id = attachment_url_to_postid( $attachment_url );
191
-
192
- // retrieve the thumbnail size of our image
193
- $image_thumb = wp_get_attachment_image_src( $attachment_id, $size );
194
- $image_url = $image_thumb[0];
195
-
196
- } elseif($attachment_ext_url) {
197
- $image_url = $attachment_ext_url;
198
- }
199
-
200
- if ( empty($image_url) )
201
- return;
202
-
203
- // return the image thumbnail
204
- return $image_url;
205
- }
206
-
207
- /**
208
- * WordPress Avatar Filter
209
- *
210
- * Replaces the WordPress avatar with your custom photo using the get_avatar hook.
211
- */
212
- add_filter( 'get_avatar', 'cupp_avatar' , 1 , 5 );
213
-
214
- function cupp_avatar( $avatar, $id_or_email, $size, $default, $alt ) {
215
- $user = false;
216
- $id = false;
217
-
218
- if ( is_numeric( $id_or_email ) ) {
219
-
220
- $id = (int) $id_or_email;
221
- $user = get_user_by( 'id' , $id );
222
-
223
- } elseif ( is_object( $id_or_email ) ) {
224
-
225
- if ( ! empty( $id_or_email->user_id ) ) {
226
- $id = (int) $id_or_email->user_id;
227
- $user = get_user_by( 'id' , $id );
228
- }
229
-
230
- } else {
231
- // $id = (int) $id_or_email;
232
- $user = get_user_by( 'email', $id_or_email );
233
- }
234
-
235
- if ( $user && is_object( $user ) ) {
236
-
237
- $custom_avatar = get_cupp_meta($id, 'thumbnail');
238
-
239
- if (isset($custom_avatar) && !empty($custom_avatar)) {
240
- $avatar = "<img alt='{$alt}' src='{$custom_avatar}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
241
- }
242
-
243
- }
244
-
245
- return $avatar;
246
- }
247
-
248
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Custom User Profile Photo
4
+ Plugin URI: http://3five.com
5
+ Description: A simple and effective custom WordPress user profile photo plugin. This plugin leverages the WordPress
6
+ Media Uploader functionality. To use this plugin go to the users tab and select a user. The new field can be found
7
+ below the password fields for that user.
8
+ Author: 3five
9
+ Author URI: http://3five.com
10
+ Text Domain: custom-user-profile-photo
11
+ Domain Path: /languages/
12
+ Version: 0.5
13
+ */
14
+
15
+ /**
16
+ * This program has been developed for use with the WordPress Software.
17
+ *
18
+ * It is distributed as free software with the intent that it will be
19
+ * useful and does not ship with any WARRANTY.
20
+ *
21
+ * USAGE
22
+ * // Default:
23
+ * This will override the WordPress get_avatar hook
24
+ *
25
+ * // Custom placement:
26
+ * <?php $imgURL = get_cupp_meta( $user_id, $size ); ?>
27
+ * or
28
+ * <img src="<?php echo get_cupp_meta( $user_id, $size ); ?>">
29
+ *
30
+ * Beginner WordPress template editing skill required. Place the above tag in your template and provide the two
31
+ * parameters.
32
+ *
33
+ * @param WP_User|int $user_id Default: $post->post_author. Will accept any valid user ID passed into this parameter.
34
+ * @param string $size Default: 'thumbnail'. Accepts all default WordPress sizes and any custom sizes made by
35
+ * the add_image_size() function.
36
+ *
37
+ * @return {url} Use this inside the src attribute of an image tag or where you need to call the image url.
38
+ *
39
+ * Inquiries, suggestions and feedback can be sent to support@3five.com
40
+ *
41
+ * This is plugin is intended for Author, Editor and Admin role post/page authors. Thank you for downloading our
42
+ * plugin.
43
+ *
44
+ * We hope this WordPress plugin meets your needs.
45
+ *
46
+ * Happy coding!
47
+ * - 3five
48
+ *
49
+ * Resources:
50
+ * • Steven Slack - http://s2web.staging.wpengine.com/226/
51
+ * • Pippin Williamson - https://gist.github.com/pippinsplugins/29bebb740e09e395dc06
52
+ * • Mike Jolley - https://gist.github.com/mikejolley/3a3b366cb62661727263#file-gistfile1-php
53
+ */
54
+
55
+ /**
56
+ * Load Translations.
57
+ */
58
+ function cupp_load_plugin_textdomain() {
59
+ load_plugin_textdomain( 'custom-user-profile-photo', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
60
+ }
61
+ add_action( 'init', 'cupp_load_plugin_textdomain' );
62
+
63
+ /**
64
+ * Enqueue scripts and styles
65
+ */
66
+ function cupp_enqueue_scripts_styles() {
67
+ // Register.
68
+ wp_register_style( 'cupp_admin_css', plugins_url( 'custom-user-profile-photo/css/styles.css' ), false, '1.0.0', 'all' );
69
+ wp_register_script( 'cupp_admin_js', plugins_url( 'custom-user-profile-photo/js/scripts.js' ), array( 'jquery' ), '1.0.0', true );
70
+
71
+ // Enqueue.
72
+ wp_enqueue_style( 'cupp_admin_css' );
73
+ wp_enqueue_script( 'cupp_admin_js' );
74
+ }
75
+
76
+ add_action( 'admin_enqueue_scripts', 'cupp_enqueue_scripts_styles' );
77
+
78
+
79
+ /**
80
+ * Show the new image field in the user profile page.
81
+ *
82
+ * @param object $user User object.
83
+ */
84
+ function cupp_profile_img_fields( $user ) {
85
+ if ( ! current_user_can( 'upload_files' ) ) {
86
+ return;
87
+ }
88
+
89
+ // vars
90
+ $url = get_the_author_meta( 'cupp_meta', $user->ID );
91
+ $upload_url = get_the_author_meta( 'cupp_upload_meta', $user->ID );
92
+ $upload_edit_url = get_the_author_meta( 'cupp_upload_edit_meta', $user->ID );
93
+ $button_text = $upload_url ? 'Change Current Image' : 'Upload New Image';
94
+
95
+ if ( $upload_url ) {
96
+ $upload_edit_url = get_site_url() . $upload_edit_url;
97
+ }
98
+ ?>
99
+
100
+ <div id="cupp_container">
101
+ <h3><?php _e( 'Custom User Profile Photo', 'custom-user-profile-photo' ); ?></h3>
102
+
103
+ <table class="form-table">
104
+ <tr>
105
+ <th><label for="cupp_meta"><?php _e( 'Profile Photo', 'custom-user-profile-photo' ); ?></label></th>
106
+ <td>
107
+ <!-- Outputs the image after save -->
108
+ <div id="current_img">
109
+ <?php if ( $upload_url ): ?>
110
+ <img class="cupp-current-img" src="<?php echo esc_url( $upload_url ); ?>"/>
111
+
112
+ <div class="edit_options uploaded">
113
+ <a class="remove_img">
114
+ <span><?php _e( 'Remove', 'custom-user-profile-photo' ); ?></span>
115
+ </a>
116
+
117
+ <a class="edit_img" href="<?php echo esc_url( $upload_edit_url ); ?>" target="_blank">
118
+ <span><?php _e( 'Edit', 'custom-user-profile-photo' ); ?></span>
119
+ </a>
120
+ </div>
121
+ <?php elseif ( $url ) : ?>
122
+ <img class="cupp-current-img" src="<?php echo esc_url( $url ); ?>"/>
123
+ <div class="edit_options single">
124
+ <a class="remove_img">
125
+ <span><?php _e( 'Remove', 'custom-user-profile-photo' ); ?></span>
126
+ </a>
127
+ </div>
128
+ <?php else : ?>
129
+ <img class="cupp-current-img placeholder"
130
+ src="<?php echo esc_url( plugins_url( 'custom-user-profile-photo/img/placeholder.gif' ) ); ?>"/>
131
+ <?php endif; ?>
132
+ </div>
133
+
134
+ <!-- Select an option: Upload to WPMU or External URL -->
135
+ <div id="cupp_options">
136
+ <input type="radio" id="upload_option" name="img_option" value="upload" class="tog" checked>
137
+ <label
138
+ for="upload_option"><?php _e( 'Upload New Image', 'custom-user-profile-photo' ); ?></label><br>
139
+
140
+ <input type="radio" id="external_option" name="img_option" value="external" class="tog">
141
+ <label
142
+ for="external_option"><?php _e( 'Use External URL', 'custom-user-profile-photo' ); ?></label><br>
143
+ </div>
144
+
145
+ <!-- Hold the value here if this is a WPMU image -->
146
+ <div id="cupp_upload">
147
+ <input class="hidden" type="hidden" name="cupp_placeholder_meta" id="cupp_placeholder_meta"
148
+ value="<?php echo esc_url( plugins_url( 'custom-user-profile-photo/img/placeholder.gif' ) ); ?>"/>
149
+ <input class="hidden" type="hidden" name="cupp_upload_meta" id="cupp_upload_meta"
150
+ value="<?php echo esc_url_raw( $upload_url ); ?>"/>
151
+ <input class="hidden" type="hidden" name="cupp_upload_edit_meta" id="cupp_upload_edit_meta"
152
+ value="<?php echo esc_url_raw( $upload_edit_url ); ?>"/>
153
+ <input id="uploadimage" type='button' class="cupp_wpmu_button button-primary"
154
+ value="<?php _e( esc_attr( $button_text ), 'custom-user-profile-photo' ); ?>"/>
155
+ <br/>
156
+ </div>
157
+
158
+ <!-- Outputs the text field and displays the URL of the image retrieved by the media uploader -->
159
+ <div id="cupp_external">
160
+ <input class="regular-text" type="text" name="cupp_meta" id="cupp_meta"
161
+ value="<?php echo esc_url_raw( $url ); ?>"/>
162
+ </div>
163
+
164
+ <!-- Outputs the save button -->
165
+ <span class="description">
166
+ <?php
167
+ _e(
168
+ 'Upload a custom photo for your user profile or use a URL to a pre-existing photo.',
169
+ 'custom-user-profile-photo'
170
+ );
171
+ ?>
172
+ </span>
173
+ <p class="description">
174
+ <?php _e( 'Update Profile to save your changes.', 'custom-user-profile-photo' ); ?>
175
+ </p>
176
+ </td>
177
+ </tr>
178
+ </table><!-- end form-table -->
179
+ </div> <!-- end #cupp_container -->
180
+
181
+ <?php
182
+ // Enqueue the WordPress Media Uploader.
183
+ wp_enqueue_media();
184
+ }
185
+
186
+ add_action( 'show_user_profile', 'cupp_profile_img_fields' );
187
+ add_action( 'edit_user_profile', 'cupp_profile_img_fields' );
188
+
189
+
190
+ /**
191
+ * Save the new user CUPP url.
192
+ *
193
+ * @param int $user_id ID of the user's profile being saved.
194
+ */
195
+ function cupp_save_img_meta( $user_id ) {
196
+ if ( ! current_user_can( 'upload_files', $user_id ) ) {
197
+ return;
198
+ }
199
+
200
+ $values = array(
201
+ // String value. Empty in this case.
202
+ 'cupp_meta' => filter_input( INPUT_POST, 'cupp_meta', FILTER_SANITIZE_STRING ),
203
+
204
+ // File path, e.g., http://3five.dev/wp-content/plugins/custom-user-profile-photo/img/placeholder.gif.
205
+ 'cupp_upload_meta' => filter_input( INPUT_POST, 'cupp_upload_meta', FILTER_SANITIZE_URL ),
206
+
207
+ // Edit path, e.g., /wp-admin/post.php?post=32&action=edit&image-editor.
208
+ 'cupp_upload_edit_meta' => filter_input( INPUT_POST, 'cupp_upload_edit_meta', FILTER_SANITIZE_URL ),
209
+ );
210
+
211
+ foreach ( $values as $key => $value ) {
212
+ update_user_attribute( $user_id, $key, $value );
213
+ }
214
+ }
215
+
216
+ add_action( 'personal_options_update', 'cupp_save_img_meta' );
217
+ add_action( 'edit_user_profile_update', 'cupp_save_img_meta' );
218
+
219
+ /**
220
+ * Retrieve the appropriate image size
221
+ *
222
+ * @param int $user_id Default: $post->post_author. Will accept any valid user ID passed into this parameter.
223
+ * @param string $size Default: 'thumbnail'. Accepts all default WordPress sizes and any custom sizes made by
224
+ * the add_image_size() function.
225
+ *
226
+ * @return string (Url) Use this inside the src attribute of an image tag or where you need to call the image url.
227
+ */
228
+ function get_cupp_meta( $user_id, $size = 'thumbnail' ) {
229
+ global $post;
230
+
231
+ if ( ! $user_id || ! is_numeric( $user_id ) ) {
232
+ /*
233
+ * Here we're assuming that the avatar being called is the author of the post.
234
+ * The theory is that when a number is not supplied, this function is being used to
235
+ * get the avatar of a post author using get_avatar() and an email address is supplied
236
+ * for the $id_or_email parameter. We need an integer to get the custom image so we force that here.
237
+ * Also, many themes use get_avatar on the single post pages and pass it the author email address so this
238
+ * acts as a fall back.
239
+ */
240
+ $user_id = $post->post_author;
241
+ }
242
+
243
+ // Check first for a custom uploaded image.
244
+ $attachment_upload_url = esc_url( get_the_author_meta( 'cupp_upload_meta', $user_id ) );
245
+
246
+ if ( $attachment_upload_url ) {
247
+ // Grabs the id from the URL using the WordPress function attachment_url_to_postid @since 4.0.0.
248
+ $attachment_id = attachment_url_to_postid( $attachment_upload_url );
249
+
250
+ // Retrieve the thumbnail size of our image. Should return an array with first index value containing the URL.
251
+ $image_thumb = wp_get_attachment_image_src( $attachment_id, $size );
252
+
253
+ return isset( $image_thumb[0] ) ? $image_thumb[0] : '';
254
+ }
255
+
256
+ // Finally, check for image from an external URL. If none exists, return an empty string.
257
+ $attachment_ext_url = esc_url( get_the_author_meta( 'cupp_meta', $user_id ) );
258
+
259
+ return $attachment_ext_url ? $attachment_ext_url : '';
260
+ }
261
+
262
+
263
+ /**
264
+ * WordPress Avatar Filter
265
+ *
266
+ * Replaces the WordPress avatar with your custom photo using the get_avatar hook.
267
+ *
268
+ * @param string $avatar Image tag for the user's avatar.
269
+ * @param int|object|string $identifier User object, UD or email address.
270
+ * @param string $size Image size.
271
+ * @param string $alt Alt text for the image tag.
272
+ *
273
+ * @return string
274
+ */
275
+ function cupp_avatar( $avatar, $identifier, $size, $alt ) {
276
+ if ( $user = cupp_get_user_by_id_or_email( $identifier ) ) {
277
+ if ( $custom_avatar = get_cupp_meta( $user->ID, 'thumbnail' ) ) {
278
+ return "<img alt='{$alt}' src='{$custom_avatar}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
279
+ }
280
+ }
281
+
282
+ return $avatar;
283
+ }
284
+
285
+ add_filter( 'get_avatar', 'cupp_avatar', 1, 5 );
286
+
287
+ /**
288
+ * Get a WordPress User by ID or email
289
+ *
290
+ * @param int|object|string $identifier User object, UD or email address.
291
+ *
292
+ * @return WP_User
293
+ */
294
+ function cupp_get_user_by_id_or_email( $identifier ) {
295
+ if ( is_numeric( $identifier ) ) {
296
+ return get_user_by( 'id', (int) $identifier );
297
+ }
298
+
299
+ if ( property_exists( $identifier, 'user_id' ) ) {
300
+ return get_user_by( 'id', (int) $identifier->user_id );
301
+ }
302
+
303
+ return get_user_by( 'email', $identifier );
304
+ }
languages/custom-user-profile-photo-es_ES.mo ADDED
Binary file
languages/custom-user-profile-photo-es_ES.po ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: Custom User Profile Photo\n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: Thu Jan 22 2015 15:00:48 GMT+0100 (CET)\n"
6
+ "PO-Revision-Date: 2015-11-26 00:04+0100\n"
7
+ "Language-Team: \n"
8
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "X-Poedit-SourceCharset: UTF-8\n"
13
+ "X-Poedit-Basepath: .\n"
14
+ "X-Poedit-KeywordsList: _:1;gettext:1;dgettext:2;ngettext:1,2;dngettext:2,3;"
15
+ "__:1;_e:1;_c:1;_n:1,2;_n_noop:1,2;_nc:1,2;__ngettext:1,2;"
16
+ "__ngettext_noop:1,2;_x:1,2c;_ex:1,2c;_nx:1,2,4c;_nx_noop:1,2,3c;_n_js:1,2;"
17
+ "_nx_js:1,2,3c;esc_attr__:1;esc_html__:1;esc_attr_e:1;esc_html_e:1;"
18
+ "esc_attr_x:1,2c;esc_html_x:1,2c;comments_number_link:2,3;t:1;st:1;trans:1;"
19
+ "transChoice:1,2\n"
20
+ "X-Loco-Target-Locale: nl_NL\n"
21
+ "X-Generator: Poedit 1.8.6\n"
22
+ "Last-Translator: David <david@closemarketing.es>\n"
23
+ "Language: es\n"
24
+ "X-Poedit-SearchPath-0: ../../plugins/custom-user-profile-photo\n"
25
+
26
+ #: ../3five_cupp.php:80 ../3five_cupp.php:114
27
+ msgid "Upload New Image"
28
+ msgstr "Cargar una nueva imagen"
29
+
30
+ #: ../3five_cupp.php:83
31
+ msgid "Change Current Image"
32
+ msgstr "Cambiar la imagen actual"
33
+
34
+ #: ../3five_cupp.php:88
35
+ msgid "Custom User Profile Photo"
36
+ msgstr "Foto de Perfil de usuario personalizado"
37
+
38
+ #: ../3five_cupp.php:93
39
+ msgid "Profile Photo"
40
+ msgstr "Foto del perfil"
41
+
42
+ #: ../3five_cupp.php:100 ../3five_cupp.php:106
43
+ msgid "Remove"
44
+ msgstr "Quitar"
45
+
46
+ #: ../3five_cupp.php:101
47
+ msgid "Edit"
48
+ msgstr "Editar"
49
+
50
+ #: ../3five_cupp.php:116
51
+ msgid "Use External URL"
52
+ msgstr "Utilizar URL externa"
53
+
54
+ #: ../3five_cupp.php:130
55
+ msgid ""
56
+ "Upload a custom photo for your user profile or use a URL to a pre-existing "
57
+ "photo."
58
+ msgstr ""
59
+ "Añadir una foto personalizada para tu perfil de usuario o utilizar una "
60
+ "dirección URL a una foto ya existente."
61
+
62
+ #: ../3five_cupp.php:131
63
+ msgid "Update Profile to save your changes."
64
+ msgstr "Actualizar el perfil para guardar los cambios."
languages/custom-user-profile-photo-hu_HU.mo CHANGED
Binary file
languages/custom-user-profile-photo-hu_HU.po CHANGED
@@ -1,55 +1,58 @@
1
- msgid ""
2
- msgstr ""
3
- "Project-Id-Version: Custom User Profile Photo\n"
4
- "Report-Msgid-Bugs-To: \n"
5
- "POT-Creation-Date: 2015-04-01 17:18:55\n"
6
- "PO-Revision-Date: 2015-04-01 17:18:55\n"
7
- "Last-Translator: Harkály Gergő <gergo.harkaly@mediamulti.nt>\n"
8
- "Language-Team: MediaMulti.Network <info@mediamulti.net> \n"
9
- "Language: hu_HU\n"
10
- "Plural-Forms: nplurals=2; plural=n != 1\n"
11
- "MIME-Version: 1.0\n"
12
- "Content-Type: text/plain; charset=UTF-8\n"
13
- "Content-Transfer-Encoding: 8bit\n"
14
- "X-Poedit-SourceCharset: UTF-8\n"
15
- "X-Poedit-Basepath: .\n"
16
- "X-Poedit-SearchPath-0: ../../plugins/custom-user-profile-photo\n"
17
- "X-Poedit-KeywordsList: _:1;gettext:1;dgettext:2;ngettext:1,2;dngettext:2,3;"
18
-
19
- #: ../3five_cupp.php:80 ../3five_cupp.php:114
20
- msgid "Upload New Image"
21
- msgstr "Új fotó feltöltése"
22
-
23
- #: ../3five_cupp.php:83
24
- msgid "Change Current Image"
25
- msgstr "Aktuális kép megváltoztatása"
26
-
27
- #: ../3five_cupp.php:88
28
- msgid "Custom User Profile Photo"
29
- msgstr "Egyedi profil fotó"
30
-
31
- #: ../3five_cupp.php:93
32
- msgid "Profile Photo"
33
- msgstr "Profil fotó"
34
-
35
- #: ../3five_cupp.php:100 ../3five_cupp.php:106
36
- msgid "Remove"
37
- msgstr "Eltávolítás"
38
-
39
- #: ../3five_cupp.php:101
40
- msgid "Edit"
41
- msgstr "Szerkesztés"
42
-
43
- #: ../3five_cupp.php:116
44
- msgid "Use External URL"
45
- msgstr "Külső link használata"
46
-
47
- #: ../3five_cupp.php:130
48
- msgid ""
49
- "Upload a custom photo for your user profile or use a URL to a pre-existing "
50
- "photo."
51
- msgstr "Töltsön fel egyedi profilfotót, vagy használjon egy interneten meglévőt URL megadásával."
52
-
53
- #: ../3five_cupp.php:131
54
- msgid "Update Profile to save your changes."
55
- msgstr "A változtatások elmentéséhez nyomjon a Mentés gombra."
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: Custom User Profile Photo\n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2015-04-01 17:18:55\n"
6
+ "PO-Revision-Date: 2015-09-25 10:34-0600\n"
7
+ "Last-Translator: Vincent Listrani <vincent@3five.com>\n"
8
+ "Language-Team: MediaMulti.Network <info@mediamulti.net>\n"
9
+ "Language: hu_HU\n"
10
+ "Plural-Forms: nplurals=2; plural=n != 1;\n"
11
+ "MIME-Version: 1.0\n"
12
+ "Content-Type: text/plain; charset=UTF-8\n"
13
+ "Content-Transfer-Encoding: 8bit\n"
14
+ "X-Poedit-SourceCharset: UTF-8\n"
15
+ "X-Poedit-Basepath: .\n"
16
+ "X-Poedit-KeywordsList: _:1;gettext:1;dgettext:2;ngettext:1,2;dngettext:2,3\n"
17
+ "X-Generator: Poedit 1.5.7\n"
18
+ "X-Poedit-SearchPath-0: ../../plugins/custom-user-profile-photo\n"
19
+
20
+ #: ../3five_cupp.php:80 ../3five_cupp.php:114
21
+ msgid "Upload New Image"
22
+ msgstr "Új fotó feltöltése"
23
+
24
+ #: ../3five_cupp.php:83
25
+ msgid "Change Current Image"
26
+ msgstr "Aktuális kép megváltoztatása"
27
+
28
+ #: ../3five_cupp.php:88
29
+ msgid "Custom User Profile Photo"
30
+ msgstr "Egyedi profil fotó"
31
+
32
+ #: ../3five_cupp.php:93
33
+ msgid "Profile Photo"
34
+ msgstr "Profil fotó"
35
+
36
+ #: ../3five_cupp.php:100 ../3five_cupp.php:106
37
+ msgid "Remove"
38
+ msgstr "Eltávolítás"
39
+
40
+ #: ../3five_cupp.php:101
41
+ msgid "Edit"
42
+ msgstr "Szerkesztés"
43
+
44
+ #: ../3five_cupp.php:116
45
+ msgid "Use External URL"
46
+ msgstr "Külső link használata"
47
+
48
+ #: ../3five_cupp.php:130
49
+ msgid ""
50
+ "Upload a custom photo for your user profile or use a URL to a pre-existing "
51
+ "photo."
52
+ msgstr ""
53
+ "Töltsön fel egyedi profilfotót, vagy használjon egy interneten meglévőt URL "
54
+ "megadásával."
55
+
56
+ #: ../3five_cupp.php:131
57
+ msgid "Update Profile to save your changes."
58
+ msgstr "A változtatások elmentéséhez nyomjon a Mentés gombra."
languages/custom-user-profile-photo.pot ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2016 Custom User Profile Photo
2
+ # This file is distributed under the same license as the Custom User Profile Photo package.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: Custom User Profile Photo 0.4\n"
6
+ "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/custom-user-"
7
+ "profile-photo\n"
8
+ "POT-Creation-Date: 2016-08-17 21:05:46+00:00\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "PO-Revision-Date: 2016-MO-DA HO:MI+ZONE\n"
13
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
+ "Language-Team: LANGUAGE <LL@li.org>\n"
15
+
16
+ #. #-#-#-#-# plugin.pot (Custom User Profile Photo 0.4) #-#-#-#-#
17
+ #. Plugin Name of the plugin/theme
18
+ #: 3five_cupp.php:83
19
+ msgid "Custom User Profile Photo"
20
+ msgstr ""
21
+
22
+ #: 3five_cupp.php:88
23
+ msgid "Profile Photo"
24
+ msgstr ""
25
+
26
+ #: 3five_cupp.php:128
27
+ msgid ""
28
+ "Upload a custom photo for your user profile or use a URL to a pre-existing "
29
+ "photo."
30
+ msgstr ""
31
+
32
+ #: 3five_cupp.php:129
33
+ msgid "Update Profile to save your changes."
34
+ msgstr ""
35
+
36
+ #. #-#-#-#-# plugin.pot (Custom User Profile Photo 0.4) #-#-#-#-#
37
+ #. Plugin URI of the plugin/theme
38
+ #. #-#-#-#-# plugin.pot (Custom User Profile Photo 0.4) #-#-#-#-#
39
+ #. Author URI of the plugin/theme
40
+ msgid "http://3five.com"
41
+ msgstr ""
42
+
43
+ #. Description of the plugin/theme
44
+ msgid ""
45
+ "A simple and effective custom WordPress user profile photo plugin. This "
46
+ "plugin leverages the WordPress Media Uploader functionality. To use this "
47
+ "plugin go to the users tab and select a user. The new field can be found "
48
+ "below the password fields for that user."
49
+ msgstr ""
50
+
51
+ #. Author of the plugin/theme
52
+ msgid "3five"
53
+ msgstr ""
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Plugin Name ===
2
- Contributors: 3five, VincentListrani
3
  Donate link:
4
- Tags: custom profile photo, user profile, profile photo, user profile photo
5
  Requires at least: 3.6.1
6
- Tested up to: 4.2.3
7
- Stable tag: 0.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -22,14 +22,16 @@ This plugin will add a custom set of fields to the user profile page which will
22
 
23
  You can add/change/edit uploaded photos directly from the user profile page. The external option allows you to provide a URL to the external image or remove it.
24
 
25
- **As of v0.4**, the plugin now overrides the get_avatar() hook found in most WordPress themes.
26
 
27
  Simply go to the users section and select a user or select "Your Profile" depending on your permission level. The new fields are added to the bottom of the user profile page. Choose which type of photo you want to use. Upload an image or add an external url. Then press the Update Profile button.
28
 
29
  If you require a customized approach or your theme does not support the get_avatar() hook, use the example below.
30
 
31
- To retrieve the photo on the front-end use the following example on your template page(s):
32
- `<?php
 
 
33
  // Retrieve The Post's Author ID
34
  $user_id = get_the_author_meta('ID');
35
  // Set the image size. Accepts all registered images sizes and array(int, int)
@@ -40,7 +42,9 @@ To retrieve the photo on the front-end use the following example on your templat
40
 
41
  // Print the image on the page
42
  echo '<img src="'. $imgURL .'" alt="">';
43
- ?>`
 
 
44
  You will need to place the code above in each area of your theme where you wish to add and retrieve your theme's custom avatar image. This can include but is not limited to single.php, page.php, and comments.php.
45
 
46
  *Future Updates to this plugin include allowing other roles to access this feature, a settings page to allow a custom default image and other options.
@@ -55,14 +59,14 @@ You will need to place the code above in each area of your theme where you wish
55
 
56
  = Who can upload and manage these images? =
57
 
58
- Currently, only a user with the upload_files capability can use this option.
59
  Editors and Admins can upload and edit files.
60
  Authors can only upload files.
61
  Subscribers and Contributors cannot do either so an Admin will need to do this for them.
62
 
63
- = I installed the plugin but I want to customize the output and placement of the image. Is this possible? =
64
 
65
- Yes, you can still customize the output by using the get_cupp_meta() function. Please reference the code snippet below or on the Description tab.
66
  `<?php echo get_cupp_meta($user_ID, $size); ?>`
67
  Where the $user_ID is the users ID number and the size is a registered image size like 'thumbnail' or an array like `array(50,50)`.
68
 
@@ -80,8 +84,17 @@ Where the $user_ID is the users ID number and the size is a registered image siz
80
 
81
  == Changelog ==
82
 
 
 
 
 
 
 
 
 
 
83
  = 0.4 =
84
- * Major Update - please be sure to backup your site and db.
85
  * The plugin now overrides the WordPress avatar by filtering the get_avatar() hook.
86
  * The get_cupp_meta() function still exists and can be used to customize the output (this will eventually be deprecated).
87
 
@@ -112,6 +125,15 @@ Where the $user_ID is the users ID number and the size is a registered image siz
112
 
113
  == Upgrade Notice ==
114
 
 
 
 
 
 
 
 
 
 
115
  = 0.2.6 =
116
  Bug Fixes and minor improvements.
117
 
@@ -119,4 +141,15 @@ Bug Fixes and minor improvements.
119
  Bug Fixes and minor improvements.
120
 
121
  = 0.2.3 =
122
- Beta Release
 
 
 
 
 
 
 
 
 
 
 
1
  === Plugin Name ===
2
+ Contributors: 3five, VincentListrani, jmichaelward
3
  Donate link:
4
+ Tags: custom profile photo, custom profile picture, profile picture, user profile, profile photo, user profile photo, user profile picture
5
  Requires at least: 3.6.1
6
+ Tested up to: 4.6
7
+ Stable tag: 0.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
22
 
23
  You can add/change/edit uploaded photos directly from the user profile page. The external option allows you to provide a URL to the external image or remove it.
24
 
25
+ **As of v0.4**, the plugin now filters the get_avatar() function found in most WordPress themes.
26
 
27
  Simply go to the users section and select a user or select "Your Profile" depending on your permission level. The new fields are added to the bottom of the user profile page. Choose which type of photo you want to use. Upload an image or add an external url. Then press the Update Profile button.
28
 
29
  If you require a customized approach or your theme does not support the get_avatar() hook, use the example below.
30
 
31
+ To retrieve the photo on the front-end use the following example on your template page(s).
32
+
33
+ `
34
+ <?php
35
  // Retrieve The Post's Author ID
36
  $user_id = get_the_author_meta('ID');
37
  // Set the image size. Accepts all registered images sizes and array(int, int)
42
 
43
  // Print the image on the page
44
  echo '<img src="'. $imgURL .'" alt="">';
45
+ ?>
46
+ `
47
+
48
  You will need to place the code above in each area of your theme where you wish to add and retrieve your theme's custom avatar image. This can include but is not limited to single.php, page.php, and comments.php.
49
 
50
  *Future Updates to this plugin include allowing other roles to access this feature, a settings page to allow a custom default image and other options.
59
 
60
  = Who can upload and manage these images? =
61
 
62
+ Currently, only a user with the upload_files capability can use this option.
63
  Editors and Admins can upload and edit files.
64
  Authors can only upload files.
65
  Subscribers and Contributors cannot do either so an Admin will need to do this for them.
66
 
67
+ = I installed the plugin but I want to customize the output and placement of the image. Is this possible? =
68
 
69
+ Yes, you can still customize the output by using the get_cupp_meta() function. Please reference the code snippet below or on the Description tab.
70
  `<?php echo get_cupp_meta($user_ID, $size); ?>`
71
  Where the $user_ID is the users ID number and the size is a registered image size like 'thumbnail' or an array like `array(50,50)`.
72
 
84
 
85
  == Changelog ==
86
 
87
+ = 0.5 =
88
+ * Major Update - please be sure to backup your site and db.
89
+ * Replaced `update_user_meta` with `update_user_attribute` per WordPress VIP Standards.
90
+ * Replaced `get_home_url` with `get_site_url` for users where the edit image link was returning a 404. Credit: SOMTIJDS
91
+ * Fixed textdomain loading issue.
92
+ * Added Spanish translation. Credit: David Pérez
93
+ * Updated and formatted code per PHPCS. Credit: jmichaelward
94
+ * Refactored multiple functions and variables for simplicity and compatibility. Credit: jmichaelward
95
+
96
  = 0.4 =
97
+ * Major Update - please be sure to backup your site and db.
98
  * The plugin now overrides the WordPress avatar by filtering the get_avatar() hook.
99
  * The get_cupp_meta() function still exists and can be used to customize the output (this will eventually be deprecated).
100
 
125
 
126
  == Upgrade Notice ==
127
 
128
+ = 0.5 =
129
+ Major Update - please be sure to backup your site and db. The plugin was refactored and restructured per PHPCS. Some functions were swapped for ones that were less costly or could cause a 404 response. Fixed textdomain issue for translations and added Spanish translation.
130
+
131
+ = 0.4 =
132
+ Major Update - please be sure to backup your site and db. The plugin now filters and overrides `get_avatar()`. This could affect your theme or other plugins you have installed.
133
+
134
+ = 0.3 =
135
+ Minor improvement.
136
+
137
  = 0.2.6 =
138
  Bug Fixes and minor improvements.
139
 
141
  Bug Fixes and minor improvements.
142
 
143
  = 0.2.3 =
144
+ Beta Release
145
+
146
+ == Translations ==
147
+
148
+ * English - default, always included
149
+ * Dutch
150
+ * Hungarian
151
+ * Spanish
152
+
153
+ == Credits ==
154
+
155
+ Thanks to [Olaf Lederer](https://profiles.wordpress.org/finalwebsites/), [Harkály Gergő](https://github.com/harkalygergo), [sqhendr](https://profiles.wordpress.org/sqhendr/), [SOMTIJDS](https://profiles.wordpress.org/somtijds/), [David Pérez](https://www.closemarketing.es)