Skip to:
Content

BuddyPress.org

Changeset 2439 for trunk/bp-core.php


Ignore:
Timestamp:
01/25/2010 12:33:37 AM (15 years ago)
Author:
apeatling
Message:

Making sure all blog comments under a BuddyPress enabled install have proper BuddyPress full names and profile links for registered users. Also improved the efficiency of this.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core.php

    r2433 r2439  
    20012001
    20022002/**
     2003 * bp_core_filter_comments()
     2004 *
     2005 * Filter the blog post comments array and insert BuddyPress URLs for users.
     2006 *
     2007 * @package BuddyPress Core
     2008 */
     2009function bp_core_filter_comments( $comments, $post_id ) {
     2010    global $wpdb;
     2011
     2012    if ( !is_site_admin() )
     2013        return $comments;
     2014
     2015    foreach( $comments as $comment ) {
     2016        if ( $comment->user_id )
     2017            $user_ids[] = $comment->user_id;
     2018    }
     2019
     2020    if ( empty( $user_ids ) )
     2021        return $comments;
     2022
     2023    $user_ids = implode( ',', $user_ids );
     2024
     2025    if ( !$userdata = $wpdb->get_results( $wpdb->prepare( "SELECT ID as user_id, user_login, user_nicename FROM {$wpdb->users} WHERE ID IN ({$user_ids})" ) ) )
     2026        return $comments;
     2027
     2028    foreach( $userdata as $user )
     2029        $users[$user->user_id] = bp_core_get_user_domain( $user->user_id, $user->user_nicename, $user->user_login );
     2030
     2031    foreach( $comments as $i => $comment ) {
     2032        if ( !empty( $comment->user_id ) ) {
     2033            if ( !empty( $users[$comment->user_id] ) )
     2034                $comments[$i]->comment_author_url = $users[$comment->user_id];
     2035        }
     2036    }
     2037
     2038    return $comments;
     2039}
     2040add_filter( 'comments_array', 'bp_core_filter_comments', 10, 2 );
     2041
     2042/**
    20032043 * bp_core_clear_user_object_cache()
    20042044 *
Note: See TracChangeset for help on using the changeset viewer.