Skip to:
Content

BuddyPress.org

Changeset 8751


Ignore:
Timestamp:
08/03/2014 02:17:58 AM (12 years ago)
Author:
johnjamesjacoby
Message:

Clean up bp_get_group_avatar():

  • Remove $bp global
  • Use bp_parse_args()
  • Code format tidying
  • Pass $r through filter
  • Add documentation
File:
1 edited

Legend:

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

    r8750 r8751  
    550550        }
    551551
     552/**
     553 * Output the group avatar while in the groups loop.
     554 *
     555 * @since BuddyPress (1.0.0)
     556 *
     557 * @param array $args {@see bp_core_fetch_avatar()}
     558 */
    552559function bp_group_avatar( $args = '' ) {
    553560        echo bp_get_group_avatar( $args );
    554561}
     562        /**
     563         * Return the group avatar while in the groups loop.
     564         *
     565         * @since BuddyPress (1.0.0)
     566         *
     567         * @param array $args {@see bp_core_fetch_avatar()}
     568         */
    555569        function bp_get_group_avatar( $args = '' ) {
    556                 global $bp, $groups_template;
    557 
     570                global $groups_template;
     571
     572                // Bail if avatars are turned off
     573                // @todo Should we maybe still filter this?
    558574                if ( ! buddypress()->avatar->show_avatars ) {
    559575                        return false;
    560576                }
    561577
    562                 $defaults = array(
     578                // Parse the arguments
     579                $r = bp_parse_args( $args, array(
    563580                        'type'   => 'full',
    564581                        'width'  => false,
    … …  
    567584                        'id'     => false,
    568585                        'alt'    => sprintf( __( 'Group logo of %s', 'buddypress' ), $groups_template->group->name )
    569                 );
    570 
    571                 $r = wp_parse_args( $args, $defaults );
    572                 extract( $r, EXTR_SKIP );
    573 
    574                 /* Fetch the avatar from the folder, if not provide backwards compat. */
    575                 if ( !$avatar = bp_core_fetch_avatar( array( 'item_id' => $groups_template->group->id, 'object' => 'group', 'type' => $type, 'avatar_dir' => 'group-avatars', 'alt' => $alt, 'css_id' => $id, 'class' => $class, 'width' => $width, 'height' => $height, 'title' => $groups_template->group->name, 'alt' => $alt ) ) )
     586                ) );
     587
     588                // Fetch the avatar from the folder
     589                $avatar = bp_core_fetch_avatar( array(
     590                        'item_id'    => $groups_template->group->id,
     591                        'title'      => $groups_template->group->name,
     592                        'avatar_dir' => 'group-avatars',
     593                        'object'     => 'group',
     594                        'type'       => $r['type'],
     595                        'alt'        => $r['alt'],
     596                        'css_id'     => $r['id'],
     597                        'class'      => $r['class'],
     598                        'width'      => $r['width'],
     599                        'height'     => $r['height']
     600                ) );
     601
     602                // If No avatar found, provide some backwards compatibility
     603                if ( empty( $avatar ) ) {
    576604                        $avatar = '<img src="' . esc_url( $groups_template->group->avatar_thumb ) . '" class="avatar" alt="' . esc_attr( $groups_template->group->name ) . '" />';
    577 
    578                 return apply_filters( 'bp_get_group_avatar', $avatar );
     605                }
     606
     607                return apply_filters( 'bp_get_group_avatar', $avatar, $r );
    579608        }
    580609
Note: See TracChangeset for help on using the changeset viewer.