Skip to:
Content

BuddyPress.org

Changeset 9884


Ignore:
Timestamp:
05/21/2015 07:17:41 PM (4 years ago)
Author:
johnjamesjacoby
Message:

Members: Updates to bp_member_class()

  • Actually use it in members-loop.php
  • Allow custom classes to be passed in via array parameter
  • Add current user class
  • Clean up comparisons and variable definitions

Props hnla. See #6384.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/bp-members-template.php

    r9877 r9884  
    723723 *
    724724 * @since BuddyPress (1.7.0)
    725  */
    726 function bp_member_class() {
    727     echo bp_get_member_class();
     725 *
     726 * @param array $classes Array of custom classes
     727 */
     728function bp_member_class( $classes = array() ) {
     729    echo bp_get_member_class( $classes );
    728730}
    729731    /**
     
    732734     * @since BuddyPress (1.7.0)
    733735     *
    734      * @return string Row class of the member.
    735      */
    736     function bp_get_member_class() {
     736     * @param array $classes Array of custom classes
     737     *
     738     * @return string Row class of the member
     739     */
     740    function bp_get_member_class( $classes = array() ) {
    737741        global $members_template;
    738742
    739         $classes      = array();
    740         $current_time = bp_core_current_time();
    741         $pos_in_loop  = (int) $members_template->current_member;
    742 
    743         // If we've only one group in the loop, don't both with odd and even.
    744         if ( $members_template->member_count > 1 )
    745             $classes[] = ( $pos_in_loop % 2 ) ? 'even' : 'odd';
    746         else
     743        // Add even/odd classes, but only if there's more than 1 member
     744        if ( $members_template->member_count > 1 ) {
     745            $pos_in_loop = (int) $members_template->current_member;
     746            $classes[]   = ( $pos_in_loop % 2 ) ? 'even' : 'odd';
     747
     748        // If we've only one member in the loop, don't bother with odd and even
     749        } else {
    747750            $classes[] = 'bp-single-member';
    748 
    749         // Has the user been active recently?
     751        }
     752
     753        // Maybe add 'is-online' class
    750754        if ( ! empty( $members_template->member->last_activity ) ) {
    751             if ( strtotime( $current_time ) <= strtotime( '+5 minutes', strtotime( $members_template->member->last_activity ) ) )
     755
     756            // Calculate some times
     757            $current_time  = strtotime( bp_core_current_time() );
     758            $last_activity = strtotime( $members_template->member->last_activity );
     759            $still_online  = strtotime( '+5 minutes', $last_activity );
     760
     761            // Has the user been active recently?
     762            if ( $current_time <= $still_online ) {
    752763                $classes[] = 'is-online';
     764            }
     765        }
     766
     767        // Add current user class
     768        if ( bp_loggedin_user_id() === (int) $members_template->member->id ) {
     769            $classes[] = 'is-current-user';
    753770        }
    754771
  • trunk/src/bp-templates/bp-legacy/buddypress/members/members-loop.php

    r9819 r9884  
    5656    <?php while ( bp_members() ) : bp_the_member(); ?>
    5757
    58         <li>
     58        <li <?php bp_member_class(); ?>>
    5959            <div class="item-avatar">
    6060                <a href="<?php bp_member_permalink(); ?>"><?php bp_member_avatar(); ?></a>
Note: See TracChangeset for help on using the changeset viewer.