bp_core_filter_comments( array $comments, int $post_id )
Filter the blog post comments array and insert BuddyPress URLs for users.
Description
Parameters
- $comments
-
(array) (Required) The array of comments supplied to the comments template.
- $post_id
-
(int) (Required) The post ID.
Return
(array) $comments The modified comment array.
Source
File: bp-core/bp-core-filters.php
function bp_core_filter_comments( $comments, $post_id ) { global $wpdb; foreach( (array) $comments as $comment ) { if ( $comment->user_id ) $user_ids[] = $comment->user_id; } if ( empty( $user_ids ) ) return $comments; $user_ids = implode( ',', wp_parse_id_list( $user_ids ) ); if ( !$userdata = $wpdb->get_results( "SELECT ID as user_id, user_login, user_nicename FROM {$wpdb->users} WHERE ID IN ({$user_ids})" ) ) return $comments; foreach( (array) $userdata as $user ) $users[$user->user_id] = bp_core_get_user_domain( $user->user_id, $user->user_nicename, $user->user_login ); foreach( (array) $comments as $i => $comment ) { if ( !empty( $comment->user_id ) ) { if ( !empty( $users[$comment->user_id] ) ) $comments[$i]->comment_author_url = $users[$comment->user_id]; } } return $comments; }
Changelog
Version | Description |
---|---|
BuddyPress 1.2.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.