Skip to:
Content

BuddyPress.org

Ticket #6622: 6622.01.patch

File 6622.01.patch, 4.9 KB (added by r-a-y, 9 years ago)
  • src/bp-core/bp-core-avatars.php

     
    172172 *     @type bool       $html        Whether to return an <img> HTML element, vs a raw URL
    173173 *                                   to an avatar. If false, <img>-specific arguments (like 'css_id')
    174174 *                                   will be ignored. Default: true.
     175 *     @type string     $extra_attr  HTML attributes to insert in the IMG element. Not sanitized. Default: ''.
     176 *                                   New as of WP 4.2.0 via get_avatar().
    175177 * }
    176178 *
    177179 * @return string Formatted HTML <img> element, or raw avatar URL based on $html arg.
     
    201203                'no_grav'    => false,
    202204                'html'       => true,
    203205                'title'      => '',
     206                'extra_attr' => '',
    204207        ) );
    205208
    206209        /** Set item_id ***********************************************************/
     
    415418        // populate the class attribute
    416419        $html_class = ' class="' . join( ' ', $avatar_classes ) . ' photo"';
    417420
     421        // Extra attributes
     422        $extra_attr = ! empty( $args['extra_attr'] ) ? $args['extra_attr'] : '';
     423
    418424        // Set img URL and DIR based on prepopulated constants
    419425        $avatar_loc        = new stdClass();
    420426        $avatar_loc->path  = trailingslashit( bp_core_avatar_upload_path() );
     
    524530                                 * @param string $avatar_folder_url Avatar URL path.
    525531                                 * @param string $avatar_folder_dir Avatar dir path.
    526532                                 */
    527                                 return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $avatar_url . '"' . $html_class . $html_css_id  . $html_width . $html_height . $html_alt . $html_title . ' />', $params, $params['item_id'], $params['avatar_dir'], $html_css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
     533                                return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $avatar_url . '"' . $html_class . $html_css_id  . $html_width . $html_height . $html_alt . $html_title . $extra_attr . ' />', $params, $params['item_id'], $params['avatar_dir'], $html_css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
    528534
    529535                        // ...or only the URL
    530536                        } else {
     
    626632        if ( true === $params['html'] ) {
    627633
    628634                /** This filter is documented in bp-core/bp-core-avatars.php */
    629                 return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $gravatar . '"' . $html_css_id . $html_class . $html_width . $html_height . $html_alt . $html_title . ' />', $params, $params['item_id'], $params['avatar_dir'], $html_css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
     635                return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $gravatar . '"' . $html_css_id . $html_class . $html_width . $html_height . $html_alt . $html_title . $extra_attr . ' />', $params, $params['item_id'], $params['avatar_dir'], $html_css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
    630636        } else {
    631637
    632638                /** This filter is documented in bp-core/bp-core-avatars.php */
     
    12811287/**
    12821288 * Replace default WordPress avatars with BP avatars, if available.
    12831289 *
    1284  * Filters 'get_avatar'.
     1290 * See 'get_avatar' filter description in wp-includes/pluggable.php.
    12851291 *
    12861292 * @param string            $avatar  The avatar path passed to 'get_avatar'.
    12871293 * @param int|string|object $user    A user ID, email address, or comment object.
    12881294 * @param int               $size    Size of the avatar image ('thumb' or 'full').
    12891295 * @param string            $default URL to a default image to use if no avatar is available.
    12901296 * @param string            $alt     Alternate text to use in image tag. Default: ''.
     1297 * @param array             $args    Arguments passed to get_avatar_data(), after processing.
    12911298 *
    12921299 * @return string BP avatar path, if found; else the original avatar path.
    12931300 */
    1294 function bp_core_fetch_avatar_filter( $avatar, $user, $size, $default, $alt = '' ) {
     1301function bp_core_fetch_avatar_filter( $avatar, $user, $size, $default, $alt = '', $args = array() ) {
    12951302        global $pagenow;
    12961303
    12971304        // Do not filter if inside WordPress options page
     
    13321339                $type = 'full';
    13331340        }
    13341341
    1335         // Let BuddyPress handle the fetching of the avatar
    1336         $bp_avatar = bp_core_fetch_avatar( array(
     1342        $avatar_args = array(
    13371343                'item_id' => $id,
    13381344                'type'    => $type,
    13391345                'width'   => $size,
    13401346                'height'  => $size,
    13411347                'alt'     => $alt,
    1342         ) );
     1348        );
     1349        if ( ! empty( $args['class'] ) ) {
     1350                $avatar_args['class'] = $args['class'];
     1351        }
     1352        if ( ! empty( $args['extra_attr'] ) ) {
     1353                $avatar_args['extra_attr'] = $args['extra_attr'];
     1354        }
     1355
     1356        // Let BuddyPress handle the fetching of the avatar
     1357        $bp_avatar = bp_core_fetch_avatar( $avatar_args );
    13431358
    13441359        // If BuddyPress found an avatar, use it. If not, use the result of get_avatar
    13451360        return ( !$bp_avatar ) ? $avatar : $bp_avatar;
    13461361}
    1347 add_filter( 'get_avatar', 'bp_core_fetch_avatar_filter', 10, 5 );
     1362add_filter( 'get_avatar', 'bp_core_fetch_avatar_filter', 10, 6 );
    13481363
    13491364/**
    13501365 * Is the current avatar upload error-free?