Last active
September 10, 2025 12:15
-
-
Save tetsuo808/c8e661d5bd37f776d06d61c912247095 to your computer and use it in GitHub Desktop.
Ensure PMPro profile page URLs update when a Username is edited
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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'); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PMPro: Keep
user_nicenamein sync withuser_loginContext
Paid Memberships Pro Member Directory & Profile Add On uses the
user_nicenamefield 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_loginbut does not updateuser_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_nicenameis automatically synced to match the currentuser_login. This keeps PMPro profile URLs correct and up to date without requiring manual intervention.Usage
functions.php(or a site-specific plugin).Notes