Skip to:
Content

BuddyPress.org

Changeset 6647


Ignore:
Timestamp:
12/17/2012 05:55:30 PM (14 years ago)
Author:
boonebgorges
Message:

Documentation and WP coding standards in xprofile_filter_comments()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-xprofile/bp-xprofile-filters.php

    r6646 r6647  
    192192}
    193193
     194/**
     195 * Ensures that BP data appears in comments array
     196 *
     197 * This filter loops through the comments return by a normal WordPress request
     198 * and swaps out user data with BP xprofile data, where available
     199 *
     200 * @param array $comments
     201 * @param int $post_id
     202 * @return array $comments
     203 */
    194204function xprofile_filter_comments( $comments, $post_id ) {
     205        // Locate comment authors with WP accounts
    195206        foreach( (array) $comments as $comment ) {
    196207                if ( $comment->user_id ) {
     
    199210        }
    200211
    201         if ( empty( $user_ids ) )
     212        // If none are found, just return the comments array
     213        if ( empty( $user_ids ) ) {
    202214                return $comments;
    203 
     215        }
     216
     217        // Pull up the xprofile fullname of each commenter
    204218        if ( $fullnames = BP_XProfile_ProfileData::get_value_byid( 1, $user_ids ) ) {
    205219                foreach( (array) $fullnames as $user ) {
    206                         $users[$user->user_id] = trim( stripslashes( $user->value ) );
    207                 }
    208         }
    209 
     220                        $users[ $user->user_id ] = trim( stripslashes( $user->value ) );
     221                }
     222        }
     223
     224        // Loop through and match xprofile fullname with commenters
    210225        foreach( (array) $comments as $i => $comment ) {
    211                 if ( !empty( $comment->user_id ) ) {
    212                         if ( !empty( $users[$comment->user_id] ) ) {
    213                                 $comments[$i]->comment_author = $users[$comment->user_id];
     226                if ( ! empty( $comment->user_id ) ) {
     227                        if ( ! empty( $users[ $comment->user_id ] ) ) {
     228                                $comments[ $i ]->comment_author = $users[ $comment->user_id ];
    214229                        }
    215230                }
Note: See TracChangeset for help on using the changeset viewer.