Skip to:
Content

bbPress.org


Ignore:
Timestamp:
09/09/2017 05:27:44 AM (9 years ago)
Author:
johnjamesjacoby
Message:

Template: rework post class assignments.

This change avoids multiple reassignments to the same $classes variable name, and instead tries to name variables logically and merge them together when necessary. The performance difference is nil, as 'array_merge()` will perform similarly to how each array was reshaped when new classes would be added, but the human difference is only positive, from having clearer and easier to understand logic.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/replies/template.php

    r6682 r6683  
    21762176                $bbp       = bbpress();
    21772177                $reply_id  = bbp_get_reply_id( $reply_id );
    2178                 $count     = isset( $bbp->reply_query->current_post ) ? $bbp->reply_query->current_post : 1;
    2179                 $classes   = (array) $classes;
    2180                 $classes[] = ( (int) $count % 2 ) ? 'even' : 'odd';
    2181                 $classes[] = 'bbp-parent-forum-'   . bbp_get_reply_forum_id( $reply_id );
    2182                 $classes[] = 'bbp-parent-topic-'   . bbp_get_reply_topic_id( $reply_id );
    2183                 $classes[] = 'bbp-reply-position-' . bbp_get_reply_position( $reply_id, true );
    2184                 $classes[] = 'user-id-' . bbp_get_reply_author_id( $reply_id );
    2185                 $classes[] = ( bbp_get_reply_author_id( $reply_id ) === bbp_get_topic_author_id( bbp_get_reply_topic_id( $reply_id ) ) ? 'topic-author' : '' );
    2186                 $classes   = array_filter( $classes );
    2187                 $classes   = get_post_class( $classes, $reply_id );
    2188                 $classes   = apply_filters( 'bbp_get_reply_class', $classes, $reply_id );
    2189                 $retval    = 'class="' . implode( ' ', $classes ) . '"';
    2190 
    2191                 return $retval;
     2178                $topic_id  = bbp_get_reply_topic_id( $reply_id );
     2179                $author_id = bbp_get_reply_author_id( $reply_id );
     2180                $classes   = array_filter( (array) $classes );
     2181                $count     = isset( $bbp->reply_query->current_post )
     2182                        ? (int) $bbp->reply_query->current_post
     2183                        : 1;
     2184
     2185                // Get reply classes
     2186                $reply_classes = array(
     2187                        'loop-item-' . $count,
     2188                        ( $count % 2                                        )   ? 'even'         : 'odd',
     2189                        ( $author_id === bbp_get_topic_author_id( $topic_id ) ) ? 'topic-author' : '',
     2190                        'user-id-' . $author_id,
     2191                        'bbp-parent-forum-'   . bbp_get_reply_forum_id( $reply_id ),
     2192                        'bbp-parent-topic-'   . $topic_id,
     2193                        'bbp-reply-position-' . bbp_get_reply_position( $reply_id, true )
     2194                );
     2195
     2196                // Run the topic classes through the post-class filters, which also
     2197                // handles the escaping of each individual class.
     2198                $post_classes = get_post_class( array_merge( $classes, $reply_classes ), $reply_id );
     2199
     2200                // Filter
     2201                $new_classes  = apply_filters( 'bbp_get_reply_class', $post_classes, $reply_id, $classes );
     2202
     2203                // Return
     2204                return 'class="' . implode( ' ', $new_classes ) . '"';
    21922205        }
    21932206
Note: See TracChangeset for help on using the changeset viewer.