Skip to:
Content

BuddyPress.org

Changeset 2626 for trunk/bp-forums.php


Ignore:
Timestamp:
02/08/2010 01:26:48 PM (15 years ago)
Author:
apeatling
Message:

Fixes #1816

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-forums.php

    r2576 r2626  
    386386
    387387    $query = new BB_Query( 'post', $args, 'get_thread' );
    388     return $query->results;
     388    return bp_forums_get_post_extras( $query->results );
    389389}
    390390
     
    450450    return $post;
    451451}
     452
     453function bp_forums_get_post_extras( $posts ) {
     454    global $bp, $wpdb;
     455
     456    if ( empty( $posts ) )
     457        return $posts;
     458
     459    /* Get the user ids */
     460    foreach ( (array)$posts as $post ) $user_ids[] = $post->poster_id;
     461    $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
     462
     463    /* Fetch the poster's user_email, user_nicename and user_login */
     464    $poster_details = $wpdb->get_results( $wpdb->prepare( "SELECT u.ID as user_id, u.user_login, u.user_nicename, u.user_email, u.display_name FROM {$wpdb->users} u WHERE u.ID IN ( {$user_ids} )" ) );
     465
     466    for ( $i = 0; $i < count( $posts ); $i++ ) {
     467        foreach ( (array)$poster_details as $poster ) {
     468            if ( $poster->user_id == $posts[$i]->poster_id ) {
     469                $posts[$i]->poster_email = $poster->user_email;
     470                $posts[$i]->poster_login = $poster->user_nicename;
     471                $posts[$i]->poster_nicename = $poster->user_login;
     472                $posts[$i]->poster_name = $poster->display_name;
     473            }
     474        }
     475    }
     476
     477    /* Fetch fullname for each poster. */
     478    if ( function_exists( 'xprofile_install' ) ) {
     479        $poster_names = $wpdb->get_results( $wpdb->prepare( "SELECT pd.user_id, pd.value FROM {$bp->profile->table_name_data} pd WHERE pd.user_id IN ( {$user_ids} )" ) );
     480        for ( $i = 0; $i < count( $posts ); $i++ ) {
     481            foreach ( (array)$poster_names as $name ) {
     482                if ( $name->user_id == $topics[$i]->user_id )
     483                $posts[$i]->poster_name = $poster->value;
     484            }
     485        }
     486    }
     487
     488    return $posts;
     489}
     490
    452491
    453492function bp_forums_get_forum_topicpost_count( $forum_id ) {
Note: See TracChangeset for help on using the changeset viewer.