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/topics/template.php

    r6682 r6683  
    22542254         */
    22552255        function bbp_get_topic_class( $topic_id = 0, $classes = array() ) {
    2256                 $bbp       = bbpress();
    2257                 $topic_id  = bbp_get_topic_id( $topic_id );
    2258                 $count     = isset( $bbp->topic_query->current_post ) ? $bbp->topic_query->current_post : 1;
    2259                 $classes   = (array) $classes;
    2260                 $classes[] = ( (int) $count % 2 )                    ? 'even'         : 'odd';
    2261                 $classes[] = bbp_is_topic_sticky( $topic_id, false ) ? 'sticky'       : '';
    2262                 $classes[] = bbp_is_topic_super_sticky( $topic_id  ) ? 'super-sticky' : '';
    2263                 $classes[] = 'bbp-parent-forum-' . bbp_get_topic_forum_id( $topic_id );
    2264                 $classes[] = 'user-id-' . bbp_get_topic_author_id( $topic_id );
    2265                 $classes   = array_filter( $classes );
    2266                 $classes   = get_post_class( $classes, $topic_id );
    2267                 $classes   = apply_filters( 'bbp_get_topic_class', $classes, $topic_id );
    2268                 $retval    = 'class="' . implode( ' ', $classes ) . '"';
    2269 
    2270                 return $retval;
     2256                $bbp      = bbpress();
     2257                $topic_id = bbp_get_topic_id( $topic_id );
     2258                $classes  = array_filter( (array) $classes );
     2259                $count    = isset( $bbp->topic_query->current_post )
     2260                        ? (int) $bbp->topic_query->current_post
     2261                        : 1;
     2262
     2263                // Get topic classes
     2264                $topic_classes = array(
     2265                        'loop-item-' . $count,
     2266                        ( $count % 2 )                          ? 'even'         : 'odd',
     2267                        bbp_is_topic_sticky( $topic_id, false ) ? 'sticky'       : '',
     2268                        bbp_is_topic_super_sticky( $topic_id  ) ? 'super-sticky' : '',
     2269                        'bbp-parent-forum-' . bbp_get_topic_forum_id( $topic_id ),
     2270                        'user-id-' . bbp_get_topic_author_id( $topic_id )
     2271                );
     2272
     2273                // Run the topic classes through the post-class filters, which also
     2274                // handles the escaping of each individual class.
     2275                $post_classes = get_post_class( array_merge( $classes, $topic_classes ), $topic_id );
     2276
     2277                // Filter
     2278                $new_classes  = apply_filters( 'bbp_get_topic_class', $post_classes, $topic_id, $classes );
     2279
     2280                // Return
     2281                return 'class="' . implode( ' ', $new_classes ) . '"';
    22712282        }
    22722283
Note: See TracChangeset for help on using the changeset viewer.