Version Description
- Released 11 November 2014
- Added the ability to remove profile images (aside from deleting the image).
- Added better internationalization capabilities.
- Added compatibility with Theme My Login.
Download this release
Release Info
| Developer | ronalfy |
| Plugin | |
| Version | 1.1.0 |
| Comparing to | |
| See all releases | |
Code changes from version 1.0.23 to 1.1.0
- js/mpp.js +70 -12
- languages/metronet-profile-picture.pot +46 -0
- metronet-profile-picture.php +57 -19
- readme.txt +13 -1
js/mpp.js
CHANGED
|
@@ -3,19 +3,41 @@ jQuery( document ).ready( function( $ ) {
|
|
| 3 |
//Refresh the profile image thumbnail
|
| 4 |
function mt_ajax_thumbnail_refresh() {
|
| 5 |
var post_id = jQuery( "#metronet_post_id" ).val();
|
| 6 |
-
$.post(
|
| 7 |
action: 'metronet_get_thumbnail',
|
| 8 |
post_id: post_id,
|
| 9 |
},
|
| 10 |
function( response ) {
|
| 11 |
-
jQuery( "#metronet-profile-image
|
| 12 |
jQuery( "#metronet-pte" ).html( response.crop_html );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
},
|
| 14 |
'json'
|
| 15 |
);
|
| 16 |
};
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
//Assign the default view for the media uploader
|
| 20 |
var uploader = wp.media({
|
| 21 |
state: 'featured-image',
|
|
@@ -23,17 +45,40 @@ jQuery( document ).ready( function( $ ) {
|
|
| 23 |
});
|
| 24 |
uploader.state('featured-image').set( 'title', metronet_profile_image.set_profile_text );
|
| 25 |
|
| 26 |
-
//Create featured image button
|
| 27 |
uploader.on( 'toolbar:create:featured-image', function( toolbar ) {
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
//For when the featured thumbnail is set
|
| 34 |
uploader.mt_featured_set = function( id ) {
|
| 35 |
var settings = wp.media.view.settings;
|
| 36 |
-
$.post(
|
| 37 |
action: 'metronet_add_thumbnail',
|
| 38 |
post_id: settings.post.id,
|
| 39 |
user_id: jQuery( "#metronet_profile_id" ).val(),
|
|
@@ -41,14 +86,17 @@ jQuery( document ).ready( function( $ ) {
|
|
| 41 |
_wpnonce: settings.post.nonce
|
| 42 |
},
|
| 43 |
function( response ) {
|
| 44 |
-
jQuery( "#metronet-profile-image
|
| 45 |
jQuery( "#metronet-pte" ).html( response.crop_html );
|
|
|
|
|
|
|
|
|
|
| 46 |
},
|
| 47 |
'json'
|
| 48 |
);
|
| 49 |
};
|
| 50 |
|
| 51 |
-
//For when the
|
| 52 |
uploader.state('featured-image').on( 'select', function() {
|
| 53 |
var settings = wp.media.view.settings,
|
| 54 |
selection = this.get('selection').single();
|
|
@@ -59,6 +107,12 @@ jQuery( document ).ready( function( $ ) {
|
|
| 59 |
settings.post.featuredImageId = selection.id;
|
| 60 |
uploader.mt_featured_set( selection ? selection.id : -1 );
|
| 61 |
} );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
//For when the window is closed (update the thumbnail)
|
| 64 |
uploader.on('escape', function(){
|
|
@@ -69,5 +123,9 @@ jQuery( document ).ready( function( $ ) {
|
|
| 69 |
uploader.open();
|
| 70 |
return false;
|
| 71 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
} );
|
| 3 |
//Refresh the profile image thumbnail
|
| 4 |
function mt_ajax_thumbnail_refresh() {
|
| 5 |
var post_id = jQuery( "#metronet_post_id" ).val();
|
| 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( 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 |
);
|
| 21 |
};
|
| 22 |
+
//Remove the profile image
|
| 23 |
+
function mt_remove_profile_image() {
|
| 24 |
+
var settings = wp.media.view.settings;
|
| 25 |
+
$.post( metronet_profile_image.ajax_url, {
|
| 26 |
+
action: 'metronet_remove_thumbnail',
|
| 27 |
+
post_id: settings.post.id,
|
| 28 |
+
user_id: jQuery( "#metronet_profile_id" ).val(),
|
| 29 |
+
_wpnonce: settings.post.nonce
|
| 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 |
+
);
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
$('#mpp').on( "click", '.mpp_add_media', function(e) {
|
| 41 |
//Assign the default view for the media uploader
|
| 42 |
var uploader = wp.media({
|
| 43 |
state: 'featured-image',
|
| 45 |
});
|
| 46 |
uploader.state('featured-image').set( 'title', metronet_profile_image.set_profile_text );
|
| 47 |
|
|
|
|
| 48 |
uploader.on( 'toolbar:create:featured-image', function( toolbar ) {
|
| 49 |
+
var options = {
|
| 50 |
+
};
|
| 51 |
+
options.items = {};
|
| 52 |
+
options.items.select = {
|
| 53 |
+
text: metronet_profile_image.set_profile_text,
|
| 54 |
+
style: 'primary',
|
| 55 |
+
click: wp.media.view.Toolbar.Select.prototype.clickSelect,
|
| 56 |
+
requires: { selection: true },
|
| 57 |
+
event: 'select',
|
| 58 |
+
reset: true,
|
| 59 |
+
close: true,
|
| 60 |
+
state: false
|
| 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,
|
| 68 |
+
event: 'remove',
|
| 69 |
+
reset: true,
|
| 70 |
+
close: true,
|
| 71 |
+
state: false
|
| 72 |
+
};
|
| 73 |
+
}
|
| 74 |
+
this.createSelectToolbar( toolbar, options );
|
| 75 |
+
}, uploader );
|
| 76 |
+
|
| 77 |
|
| 78 |
//For when the featured thumbnail is set
|
| 79 |
uploader.mt_featured_set = function( id ) {
|
| 80 |
var settings = wp.media.view.settings;
|
| 81 |
+
$.post( metronet_profile_image.ajax_url, {
|
| 82 |
action: 'metronet_add_thumbnail',
|
| 83 |
post_id: settings.post.id,
|
| 84 |
user_id: jQuery( "#metronet_profile_id" ).val(),
|
| 86 |
_wpnonce: settings.post.nonce
|
| 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 |
);
|
| 97 |
};
|
| 98 |
|
| 99 |
+
//For when the Add Profile Image is clicked
|
| 100 |
uploader.state('featured-image').on( 'select', function() {
|
| 101 |
var settings = wp.media.view.settings,
|
| 102 |
selection = this.get('selection').single();
|
| 107 |
settings.post.featuredImageId = selection.id;
|
| 108 |
uploader.mt_featured_set( selection ? selection.id : -1 );
|
| 109 |
} );
|
| 110 |
+
|
| 111 |
+
//When the remove buttons is clicked
|
| 112 |
+
uploader.state( 'featured-image' ).on( 'remove', function() {
|
| 113 |
+
mt_remove_profile_image();
|
| 114 |
+
} );
|
| 115 |
+
|
| 116 |
|
| 117 |
//For when the window is closed (update the thumbnail)
|
| 118 |
uploader.on('escape', 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 |
+
} );
|
| 130 |
|
| 131 |
} );
|
languages/metronet-profile-picture.pot
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
msgid ""
|
| 2 |
+
msgstr ""
|
| 3 |
+
"Project-Id-Version: Metronet Profile Picture\n"
|
| 4 |
+
"Report-Msgid-Bugs-To: http://wordpress.org/tag/simple-comment-editing\n"
|
| 5 |
+
"POT-Creation-Date: 2014-11-11 20:47-0600\n"
|
| 6 |
+
"PO-Revision-Date: 2014-11-11 20:48-0600\n"
|
| 7 |
+
"Last-Translator: Ronald Huereca <ron@ronalfy.com>\n"
|
| 8 |
+
"Language-Team: \n"
|
| 9 |
+
"Language: English\n"
|
| 10 |
+
"MIME-Version: 1.0\n"
|
| 11 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
| 12 |
+
"Content-Transfer-Encoding: 8bit\n"
|
| 13 |
+
"X-Generator: Poedit 1.5.3\n"
|
| 14 |
+
"X-Poedit-SourceCharset: UTF-8\n"
|
| 15 |
+
"X-Poedit-KeywordsList: _e;__;esc_html__;esc_html_e;esc_attr__;esc_attr_e\n"
|
| 16 |
+
"X-Poedit-Basepath: .\n"
|
| 17 |
+
"X-Poedit-SearchPath-0: ..\n"
|
| 18 |
+
|
| 19 |
+
#: ../metronet-profile-picture.php:257 ../metronet-profile-picture.php:393
|
| 20 |
+
msgid "Crop Thumbnail"
|
| 21 |
+
msgstr ""
|
| 22 |
+
|
| 23 |
+
#: ../metronet-profile-picture.php:320
|
| 24 |
+
msgid "Upload or Change Profile Picture"
|
| 25 |
+
msgstr ""
|
| 26 |
+
|
| 27 |
+
#: ../metronet-profile-picture.php:323
|
| 28 |
+
msgid "Profile Image"
|
| 29 |
+
msgstr ""
|
| 30 |
+
|
| 31 |
+
#: ../metronet-profile-picture.php:337
|
| 32 |
+
msgid ""
|
| 33 |
+
"Select \"Set profile image\" after uploading to choose the profile image"
|
| 34 |
+
msgstr ""
|
| 35 |
+
|
| 36 |
+
#: ../metronet-profile-picture.php:358
|
| 37 |
+
msgid "Override Avatar?"
|
| 38 |
+
msgstr ""
|
| 39 |
+
|
| 40 |
+
#: ../metronet-profile-picture.php:368 ../metronet-profile-picture.php:392
|
| 41 |
+
msgid "Remove profile image"
|
| 42 |
+
msgstr ""
|
| 43 |
+
|
| 44 |
+
#: ../metronet-profile-picture.php:391
|
| 45 |
+
msgid "Set profile image"
|
| 46 |
+
msgstr ""
|
metronet-profile-picture.php
CHANGED
|
@@ -4,10 +4,12 @@ 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.0
|
| 8 |
Requires at least: 3.5
|
| 9 |
Author URI: http://www.metronet.no
|
| 10 |
Contributors: ronalfy, metronet
|
|
|
|
|
|
|
| 11 |
*/
|
| 12 |
|
| 13 |
class Metronet_Profile_Picture {
|
|
@@ -24,7 +26,10 @@ class Metronet_Profile_Picture {
|
|
| 24 |
*
|
| 25 |
*/
|
| 26 |
function __construct(){
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
| 28 |
$this->plugin_path = plugin_basename( __FILE__ );
|
| 29 |
$this->plugin_url = rtrim( plugin_dir_url(__FILE__), '/' );
|
| 30 |
$this->plugin_dir = rtrim( plugin_dir_path(__FILE__), '/' );
|
|
@@ -35,6 +40,7 @@ class Metronet_Profile_Picture {
|
|
| 35 |
//Scripts
|
| 36 |
add_action( 'admin_print_scripts-user-edit.php', array( &$this, 'print_media_scripts' ) );
|
| 37 |
add_action( 'admin_print_scripts-profile.php', array( &$this, 'print_media_scripts' ) );
|
|
|
|
| 38 |
|
| 39 |
//Styles
|
| 40 |
add_action( 'admin_print_styles-user-edit.php', array( &$this, 'print_media_styles' ) );
|
|
@@ -43,6 +49,7 @@ class Metronet_Profile_Picture {
|
|
| 43 |
//Ajax
|
| 44 |
add_action( 'wp_ajax_metronet_add_thumbnail', array( &$this, 'ajax_add_thumbnail' ) );
|
| 45 |
add_action( 'wp_ajax_metronet_get_thumbnail', array( &$this, 'ajax_get_thumbnail' ) );
|
|
|
|
| 46 |
|
| 47 |
//User update action
|
| 48 |
add_action( 'edit_user_profile_update', array( &$this, 'save_user_profile' ) );
|
|
@@ -74,11 +81,12 @@ class Metronet_Profile_Picture {
|
|
| 74 |
$post_thumbnail = get_the_post_thumbnail( $post_id, 'thumbnail' );
|
| 75 |
$crop_html = $this->get_post_thumbnail_editor_link( $post_id );
|
| 76 |
die( json_encode( array(
|
| 77 |
-
'thumb_html' => $post_thumbnail,
|
| 78 |
-
'crop_html' => $crop_html
|
|
|
|
| 79 |
) ) );
|
| 80 |
}
|
| 81 |
-
die( json_encode( array( 'thumb_html' => '', 'crop_html' => '' ) ) );
|
| 82 |
} //end ajax_add_thumbnail
|
| 83 |
|
| 84 |
/**
|
|
@@ -94,13 +102,32 @@ class Metronet_Profile_Picture {
|
|
| 94 |
$post_thumbnail = get_the_post_thumbnail( $post_id, 'thumbnail' );
|
| 95 |
$crop_html = $this->get_post_thumbnail_editor_link( $post_id );
|
| 96 |
die( json_encode( array(
|
| 97 |
-
'thumb_html' => $post_thumbnail,
|
| 98 |
-
'crop_html' => $crop_html
|
|
|
|
| 99 |
) ) );
|
| 100 |
}
|
| 101 |
-
die( json_encode( array( 'thumb_html' => '', 'crop_html' => '' ) ) );
|
| 102 |
} //end ajax_get_thumbnail
|
| 103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
/**
|
| 105 |
* avatar_override()
|
| 106 |
*
|
|
@@ -260,9 +287,6 @@ class Metronet_Profile_Picture {
|
|
| 260 |
*/
|
| 261 |
function init() {
|
| 262 |
|
| 263 |
-
//* Localization Code */
|
| 264 |
-
load_plugin_textdomain( 'metronet_profile_picture', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
|
| 265 |
-
|
| 266 |
add_theme_support( 'post-thumbnails' ); //This should be part of the theme, but the plugin registers it just in case.
|
| 267 |
//Register post types
|
| 268 |
$post_type_args = array(
|
|
@@ -294,23 +318,22 @@ class Metronet_Profile_Picture {
|
|
| 294 |
$post_id = $this->get_post_id( $user_id );
|
| 295 |
|
| 296 |
//Create upload link
|
| 297 |
-
$upload_link = sprintf( "<a href='#' class='
|
| 298 |
?>
|
| 299 |
<tr valign="top">
|
| 300 |
<th scope="row"><?php esc_html_e( "Profile Image", "metronet_profile_picture" ); ?></th>
|
| 301 |
-
<td>
|
| 302 |
<input type="hidden" name="metronet_profile_id" id="metronet_profile_id" value="<?php echo esc_attr( $user_id ); ?>" />
|
| 303 |
<input type="hidden" name="metronet_post_id" id="metronet_post_id" value="<?php echo esc_attr( $post_id ); ?>" />
|
| 304 |
<div id="metronet-profile-image">
|
| 305 |
<?php
|
| 306 |
-
echo '<a href="#" class="add_media">';
|
| 307 |
if ( has_post_thumbnail( $post_id ) ) {
|
|
|
|
| 308 |
$post_thumbnail = get_the_post_thumbnail( $post_id, 'thumbnail' );
|
| 309 |
echo $post_thumbnail;
|
|
|
|
| 310 |
}
|
| 311 |
-
echo '</a>';
|
| 312 |
?>
|
| 313 |
-
</a>
|
| 314 |
</div><!-- #metronet-profile-image -->
|
| 315 |
<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 -->
|
| 316 |
<div id="metronet-override-avatar">
|
|
@@ -339,11 +362,25 @@ class Metronet_Profile_Picture {
|
|
| 339 |
<div id="metronet-pte">
|
| 340 |
<?php echo $this->get_post_thumbnail_editor_link( $post_id ); ?>
|
| 341 |
</div><!-- #metronet-pte -->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
</td>
|
| 343 |
</tr>
|
| 344 |
<?php
|
| 345 |
} //end insert_upload_form
|
| 346 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 347 |
/**
|
| 348 |
* print_media_scripts
|
| 349 |
*
|
|
@@ -352,13 +389,14 @@ class Metronet_Profile_Picture {
|
|
| 352 |
public function print_media_scripts() {
|
| 353 |
$post_id = $this->get_post_id( $this->get_user_id() );
|
| 354 |
wp_enqueue_media( array( 'post' => $post_id ) );
|
| 355 |
-
|
| 356 |
$script_deps = array( 'media-editor' );
|
| 357 |
-
wp_enqueue_script( 'mt-pp', $this->get_plugin_url( '/js/mpp.js' ), $script_deps, '
|
| 358 |
wp_localize_script( 'mt-pp', 'metronet_profile_image',
|
| 359 |
array(
|
| 360 |
'set_profile_text' => __( 'Set profile image', 'metronet_profile_picture' ),
|
| 361 |
-
'
|
|
|
|
|
|
|
| 362 |
)
|
| 363 |
);
|
| 364 |
} //end print_media_scripts
|
| 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
|
| 11 |
+
Text Domain: metronet-profile-picture
|
| 12 |
+
Domain Path: /languages
|
| 13 |
*/
|
| 14 |
|
| 15 |
class Metronet_Profile_Picture {
|
| 26 |
*
|
| 27 |
*/
|
| 28 |
function __construct(){
|
| 29 |
+
|
| 30 |
+
//* Localization Code */
|
| 31 |
+
load_plugin_textdomain( 'metronet-profile-picture', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
|
| 32 |
+
|
| 33 |
$this->plugin_path = plugin_basename( __FILE__ );
|
| 34 |
$this->plugin_url = rtrim( plugin_dir_url(__FILE__), '/' );
|
| 35 |
$this->plugin_dir = rtrim( plugin_dir_path(__FILE__), '/' );
|
| 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' ) );
|
| 49 |
//Ajax
|
| 50 |
add_action( 'wp_ajax_metronet_add_thumbnail', array( &$this, 'ajax_add_thumbnail' ) );
|
| 51 |
add_action( 'wp_ajax_metronet_get_thumbnail', array( &$this, 'ajax_get_thumbnail' ) );
|
| 52 |
+
add_action( 'wp_ajax_metronet_remove_thumbnail', array( &$this, 'ajax_remove_thumbnail' ) );
|
| 53 |
|
| 54 |
//User update action
|
| 55 |
add_action( 'edit_user_profile_update', array( &$this, 'save_user_profile' ) );
|
| 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 |
) ) );
|
| 88 |
}
|
| 89 |
+
die( json_encode( array( 'thumb_html' => '', 'crop_html' => '', 'has_thumb' => false ) ) );
|
| 90 |
} //end ajax_add_thumbnail
|
| 91 |
|
| 92 |
/**
|
| 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 |
+
/**
|
| 114 |
+
* ajax_remove_thumbnail()
|
| 115 |
+
*
|
| 116 |
+
* Removes a featured thumbnail
|
| 117 |
+
*
|
| 118 |
+
*/
|
| 119 |
+
public function ajax_remove_thumbnail() {
|
| 120 |
+
$post_id = isset( $_POST[ 'post_id' ] ) ? absint( $_POST[ 'post_id' ] ) : 0;
|
| 121 |
+
$user_id = isset( $_POST[ 'user_id' ] ) ? absint( $_POST[ 'user_id' ] ) : 0;
|
| 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 |
/**
|
| 132 |
* avatar_override()
|
| 133 |
*
|
| 287 |
*/
|
| 288 |
function init() {
|
| 289 |
|
|
|
|
|
|
|
|
|
|
| 290 |
add_theme_support( 'post-thumbnails' ); //This should be part of the theme, but the plugin registers it just in case.
|
| 291 |
//Register post types
|
| 292 |
$post_type_args = array(
|
| 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>
|
| 325 |
+
<td id="mpp">
|
| 326 |
<input type="hidden" name="metronet_profile_id" id="metronet_profile_id" value="<?php echo esc_attr( $user_id ); ?>" />
|
| 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">
|
| 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
|
| 377 |
} //end insert_upload_form
|
| 378 |
|
| 379 |
+
function profile_print_media_scripts() {
|
| 380 |
+
if ( defined( 'IS_PROFILE_PAGE' ) && IS_PROFILE_PAGE == true ) {
|
| 381 |
+
$this->print_media_scripts();
|
| 382 |
+
}
|
| 383 |
+
}
|
| 384 |
/**
|
| 385 |
* print_media_scripts
|
| 386 |
*
|
| 389 |
public function print_media_scripts() {
|
| 390 |
$post_id = $this->get_post_id( $this->get_user_id() );
|
| 391 |
wp_enqueue_media( array( 'post' => $post_id ) );
|
|
|
|
| 392 |
$script_deps = array( 'media-editor' );
|
| 393 |
+
wp_enqueue_script( 'mt-pp', $this->get_plugin_url( '/js/mpp.js' ), $script_deps, '20141111', true );
|
| 394 |
wp_localize_script( 'mt-pp', 'metronet_profile_image',
|
| 395 |
array(
|
| 396 |
'set_profile_text' => __( 'Set profile image', 'metronet_profile_picture' ),
|
| 397 |
+
'remove_profile_text' => __( 'Remove profile image', 'metronet_profile_picture' ),
|
| 398 |
+
'crop' => __( 'Crop Thumbnail', 'metronet_profile_picture' ),
|
| 399 |
+
'ajax_url' => esc_url( admin_url( 'admin-ajax.php' ) )
|
| 400 |
)
|
| 401 |
);
|
| 402 |
} //end print_media_scripts
|
readme.txt
CHANGED
|
@@ -3,7 +3,7 @@ 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.0
|
| 7 |
License: GPLv2 or later
|
| 8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 9 |
|
|
@@ -18,6 +18,9 @@ This plugin is fully compatible with <a href="http://wordpress.org/extend/plugin
|
|
| 18 |
|
| 19 |
If you like this plugin, please leave a rating/review and mark the plugin as working.
|
| 20 |
|
|
|
|
|
|
|
|
|
|
| 21 |
== Installation ==
|
| 22 |
|
| 23 |
1. Upload `metronet-profile-picture` folder to the `/wp-content/plugins/` directory
|
|
@@ -101,6 +104,12 @@ Yes, but you'll have to set a new profile image per site. This is currently a l
|
|
| 101 |
|
| 102 |
== Changelog ==
|
| 103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
= 1.0.23 =
|
| 105 |
* Released 20 October 2014
|
| 106 |
* Added a new filter to allow the "Override Avatar" interface to be hidden (and turned on my default).
|
|
@@ -154,6 +163,9 @@ Yes, but you'll have to set a new profile image per site. This is currently a l
|
|
| 154 |
|
| 155 |
== Upgrade Notice ==
|
| 156 |
|
|
|
|
|
|
|
|
|
|
| 157 |
= 1.0.23 =
|
| 158 |
Added a new filter to allow the "Override Avatar" interface to be hidden (and turned on my default).
|
| 159 |
|
| 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 |
|
| 18 |
|
| 19 |
If you like this plugin, please leave a rating/review and mark the plugin as working.
|
| 20 |
|
| 21 |
+
<h3>Translations</h3>
|
| 22 |
+
If you would like to contribute a translation, please leave a support request with a link to your translation or <a href="http://www.ronalfy.com/contact/">get in touch</a>.
|
| 23 |
+
|
| 24 |
== Installation ==
|
| 25 |
|
| 26 |
1. Upload `metronet-profile-picture` folder to the `/wp-content/plugins/` directory
|
| 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).
|
| 110 |
+
* Added better internationalization capabilities.
|
| 111 |
+
* Added compatibility with <a href="https://wordpress.org/plugins/theme-my-login/">Theme My Login</a>.
|
| 112 |
+
|
| 113 |
= 1.0.23 =
|
| 114 |
* Released 20 October 2014
|
| 115 |
* Added a new filter to allow the "Override Avatar" interface to be hidden (and turned on my default).
|
| 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 |
+
|
| 169 |
= 1.0.23 =
|
| 170 |
Added a new filter to allow the "Override Avatar" interface to be hidden (and turned on my default).
|
| 171 |
|
