BuddyDev

Allow Your Users to Change their Username on your BuddyPress Based site

Well, here is a small weekend fun project. The plugin will allow your users to change their Username(yes, It's the username you log with) from the front end. It may be helpful for a couple of sites if you want to allow your users to change their username.

A couple of screenshots will help better.

Change Username Screen:-

The User can enter a new username there as shown below

And if the username is available and is not reserved, The username will be changed and the user will be redirected to new url of his profile as shown below

And if the user enters a reserved name(say admin, administrator etc), the username will not be changed, and the user will see an error as shown below

Since the plugin updates username as well as user_nicename, there won't be any issues with author archive or any user page,.

Caution:-

In BuddyPress activity stream, the username and link are inserted statically. So, It will not update the old activity stream. Though, the activity will still belong to user but clicking on the username in activity stream for older link will redirect to homepage. Clicking view will work.

Download &Installation:

https://buddydev.com/plugins/bp-username-changer/
For all of you, who revel in looking at the code, I have commented it properly. So, If you want to take a look, It should be pleasure for your eyes 🙂

Please do let me know your suggestions or anything you want to say in comment. I am very much looking forward to that 🙂

30 Responses to Allow Your Users to Change their Username on your BuddyPress Based site

  • I like this idea to custom down on admin duties but I would love to see a way to limit how many times they can do this. Don't want troublemakers changing names everyday causing havoc.

    • Hi Robot,
      Thanks for the comment.
      I am not sure if we really want to limit the users to 'n' number of allowed changes. If i get a few more opinions on it, I can certainly put it.

  • Hello,

    I was not able to translate this plugin, it was not working using my nb_NO.mo file. I changed script as below, and also renamed languagefile to bpcu-nb_NO.mo and it works OK. BUT it will not translate the Change Username menu and submenu??

    Any idea?

    //settings subtab slug
    define("BPCU_PLUGIN_NAME","bpcu");//for localized text domain

    if(!defined("BPCU_SLUG"))
    define("BPCU_SLUG","change-username");

    $bpcu_dir =str_replace(basename( __FILE__),"",plugin_basename(__FILE__));
    define("BPCU_DIR_NAME",$bpcu_dir);//the directory name of bp-username-change
    define("BPCU_PLUGIN_DIR",WP_PLUGIN_DIR."/".BPCU_DIR_NAME);
    define("BPCU_PLUGIN_URL",WP_PLUGIN_URL."/".BPCU_DIR_NAME);

    //load text domain
    /*
    * Localization support
    * Put your files into
    * bp-username-change/languages/bpcu-your_local.mo
    */
    function bpcu_load_textdomain() {
    $locale = apply_filters( 'bpcu_load_textdomain_get_locale', get_locale() );
    // if load .mo file
    if ( !empty( $locale ) ) {
    $mofile_default = sprintf( '%s/languages/%s-%s.mo', BPCU_PLUGIN_DIR, BPCU_PLUGIN_NAME, $locale );
    $mofile = apply_filters( 'bpcu_load_textdomain_mofile', $mofile_default );
    // make sure file exists, and load it
    if ( file_exists( $mofile ) ) {
    load_textdomain( BPCU_PLUGIN_NAME, $mofile );
    }
    }
    }
    add_action ( 'bp_init', 'bpcu_load_textdomain', 2 );

    //setup nav
    function bpdev_bpcu_nav_setup(){
    global $bp;
    $settings_link = $bp->loggedin_user->domain . $bp->settings->slug . '/';
    bp_core_new_subnav_item( array( 'name' => __( 'Change Username', 'bpcu' ), 'slug' => 'change-username', 'parent_url' => $settings_link, 'parent_slug' => $bp->settings->slug, 'screen_function' => 'bpdev_bpcu_settings_screen', 'position' => 30, 'user_has_access' => bp_is_my_profile() ) );

    }
    add_action( 'bp_setup_nav', 'bpdev_bpcu_nav_setup',11 );

  • Also, i am using BPMag theme and i am not getting any messages if success, if username already in use, or if no username added.. No error or success messages..

    Thanks
    Rune

  • I have now fixed the above translation issue, only issue left is the missing success/error messages..

    This means i now have a complete Norwegian translation for the following plugins:

    – BP Branded Login
    – Buddypress Username Changer (need fix of the message issue)
    – Recent Visitors

    But all these plugins i had to make changes into their respective files for translation to work properly..

    If you want these updates/translations i am happy to send them to you..

    Regards
    Rune

  • Wow.. this will be so helpful for users who sign in with gmail and have dots in their username and users cannot tag them or send them inbox messages.

    thanks Brajesh..

    NB: I have asked many times without a response. How can i contact you to discuss a potential outsourcing for custom BP design?

  • thanks Brajesh, very helpful for all the plugins like "signin with facebook" etc.
    all works well on child theme of bp-default, except translation. Rune Kristoffersen could you please share some info re how to get translations working?

    thanks

  • Hi James,

    This as below is actually what i mostly changed to get the translation and translation of menu to work. This also means that i have renamed my language .mo file to: bpcu-nb_NO.mo

    //settings subtab slug
    define(“BPCU_PLUGIN_NAME”,”bpcu”);//for localized text domain

    if(!defined(“BPCU_SLUG”))
    define(“BPCU_SLUG”,”change-username”);

    $bpcu_dir =str_replace(basename( __FILE__),”",plugin_basename(__FILE__));
    define(“BPCU_DIR_NAME”,$bpcu_dir);//the directory name of bp-username-change
    define(“BPCU_PLUGIN_DIR”,WP_PLUGIN_DIR.”/”.BPCU_DIR_NAME);
    define(“BPCU_PLUGIN_URL”,WP_PLUGIN_URL.”/”.BPCU_DIR_NAME);

    //load text domain
    /*
    * Localization support
    * Put your files into
    * bp-username-change/languages/bpcu-your_local.mo
    */
    function bpcu_load_textdomain() {
    $locale = apply_filters( ‘bpcu_load_textdomain_get_locale’, get_locale() );
    // if load .mo file
    if ( !empty( $locale ) ) {
    $mofile_default = sprintf( ‘%s/languages/%s-%s.mo’, BPCU_PLUGIN_DIR, BPCU_PLUGIN_NAME, $locale );
    $mofile = apply_filters( ‘bpcu_load_textdomain_mofile’, $mofile_default );
    // make sure file exists, and load it
    if ( file_exists( $mofile ) ) {
    load_textdomain( BPCU_PLUGIN_NAME, $mofile );
    }
    }
    }
    add_action ( ‘bp_init’, ‘bpcu_load_textdomain’, 2 );

    //setup nav
    function bpdev_bpcu_nav_setup(){
    global $bp;
    $settings_link = $bp->loggedin_user->domain . $bp->settings->slug . ‘/’;
    bp_core_new_subnav_item( array( ‘name’ => __( ‘Change Username’, ‘bpcu’ ), ‘slug’ => ‘change-username’, ‘parent_url’ => $settings_link, ‘parent_slug’ => $bp->settings->slug, ‘screen_function’ => ‘bpdev_bpcu_settings_screen’, ‘position’ => 30, ‘user_has_access’ => bp_is_my_profile() ) );

    }
    add_action( ‘bp_setup_nav’, ‘bpdev_bpcu_nav_setup’,11 );

    • thanks Rune, it makes my translation working, but I still do not see any changes to 'Change Username' subnav button and to the same text in adminbar settings. are there any other changes I should make?

      Brajesh, I use your username checker too, is there any easy way to add it to the username changer.

      thank you a lot!

      • Sorry, you got the old one, this as below should make it work:

        //setup nav
        function bpdev_bpcu_nav_setup(){
        global $bp;
        $settings_link = $bp->loggedin_user->domain . $bp->settings->slug . '/';
        bp_core_new_subnav_item( array( 'name' => __( 'Change Username', 'bpcu' ), 'slug' => 'change-username', 'parent_url' => $settings_link, 'parent_slug' => $bp->settings->slug, 'screen_function' => 'bpdev_bpcu_settings_screen', 'position' => 30, 'user_has_access' => bp_is_my_profile() ) );

        }
        add_action( 'wp', 'bpdev_bpcu_nav_setup', 2 );
        add_action( 'admin_menu', 'bpdev_bpcu_nav_setup', 2 );

      • James, after this update do you still get success/error messages when changing username?

        Just interesting to know if it on my end is a BPMag issue..

        Thanks

        • thanks again Rune, this correction works like a charm.
          yes, I use custom child theme of bp-dafault and messages work before/after your changes.

  • James, I can email you the updated file if you just send me your email address, here or on my site her: http://www.arctic-peaks.com/kontakt/ or english http://www.arctic-peaks.com/en/contact/

    Rune

  • Great James, then i can start looking into the BPmag theme..

    Thanks

  • hi Brajesh, don't know how every part of BP works, but wouldn't username change affect friends, followers, groups etc. connections, as change means other slug?

    thanks.

    • Hi James,
      No It won't affect any other thing. Everything works on the basis of numerical user id, so changing username won't affect that.

  • Hi! I translated your bpcu.po file and placed ru_RU.mo into languages folder but nothing happend, all the text is in English as before. What I did wrong?

  • Hi Brajesh,
    is there a way to let users only change their username once? And after that not show the option to change the username anymore.

    • Hi Sascha,
      Thank you for the comment. Yes that is possible. I will provide some hack tomorrow(It is too late here, leaving from work)
      Hope you won't mind that.

      regards
      Brajesh

  • Hi – has anyone found a similar thing that enables the user to change their email address?

    • Hi Simon,
      Thank you for the comment.

      This functionality comes packed with BuddyPress. you can change the email via visiting your profile->settings tab.

  • https://alertscentral.com/members/abil/profile/edit/group/1/

    I think because we are using Xprofile fields….it does not show up here.

    Regards
    Simon

    • Hi,
      I have the same problem, did you figure out an solution?

      • Hi Christopher,
        Can you please open a topic on our forums with more details?
        Thank you
        Brajesh

  • Hi Brajesh, is it possible to only let the admin (myself) change a person's username by going to their profile/settings page?

    So the tab will be visible when I visit it, but not the user.

    Thanks for a great plugin.

  • Pingback:12 Top Buddypress Plugins for Customizing Your Social Network