Skip to content

Instantly share code, notes, and snippets.

@tetsuo808
Last active September 10, 2025 12:15
Show Gist options
  • Select an option

  • Save tetsuo808/c8e661d5bd37f776d06d61c912247095 to your computer and use it in GitHub Desktop.

Select an option

Save tetsuo808/c8e661d5bd37f776d06d61c912247095 to your computer and use it in GitHub Desktop.
Ensure PMPro profile page URLs update when a Username is edited
<?php
/**
* Sync user_nicename with user_login so PMPro profile URLs
* always reflect updated usernames.
*/
function pmpromd_sync_nicename_on_profile_update($user_id) {
$user = get_userdata($user_id);
if ($user) {
$expected = sanitize_title($user->user_login);
if ($user->user_nicename !== $expected) {
wp_update_user(array(
'ID' => $user_id,
'user_nicename' => $expected,
));
}
}
}
add_action('profile_update', 'pmpromd_sync_nicename_on_profile_update');
@tetsuo808
Copy link
Author

tetsuo808 commented Sep 9, 2025

PMPro: Keep user_nicename in sync with user_login

Context

Paid Memberships Pro Member Directory & Profile Add On uses the user_nicename field to generate member profile URLs, e.g.:

https://example.com/profile/{user_nicename}/

By default in WordPress, user_login (username) cannot be changed once set.
However, plugins like Easy Username Updater allow admins to change usernames.
When that happens, WordPress updates user_login but does not update user_nicename.
As a result, PMPro profile URLs remain tied to the old username slug.

Solution

This snippet ensures that whenever a user profile is updated (such as with the Easy Username Updater plugin), the user_nicename is automatically synced to match the current user_login. This keeps PMPro profile URLs correct and up to date without requiring manual intervention.

Usage

  • Add this snippet to your theme’s functions.php (or a site-specific plugin).
  • From then on, any time a username is updated, the profile URL will update too.

Notes

  • No need to flush permalinks; WordPress rewrite rules are unaffected.
  • This does not retroactively fix past users unless their profiles are updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment