Skip to:
Content
Pages
Categories
Search
Top
Bottom

Clearing user nicename cache


  • Jason Lawton
    Participant

    @phoopee3

    I have a hook where when the user updates their first and last name, it updates their @ name as well. So if their name is ‘Jason Lawton’, their @ name is ‘@jason-lawton’. If they change their name to ‘Jay Lawton’ it will change their @ name to ‘@jay-lawton’.

    The issue I’m running into is that when the user_nicename is updated, it doesn’t redirect to the proper url. It tries going to the url with the old username, like ‘/members/jason-lawton/’ instead of the updated ‘/members/jay-lawton’.

    I’m trying to figure out what cache to invalidate, but I’ve tried stuff like wp_cache_delete( 'bp_core_userdata_' . $user_id, 'bp' ); but when the bp_displayed_user_domain() is called it still gets the old incorrect value.

    Any suggestions on how to clear out the user name? or a way to replace the value the bp_displayed_user_domain() is getting?

Viewing 5 replies - 1 through 5 (of 5 total)

  • Jason Lawton
    Participant

    @phoopee3

    I’m calling this via an add_action('xprofile_updated_profile', 'updateUserNicename', 1, 5); hook.


    Jason Lawton
    Participant

    @phoopee3

    I’ve also tried wp_cache_delete( 'bp_user_username_' . $user_id, 'bp' ); which didn’t work either.

    I’ve also tried looking into changing it before it saves, via the xprofile_data_before_save hook, but not enough data gets passed to the function to update the nicename.


    Jason Lawton
    Participant

    @phoopee3

    I got it working, I was trying to use wp_get_current_user, which was using cached information, so I had to use get_userdata instead. Then I forcefully (search/replace) updated the url by replacing it in the $bp->displayed_user->domain.

    Full function available here: https://gist.github.com/phoopee3/69e991f08eb595efdaedb7a02bc0e8ef


    liutauras2
    Participant

    @liutauras2

    Hello buddy, I have a question, how did you managed to make that users would get their username similar to their buddypress display name?


    Jason Lawton
    Participant

    @phoopee3

    If you look in the gist that I linked to, you’ll see that when the user updates their xprofile info, I update their nicename from their first and last name.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar