User Profile Picture - Version 1.2.0

Version Description

  • Released 07 December 2014
  • Reducing clutter in the interface. Removed text option to upload. Added default image if no profile image is available. Added option to remove the profile image.
  • Fixed internationalization bug in the JavaScript.
Download this release

Release Info

Developer ronalfy
Plugin Icon 128x128 User Profile Picture
Version 1.2.0
Comparing to
See all releases

Code changes from version 1.1.0 to 1.2.0

Files changed (4) hide show
  1. img/mystery.png +0 -0
  2. js/mpp.js +2 -14
  3. metronet-profile-picture.php +65 -21
  4. readme.txt +12 -8
img/mystery.png ADDED
Binary file
js/mpp.js CHANGED
@@ -9,12 +9,6 @@ jQuery( document ).ready( function( $ ) {
9
  },
10
  function( response ) {
11
  jQuery( "#metronet-profile-image" ).html( response.thumb_html );
12
- jQuery( "#metronet-pte" ).html( response.crop_html );
13
- if ( response.has_thumb == true ) {
14
- jQuery( "#metronet-remove" ).show();
15
- } else {
16
- jQuery( "#metronet-remove" ).hide();
17
- }
18
  },
19
  'json'
20
  );
@@ -30,8 +24,6 @@ jQuery( document ).ready( function( $ ) {
30
  },
31
  function( response ) {
32
  jQuery( "#metronet-profile-image" ).html( response.thumb_html );
33
- jQuery( "#metronet-pte" ).html( response.crop_html );
34
- jQuery( "#metronet-remove" ).hide();
35
  },
36
  'json'
37
  );
@@ -61,7 +53,7 @@ jQuery( document ).ready( function( $ ) {
61
  };
62
  if ( $( '#metronet-profile-image img' ).length > 0 ) {
63
  options.items.remove = {
64
- text: 'Remove Profile Image',
65
  style: 'secondary',
66
  requires: { selection: false },
67
  click: wp.media.view.Toolbar.Select.prototype.clickSelect,
@@ -87,10 +79,6 @@ jQuery( document ).ready( function( $ ) {
87
  },
88
  function( response ) {
89
  jQuery( "#metronet-profile-image" ).html( response.thumb_html );
90
- jQuery( "#metronet-pte" ).html( response.crop_html );
91
- if ( response.has_thumb == true ) {
92
- jQuery( "#metronet-remove" ).show();
93
- }
94
  },
95
  'json'
96
  );
@@ -123,7 +111,7 @@ jQuery( document ).ready( function( $ ) {
123
  uploader.open();
124
  return false;
125
  });
126
- $( "#metronet-remove" ).on( 'click', 'a', function( e ) {
127
  e.preventDefault();
128
  mt_remove_profile_image();
129
  } );
9
  },
10
  function( response ) {
11
  jQuery( "#metronet-profile-image" ).html( response.thumb_html );
 
 
 
 
 
 
12
  },
13
  'json'
14
  );
24
  },
25
  function( response ) {
26
  jQuery( "#metronet-profile-image" ).html( response.thumb_html );
 
 
27
  },
28
  'json'
29
  );
53
  };
54
  if ( $( '#metronet-profile-image img' ).length > 0 ) {
55
  options.items.remove = {
56
+ text: metronet_profile_image.remove_profile_text,
57
  style: 'secondary',
58
  requires: { selection: false },
59
  click: wp.media.view.Toolbar.Select.prototype.clickSelect,
79
  },
80
  function( response ) {
81
  jQuery( "#metronet-profile-image" ).html( response.thumb_html );
 
 
 
 
82
  },
83
  'json'
84
  );
111
  uploader.open();
112
  return false;
113
  });
114
+ $( "#mpp" ).on( 'click', 'a#metronet-remove', function( e ) {
115
  e.preventDefault();
116
  mt_remove_profile_image();
117
  } );
metronet-profile-picture.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Metronet Profile Picture
4
  Plugin URI: http://wordpress.org/extend/plugins/metronet-profile-picture/
5
  Description: Use the native WP uploader on your user profile page.
6
  Author: Metronet
7
- Version: 1.1.0
8
  Requires at least: 3.5
9
  Author URI: http://www.metronet.no
10
  Contributors: ronalfy, metronet
@@ -40,7 +40,7 @@ class Metronet_Profile_Picture {
40
  //Scripts
41
  add_action( 'admin_print_scripts-user-edit.php', array( &$this, 'print_media_scripts' ) );
42
  add_action( 'admin_print_scripts-profile.php', array( &$this, 'print_media_scripts' ) );
43
- add_action( 'wp_enqueue_scripts', array( $this, 'profile_print_media_scripts' ) );
44
 
45
  //Styles
46
  add_action( 'admin_print_styles-user-edit.php', array( &$this, 'print_media_styles' ) );
@@ -55,6 +55,7 @@ class Metronet_Profile_Picture {
55
  add_action( 'edit_user_profile_update', array( &$this, 'save_user_profile' ) );
56
  add_action( 'personal_options_update', array( &$this, 'save_user_profile' ) );
57
 
 
58
  //User Avatar override
59
  add_filter( 'get_avatar', array( &$this, 'avatar_override' ), 10, 5 );
60
  } //end constructor
@@ -80,8 +81,10 @@ class Metronet_Profile_Picture {
80
  if ( has_post_thumbnail( $post_id ) ) {
81
  $post_thumbnail = get_the_post_thumbnail( $post_id, 'thumbnail' );
82
  $crop_html = $this->get_post_thumbnail_editor_link( $post_id );
 
 
83
  die( json_encode( array(
84
- 'thumb_html' => '<a href="#" class="mpp_add_media">' . $post_thumbnail . '</a>',
85
  'crop_html' => $crop_html,
86
  'has_thumb' => true
87
  ) ) );
@@ -101,13 +104,19 @@ class Metronet_Profile_Picture {
101
  if ( has_post_thumbnail( $post_id ) ) {
102
  $post_thumbnail = get_the_post_thumbnail( $post_id, 'thumbnail' );
103
  $crop_html = $this->get_post_thumbnail_editor_link( $post_id );
 
 
104
  die( json_encode( array(
105
- 'thumb_html' => '<a href="#" class="mpp_add_media">' . $post_thumbnail . '</a>',
106
  'crop_html' => $crop_html,
107
  'has_thumb' => true
108
  ) ) );
 
 
 
 
109
  }
110
- die( json_encode( array( 'thumb_html' => '', 'crop_html' => '', 'has_thumb' => false ) ) );
111
  } //end ajax_get_thumbnail
112
 
113
  /**
@@ -122,10 +131,14 @@ class Metronet_Profile_Picture {
122
  if ( $post_id == 0 || $user_id == 0 ) die( '' );
123
  check_ajax_referer( "update-post_$post_id" );
124
 
 
 
 
 
125
  //Save user meta and update thumbnail
126
  update_user_option( $user_id, 'metronet_image_id', 0 );
127
  delete_post_meta( $post_id, '_thumbnail_id' );
128
- die( json_encode( array( 'thumb_html' => '', 'crop_html' => '' ) ) );
129
  }
130
 
131
  /**
@@ -317,8 +330,6 @@ class Metronet_Profile_Picture {
317
  $user_id = $this->get_user_id();
318
  $post_id = $this->get_post_id( $user_id );
319
 
320
- //Create upload link
321
- $upload_link = sprintf( "<a href='#' class='mpp_add_media'>%s</a>", esc_html__( "Upload or Change Profile Picture", 'metronet_profile_picture' ) );
322
  ?>
323
  <tr valign="top">
324
  <th scope="row"><?php esc_html_e( "Profile Image", "metronet_profile_picture" ); ?></th>
@@ -327,15 +338,26 @@ class Metronet_Profile_Picture {
327
  <input type="hidden" name="metronet_post_id" id="metronet_post_id" value="<?php echo esc_attr( $post_id ); ?>" />
328
  <div id="metronet-profile-image">
329
  <?php
 
330
  if ( has_post_thumbnail( $post_id ) ) {
 
331
  echo '<a href="#" class="mpp_add_media">';
332
  $post_thumbnail = get_the_post_thumbnail( $post_id, 'thumbnail' );
333
  echo $post_thumbnail;
334
  echo '</a>';
 
 
 
 
 
 
 
 
 
335
  }
336
  ?>
 
337
  </div><!-- #metronet-profile-image -->
338
- <div id="metronet-upload-link"><?php echo $upload_link; ?> - <span class="description"><?php esc_html_e( 'Select "Set profile image" after uploading to choose the profile image', 'metronet_profile_picture' ); ?></span></div><!-- #metronet-upload-link -->
339
  <div id="metronet-override-avatar">
340
  <input type="hidden" name="metronet-user-avatar" value="off" />
341
  <?php
@@ -359,18 +381,6 @@ class Metronet_Profile_Picture {
359
  <br /><input type="checkbox" name="metronet-user-avatar" id="metronet-user-avatar" value="on" <?php echo $checked; ?> /><label for="metronet-user-avatar"> <?php esc_html_e( "Override Avatar?", "metronet_profile_picture" ); ?></label>
360
  <?php endif; ?>
361
  </div><!-- #metronet-override-avatar -->
362
- <div id="metronet-pte">
363
- <?php echo $this->get_post_thumbnail_editor_link( $post_id ); ?>
364
- </div><!-- #metronet-pte -->
365
- <div id="metronet-remove" <?php if ( !has_post_thumbnail( $post_id ) ) { echo 'style="display: none;"'; } ?>>
366
- <br />
367
- <?php
368
- echo '<a href="#">';
369
- esc_html_e( "Remove profile image", "metronet_profile_picture" );
370
- echo '</a>';
371
- ?>
372
- </div><!-- #metronet-remove -->
373
-
374
  </td>
375
  </tr>
376
  <?php
@@ -399,6 +409,40 @@ class Metronet_Profile_Picture {
399
  'ajax_url' => esc_url( admin_url( 'admin-ajax.php' ) )
400
  )
401
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
402
  } //end print_media_scripts
403
 
404
  public function print_media_styles() {
4
  Plugin URI: http://wordpress.org/extend/plugins/metronet-profile-picture/
5
  Description: Use the native WP uploader on your user profile page.
6
  Author: Metronet
7
+ Version: 1.2.0
8
  Requires at least: 3.5
9
  Author URI: http://www.metronet.no
10
  Contributors: ronalfy, metronet
40
  //Scripts
41
  add_action( 'admin_print_scripts-user-edit.php', array( &$this, 'print_media_scripts' ) );
42
  add_action( 'admin_print_scripts-profile.php', array( &$this, 'print_media_scripts' ) );
43
+ add_action( 'wp_enqueue_scripts', array( &$this, 'profile_print_media_scripts' ) );
44
 
45
  //Styles
46
  add_action( 'admin_print_styles-user-edit.php', array( &$this, 'print_media_styles' ) );
55
  add_action( 'edit_user_profile_update', array( &$this, 'save_user_profile' ) );
56
  add_action( 'personal_options_update', array( &$this, 'save_user_profile' ) );
57
 
58
+
59
  //User Avatar override
60
  add_filter( 'get_avatar', array( &$this, 'avatar_override' ), 10, 5 );
61
  } //end constructor
81
  if ( has_post_thumbnail( $post_id ) ) {
82
  $post_thumbnail = get_the_post_thumbnail( $post_id, 'thumbnail' );
83
  $crop_html = $this->get_post_thumbnail_editor_link( $post_id );
84
+ $thumb_html = sprintf( '<a href="#" class="mpp_add_media">%s</a>', $post_thumbnail );
85
+ $thumb_html .= sprintf( '<a id="metronet-remove" class="dashicons dashicons-trash" href="#" title="%s">%s</a>', esc_attr__( 'Remove profile image', 'metronet_profile_picture' ), esc_html__( "Remove profile image", "metronet_profile_picture" ) );
86
  die( json_encode( array(
87
+ 'thumb_html' => $thumb_html,
88
  'crop_html' => $crop_html,
89
  'has_thumb' => true
90
  ) ) );
104
  if ( has_post_thumbnail( $post_id ) ) {
105
  $post_thumbnail = get_the_post_thumbnail( $post_id, 'thumbnail' );
106
  $crop_html = $this->get_post_thumbnail_editor_link( $post_id );
107
+ $thumb_html = sprintf( '<a href="#" class="mpp_add_media">%s</a>', $post_thumbnail );
108
+ $thumb_html .= sprintf( '<a id="metronet-remove" class="dashicons dashicons-trash" href="#" title="%s">%s</a>', esc_attr__( 'Remove profile image', 'metronet_profile_picture' ), esc_html__( "Remove profile image", "metronet_profile_picture" ) );
109
  die( json_encode( array(
110
+ 'thumb_html' => $thumb_html,
111
  'crop_html' => $crop_html,
112
  'has_thumb' => true
113
  ) ) );
114
+ } else {
115
+ $thumb_html = '<a href="#" class="mpp_add_media">';
116
+ $thumb_html.= sprintf( '<img src="%s" width="150" height="150" title="%s" />', $this->get_plugin_url( 'img/mystery.png' ), esc_attr__( "Upload or Change Profile Picture", 'metronet_profile_picture' ) );
117
+ $thumb_html .= '</a>';
118
  }
119
+ die( json_encode( array( 'thumb_html' => $thumb_html, 'crop_html' => '', 'has_thumb' => false ) ) );
120
  } //end ajax_get_thumbnail
121
 
122
  /**
131
  if ( $post_id == 0 || $user_id == 0 ) die( '' );
132
  check_ajax_referer( "update-post_$post_id" );
133
 
134
+ $thumb_html = '<a href="#" class="mpp_add_media">';
135
+ $thumb_html.= sprintf( '<img src="%s" width="150" height="150" title="%s" />', $this->get_plugin_url( 'img/mystery.png' ), esc_attr__( "Upload or Change Profile Picture", 'metronet_profile_picture' ) );
136
+ $thumb_html .= '</a>';
137
+
138
  //Save user meta and update thumbnail
139
  update_user_option( $user_id, 'metronet_image_id', 0 );
140
  delete_post_meta( $post_id, '_thumbnail_id' );
141
+ die( json_encode( array( 'thumb_html' => $thumb_html, 'crop_html' => '' ) ) );
142
  }
143
 
144
  /**
330
  $user_id = $this->get_user_id();
331
  $post_id = $this->get_post_id( $user_id );
332
 
 
 
333
  ?>
334
  <tr valign="top">
335
  <th scope="row"><?php esc_html_e( "Profile Image", "metronet_profile_picture" ); ?></th>
338
  <input type="hidden" name="metronet_post_id" id="metronet_post_id" value="<?php echo esc_attr( $post_id ); ?>" />
339
  <div id="metronet-profile-image">
340
  <?php
341
+ $has_profile_image = false;
342
  if ( has_post_thumbnail( $post_id ) ) {
343
+ $has_profile_image = true;
344
  echo '<a href="#" class="mpp_add_media">';
345
  $post_thumbnail = get_the_post_thumbnail( $post_id, 'thumbnail' );
346
  echo $post_thumbnail;
347
  echo '</a>';
348
+ } else {
349
+ echo '<a href="#" class="mpp_add_media">';
350
+ $post_thumbnail = sprintf( '<img src="%s" width="150" height="150" title="%s" />', $this->get_plugin_url( 'img/mystery.png' ), esc_attr__( "Upload or Change Profile Picture", 'metronet_profile_picture' ) );
351
+ echo $post_thumbnail;
352
+ echo '</a>';
353
+ }
354
+ $remove_classes = array( 'dashicons', 'dashicons-trash' );
355
+ if ( !$has_profile_image ) {
356
+ $remove_classes[] = 'mpp-no-profile-image';
357
  }
358
  ?>
359
+ <a id="metronet-remove" class="<?php echo implode( ' ', $remove_classes ); ?>" href="#" title="<?php esc_attr_e( 'Remove profile image', 'metronet_profile_picture' ); ?>"><?php esc_html_e( "Remove profile image", "metronet_profile_picture" );?></a>
360
  </div><!-- #metronet-profile-image -->
 
361
  <div id="metronet-override-avatar">
362
  <input type="hidden" name="metronet-user-avatar" value="off" />
363
  <?php
381
  <br /><input type="checkbox" name="metronet-user-avatar" id="metronet-user-avatar" value="on" <?php echo $checked; ?> /><label for="metronet-user-avatar"> <?php esc_html_e( "Override Avatar?", "metronet_profile_picture" ); ?></label>
382
  <?php endif; ?>
383
  </div><!-- #metronet-override-avatar -->
 
 
 
 
 
 
 
 
 
 
 
 
384
  </td>
385
  </tr>
386
  <?php
409
  'ajax_url' => esc_url( admin_url( 'admin-ajax.php' ) )
410
  )
411
  );
412
+ ?>
413
+ <style>
414
+ /* Metronet Profile Picture */
415
+ #metronet-profile-image {
416
+ position: relative;
417
+ float: left;
418
+ }
419
+ #metronet-remove {
420
+ position: absolute;
421
+ background: #424242;
422
+ top: 0;
423
+ right: 0;
424
+ display: block;
425
+ padding: 3px;
426
+ width: 20px;
427
+ height: 20px;
428
+ overflow: hidden;
429
+ }
430
+ #metronet-remove:before {
431
+ content: "\f182";
432
+ color: #fd6a6a;
433
+ font-size: 20px;
434
+ }
435
+ #metronet-remove:hover:before {
436
+ color: #ff3e3e;
437
+ }
438
+ #metronet-remove.mpp-no-profile-image {
439
+ display: none;
440
+ }
441
+ #metronet-override-avatar {
442
+ clear: left;
443
+ }
444
+ </style>
445
+ <?php
446
  } //end print_media_scripts
447
 
448
  public function print_media_styles() {
readme.txt CHANGED
@@ -2,20 +2,18 @@
2
  Contributors: metronet, ronalfy
3
  Tags: users, user, user profile
4
  Requires at least: 3.5
5
- Tested up to: 4.0
6
- Stable tag: 1.1.0
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
10
  Set a custom profile image for a user using the standard WordPress media upload tool.
11
  == Description ==
12
 
13
- Set a custom profile image for a user using the standard WordPress media upload tool.
14
 
15
  A template tag is supplied for outputting to a theme and the option to override a user's default avatar is also available.
16
 
17
- This plugin is fully compatible with <a href="http://wordpress.org/extend/plugins/post-thumbnail-editor/">Post Thumbnail Editor</a> for cropping any uploaded images.
18
-
19
  If you like this plugin, please leave a rating/review and mark the plugin as working.
20
 
21
  <h3>Translations</h3>
@@ -75,8 +73,7 @@ If you want to hide the "Override Avatar" checkbox, use this filter (the overrid
75
  = How do you set a user profile image? =
76
 
77
  1. Visit the profile page you would like to edit.
78
- 2. Click "Upload or Change Profile Picture"
79
- 3. Upload a new image and select "Set profile image", which will save the image.
80
 
81
  To override an avatar, select the "Override Avatar?" checkbox and save the profile page.
82
 
@@ -100,10 +97,14 @@ Yes, but you'll have to set a new profile image per site. This is currently a l
100
 
101
  1. Profile page options.
102
  2. Media upload dialog.
103
- 3. Post Thumbnail Editor compatibility.
104
 
105
  == Changelog ==
106
 
 
 
 
 
 
107
  = 1.1.0 =
108
  * Released 11 November 2014
109
  * Added the ability to remove profile images (aside from deleting the image).
@@ -163,6 +164,9 @@ Yes, but you'll have to set a new profile image per site. This is currently a l
163
 
164
  == Upgrade Notice ==
165
 
 
 
 
166
  = 1.1.0 =
167
  Added the ability to remove profile images (aside from deleting the image). Added better internationalization capabilities. Added compatibility with Theme My Login.
168
 
2
  Contributors: metronet, ronalfy
3
  Tags: users, user, user profile
4
  Requires at least: 3.5
5
+ Tested up to: 4.1
6
+ Stable tag: 1.2.0
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
10
  Set a custom profile image for a user using the standard WordPress media upload tool.
11
  == Description ==
12
 
13
+ Set or remove a custom profile image for a user using the standard WordPress media upload tool.
14
 
15
  A template tag is supplied for outputting to a theme and the option to override a user's default avatar is also available.
16
 
 
 
17
  If you like this plugin, please leave a rating/review and mark the plugin as working.
18
 
19
  <h3>Translations</h3>
73
  = How do you set a user profile image? =
74
 
75
  1. Visit the profile page you would like to edit.
76
+ 2. Click on the profile picture to add, edit, or remove the profile picture.
 
77
 
78
  To override an avatar, select the "Override Avatar?" checkbox and save the profile page.
79
 
97
 
98
  1. Profile page options.
99
  2. Media upload dialog.
 
100
 
101
  == Changelog ==
102
 
103
+ = 1.2.0 =
104
+ * Released 07 December 2014
105
+ * Reducing clutter in the interface. Removed text option to upload. Added default image if no profile image is available. Added option to remove the profile image.
106
+ * Fixed internationalization bug in the JavaScript.
107
+
108
  = 1.1.0 =
109
  * Released 11 November 2014
110
  * Added the ability to remove profile images (aside from deleting the image).
164
 
165
  == Upgrade Notice ==
166
 
167
+ = 1.2.0 =
168
+ Reducing clutter in the interface. Removed text option to upload. Added default image if no profile image is available. Added option to remove the profile image.
169
+
170
  = 1.1.0 =
171
  Added the ability to remove profile images (aside from deleting the image). Added better internationalization capabilities. Added compatibility with Theme My Login.
172