Version Description
Download this release
Release Info
Developer | section214 |
Plugin | Username Changer |
Version | 3.1.0 |
Comparing to | |
See all releases |
Code changes from version 3.0.1 to 3.1.0
- assets/js/admin.js +22 -5
- includes/admin/actions.php +19 -0
- includes/admin/settings/register.php +52 -0
- includes/class.template-tags.php +2 -2
- includes/functions.php +16 -18
- readme.txt +8 -2
- username-changer.php +2 -2
assets/js/admin.js
CHANGED
@@ -164,7 +164,7 @@ jQuery(document.body).ready(function ($) {
|
|
164 |
onSubmit : function(e) {
|
165 |
e.preventDefault();
|
166 |
|
167 |
-
var newUsername, currentUsername, postData;
|
168 |
|
169 |
newUsername = profileForm.new_user_login.value;
|
170 |
currentUsername = currentUsernameInput.value;
|
@@ -205,15 +205,14 @@ jQuery(document.body).ready(function ($) {
|
|
205 |
success: function (response) {
|
206 |
if(response !== null) {
|
207 |
try {
|
208 |
-
username_changer_vars.nonce =
|
209 |
message.style.color = response.success ? 'green' : 'red';
|
210 |
message.innerHTML = response.message;
|
211 |
|
212 |
if(response.success) {
|
213 |
currentUsernameInput.value = newUsername;
|
|
|
214 |
}
|
215 |
-
|
216 |
-
cancelButton.click();
|
217 |
} catch(e) {
|
218 |
message.style.color = 'red';
|
219 |
message.textContent = username_changer_vars.error_unknown;
|
@@ -225,8 +224,26 @@ jQuery(document.body).ready(function ($) {
|
|
225 |
|
226 |
message.style.display = '';
|
227 |
|
228 |
-
submitButton.value = username_changer_vars.save_button_label;
|
229 |
cancelButton.disabled = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
}
|
231 |
}).fail(function (data) {
|
232 |
if(window.console && window.console.log) {
|
164 |
onSubmit : function(e) {
|
165 |
e.preventDefault();
|
166 |
|
167 |
+
var newUsername, currentUsername, postData, error = true;
|
168 |
|
169 |
newUsername = profileForm.new_user_login.value;
|
170 |
currentUsername = currentUsernameInput.value;
|
205 |
success: function (response) {
|
206 |
if(response !== null) {
|
207 |
try {
|
208 |
+
username_changer_vars.nonce = response.new_nonce;
|
209 |
message.style.color = response.success ? 'green' : 'red';
|
210 |
message.innerHTML = response.message;
|
211 |
|
212 |
if(response.success) {
|
213 |
currentUsernameInput.value = newUsername;
|
214 |
+
error = false;
|
215 |
}
|
|
|
|
|
216 |
} catch(e) {
|
217 |
message.style.color = 'red';
|
218 |
message.textContent = username_changer_vars.error_unknown;
|
224 |
|
225 |
message.style.display = '';
|
226 |
|
|
|
227 |
cancelButton.disabled = false;
|
228 |
+
submitButton.value = username_changer_vars.save_button_label;
|
229 |
+
|
230 |
+
if(error === false) {
|
231 |
+
currentUsernameInput.value = newUsername;
|
232 |
+
|
233 |
+
if($('input[name="nickname"]').val() === currentUsername) {
|
234 |
+
$('input[name="nickname"]').val(newUsername);
|
235 |
+
}
|
236 |
+
|
237 |
+
if($('select[name="display_name"] option:selected').text() === currentUsername) {
|
238 |
+
$('select[name="display_name"] option:selected').text(newUsername);
|
239 |
+
}
|
240 |
+
|
241 |
+
profileForm.style.display = 'none';
|
242 |
+
link.style.display = 'inline';
|
243 |
+
currentUsernameInput.style.display = '';
|
244 |
+
|
245 |
+
return;
|
246 |
+
}
|
247 |
}
|
248 |
}).fail(function (data) {
|
249 |
if(window.console && window.console.log) {
|
includes/admin/actions.php
CHANGED
@@ -84,6 +84,25 @@ function username_changer_ajax_username_change() {
|
|
84 |
);
|
85 |
} else {
|
86 |
$response['message'] = username_changer_do_tags( username_changer()->settings->get_option( 'success_message', __( 'Username successfully changed to {new_username}.', 'username-changer' ) ), $old_username_tag, $new_username_tag );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
}
|
88 |
} else {
|
89 |
$response['message'] = __( 'An unknown error occurred.', 'username-changer' );
|
84 |
);
|
85 |
} else {
|
86 |
$response['message'] = username_changer_do_tags( username_changer()->settings->get_option( 'success_message', __( 'Username successfully changed to {new_username}.', 'username-changer' ) ), $old_username_tag, $new_username_tag );
|
87 |
+
|
88 |
+
// Send emails as necessary
|
89 |
+
if ( username_changer()->settings->get_option( 'enable_notifications', false ) ) {
|
90 |
+
$changed_user = get_user_by( 'login', $old_username );
|
91 |
+
$mail_to = $changed_user->user_email;
|
92 |
+
$subject = username_changer_do_tags( username_changer()->settings->get_option( 'email_subject', __( 'Username change notification - {sitename}', 'username-changer' ) ), $old_username_tag, $new_username_tag );
|
93 |
+
$message = username_changer_do_tags( username_changer()->settings->get_option( 'email_message', __( 'Howdy! We\'re just writing to let you know that your username for {siteurl} has been changed to {new_username}.', 'username-changer' ) . "\n\n" . __( 'Login now at {loginurl}', 'username-changer' ) ), $old_username_tag, $new_username_tag );
|
94 |
+
|
95 |
+
$subject = stripslashes( $subject );
|
96 |
+
$message = stripslashes( $message );
|
97 |
+
|
98 |
+
$from_name = get_bloginfo( 'name' );
|
99 |
+
$from_email = get_bloginfo( 'admin_email' );
|
100 |
+
|
101 |
+
$headers = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n";
|
102 |
+
$headers .= "Reply-To: ". $from_email . "\r\n";
|
103 |
+
|
104 |
+
wp_mail( $mail_to, $subject, $message, $headers );
|
105 |
+
}
|
106 |
}
|
107 |
} else {
|
108 |
$response['message'] = __( 'An unknown error occurred.', 'username-changer' );
|
includes/admin/settings/register.php
CHANGED
@@ -119,6 +119,40 @@ function username_changer_registered_settings( $settings ) {
|
|
119 |
'std' => 3,
|
120 |
'tooltip_title' => __( 'Minimum Length', 'username-changer' ),
|
121 |
'tooltip_desc' => __( 'The minimum allowed length for usernames is {minlength} characters.', 'username-changer' )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
)
|
123 |
),
|
124 |
'strings' => array(
|
@@ -246,6 +280,24 @@ function username_changer_display_help() {
|
|
246 |
add_action( 'username_changer_get_help', 'username_changer_display_help' );
|
247 |
|
248 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
249 |
/**
|
250 |
* Display the subheader for the messages section
|
251 |
*
|
119 |
'std' => 3,
|
120 |
'tooltip_title' => __( 'Minimum Length', 'username-changer' ),
|
121 |
'tooltip_desc' => __( 'The minimum allowed length for usernames is {minlength} characters.', 'username-changer' )
|
122 |
+
),
|
123 |
+
array(
|
124 |
+
'id' => 'email_header',
|
125 |
+
'name' => __( 'Email Settings', 'username-changer' ),
|
126 |
+
'desc' => '',
|
127 |
+
'type' => 'header'
|
128 |
+
),
|
129 |
+
array(
|
130 |
+
'id' => 'enable_notifications',
|
131 |
+
'name' => __( 'Enable Email Notifications', 'username-changer' ),
|
132 |
+
'desc' => __( 'Enable to send notification emails when usernames are changed.', 'username-changer' ),
|
133 |
+
'type' => 'checkbox',
|
134 |
+
'tooltip_title' => __( 'Enable Email Notifications', 'username-changer' ),
|
135 |
+
'tooltip_desc' => __( 'Notifications are not sent when a user changes their own username.', 'username-changer' )
|
136 |
+
),
|
137 |
+
array(
|
138 |
+
'id' => 'email_subheader',
|
139 |
+
'name' => '',
|
140 |
+
'desc' => '',
|
141 |
+
'type' => 'hook'
|
142 |
+
),
|
143 |
+
array(
|
144 |
+
'id' => 'email_subject',
|
145 |
+
'name' => __( 'Email Subject', 'username-changer' ),
|
146 |
+
'desc' => __( 'Specify the subject for username change notifications.', 'username-changer' ),
|
147 |
+
'type' => 'text',
|
148 |
+
'std' => __( 'Username change notification - {sitename}', 'username-changer' ),
|
149 |
+
),
|
150 |
+
array(
|
151 |
+
'id' => 'email_message',
|
152 |
+
'name' => __( 'Email Message', 'username-changer' ),
|
153 |
+
'desc' => __( 'Specify the message to send for username change notifications.', 'username-changer' ),
|
154 |
+
'type' => 'editor',
|
155 |
+
'std' => __( 'Howdy! We\'re just writing to let you know that your username for {siteurl} has been changed to {new_username}.', 'username-changer' ) . "\n\n" . __( 'Login now at {loginurl}', 'username-changer' )
|
156 |
)
|
157 |
),
|
158 |
'strings' => array(
|
280 |
add_action( 'username_changer_get_help', 'username_changer_display_help' );
|
281 |
|
282 |
|
283 |
+
/**
|
284 |
+
* Display the subheader for the emails section
|
285 |
+
*
|
286 |
+
* @since 3.1.0
|
287 |
+
* @return void
|
288 |
+
*/
|
289 |
+
function username_changer_display_email_subheader() {
|
290 |
+
?>
|
291 |
+
<div class="username-changer-settings-note">
|
292 |
+
<span class="note-title"><?php _e( 'Template Tags', 'username-changer' ); ?></span>
|
293 |
+
<p><?php _e( 'Emails allow the use of the following template tags:', 'username-changer' ); ?></p>
|
294 |
+
<?php echo username_changer_tags_list( 'email' ); ?>
|
295 |
+
</div>
|
296 |
+
<?php
|
297 |
+
}
|
298 |
+
add_action( 'username_changer_email_subheader', 'username_changer_display_email_subheader' );
|
299 |
+
|
300 |
+
|
301 |
/**
|
302 |
* Display the subheader for the messages section
|
303 |
*
|
includes/class.template-tags.php
CHANGED
@@ -457,7 +457,7 @@ function username_changer_template_tag_date( $old_username, $new_username ) {
|
|
457 |
* @return string $name The first name of the user
|
458 |
*/
|
459 |
function username_changer_template_tag_name( $old_username, $new_username ) {
|
460 |
-
$current_user =
|
461 |
|
462 |
if ( isset( $current_user->user_firstname ) ) {
|
463 |
$name = $current_user->user_firstname;
|
@@ -478,7 +478,7 @@ function username_changer_template_tag_name( $old_username, $new_username ) {
|
|
478 |
* @return string $name The full name of the user
|
479 |
*/
|
480 |
function username_changer_template_tag_fullname( $old_username, $new_username ) {
|
481 |
-
$current_user =
|
482 |
|
483 |
if ( isset( $current_user->user_firstname ) && isset( $current_user->user_lastname ) ) {
|
484 |
$name = $current_user->user_firstname . ' ' . $current_user->user_lastname;
|
457 |
* @return string $name The first name of the user
|
458 |
*/
|
459 |
function username_changer_template_tag_name( $old_username, $new_username ) {
|
460 |
+
$current_user = get_user_by( 'login', $new_username );
|
461 |
|
462 |
if ( isset( $current_user->user_firstname ) ) {
|
463 |
$name = $current_user->user_firstname;
|
478 |
* @return string $name The full name of the user
|
479 |
*/
|
480 |
function username_changer_template_tag_fullname( $old_username, $new_username ) {
|
481 |
+
$current_user = get_user_by( 'login', $new_username );
|
482 |
|
483 |
if ( isset( $current_user->user_firstname ) && isset( $current_user->user_lastname ) ) {
|
484 |
$name = $current_user->user_firstname . ' ' . $current_user->user_lastname;
|
includes/functions.php
CHANGED
@@ -77,28 +77,26 @@ function username_changer_process( $old_username, $new_username ) {
|
|
77 |
$user_id = username_exists( $old_username );
|
78 |
if ( $user_id ) {
|
79 |
// Update username!
|
80 |
-
$q
|
81 |
-
$qnn = $wpdb->prepare( "UPDATE $wpdb->users SET user_nicename = %s WHERE user_login = %s", $new_username, strtolower( str_replace( ' ', '-', $new_username ) ) );
|
82 |
-
|
83 |
-
// Check if display name is the same as username
|
84 |
-
$usersql = $wpdb->prepare( "SELECT * from $wpdb->users WHERE user_login = %s", $old_username );
|
85 |
-
$userinfo = $wpdb->get_row( $usersql );
|
86 |
-
|
87 |
-
// If display name is the same as username, update both
|
88 |
-
if ( $old_username == $userinfo->display_name ) {
|
89 |
-
$qdn = $wpdb->prepare( "UPDATE $wpdb->users SET display_name = %s WHERE user_login = %s", $new_username, $new_username );
|
90 |
-
}
|
91 |
-
|
92 |
-
// If the user is a Super Admin, update their permissions
|
93 |
-
if ( is_multisite() && is_super_admin( $user_id ) ) {
|
94 |
-
grant_super_admin( $user_id );
|
95 |
-
}
|
96 |
|
97 |
if ( false !== $wpdb->query( $q ) ) {
|
|
|
|
|
98 |
$wpdb->query( $qnn );
|
99 |
|
100 |
-
|
101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
}
|
103 |
|
104 |
// Reassign Coauthor Attribution
|
77 |
$user_id = username_exists( $old_username );
|
78 |
if ( $user_id ) {
|
79 |
// Update username!
|
80 |
+
$q = $wpdb->prepare( "UPDATE $wpdb->users SET user_login = %s WHERE user_login = %s", $new_username, $old_username );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
if ( false !== $wpdb->query( $q ) ) {
|
83 |
+
// Update user_nicename
|
84 |
+
$qnn = $wpdb->prepare( "UPDATE $wpdb->users SET user_nicename = %s WHERE user_login = %s AND user_nicename = %s", $new_username, $new_username, $old_username );
|
85 |
$wpdb->query( $qnn );
|
86 |
|
87 |
+
// Update display_name
|
88 |
+
$qdn = $wpdb->prepare( "UPDATE $wpdb->users SET display_name = %s WHERE user_login = %s AND display_name = %s", $new_username, $new_username, $old_username );
|
89 |
+
$wpdb->query( $qdn );
|
90 |
+
|
91 |
+
// Update nickname
|
92 |
+
$nickname = get_user_meta( $user_id, 'nickname', true );
|
93 |
+
if ( $nickname == $old_username ) {
|
94 |
+
update_user_meta( $user_id, 'nickname', $new_username );
|
95 |
+
}
|
96 |
+
|
97 |
+
// If the user is a Super Admin, update their permissions
|
98 |
+
if ( is_multisite() && is_super_admin( $user_id ) ) {
|
99 |
+
grant_super_admin( $user_id );
|
100 |
}
|
101 |
|
102 |
// Reassign Coauthor Attribution
|
readme.txt
CHANGED
@@ -4,13 +4,13 @@ Donate link: https://section214.com/donate/
|
|
4 |
Tags: user, username, display name, login
|
5 |
Requires at least: 3.0
|
6 |
Tested up to: 4.7.1
|
7 |
-
Stable tag: 3.0
|
8 |
|
9 |
Change usernames easily
|
10 |
|
11 |
== Description ==
|
12 |
|
13 |
-
|
14 |
|
15 |
== Installation ==
|
16 |
|
@@ -38,6 +38,12 @@ Yes! Username Changer works out of the box with Co-Authors Plus.
|
|
38 |
2. **Changing A Username** - Since version 3.0.0, usernames are now changed through the user profile page.
|
39 |
|
40 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
= Version 3.0.1 =
|
42 |
* Fixed: Typo in readme file
|
43 |
|
4 |
Tags: user, username, display name, login
|
5 |
Requires at least: 3.0
|
6 |
Tested up to: 4.7.1
|
7 |
+
Stable tag: 3.1.0
|
8 |
|
9 |
Change usernames easily
|
10 |
|
11 |
== Description ==
|
12 |
|
13 |
+
Changing usernames should be a pretty straightforward feature. Unfortunately, WordPress doesn't allow it by default. Username Changer attempts to remedy that oversight.
|
14 |
|
15 |
== Installation ==
|
16 |
|
38 |
2. **Changing A Username** - Since version 3.0.0, usernames are now changed through the user profile page.
|
39 |
|
40 |
== Changelog ==
|
41 |
+
+ Version 3.1.0 =
|
42 |
+
* Added: Email notification support
|
43 |
+
* Added: Nickname support
|
44 |
+
* Improved: SQL performance
|
45 |
+
* Improved: Dynamically update profile files
|
46 |
+
|
47 |
= Version 3.0.1 =
|
48 |
* Fixed: Typo in readme file
|
49 |
|
username-changer.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
/**
|
3 |
* Plugin Name: Username Changer
|
4 |
* Description: Change usernames easily
|
5 |
-
* Version: 3.0
|
6 |
* Author: Daniel J Griffiths
|
7 |
* Author URI: http://section214.com
|
8 |
* Text Domain: username-changer
|
@@ -85,7 +85,7 @@ if ( ! class_exists( 'Username_Changer' ) ) {
|
|
85 |
define( 'USERNAME_CHANGER_URL', plugin_dir_url( __FILE__ ) );
|
86 |
|
87 |
// Plugin version
|
88 |
-
define( 'USERNAME_CHANGER_VER', '3.0
|
89 |
}
|
90 |
|
91 |
|
2 |
/**
|
3 |
* Plugin Name: Username Changer
|
4 |
* Description: Change usernames easily
|
5 |
+
* Version: 3.1.0
|
6 |
* Author: Daniel J Griffiths
|
7 |
* Author URI: http://section214.com
|
8 |
* Text Domain: username-changer
|
85 |
define( 'USERNAME_CHANGER_URL', plugin_dir_url( __FILE__ ) );
|
86 |
|
87 |
// Plugin version
|
88 |
+
define( 'USERNAME_CHANGER_VER', '3.1.0' );
|
89 |
}
|
90 |
|
91 |
|