Skip to:
Content

BuddyPress.org

Changeset 9885


Ignore:
Timestamp:
05/21/2015 07:25:07 PM (11 years ago)
Author:
johnjamesjacoby
Message:

Groups: Updates to bp_get_group_class()

  • Allow custom classes to be passed in via array parameter
  • Clean up comparisons and variable definitions

Fixes #6384. See r9884.

File:
1 edited

Legend:

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

    r9848 r9885  
    672672 *
    673673 * @since BuddyPress (1.7.0)
    674  */
    675 function bp_group_class() {
    676         echo bp_get_group_class();
     674 *
     675 * @param array $classes Array of custom classes
     676 */
     677function bp_group_class( $classes = array() ) {
     678        echo bp_get_group_class( $classes );
    677679}
    678680        /**
     
    681683         * @since BuddyPress (1.7.0)
    682684         *
     685         * @param array $classes Array of custom classes
     686         *
    683687         * @return string Row class of the group.
    684688         */
    685         function bp_get_group_class() {
     689        function bp_get_group_class( $classes = array() ) {
    686690                global $groups_template;
    687691
    688                 $classes      = array();
    689                 $pos_in_loop  = (int) $groups_template->current_group;
    690 
    691                 // If we've only one group in the loop, don't both with odd and even.
    692                 if ( $groups_template->group_count > 1 )
    693                         $classes[] = ( $pos_in_loop % 2 ) ? 'even' : 'odd';
    694                 else
     692                // Add even/odd classes, but only if there's more than 1 group
     693                if ( $groups_template->group_count > 1 ) {
     694                        $pos_in_loop = (int) $groups_template->current_group;
     695                        $classes[]   = ( $pos_in_loop % 2 ) ? 'even' : 'odd';
     696
     697                // If we've only one group in the loop, don't bother with odd and even
     698                } else {
    695699                        $classes[] = 'bp-single-group';
     700                }
    696701
    697702                // Group type - public, private, hidden.
    698                 $classes[] = esc_attr( $groups_template->group->status );
    699 
    700                 // User's group status
     703                $classes[] = sanitize_key( $groups_template->group->status );
     704
     705                // User's group role
    701706                if ( bp_is_user_active() ) {
    702                         if ( bp_group_is_admin() )
     707
     708                        // Admin
     709                        if ( bp_group_is_admin() ) {
    703710                                $classes[] = 'is-admin';
    704 
    705                         if ( bp_group_is_member() )
     711                        }
     712
     713                        // Moderator
     714                        if ( bp_group_is_mod() ) {
     715                                $classes[] = 'is-mod';
     716                        }
     717
     718                        // Member
     719                        if ( bp_group_is_member() ) {
    706720                                $classes[] = 'is-member';
    707 
    708                         if ( bp_group_is_mod() )
    709                                 $classes[] = 'is-mod';
     721                        }
    710722                }
    711723
Note: See TracChangeset for help on using the changeset viewer.