Skip to:
Content

bbPress.org

Changeset 4931


Ignore:
Timestamp:
05/19/2013 07:05:57 AM (11 years ago)
Author:
johnjamesjacoby
Message:

Improve user logic in bbp_parse_query(), so that numeric user slugs display correctly even when pretty permalinks are enabled. Also eliminates duplicate get_userdata() call, and renames some variables to prevent accidental stomping.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/core/template-functions.php

    r4821 r4931  
    331331    if ( !empty( $bbp_user ) ) {
    332332
    333         // Not a user_id so try email and slug
    334         if ( get_option( 'permalink_structure' ) || ! is_numeric( $bbp_user ) ) {
     333        /** Find User *********************************************************/
     334
     335        // Setup the default user variable
     336        $the_user = false;
     337
     338        // If using pretty permalinks, use the email or slug
     339        if ( get_option( 'permalink_structure' ) ) {
    335340
    336341            // Email was passed
    337342            if ( is_email( $bbp_user ) ) {
    338                 $bbp_user = get_user_by( 'email', $bbp_user );
     343                $the_user = get_user_by( 'email', $bbp_user );
    339344
    340345            // Try nicename
    341346            } else {
    342                 $bbp_user = get_user_by( 'slug', $bbp_user );
    343             }
    344 
    345             // If we were successful, set to ID
    346             if ( is_object( $bbp_user ) ) {
    347                 $bbp_user = $bbp_user->ID;
    348             }
    349         }
    350 
    351         // Cast as int, just in case
    352         $bbp_user = (int) $bbp_user;
     347                $the_user = get_user_by( 'slug', $bbp_user );
     348            }
     349        }
     350
     351        // No user found by slug/email, so try the ID if it's numeric
     352        if ( empty( $the_user ) && is_numeric( $bbp_user ) ) {
     353            $the_user = get_user_by( 'id', $bbp_user );
     354        }
    353355
    354356        // 404 and bail if user does not have a profile
    355         if ( ! bbp_user_has_profile( $bbp_user ) ) {
     357        if ( empty( $the_user->ID ) || ! bbp_user_has_profile( $the_user->ID ) ) {
    356358            $posts_query->set_404();
    357359            return;
     
    419421        $posts_query->is_home = false;
    420422
    421         // Get the user data
    422         $user = get_userdata( $bbp_user );
    423 
    424423        // User is looking at their own profile
    425         if ( get_current_user_id() == $user->ID ) {
     424        if ( get_current_user_id() == $the_user->ID ) {
    426425            $posts_query->bbp_is_single_user_home = true;
    427426        }
    428427
    429428        // Set bbp_user_id for future reference
    430         $posts_query->set( 'bbp_user_id', $user->ID );
     429        $posts_query->set( 'bbp_user_id', $the_user->ID );
    431430
    432431        // Set author_name as current user's nicename to get correct posts
    433         $posts_query->set( 'author_name', $user->user_nicename );
     432        $posts_query->set( 'author_name', $the_user->user_nicename );
    434433
    435434        // Set the displayed user global to this user
    436         bbpress()->displayed_user = $user;
     435        bbpress()->displayed_user = $the_user;
    437436
    438437    // View Page
Note: See TracChangeset for help on using the changeset viewer.