User Profile Picture - Version 1.4.0

Version Description

  • Released 2016-08-29 (props kelderic)
  • Bug fix: CSS Fixes to the trashcan icon and image placeholders
  • Bug fix: Modal window was set to the wrong settings
  • Enhancement: Avatar override is now the default option
Download this release

Release Info

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

Code changes from version 1.3.1 to 1.4.0

Files changed (3) hide show
  1. js/mpp.js +32 -16
  2. metronet-profile-picture.php +19 -15
  3. readme.txt +18 -3
js/mpp.js CHANGED
@@ -7,7 +7,7 @@ jQuery( document ).ready( function( $ ) {
7
  post_id: post_id,
8
  },
9
  function( response ) {
10
- jQuery( "#metronet-profile-image" ).html( response.thumb_html );
11
  },
12
  'json'
13
  );
@@ -21,27 +21,40 @@ jQuery( document ).ready( function( $ ) {
21
  _wpnonce: metronet_profile_image.nonce
22
  },
23
  function( response ) {
24
- jQuery( "#metronet-profile-image" ).html( response.thumb_html );
25
  },
26
  'json'
27
  );
28
  }
 
 
 
 
 
 
 
 
29
 
30
  $('#mpp').on( "click", '.mpp_add_media', function(e) {
 
31
  //Assign the default view for the media uploader
 
32
  var uploader = wp.media({
33
- state: 'featured-image',
34
- states: [ new wp.media.controller.FeaturedImage() ],
 
 
 
35
  });
36
- uploader.state('featured-image').set( 'title', metronet_profile_image.set_profile_text );
37
-
38
- uploader.on( 'toolbar:create:featured-image', function( toolbar ) {
39
- var options = {
40
- };
41
  options.items = {};
42
  options.items.select = {
43
  text: metronet_profile_image.set_profile_text,
44
- style: 'primary',
45
  click: wp.media.view.Toolbar.Select.prototype.clickSelect,
46
  requires: { selection: true },
47
  event: 'select',
@@ -49,7 +62,7 @@ jQuery( document ).ready( function( $ ) {
49
  close: true,
50
  state: false
51
  };
52
- if ( $( '#metronet-profile-image img' ).length > 0 ) {
53
  options.items.remove = {
54
  text: metronet_profile_image.remove_profile_text,
55
  style: 'secondary',
@@ -75,24 +88,27 @@ jQuery( document ).ready( function( $ ) {
75
  _wpnonce: metronet_profile_image.nonce
76
  },
77
  function( response ) {
78
- jQuery( "#metronet-profile-image" ).html( response.thumb_html );
79
  },
80
  'json'
81
  );
82
  };
83
 
84
  //For when the Add Profile Image is clicked
85
- uploader.state('featured-image').on( 'select', function() {
86
- var featured_id = this.get('selection').single().id;
 
87
 
88
- if ( ! featured_id )
89
  return;
 
90
 
91
  uploader.mt_featured_set( featured_id );
 
92
  } );
93
 
94
  //When the remove buttons is clicked
95
- uploader.state( 'featured-image' ).on( 'remove', function() {
96
  mt_remove_profile_image();
97
  } );
98
 
7
  post_id: post_id,
8
  },
9
  function( response ) {
10
+ jQuery( "#metronet-profile-image" ).html( mt_display_block( response.thumb_html ) );
11
  },
12
  'json'
13
  );
21
  _wpnonce: metronet_profile_image.nonce
22
  },
23
  function( response ) {
24
+ jQuery( "#metronet-profile-image" ).html( mt_display_block( response.thumb_html ) );
25
  },
26
  'json'
27
  );
28
  }
29
+ // Set thumbnail img and wrapping a to display:block to fix visual bug
30
+ function mt_display_block(htmlString) {
31
+ var temp = document.createElement('div');
32
+ temp.innerHTML = htmlString;
33
+ temp.firstElementChild.style.display = 'block';
34
+ temp.firstElementChild.firstElementChild.style.display = 'block';
35
+ return temp.innerHTML;
36
+ }
37
 
38
  $('#mpp').on( "click", '.mpp_add_media', function(e) {
39
+
40
  //Assign the default view for the media uploader
41
+
42
  var uploader = wp.media({
43
+ title: metronet_profile_image.set_profile_text,
44
+ button: {
45
+ text: metronet_profile_image.remove_profile_text
46
+ },
47
+ multiple: false // Set to true to allow multiple files to be selected
48
  });
49
+
50
+ // CUSTOM TOOLBAR ON BOTTOM OF MEDIA MANAGER. SETS UP THE TWO ACTION BUTTONS
51
+
52
+ uploader.on( 'toolbar:create', function( toolbar ) {
53
+ var options = {};
54
  options.items = {};
55
  options.items.select = {
56
  text: metronet_profile_image.set_profile_text,
57
+ style: 'primary',
58
  click: wp.media.view.Toolbar.Select.prototype.clickSelect,
59
  requires: { selection: true },
60
  event: 'select',
62
  close: true,
63
  state: false
64
  };
65
+ if ( ! $( '#metronet-profile-image a' ).hasClass('default-image') ) {
66
  options.items.remove = {
67
  text: metronet_profile_image.remove_profile_text,
68
  style: 'secondary',
88
  _wpnonce: metronet_profile_image.nonce
89
  },
90
  function( response ) {
91
+ jQuery( "#metronet-profile-image" ).html( mt_display_block( response.thumb_html ) );
92
  },
93
  'json'
94
  );
95
  };
96
 
97
  //For when the Add Profile Image is clicked
98
+ uploader.on( 'select', function() {
99
+
100
+ var featured_id = uploader.state().get('selection').first().id;
101
 
102
+ if ( ! featured_id ) {
103
  return;
104
+ }
105
 
106
  uploader.mt_featured_set( featured_id );
107
+
108
  } );
109
 
110
  //When the remove buttons is clicked
111
+ uploader.on( 'remove', function() {
112
  mt_remove_profile_image();
113
  } );
114
 
metronet-profile-picture.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: User 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: Ronald Huereca
7
- Version: 1.3.1
8
  Requires at least: 3.5
9
  Author URI: https://www.mediaron.com
10
  Contributors: ronalfy
@@ -63,6 +63,9 @@ class Metronet_Profile_Picture {
63
 
64
  //Rest API
65
  add_action( 'rest_api_init', array( $this, 'rest_api_register' ) );
 
 
 
66
  } //end constructor
67
 
68
  /**
@@ -76,7 +79,7 @@ class Metronet_Profile_Picture {
76
  $post_id = isset( $_POST[ 'post_id' ] ) ? absint( $_POST[ 'post_id' ] ) : 0;
77
  $user_id = isset( $_POST[ 'user_id' ] ) ? absint( $_POST[ 'user_id' ] ) : 0;
78
  $thumbnail_id = isset( $_POST[ 'thumbnail_id' ] ) ? absint( $_POST[ 'thumbnail_id' ] ) : 0;
79
- if ( $post_id == 0 || $user_id == 0 || $thumbnail_id == 0 ) die( '' );
80
  check_ajax_referer( "mt-update-post_$post_id" );
81
 
82
  //Save user meta
@@ -111,9 +114,9 @@ class Metronet_Profile_Picture {
111
 
112
  if ( has_post_thumbnail( $post_id ) ) {
113
  $thumb_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'thumbnail' , false, '' );
114
- $post_thumbnail = sprintf( '<img src="%s" width="150" height="150" title="%s" />', esc_url( $thumb_src[0] ), esc_attr__( "Upload or Change Profile Picture", 'metronet-profile-picture' ) );
115
  $crop_html = $this->get_post_thumbnail_editor_link( $post_id );
116
- $thumb_html = sprintf( '<a href="#" class="mpp_add_media">%s</a>', $post_thumbnail );
117
  $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" ) );
118
  die( json_encode( array(
119
  'thumb_html' => $thumb_html,
@@ -121,8 +124,8 @@ class Metronet_Profile_Picture {
121
  'has_thumb' => true
122
  ) ) );
123
  } else {
124
- $thumb_html = '<a href="#" class="mpp_add_media">';
125
- $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' ) );
126
  $thumb_html .= '</a>';
127
  }
128
  die( json_encode( array( 'thumb_html' => $thumb_html, 'crop_html' => '', 'has_thumb' => false ) ) );
@@ -141,8 +144,8 @@ class Metronet_Profile_Picture {
141
  if ( $post_id == 0 || $user_id == 0 ) die( '' );
142
  check_ajax_referer( "mt-update-post_$post_id" );
143
 
144
- $thumb_html = '<a href="#" class="mpp_add_media">';
145
- $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' ) );
146
  $thumb_html .= '</a>';
147
 
148
  //Save user meta and update thumbnail
@@ -368,14 +371,14 @@ class Metronet_Profile_Picture {
368
  $has_profile_image = false;
369
  if ( has_post_thumbnail( $post_id ) ) {
370
  $has_profile_image = true;
371
- echo '<a href="#" class="mpp_add_media">';
372
  $thumb_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'thumbnail' , false, '' );
373
- $post_thumbnail = sprintf( '<img src="%s" width="150" height="150" title="%s" />', esc_url( $thumb_src[0] ), esc_attr__( "Upload or Change Profile Picture", 'metronet-profile-picture' ) );
374
  echo $post_thumbnail;
375
  echo '</a>';
376
  } else {
377
- echo '<a href="#" class="mpp_add_media">';
378
- $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' ) );
379
  echo $post_thumbnail;
380
  echo '</a>';
381
  }
@@ -428,11 +431,11 @@ class Metronet_Profile_Picture {
428
  $post_id = $this->get_post_id( $this->get_user_id() );
429
  wp_enqueue_media( array( 'post' => $post_id ) );
430
  $script_deps = array( 'media-editor' );
431
- wp_enqueue_script( 'mt-pp', $this->get_plugin_url( '/js/mpp.js' ), $script_deps, '20150416', true );
432
  wp_localize_script( 'mt-pp', 'metronet_profile_image',
433
  array(
434
- 'set_profile_text' => __( 'Set profile image', 'metronet-profile-picture' ),
435
- 'remove_profile_text' => __( 'Remove profile image', 'metronet-profile-picture' ),
436
  'crop' => __( 'Crop Thumbnail', 'metronet-profile-picture' ),
437
  'ajax_url' => esc_url( admin_url( 'admin-ajax.php' ) ),
438
  'user_post_id' => absint( $post_id ),
@@ -461,6 +464,7 @@ class Metronet_Profile_Picture {
461
  content: "\f182";
462
  color: #fd6a6a;
463
  font-size: 20px;
 
464
  }
465
  #metronet-remove:hover:before {
466
  color: #ff3e3e;
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: Ronald Huereca
7
+ Version: 1.4.0
8
  Requires at least: 3.5
9
  Author URI: https://www.mediaron.com
10
  Contributors: ronalfy
63
 
64
  //Rest API
65
  add_action( 'rest_api_init', array( $this, 'rest_api_register' ) );
66
+
67
+ //Avatar check overridden - Can be overridden using a higher priority
68
+ add_filter( 'mpp_hide_avatar_override', '__return_true', 5 );
69
  } //end constructor
70
 
71
  /**
79
  $post_id = isset( $_POST[ 'post_id' ] ) ? absint( $_POST[ 'post_id' ] ) : 0;
80
  $user_id = isset( $_POST[ 'user_id' ] ) ? absint( $_POST[ 'user_id' ] ) : 0;
81
  $thumbnail_id = isset( $_POST[ 'thumbnail_id' ] ) ? absint( $_POST[ 'thumbnail_id' ] ) : 0;
82
+ if ( $post_id == 0 || $user_id == 0 || $thumbnail_id == 0 || 'mt_pp' !== get_post_type( $post_id ) ) die( '' );
83
  check_ajax_referer( "mt-update-post_$post_id" );
84
 
85
  //Save user meta
114
 
115
  if ( has_post_thumbnail( $post_id ) ) {
116
  $thumb_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'thumbnail' , false, '' );
117
+ $post_thumbnail = sprintf( '<img style="display:block" src="%s" width="150" height="150" title="%s" />', esc_url( $thumb_src[0] ), esc_attr__( "Upload or Change Profile Picture", 'metronet-profile-picture' ) );
118
  $crop_html = $this->get_post_thumbnail_editor_link( $post_id );
119
+ $thumb_html = sprintf( '<a style="display:block" href="#" class="mpp_add_media">%s</a>', $post_thumbnail );
120
  $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" ) );
121
  die( json_encode( array(
122
  'thumb_html' => $thumb_html,
124
  'has_thumb' => true
125
  ) ) );
126
  } else {
127
+ $thumb_html = '<a style="display:block" href="#" class="mpp_add_media default-image">';
128
+ $thumb_html.= sprintf( '<img style="display:block" 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' ) );
129
  $thumb_html .= '</a>';
130
  }
131
  die( json_encode( array( 'thumb_html' => $thumb_html, 'crop_html' => '', 'has_thumb' => false ) ) );
144
  if ( $post_id == 0 || $user_id == 0 ) die( '' );
145
  check_ajax_referer( "mt-update-post_$post_id" );
146
 
147
+ $thumb_html = '<a style="display:block" href="#" class="mpp_add_media default-image">';
148
+ $thumb_html.= sprintf( '<img style="display:block" 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' ) );
149
  $thumb_html .= '</a>';
150
 
151
  //Save user meta and update thumbnail
371
  $has_profile_image = false;
372
  if ( has_post_thumbnail( $post_id ) ) {
373
  $has_profile_image = true;
374
+ echo '<a style="display:block" href="#" class="mpp_add_media">';
375
  $thumb_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'thumbnail' , false, '' );
376
+ $post_thumbnail = sprintf( '<img style="display:block" src="%s" width="150" height="150" title="%s" />', esc_url( $thumb_src[0] ), esc_attr__( "Upload or Change Profile Picture", 'metronet-profile-picture' ) );
377
  echo $post_thumbnail;
378
  echo '</a>';
379
  } else {
380
+ echo '<a style="display:block" href="#" class="mpp_add_media default-image">';
381
+ $post_thumbnail = sprintf( '<img style="display:block" 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' ) );
382
  echo $post_thumbnail;
383
  echo '</a>';
384
  }
431
  $post_id = $this->get_post_id( $this->get_user_id() );
432
  wp_enqueue_media( array( 'post' => $post_id ) );
433
  $script_deps = array( 'media-editor' );
434
+ wp_enqueue_script( 'mt-pp', $this->get_plugin_url( '/js/mpp.js' ), $script_deps, '20160829', true );
435
  wp_localize_script( 'mt-pp', 'metronet_profile_image',
436
  array(
437
+ 'set_profile_text' => __( 'Set Profile Image', 'metronet-profile-picture' ),
438
+ 'remove_profile_text' => __( 'Remove Profile Image', 'metronet-profile-picture' ),
439
  'crop' => __( 'Crop Thumbnail', 'metronet-profile-picture' ),
440
  'ajax_url' => esc_url( admin_url( 'admin-ajax.php' ) ),
441
  'user_post_id' => absint( $post_id ),
464
  content: "\f182";
465
  color: #fd6a6a;
466
  font-size: 20px;
467
+ margin-right:20px;
468
  }
469
  #metronet-remove:hover:before {
470
  color: #ff3e3e;
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: ronalfy
3
  Tags: users, user, user profile
4
  Requires at least: 3.5
5
  Tested up to: 4.6
6
- Stable tag: 1.3.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Donate link: https://mediaron.com/contribute/
@@ -11,11 +11,17 @@ Donate link: https://mediaron.com/contribute/
11
  Set a custom profile image for a user using the standard WordPress media upload tool.
12
  == Description ==
13
 
14
- Set or remove a custom profile image for a user using the standard WordPress media upload tool.
 
 
15
 
16
  A template tag is supplied for outputting to a theme and the option to override a user's default avatar is also available.
17
 
18
- If you like this plugin, please leave a rating/review and mark the plugin as working.
 
 
 
 
19
 
20
  == Installation ==
21
 
@@ -108,6 +114,12 @@ Yes, but you'll have to set a new profile image per site. This is currently a l
108
 
109
  == Changelog ==
110
 
 
 
 
 
 
 
111
  = 1.3.1 =
112
  * Released 2016-04-02
113
  * Fixing thumbnail calls that could potential be inadvertently filtered and cause the profile picture to provide an erroneous callback. Props @Monter.
@@ -207,6 +219,9 @@ Yes, but you'll have to set a new profile image per site. This is currently a l
207
 
208
  == Upgrade Notice ==
209
 
 
 
 
210
  = 1.3.1 =
211
  Fixing thumbnail calls that could potential be inadvertently filtered and cause the profile picture to provide an erroneous callback.
212
 
3
  Tags: users, user, user profile
4
  Requires at least: 3.5
5
  Tested up to: 4.6
6
+ Stable tag: 1.4.0
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Donate link: https://mediaron.com/contribute/
11
  Set a custom profile image for a user using the standard WordPress media upload tool.
12
  == Description ==
13
 
14
+ Set or remove a custom profile image for a user using the standard WordPress media upload tool.
15
+
16
+ Users must have the ability to upload images (typically author role or greater). You can use the plugin <a href="https://wordpress.org/plugins/members/">Members</a> to allow other roles (e.g. subscribers) the ability to upload images.
17
 
18
  A template tag is supplied for outputting to a theme and the option to override a user's default avatar is also available.
19
 
20
+ <h3>Help Contribute</h3>
21
+
22
+ * Leave a star rating
23
+ * <a href="https://translate.wordpress.org/projects/wp-plugins/metronet-profile-picture">Contribute a translation</a>
24
+ * <a href="https://github.com/ronalfy/user-profile-picture">Contribute some code</a>
25
 
26
  == Installation ==
27
 
114
 
115
  == Changelog ==
116
 
117
+ = 1.4.0 =
118
+ * Released 2016-08-29 (props kelderic)
119
+ * Bug fix: CSS Fixes to the trashcan icon and image placeholders
120
+ * Bug fix: Modal window was set to the wrong settings
121
+ * Enhancement: Avatar override is now the default option
122
+
123
  = 1.3.1 =
124
  * Released 2016-04-02
125
  * Fixing thumbnail calls that could potential be inadvertently filtered and cause the profile picture to provide an erroneous callback. Props @Monter.
219
 
220
  == Upgrade Notice ==
221
 
222
+ = 1.4.0 =
223
+ Avatar override is now a default option. Numerous bug fixes. Please see changelog.
224
+
225
  = 1.3.1 =
226
  Fixing thumbnail calls that could potential be inadvertently filtered and cause the profile picture to provide an erroneous callback.
227