Custom User Profile Photo - Version 0.3

Version Description

  • Changed the function which gets the attachment post ID by GUID to the WordPress core function attachment_url_to_postid() for better reliability. (Props to sqhendr).
Download this release

Release Info

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

Code changes from version 0.2.6 to 0.3

3five_cupp.php CHANGED
@@ -7,7 +7,7 @@ Author: 3five
7
  Author URI: http://3five.com
8
  Text Domain: custom-user-profile-photo
9
  Domain Path: /languages/
10
- Version: 0.2.6
11
  */
12
 
13
  /**
@@ -150,44 +150,6 @@ function cupp_save_img_meta( $user_id ) {
150
  update_user_meta( $user_id, 'cupp_upload_edit_meta', $_POST['cupp_upload_edit_meta'] );
151
  }
152
 
153
- /**
154
- * Return an ID of an attachment by searching the database with the file URL.
155
- *
156
- * First checks to see if the $url is pointing to a file that exists in
157
- * the wp-content directory. If so, then we search the database for a
158
- * partial match consisting of the remaining path AFTER the wp-content
159
- * directory. Finally, if a match is found the attachment ID will be
160
- * returned.
161
- *
162
- * http://frankiejarrett.com/get-an-attachment-id-by-url-in-wordpress/
163
- *
164
- * @return {int} $attachment
165
- */
166
- function get_attachment_image_by_url( $url ) {
167
-
168
- // Split the $url into two parts with the wp-content directory as the separator.
169
- $parse_url = explode( parse_url( WP_CONTENT_URL, PHP_URL_PATH ), $url );
170
-
171
- // Get the host of the current site and the host of the $url, ignoring www.
172
- $this_host = str_ireplace( 'www.', '', parse_url( home_url(), PHP_URL_HOST ) );
173
- $file_host = str_ireplace( 'www.', '', parse_url( $url, PHP_URL_HOST ) );
174
-
175
- // Return nothing if there aren't any $url parts or if the current host and $url host do not match.
176
- if ( !isset( $parse_url[1] ) || empty( $parse_url[1] ) || ( $this_host != $file_host ) ) {
177
- return;
178
- }
179
-
180
- // Now we're going to quickly search the DB for any attachment GUID with a partial path match.
181
- // Example: /uploads/2013/05/test-image.jpg
182
- global $wpdb;
183
-
184
- $prefix = $wpdb->prefix;
185
- $attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM " . $prefix . "posts WHERE guid RLIKE %s;", $parse_url[1] ) );
186
-
187
- // Returns null if no attachment is found.
188
- return $attachment[0];
189
- }
190
-
191
  /**
192
  * Retrieve the appropriate image size
193
  *
@@ -215,8 +177,8 @@ function get_cupp_meta( $user_id, $size ) {
215
  if($attachment_upload_url){
216
  $attachment_url = $attachment_upload_url;
217
 
218
- // grabs the id from the URL using Frankie Jarretts function
219
- $attachment_id = get_attachment_image_by_url( $attachment_url );
220
 
221
  // retrieve the thumbnail size of our image
222
  $image_thumb = wp_get_attachment_image_src( $attachment_id, $size );
7
  Author URI: http://3five.com
8
  Text Domain: custom-user-profile-photo
9
  Domain Path: /languages/
10
+ Version: 0.3
11
  */
12
 
13
  /**
150
  update_user_meta( $user_id, 'cupp_upload_edit_meta', $_POST['cupp_upload_edit_meta'] );
151
  }
152
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  /**
154
  * Retrieve the appropriate image size
155
  *
177
  if($attachment_upload_url){
178
  $attachment_url = $attachment_upload_url;
179
 
180
+ // grabs the id from the URL using the WordPress function attachment_url_to_postid @since 4.0.0
181
+ $attachment_id = attachment_url_to_postid( $attachment_url );
182
 
183
  // retrieve the thumbnail size of our image
184
  $image_thumb = wp_get_attachment_image_src( $attachment_id, $size );
languages/custom-user-profile-photo-hu_HU.mo ADDED
Binary file
languages/custom-user-profile-photo-hu_HU.po ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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."
readme.txt CHANGED
@@ -3,8 +3,8 @@ 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
7
- Stable tag: 0.2.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -24,9 +24,9 @@ This plugin will add a custom set of fields to the user profile page which will
24
 
25
  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.
26
 
27
- *Future Updates to this plugin include full WordPress avatar integration (posts and comments), allowing other roles to access this feature, and ajax processing of images that use the WordPress Media Uploader.
28
 
29
- To use this plugin, simply go to the users section and select a user. The new fields are added to the bottom of the user profile page. Choose which type of photo you want to use. Upload or add the url, depending on your option. Then press the Update Profile button.
30
 
31
  To retrieve the photo on the front-end use the following example on your template page(s):
32
  `<?php
@@ -41,6 +41,9 @@ To retrieve the photo on the front-end use the following example on your templat
41
  // Print the image on the page
42
  echo '<img src="'. $imgURL .'" alt="">';
43
  ?>`
 
 
 
44
 
45
  == Installation ==
46
 
@@ -50,15 +53,19 @@ To retrieve the photo on the front-end use the following example on your templat
50
 
51
  == Frequently Asked Questions ==
52
 
53
- = How do I retrieve the image after I've updated the user profile. =
54
 
55
  You can call it in your template page(s) like so: `<?php echo get_cupp_meta($user_ID, $size); ?>`
56
  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)`
57
 
58
- = Who can upload and manage these images. =
59
 
60
  Currently, only a user with admin privileges can manage this option.
61
 
 
 
 
 
62
  == Screenshots ==
63
 
64
  1. The new fields that are added to the user profile page.
@@ -73,6 +80,12 @@ Currently, only a user with admin privileges can manage this option.
73
 
74
  == Changelog ==
75
 
 
 
 
 
 
 
76
  = 0.2.6 =
77
  * Fixed a bug where the save function required a different capability than the upload function (courtesy of douglas_johnson).
78
 
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.2
7
+ Stable tag: 0.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
24
 
25
  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.
26
 
27
+ **To use this plugin, you will need basic to intermediate WordPress theme development skills. It *does not* overwrite a theme's gravatar/avatar settings.**
28
 
29
+ Simply go to the users section and select a user. The new fields are added to the bottom of the user profile page. Choose which type of photo you want to use. Upload or add the url, depending on your option. Then press the Update Profile button.
30
 
31
  To retrieve the photo on the front-end use the following example on your template page(s):
32
  `<?php
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 or overwrite your theme's gravatar/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 full WordPress avatar integration (posts and comments), allowing other roles to access this feature, and ajax processing of images that use the WordPress Media Uploader.
47
 
48
  == Installation ==
49
 
53
 
54
  == Frequently Asked Questions ==
55
 
56
+ = How do I retrieve the image after I've updated the user profile? =
57
 
58
  You can call it in your template page(s) like so: `<?php echo get_cupp_meta($user_ID, $size); ?>`
59
  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)`
60
 
61
+ = Who can upload and manage these images? =
62
 
63
  Currently, only a user with admin privileges can manage this option.
64
 
65
+ = I installed the plugin but it doesn't show the new image anywhere. What gives? =
66
+
67
+ The plugin does not overwrite the default WordPress gravatar/avatar image. You need at least basic to intermediate WordPress theme editing skills. Please reference the code snippet above or on the Description tab.
68
+
69
  == Screenshots ==
70
 
71
  1. The new fields that are added to the user profile page.
80
 
81
  == Changelog ==
82
 
83
+ = 0.3 =
84
+ * Changed the function which gets the attachment post ID by GUID to the WordPress core function attachment_url_to_postid() for better reliability. (Props to sqhendr).
85
+
86
+ = 0.2.7 =
87
+ * Added Hungarian Translation (Thanks to Harkály Gergő)
88
+
89
  = 0.2.6 =
90
  * Fixed a bug where the save function required a different capability than the upload function (courtesy of douglas_johnson).
91