Version Description
- Released 2018-08-19
- Enhancement: Loading image now shows between states for better UX
- Enhancement: Plugin attempts to override the default WordPress avatar in the User Profile page
- Enhancement: Plugin attempts to override the admin bar avatars if the users match
- Enhancement: Added Click to Edit bar to make it more obvious what to do with the profile picture
- Refactor: Plugin now uses wp_send_json instead of json_encode for more compatibility
Download this release
Release Info
| Developer | ronalfy |
| Plugin | |
| Version | 1.5.5 |
| Comparing to | |
| See all releases | |
Code changes from version 1.5.1 to 1.5.5
- img/loading.gif +0 -0
- js/mpp.js +18 -0
- metronet-profile-picture.php +116 -31
- readme.txt +17 -2
img/loading.gif
ADDED
|
Binary file
|
js/mpp.js
CHANGED
|
@@ -2,18 +2,25 @@ jQuery( document ).ready( function( $ ) {
|
|
| 2 |
//Refresh the profile image thumbnail
|
| 3 |
function mt_ajax_thumbnail_refresh() {
|
| 4 |
var post_id = jQuery( "#metronet_post_id" ).val();
|
|
|
|
| 5 |
$.post( metronet_profile_image.ajax_url, {
|
| 6 |
action: 'metronet_get_thumbnail',
|
| 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 |
);
|
| 14 |
};
|
| 15 |
//Remove the profile image
|
| 16 |
function mt_remove_profile_image() {
|
|
|
|
| 17 |
$.post( metronet_profile_image.ajax_url, {
|
| 18 |
action: 'metronet_remove_thumbnail',
|
| 19 |
post_id: metronet_profile_image.user_post_id,
|
|
@@ -22,6 +29,11 @@ jQuery( document ).ready( function( $ ) {
|
|
| 22 |
},
|
| 23 |
function( response ) {
|
| 24 |
jQuery( "#metronet-profile-image" ).html( mt_display_block( response.thumb_html ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
},
|
| 26 |
'json'
|
| 27 |
);
|
|
@@ -84,6 +96,7 @@ jQuery( document ).ready( function( $ ) {
|
|
| 84 |
|
| 85 |
//For when the featured thumbnail is set
|
| 86 |
uploader.mt_featured_set = function( id ) {
|
|
|
|
| 87 |
$.post( metronet_profile_image.ajax_url, {
|
| 88 |
action: 'metronet_add_thumbnail',
|
| 89 |
post_id: metronet_profile_image.user_post_id,
|
|
@@ -93,6 +106,11 @@ jQuery( document ).ready( function( $ ) {
|
|
| 93 |
},
|
| 94 |
function( response ) {
|
| 95 |
jQuery( "#metronet-profile-image" ).html( mt_display_block( response.thumb_html ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
},
|
| 97 |
'json'
|
| 98 |
);
|
| 2 |
//Refresh the profile image thumbnail
|
| 3 |
function mt_ajax_thumbnail_refresh() {
|
| 4 |
var post_id = jQuery( "#metronet_post_id" ).val();
|
| 5 |
+
jQuery( '#metronet-profile-image' ).html( '<img class="mpp-loading" alt="Loading" width="150" height="150" src="' + metronet_profile_image.loading_gif + '" />' );
|
| 6 |
$.post( metronet_profile_image.ajax_url, {
|
| 7 |
action: 'metronet_get_thumbnail',
|
| 8 |
post_id: post_id,
|
| 9 |
},
|
| 10 |
function( response ) {
|
| 11 |
jQuery( "#metronet-profile-image" ).html( mt_display_block( response.thumb_html ) );
|
| 12 |
+
jQuery( '.user-profile-picture img ').replaceWith( response.avatar );
|
| 13 |
+
if ( response.user_id === response.logged_in_user_id ) {
|
| 14 |
+
jQuery( '#wp-admin-bar-my-account img.avatar-26' ).replaceWith( response.avatar_admin_small );
|
| 15 |
+
jQuery( '#wp-admin-bar-my-account img.avatar-64' ).replaceWith( response.avatar_admin_medium );
|
| 16 |
+
}
|
| 17 |
},
|
| 18 |
'json'
|
| 19 |
);
|
| 20 |
};
|
| 21 |
//Remove the profile image
|
| 22 |
function mt_remove_profile_image() {
|
| 23 |
+
jQuery( '#metronet-profile-image' ).html( '<img class="mpp-loading" alt="Loading" width="150" height="150" src="' + metronet_profile_image.loading_gif + '" />' );
|
| 24 |
$.post( metronet_profile_image.ajax_url, {
|
| 25 |
action: 'metronet_remove_thumbnail',
|
| 26 |
post_id: metronet_profile_image.user_post_id,
|
| 29 |
},
|
| 30 |
function( response ) {
|
| 31 |
jQuery( "#metronet-profile-image" ).html( mt_display_block( response.thumb_html ) );
|
| 32 |
+
jQuery( '.user-profile-picture img ').replaceWith( response.avatar );
|
| 33 |
+
if ( response.user_id === response.logged_in_user_id ) {
|
| 34 |
+
jQuery( '#wp-admin-bar-my-account img.avatar-26' ).replaceWith( response.avatar_admin_small );
|
| 35 |
+
jQuery( '#wp-admin-bar-my-account img.avatar-64' ).replaceWith( response.avatar_admin_medium );
|
| 36 |
+
}
|
| 37 |
},
|
| 38 |
'json'
|
| 39 |
);
|
| 96 |
|
| 97 |
//For when the featured thumbnail is set
|
| 98 |
uploader.mt_featured_set = function( id ) {
|
| 99 |
+
jQuery( '#metronet-profile-image' ).html( '<img class="mpp-loading" alt="Loading" width="150" height="150" src="' + metronet_profile_image.loading_gif + '" />' );
|
| 100 |
$.post( metronet_profile_image.ajax_url, {
|
| 101 |
action: 'metronet_add_thumbnail',
|
| 102 |
post_id: metronet_profile_image.user_post_id,
|
| 106 |
},
|
| 107 |
function( response ) {
|
| 108 |
jQuery( "#metronet-profile-image" ).html( mt_display_block( response.thumb_html ) );
|
| 109 |
+
jQuery( '.user-profile-picture img ').replaceWith( response.avatar );
|
| 110 |
+
if ( response.user_id === response.logged_in_user_id ) {
|
| 111 |
+
jQuery( '#wp-admin-bar-my-account img.avatar-26' ).replaceWith( response.avatar_admin_small );
|
| 112 |
+
jQuery( '#wp-admin-bar-my-account img.avatar-64' ).replaceWith( response.avatar_admin_medium );
|
| 113 |
+
}
|
| 114 |
},
|
| 115 |
'json'
|
| 116 |
);
|
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.5.
|
| 8 |
Requires at least: 3.5
|
| 9 |
Author URI: https://www.mediaron.com
|
| 10 |
Contributors: ronalfy
|
|
@@ -92,15 +92,29 @@ class Metronet_Profile_Picture {
|
|
| 92 |
$thumb_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'thumbnail' , false, '' );
|
| 93 |
$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' ) );
|
| 94 |
$crop_html = $this->get_post_thumbnail_editor_link( $post_id );
|
| 95 |
-
$thumb_html = sprintf( '<a href="#" class="mpp_add_media">%s</a>', $post_thumbnail );
|
| 96 |
$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" ) );
|
| 97 |
-
|
| 98 |
-
'thumb_html'
|
| 99 |
-
'crop_html'
|
| 100 |
-
'has_thumb'
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
}
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
} //end ajax_add_thumbnail
|
| 105 |
|
| 106 |
/**
|
|
@@ -112,24 +126,45 @@ class Metronet_Profile_Picture {
|
|
| 112 |
public function ajax_get_thumbnail() {
|
| 113 |
if ( !current_user_can( 'upload_files' ) ) die( '' );
|
| 114 |
$post_id = isset( $_POST[ 'post_id' ] ) ? absint( $_POST[ 'post_id' ] ) : 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
if ( has_post_thumbnail( $post_id ) ) {
|
| 117 |
$thumb_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'thumbnail' , false, '' );
|
| 118 |
$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' ) );
|
| 119 |
$crop_html = $this->get_post_thumbnail_editor_link( $post_id );
|
| 120 |
-
$thumb_html = sprintf( '<a
|
| 121 |
$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" ) );
|
| 122 |
-
|
| 123 |
-
'thumb_html'
|
| 124 |
-
'crop_html'
|
| 125 |
-
'has_thumb'
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
} else {
|
| 128 |
$thumb_html = '<a style="display:block" href="#" class="mpp_add_media default-image">';
|
| 129 |
$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' ) );
|
|
|
|
| 130 |
$thumb_html .= '</a>';
|
| 131 |
}
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
} //end ajax_get_thumbnail
|
| 134 |
|
| 135 |
/**
|
|
@@ -147,12 +182,22 @@ class Metronet_Profile_Picture {
|
|
| 147 |
|
| 148 |
$thumb_html = '<a style="display:block" href="#" class="mpp_add_media default-image">';
|
| 149 |
$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' ) );
|
|
|
|
| 150 |
$thumb_html .= '</a>';
|
| 151 |
|
| 152 |
//Save user meta and update thumbnail
|
| 153 |
update_user_option( $user_id, 'metronet_image_id', 0 );
|
| 154 |
delete_post_meta( $post_id, '_thumbnail_id' );
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
}
|
| 157 |
|
| 158 |
/**
|
|
@@ -427,11 +472,13 @@ class Metronet_Profile_Picture {
|
|
| 427 |
$thumb_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'thumbnail' , false, '' );
|
| 428 |
$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' ) );
|
| 429 |
echo $post_thumbnail;
|
|
|
|
| 430 |
echo '</a>';
|
| 431 |
} else {
|
| 432 |
echo '<a style="display:block" href="#" class="mpp_add_media default-image">';
|
| 433 |
$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' ) );
|
| 434 |
echo $post_thumbnail;
|
|
|
|
| 435 |
echo '</a>';
|
| 436 |
}
|
| 437 |
$remove_classes = array( 'dashicons', 'dashicons-trash' );
|
|
@@ -440,6 +487,9 @@ class Metronet_Profile_Picture {
|
|
| 440 |
}
|
| 441 |
?>
|
| 442 |
<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>
|
|
|
|
|
|
|
|
|
|
| 443 |
</div><!-- #metronet-profile-image -->
|
| 444 |
<div id="metronet-override-avatar">
|
| 445 |
<input type="hidden" name="metronet-user-avatar" value="off" />
|
|
@@ -483,15 +533,16 @@ class Metronet_Profile_Picture {
|
|
| 483 |
$post_id = $this->get_post_id( $this->get_user_id() );
|
| 484 |
wp_enqueue_media( array( 'post' => $post_id ) );
|
| 485 |
$script_deps = array( 'media-editor' );
|
| 486 |
-
wp_enqueue_script( 'mt-pp', $this->get_plugin_url( '/js/mpp.js' ), $script_deps, '
|
| 487 |
wp_localize_script( 'mt-pp', 'metronet_profile_image',
|
| 488 |
array(
|
| 489 |
-
'set_profile_text'
|
| 490 |
'remove_profile_text' => __( 'Remove Profile Image', 'metronet-profile-picture' ),
|
| 491 |
-
'crop'
|
| 492 |
-
'ajax_url'
|
| 493 |
-
'user_post_id'
|
| 494 |
-
'nonce'
|
|
|
|
| 495 |
)
|
| 496 |
);
|
| 497 |
?>
|
|
@@ -501,6 +552,28 @@ class Metronet_Profile_Picture {
|
|
| 501 |
position: relative;
|
| 502 |
float: left;
|
| 503 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 504 |
#metronet-remove {
|
| 505 |
position: absolute;
|
| 506 |
background: #424242;
|
|
@@ -708,15 +781,15 @@ function mt_mpp_instantiate() {
|
|
| 708 |
$mt_pp = new Metronet_Profile_Picture();
|
| 709 |
}
|
| 710 |
/**
|
| 711 |
-
* mt_profile_img
|
| 712 |
-
*
|
| 713 |
-
* Adds a profile image
|
| 714 |
-
*
|
| 715 |
-
@param $user_id INT - The user ID for the user to retrieve the image for
|
| 716 |
-
@
|
| 717 |
-
size - string || array (see get_the_post_thumbnail)
|
| 718 |
-
attr - string || array (see get_the_post_thumbnail)
|
| 719 |
-
echo - bool (true or false) - whether to echo the image or return it
|
| 720 |
*/
|
| 721 |
function mt_profile_img( $user_id, $args = array() ) {
|
| 722 |
$profile_post_id = absint( get_user_option( 'metronet_post_id', $user_id ) );
|
|
@@ -750,6 +823,18 @@ function mt_profile_img( $user_id, $args = array() ) {
|
|
| 750 |
}
|
| 751 |
|
| 752 |
$post_thumbnail = wp_get_attachment_image( $post_thumbnail_id, $size, false, $attr );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 753 |
$post_thumbnail = apply_filters( 'mpp_thumbnail_html', $post_thumbnail, $profile_post_id, $post_thumbnail_id, $user_id );
|
| 754 |
if ( $echo ) {
|
| 755 |
echo $post_thumbnail;
|
| 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.5.5
|
| 8 |
Requires at least: 3.5
|
| 9 |
Author URI: https://www.mediaron.com
|
| 10 |
Contributors: ronalfy
|
| 92 |
$thumb_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'thumbnail' , false, '' );
|
| 93 |
$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' ) );
|
| 94 |
$crop_html = $this->get_post_thumbnail_editor_link( $post_id );
|
| 95 |
+
$thumb_html = sprintf( '<a href="#" class="mpp_add_media">%s%s</a>', $post_thumbnail, sprintf( '<div id="metronet-click-edit">%s</div>', esc_html__( 'Click to Edit', 'metronet-profile-picture' ) ) );
|
| 96 |
$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" ) );
|
| 97 |
+
wp_send_json( array(
|
| 98 |
+
'thumb_html' => $thumb_html,
|
| 99 |
+
'crop_html' => $crop_html,
|
| 100 |
+
'has_thumb' => true,
|
| 101 |
+
'avatar' => get_avatar( $user_id, 96 ),
|
| 102 |
+
'avatar_admin_small' => get_avatar( $user_id, 26 ),
|
| 103 |
+
'avatar_admin_medium' => get_avatar( $user_id, 64 ),
|
| 104 |
+
'user_id' => $user_id,
|
| 105 |
+
'logged_in_user_id' => get_current_user_id(),
|
| 106 |
+
) );
|
| 107 |
}
|
| 108 |
+
wp_send_json( array(
|
| 109 |
+
'thumb_html' => '',
|
| 110 |
+
'crop_html' => '',
|
| 111 |
+
'has_thumb' => false,
|
| 112 |
+
'avatar' => get_avatar( $user_id, 96 ),
|
| 113 |
+
'avatar_admin_small' => get_avatar( $user_id, 26 ),
|
| 114 |
+
'avatar_admin_medium' => get_avatar( $user_id, 64 ),
|
| 115 |
+
'user_id' => $user_id,
|
| 116 |
+
'logged_in_user_id' => get_current_user_id(),
|
| 117 |
+
) );
|
| 118 |
} //end ajax_add_thumbnail
|
| 119 |
|
| 120 |
/**
|
| 126 |
public function ajax_get_thumbnail() {
|
| 127 |
if ( !current_user_can( 'upload_files' ) ) die( '' );
|
| 128 |
$post_id = isset( $_POST[ 'post_id' ] ) ? absint( $_POST[ 'post_id' ] ) : 0;
|
| 129 |
+
$post = get_post( $post_id );
|
| 130 |
+
$user_id = 0;
|
| 131 |
+
if( $post ) {
|
| 132 |
+
$user_id = $post->post_author;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
|
| 136 |
if ( has_post_thumbnail( $post_id ) ) {
|
| 137 |
$thumb_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'thumbnail' , false, '' );
|
| 138 |
$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' ) );
|
| 139 |
$crop_html = $this->get_post_thumbnail_editor_link( $post_id );
|
| 140 |
+
$thumb_html = sprintf( '<a href="#" class="mpp_add_media">%s%s</a>', $post_thumbnail, sprintf( '<div id="metronet-click-edit">%s</div>', esc_html__( 'Click to Edit', 'metronet-profile-picture' ) ) );
|
| 141 |
$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" ) );
|
| 142 |
+
wp_send_json( array(
|
| 143 |
+
'thumb_html' => $thumb_html,
|
| 144 |
+
'crop_html' => $crop_html,
|
| 145 |
+
'has_thumb' => true,
|
| 146 |
+
'avatar' => get_avatar( $user_id, 96 ),
|
| 147 |
+
'avatar_admin_small' => get_avatar( $user_id, 26 ),
|
| 148 |
+
'avatar_admin_medium' => get_avatar( $user_id, 64 ),
|
| 149 |
+
'user_id' => $user_id,
|
| 150 |
+
'logged_in_user_id' => get_current_user_id(),
|
| 151 |
+
) );
|
| 152 |
} else {
|
| 153 |
$thumb_html = '<a style="display:block" href="#" class="mpp_add_media default-image">';
|
| 154 |
$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' ) );
|
| 155 |
+
$thumb_html .= sprintf( '<div id="metronet-click-edit">%s</div>', esc_html__( 'Click to Edit', 'metronet-profile-picture' ) );
|
| 156 |
$thumb_html .= '</a>';
|
| 157 |
}
|
| 158 |
+
wp_send_json( array(
|
| 159 |
+
'thumb_html' => $thumb_html,
|
| 160 |
+
'crop_html' => '',
|
| 161 |
+
'has_thumb' => false,
|
| 162 |
+
'avatar' => get_avatar( $user_id, 96 ),
|
| 163 |
+
'avatar_admin_small' => get_avatar( $user_id, 26 ),
|
| 164 |
+
'avatar_admin_medium' => get_avatar( $user_id, 64 ),
|
| 165 |
+
'user_id' => $user_id,
|
| 166 |
+
'logged_in_user_id' => get_current_user_id(),
|
| 167 |
+
) );
|
| 168 |
} //end ajax_get_thumbnail
|
| 169 |
|
| 170 |
/**
|
| 182 |
|
| 183 |
$thumb_html = '<a style="display:block" href="#" class="mpp_add_media default-image">';
|
| 184 |
$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' ) );
|
| 185 |
+
$thumb_html .= sprintf( '<div id="metronet-click-edit">%s</div>', esc_html__( 'Click to Edit', 'metronet-profile-picture' ) );
|
| 186 |
$thumb_html .= '</a>';
|
| 187 |
|
| 188 |
//Save user meta and update thumbnail
|
| 189 |
update_user_option( $user_id, 'metronet_image_id', 0 );
|
| 190 |
delete_post_meta( $post_id, '_thumbnail_id' );
|
| 191 |
+
wp_send_json( array(
|
| 192 |
+
'thumb_html' => $thumb_html,
|
| 193 |
+
'crop_html' => '',
|
| 194 |
+
'has_thumb' => false,
|
| 195 |
+
'avatar' => get_avatar( $user_id, 96 ),
|
| 196 |
+
'avatar_admin_small' => get_avatar( $user_id, 26 ),
|
| 197 |
+
'avatar_admin_medium' => get_avatar( $user_id, 64 ),
|
| 198 |
+
'user_id' => $user_id,
|
| 199 |
+
'logged_in_user_id' => get_current_user_id(),
|
| 200 |
+
) );
|
| 201 |
}
|
| 202 |
|
| 203 |
/**
|
| 472 |
$thumb_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'thumbnail' , false, '' );
|
| 473 |
$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' ) );
|
| 474 |
echo $post_thumbnail;
|
| 475 |
+
echo sprintf( '<div id="metronet-click-edit">%s</div>', esc_html__( 'Click to Edit', 'metronet-profile-picture' ) );
|
| 476 |
echo '</a>';
|
| 477 |
} else {
|
| 478 |
echo '<a style="display:block" href="#" class="mpp_add_media default-image">';
|
| 479 |
$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' ) );
|
| 480 |
echo $post_thumbnail;
|
| 481 |
+
echo sprintf( '<div id="metronet-click-edit">%s</div>', esc_html__( 'Click to Edit', 'metronet-profile-picture' ) );
|
| 482 |
echo '</a>';
|
| 483 |
}
|
| 484 |
$remove_classes = array( 'dashicons', 'dashicons-trash' );
|
| 487 |
}
|
| 488 |
?>
|
| 489 |
<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>
|
| 490 |
+
<div style="display: none">
|
| 491 |
+
<?php printf( '<img class="mpp-loading" width="150" height="150" alt="Loading" src="%s" />', esc_url( $this->get_plugin_url( '/img/loading.gif' ) ) ); ?>
|
| 492 |
+
</div>
|
| 493 |
</div><!-- #metronet-profile-image -->
|
| 494 |
<div id="metronet-override-avatar">
|
| 495 |
<input type="hidden" name="metronet-user-avatar" value="off" />
|
| 533 |
$post_id = $this->get_post_id( $this->get_user_id() );
|
| 534 |
wp_enqueue_media( array( 'post' => $post_id ) );
|
| 535 |
$script_deps = array( 'media-editor' );
|
| 536 |
+
wp_enqueue_script( 'mt-pp', $this->get_plugin_url( '/js/mpp.js' ), $script_deps, '20180819', true );
|
| 537 |
wp_localize_script( 'mt-pp', 'metronet_profile_image',
|
| 538 |
array(
|
| 539 |
+
'set_profile_text' => __( 'Set Profile Image', 'metronet-profile-picture' ),
|
| 540 |
'remove_profile_text' => __( 'Remove Profile Image', 'metronet-profile-picture' ),
|
| 541 |
+
'crop' => __( 'Crop Thumbnail', 'metronet-profile-picture' ),
|
| 542 |
+
'ajax_url' => esc_url( admin_url( 'admin-ajax.php' ) ),
|
| 543 |
+
'user_post_id' => absint( $post_id ),
|
| 544 |
+
'nonce' => wp_create_nonce( 'mt-update-post_' . absint( $post_id ) ),
|
| 545 |
+
'loading_gif' => esc_url( $this->get_plugin_url( '/img/loading.gif' ) )
|
| 546 |
)
|
| 547 |
);
|
| 548 |
?>
|
| 552 |
position: relative;
|
| 553 |
float: left;
|
| 554 |
}
|
| 555 |
+
#metronet-profile-image a.mpp_add_media #metronet-click-edit,
|
| 556 |
+
#metronet-profile-image a.mpp_add_media:hover #metronet-click-edit,
|
| 557 |
+
#metronet-profile-image a.mpp_add_media:visited #metronet-click-edit {
|
| 558 |
+
color: #FFF;
|
| 559 |
+
}
|
| 560 |
+
#metronet-profile-image a.mpp_add_media:hover #metronet-click-edit {
|
| 561 |
+
background: #000;
|
| 562 |
+
background: rgba(51,51,51,1);
|
| 563 |
+
font-weight: normal;
|
| 564 |
+
}
|
| 565 |
+
#metronet-click-edit {
|
| 566 |
+
position: absolute;
|
| 567 |
+
bottom: 0;
|
| 568 |
+
left: 0;
|
| 569 |
+
width: 100%;
|
| 570 |
+
background: #333;
|
| 571 |
+
background: rgba(51,51,51,0.5);
|
| 572 |
+
font-size: 14px;
|
| 573 |
+
line-height: 14px;
|
| 574 |
+
text-align: center;
|
| 575 |
+
padding: 8px 0;
|
| 576 |
+
}
|
| 577 |
#metronet-remove {
|
| 578 |
position: absolute;
|
| 579 |
background: #424242;
|
| 781 |
$mt_pp = new Metronet_Profile_Picture();
|
| 782 |
}
|
| 783 |
/**
|
| 784 |
+
* mt_profile_img
|
| 785 |
+
*
|
| 786 |
+
* Adds a profile image
|
| 787 |
+
*
|
| 788 |
+
* @param $user_id INT - The user ID for the user to retrieve the image for
|
| 789 |
+
* @param $args mixed
|
| 790 |
+
* size - string || array (see get_the_post_thumbnail)
|
| 791 |
+
* attr - string || array (see get_the_post_thumbnail)
|
| 792 |
+
* echo - bool (true or false) - whether to echo the image or return it
|
| 793 |
*/
|
| 794 |
function mt_profile_img( $user_id, $args = array() ) {
|
| 795 |
$profile_post_id = absint( get_user_option( 'metronet_post_id', $user_id ) );
|
| 823 |
}
|
| 824 |
|
| 825 |
$post_thumbnail = wp_get_attachment_image( $post_thumbnail_id, $size, false, $attr );
|
| 826 |
+
|
| 827 |
+
/**
|
| 828 |
+
* Filter outputted HTML.
|
| 829 |
+
*
|
| 830 |
+
* Filter outputted HTML.
|
| 831 |
+
*
|
| 832 |
+
* @param string $post_thumbnail img tag with formed HTML
|
| 833 |
+
* @param int $profile_post_id The profile in which the image is attached
|
| 834 |
+
* @param int $profile_thumbnail_id The thumbnail ID for the attached image
|
| 835 |
+
* @param int $user_id The user id for which the image is attached
|
| 836 |
+
*
|
| 837 |
+
*/
|
| 838 |
$post_thumbnail = apply_filters( 'mpp_thumbnail_html', $post_thumbnail, $profile_post_id, $post_thumbnail_id, $user_id );
|
| 839 |
if ( $echo ) {
|
| 840 |
echo $post_thumbnail;
|
readme.txt
CHANGED
|
@@ -3,16 +3,20 @@ Contributors: ronalfy
|
|
| 3 |
Tags: users, user, user profile
|
| 4 |
Requires at least: 3.5
|
| 5 |
Tested up to: 4.9
|
| 6 |
-
Stable tag: 1.5.
|
| 7 |
License: GPLv2 or later
|
| 8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 9 |
-
Donate link: https://mediaron.com/
|
| 10 |
|
| 11 |
Set a custom profile image (avatar) 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.
|
|
@@ -88,6 +92,14 @@ Yes, but you'll have to set a new profile image per site. This is currently a l
|
|
| 88 |
|
| 89 |
== Changelog ==
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
= 1.5.1 =
|
| 92 |
* Released 2018-07-12
|
| 93 |
* Fixed a condition where a featured image was shown for the author instead of a blank gravatar
|
|
@@ -210,6 +222,9 @@ Yes, but you'll have to set a new profile image per site. This is currently a l
|
|
| 210 |
|
| 211 |
== Upgrade Notice ==
|
| 212 |
|
|
|
|
|
|
|
|
|
|
| 213 |
= 1.5.1 =
|
| 214 |
Fixed a condition where a featured image was shown for the author instead of a blank gravatar
|
| 215 |
|
| 3 |
Tags: users, user, user profile
|
| 4 |
Requires at least: 3.5
|
| 5 |
Tested up to: 4.9
|
| 6 |
+
Stable tag: 1.5.5
|
| 7 |
License: GPLv2 or later
|
| 8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 9 |
+
Donate link: https://mediaron.com/give/
|
| 10 |
|
| 11 |
Set a custom profile image (avatar) 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 |
+
> Please <a href="https://wordpress.org/support/plugin/metronet-profile-picture/reviews/#new-post">Rate the Plugin</a> or <a href="https://mediaron.com/give/">Give Back</a> to show support.
|
| 17 |
+
|
| 18 |
+
https://www.youtube.com/watch?v=9icnOWWZUpA?rel=0
|
| 19 |
+
|
| 20 |
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.
|
| 21 |
|
| 22 |
A template tag is supplied for outputting to a theme and the option to override a user's default avatar is also available.
|
| 92 |
|
| 93 |
== Changelog ==
|
| 94 |
|
| 95 |
+
= 1.5.5 =
|
| 96 |
+
* Released 2018-08-19
|
| 97 |
+
* Enhancement: Loading image now shows between states for better UX
|
| 98 |
+
* Enhancement: Plugin attempts to override the default WordPress avatar in the User Profile page
|
| 99 |
+
* Enhancement: Plugin attempts to override the admin bar avatars if the users match
|
| 100 |
+
* Enhancement: Added Click to Edit bar to make it more obvious what to do with the profile picture
|
| 101 |
+
* Refactor: Plugin now uses wp_send_json instead of json_encode for more compatibility
|
| 102 |
+
|
| 103 |
= 1.5.1 =
|
| 104 |
* Released 2018-07-12
|
| 105 |
* Fixed a condition where a featured image was shown for the author instead of a blank gravatar
|
| 222 |
|
| 223 |
== Upgrade Notice ==
|
| 224 |
|
| 225 |
+
= 1.5.5 =
|
| 226 |
+
Loading image now shows between states. New "Click to Edit" bar added to interface.
|
| 227 |
+
|
| 228 |
= 1.5.1 =
|
| 229 |
Fixed a condition where a featured image was shown for the author instead of a blank gravatar
|
| 230 |
|
