Ticket #6622: 6622.01.patch
File 6622.01.patch, 4.9 KB (added by , 9 years ago) |
---|
-
src/bp-core/bp-core-avatars.php
172 172 * @type bool $html Whether to return an <img> HTML element, vs a raw URL 173 173 * to an avatar. If false, <img>-specific arguments (like 'css_id') 174 174 * 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(). 175 177 * } 176 178 * 177 179 * @return string Formatted HTML <img> element, or raw avatar URL based on $html arg. … … 201 203 'no_grav' => false, 202 204 'html' => true, 203 205 'title' => '', 206 'extra_attr' => '', 204 207 ) ); 205 208 206 209 /** Set item_id ***********************************************************/ … … 415 418 // populate the class attribute 416 419 $html_class = ' class="' . join( ' ', $avatar_classes ) . ' photo"'; 417 420 421 // Extra attributes 422 $extra_attr = ! empty( $args['extra_attr'] ) ? $args['extra_attr'] : ''; 423 418 424 // Set img URL and DIR based on prepopulated constants 419 425 $avatar_loc = new stdClass(); 420 426 $avatar_loc->path = trailingslashit( bp_core_avatar_upload_path() ); … … 524 530 * @param string $avatar_folder_url Avatar URL path. 525 531 * @param string $avatar_folder_dir Avatar dir path. 526 532 */ 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 ); 528 534 529 535 // ...or only the URL 530 536 } else { … … 626 632 if ( true === $params['html'] ) { 627 633 628 634 /** 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 ); 630 636 } else { 631 637 632 638 /** This filter is documented in bp-core/bp-core-avatars.php */ … … 1281 1287 /** 1282 1288 * Replace default WordPress avatars with BP avatars, if available. 1283 1289 * 1284 * Filters 'get_avatar'.1290 * See 'get_avatar' filter description in wp-includes/pluggable.php. 1285 1291 * 1286 1292 * @param string $avatar The avatar path passed to 'get_avatar'. 1287 1293 * @param int|string|object $user A user ID, email address, or comment object. 1288 1294 * @param int $size Size of the avatar image ('thumb' or 'full'). 1289 1295 * @param string $default URL to a default image to use if no avatar is available. 1290 1296 * @param string $alt Alternate text to use in image tag. Default: ''. 1297 * @param array $args Arguments passed to get_avatar_data(), after processing. 1291 1298 * 1292 1299 * @return string BP avatar path, if found; else the original avatar path. 1293 1300 */ 1294 function bp_core_fetch_avatar_filter( $avatar, $user, $size, $default, $alt = '' ) {1301 function bp_core_fetch_avatar_filter( $avatar, $user, $size, $default, $alt = '', $args = array() ) { 1295 1302 global $pagenow; 1296 1303 1297 1304 // Do not filter if inside WordPress options page … … 1332 1339 $type = 'full'; 1333 1340 } 1334 1341 1335 // Let BuddyPress handle the fetching of the avatar 1336 $bp_avatar = bp_core_fetch_avatar( array( 1342 $avatar_args = array( 1337 1343 'item_id' => $id, 1338 1344 'type' => $type, 1339 1345 'width' => $size, 1340 1346 'height' => $size, 1341 1347 '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 ); 1343 1358 1344 1359 // If BuddyPress found an avatar, use it. If not, use the result of get_avatar 1345 1360 return ( !$bp_avatar ) ? $avatar : $bp_avatar; 1346 1361 } 1347 add_filter( 'get_avatar', 'bp_core_fetch_avatar_filter', 10, 5);1362 add_filter( 'get_avatar', 'bp_core_fetch_avatar_filter', 10, 6 ); 1348 1363 1349 1364 /** 1350 1365 * Is the current avatar upload error-free?