Skip to:
Content
Pages
Categories
Search
Top
Bottom

All links are working, minus my admin/author/all of my pages


  • Anonymous
    Inactive

    I’m using buddypress version 1.2 beta in the latest version of WordPress 2.9.1

    If you visit my site http://www.tonsil-help.com, you’ll see I’ve created my own theme that I’ve integrated into buddypress.

    The only thing that I can’t get working are all of my links, EX: under “My Account” in the admin bar, all of these point to siteurl/members/Josh Katherman which is my full name.

    If I type in “admin” instead of “Josh Katherman”, everything works fine, as admin is technically my user name on this site. Everyone else’s account information and profiles/links work fine except mine.

    So I guess I’m not understanding why it’s using my actual name instead of my username, as this is why none of my links works.

    Any help would be awesome! – Josh

    edit:

    for an example link go to http://www.tonsil-help.com/author/Josh%20Katherman/ as you can see, that’s the link to my author page, and all my pages under “my account” use “Josh Katherman” which seems to be the reason why they aren’t working.

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

  • Peter Anselmo
    Participant

    @peter-anselmo

    This may or may not be your problem, but Buddypress has some issues with spaces in names. Try clicking on the right of this post to view my profile. It uses my actual name “Peter Anselmo” instead of my username “peter-anselmo”. It won’t work. Fun.


    Anonymous
    Inactive

    yeah exactly! That’s the same issue I’m having. So no fix on this yet?


    Peter Anselmo
    Participant

    @peter-anselmo

    On the 2nd, Andy worked on this by trimming all whitespace from newly entered values. You can see the changes here:

    https://trac.buddypress.org/changeset/2547

    I tested this on http://testbp.org/, and yes, it does keep the problem from happening for new members. There are two outstanding issues with this however.

    1. It silently trims the whitespace, so you have no way of knowing that your username is not what you entered. At a minimum, it should send you an updated username with the confirmation email. Only after looking at the site activity, and seeing my username with the space trimmed, did I realize why I wasn’t able to log in.

    2. It doesn’t help any of the existing users with spaces in their names (such as myself on this forum).

    Admittedly, this is a tough problem to solve for existing users, but yes, AFIK, it is still unsolved.

    I doubt this helps but I changed up some of the core files to use the user_nicename column

    not at my machine with the code but i believe just a few files that required changing to lookup the slug by login and changing a sql statement


    alextababa2
    Participant

    @alextababa2

    Thanks etiviti – i think it’s a similar problem or the same as what you’ve been dicussining the the last thread.

    If I replace “ali” in this url with “admin” – my actual username , I can get around fine.

    Do you have more info on the changes you made… ? Wouldn’t know where to start.

    Also, is this an official bug that you know of?

    http://bcosuluvit.com/members/ali/ (not my username – my nickname)

    should be

    http://bcosuluvit.com/members/admin/ (my username)

    Ok, I *believe* this is what i changed (i’m on latest trunk) to default urls to the nicename – I’ll double check tomorrow though.

    in bp-core.php – i modified the two functions here:

    function bp_core_get_userid( $username ) {

    global $wpdb;

    if ( !empty( $username ) ) {

    //MYCHANGE - default to user_nicename

    if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )

    return apply_filters( 'bp_core_get_userid', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ) );

    else

    return apply_filters( 'bp_core_get_userid', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_nicename = %s", $username ) ) );

    }

    }

    function bp_core_get_username( $user_id, $user_nicename = false, $user_login = false ) {

    global $bp;

    if ( !$username = wp_cache_get( 'bp_user_username_' . $user_id, 'bp' ) ) {

    if ( empty( $user_nicename ) && empty( $user_login ) ) {

    $ud = false;

    if ( $bp->loggedin_user->id == $user_id )

    $ud = &$bp->loggedin_user->userdata;

    if ( $bp->displayed_user->id == $user_id )

    $ud = &$bp->displayed_user->userdata;

    if ( empty( $ud ) ) {

    if ( !$ud = bp_core_get_core_userdata( $user_id ) )

    return false;

    }

    $user_nicename = $ud->user_nicename;

    $user_login = $ud->user_login;

    }

    //MYCHANGE - default to user_nicename

    if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )

    $username = $user_login;

    else

    $username = $user_nicename;

    }

    /* Add this to cache */

    if ( !empty( $username ) )

    wp_cache_set( 'bp_user_username_' . $user_id, $username, 'bp' );

    return apply_filters( 'bp_core_get_username', $username );

    }

    then in bp-core-catchuri.php under function bp_core_set_uri_globals()

    /* Catch a member page and set the current member ID */

    if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) ) {

    if ( ( $bp_uri[0] == BP_MEMBERS_SLUG && !empty( $bp_uri[1] ) ) || in_array( 'wp-load.php', $bp_uri ) ) {

    // We are within a member page, set up user id globals

    $displayed_user_id = bp_core_get_displayed_userid( $bp_uri[1] );

    unset($bp_uri[0]);

    unset($bp_uri[1]);

    /* Reset the keys by merging with an empty array */

    $bp_uri = array_merge( array(), $bp_uri );

    }

    } else {

    //MYCHANGE - default to user_nicename

    if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) ) {

    $_udl = get_userdatabylogin( $bp_uri[0] );

    } else {

    $_udl = get_user_by('slug', $bp_uri[0] );

    }

    if ( $_udl || in_array( 'wp-load.php', $bp_uri ) ) {

    $is_member_page = true;

    $is_root_component = true;

    // We are within a member page, set up user id globals

    $displayed_user_id = bp_core_get_displayed_userid( $bp_uri[0] );

    unset($bp_uri[0]);

    /* Reset the keys by merging with an empty array */

    $bp_uri = array_merge( array(), $bp_uri );

    }

    }

    (sorry, some reason the code tags failed)

    i only wrapped it in BP_ENABLE_USERNAME_COMPATIBILITY_MODE if case i wanted to switch back to user_login urls


    alextababa2
    Participant

    @alextababa2

    Hi Etiviti

    Thanks for the follow up, it’s really appreciated. The issue seems to have been only related to my admin username which was created before buddypress was installed.

    Also, it wasn’t the spaces that were throwing if off… it might be some other vauge incompatibility between wmpu and buddypress names.

    I’ll double check before I ask for some more info next time, but I’m sure someone with the same issues as you will benefit from your effort.


    Tim Nicholson
    Participant

    @timnicholson

    etiviti, I’m on BP v1.2.1 and the code I have in bp-core is different than what you have above. There is no reference to $_udl anywhere in bp-core-catchuri.

    I *do* see some code that looks like it should adress the issue, but doesn’t seem to work.

    function bp_core_get_username( $user_id, $user_nicename = false, $user_login = false ) {
    global $bp;

    if ( !$username = wp_cache_get( 'bp_user_username_' . $user_id, 'bp' ) ) {
    if ( empty( $user_nicename ) && empty( $user_login ) ) {
    $ud = false;

    if ( $bp->loggedin_user->id == $user_id )
    $ud = &$bp->loggedin_user->userdata;

    if ( $bp->displayed_user->id == $user_id )
    $ud = &$bp->displayed_user->userdata;

    if ( empty( $ud ) ) {
    if ( !$ud = bp_core_get_core_userdata( $user_id ) )
    return false;
    }

    $user_nicename = $ud->user_nicename;
    $user_login = $ud->user_login;
    }

    if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )
    $username = $user_login;
    else
    $username = $user_nicename;
    }

    /* Add this to cache */
    if ( !empty( $username ) )
    wp_cache_set( 'bp_user_username_' . $user_id, $username, 'bp' );

    return apply_filters( 'bp_core_get_username', $username );
    }

    Notice how the $username that gets returned should either be user_login or user_nicename, depending on whether BP_ENABLE_USERNAME_COMPATIBILITY_MODE is set or not. However, on all my BP pages, the user permalink is always showing the display_name with the space in it and the URL’s don’t work.

    Digging further, I see that the function that returns the link to the member profile, bp_get_member_permalink(), is defined in bp-core-templatetags and calls bp_core_get_user_domain(), which in turn bases the URL on the above function bp_core_get_username().

    So this SHOULD work, but doesn’t seem to. There IS some cache logic in the code above, so maybe that’s part of the issue but I still can’t for the life of me figure out how that code above could ever return a URL based on the user’s “display name”.


    Tim Nicholson
    Participant

    @timnicholson

    Ok, this is *really* whacked. When setting BP_ENABLE_USERNAME_COMPATIBILITY_MODE to true in BP v1.2.1, this fixes the member profile link on the member *directory* page only by using the user login name. However, on the actual member profile page itself, the user nicename is still be used in all the links. The wrong name is also being used on all the activity stream pages. Could this be a cache issue that will resolve itself over time? I can’t see how this behavior would happen unless it was cache-related.


    Tim Nicholson
    Participant

    @timnicholson

    What a nightmare this has been! Anyway, thanks to etiviti’s original code, I was able to patch up the bp-core/bp-core-catchuri.php file as follows. This is replacement code within the function bp_core_set_uri_globals(). The // is lines I commented out and I added // ADD to the new lines that replaced them.

    /* Catch a member page and set the current member ID */
    if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) ) {
    //if ( ( $bp_uri[0] == BP_MEMBERS_SLUG && !empty( $bp_uri[1] ) ) || in_array( 'wp-load.php', $bp_uri ) ) {
    if ( ( $bp_uri[0] == BP_MEMBERS_SLUG && !empty( $bp_uri[1] ) ) || in_array( 'wp-load.php', $bp_uri ) ) { //ADD
    // We are within a member page, set up user id globals
    //$displayed_user_id = bp_core_get_displayed_userid( $bp_uri[1] );
    //$user_temp = get_user_by('slug', str_replace('%20',' ',$bp_uri[1]) ); //ADD
    $user_temp = get_user_by('slug', urldecode($bp_uri[1]) ); //ADD
    $displayed_user_id = $user_temp->ID; //ADD

    unset($bp_uri[0]);
    unset($bp_uri[1]);

    /* Reset the keys by merging with an empty array */
    $bp_uri = array_merge( array(), $bp_uri );
    }

    This code assumes that you will be using nicename for the URL’s so DO NOT set BP_ENABLE_USERNAME_COMPATIBILITY_MODE in wp-config.php. What this code does is look up the user by “slug”, which is what WP refers to the nice name as. Since I had to hack the code to get anything to work, I went ahead and fixed the issue with spaces being in the nice name as well. The function urldecode() will replace the %20 in the URL with the space that is needed for the “slug” lookup. In fact, it should fix similar issues with other characters in the user nicename field that get replaced when its converted to a URL.

    If you really want to fix this by using the user’s login name, original function call I commented out bp_core_get_displayed_userid() will accept a user login name (and ONLY a user login name… its not designed to accept “slugs” or full names or anything else). So you shouldn’t need However, the bigger issue with this is that the various BP pages seem to spit out many links using the nicename, not the user_login name.

    If you have figured out an inconsistency between BP page use the different “user names”, please add this information to a Trac ticket so we know where to dive in.


    hotforwords
    Participant

    @hotforwords

    Tim Nicholson, I don’t understand why the two lines you list are exactly the same.. you say to:
    //if ( ( $bp_uri[0] == BP_MEMBERS_SLUG && !empty( $bp_uri[1] ) ) || in_array( 'wp-load.php', $bp_uri ) ) {
    if ( ( $bp_uri[0] == BP_MEMBERS_SLUG && !empty( $bp_uri[1] ) ) || in_array( 'wp-load.php', $bp_uri ) ) { //ADD

    Yet the two lines are exactly the same! Am I missing something?

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘All links are working, minus my admin/author/all of my pages’ is closed to new replies.
Skip to toolbar