| 1368 | | * @since 1.1.0 |
| 1369 | | * @since 2.4.0 Added $args parameter to coincide with WordPress 4.2.0. |
| 1370 | | * |
| 1371 | | * @param string $avatar The avatar path passed to 'get_avatar'. |
| 1372 | | * @param int|string|object $user A user ID, email address, or comment object. |
| 1373 | | * @param int $size Size of the avatar image ('thumb' or 'full'). |
| 1374 | | * @param string $default URL to a default image to use if no avatar is available. |
| 1375 | | * @param string $alt Alternate text to use in image tag. Default: ''. |
| 1376 | | * @param array $args Arguments passed to get_avatar_data(), after processing. |
| 1377 | | * @return string BP avatar path, if found; else the original avatar path. |
| | 1368 | * @param array $args Arguments passed to get_avatar_data(), after processing. |
| | 1369 | * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash, |
| | 1370 | * user email, WP_User object, WP_Post object, or WP_Comment object. |
| | 1371 | * @return array |
| 1382 | | // Don't filter if inside WordPress options page and force_default is true. |
| 1383 | | if ( 'options-discussion.php' === $pagenow && true === $args['force_default'] ) { |
| 1384 | | return $avatar; |
| | 1376 | // Ugh, hate duplicating code; process the user identifier. |
| | 1377 | if ( is_numeric( $id_or_email ) ) { |
| | 1378 | $user = get_user_by( 'id', absint( $id_or_email ) ); |
| | 1379 | } elseif ( $id_or_email instanceof WP_User ) { |
| | 1380 | // User Object |
| | 1381 | $user = $id_or_email; |
| | 1382 | } elseif ( $id_or_email instanceof WP_Post ) { |
| | 1383 | // Post Object |
| | 1384 | $user = get_user_by( 'id', (int) $id_or_email->post_author ); |
| | 1385 | } elseif ( $id_or_email instanceof WP_Comment && ! empty( $id_or_email->user_id ) ) { |
| | 1386 | $user = get_user_by( 'id', (int) $id_or_email->user_id ); |
| 1387 | | // If passed an object, assume $user->user_id. |
| 1388 | | if ( is_object( $user ) ) { |
| 1389 | | if ( isset( $user->user_id ) ) { |
| 1390 | | $id = $user->user_id; |
| 1391 | | } else { |
| 1392 | | $id = $user->ID; |
| 1393 | | } |
| 1394 | | |
| 1395 | | // If passed a number, assume it was a $user_id. |
| 1396 | | } elseif ( is_numeric( $user ) ) { |
| 1397 | | $id = $user; |
| 1398 | | |
| 1399 | | // If passed a string and that string returns a user, get the $id. |
| 1400 | | } elseif ( is_string( $user ) && ( $user_by_email = get_user_by( 'email', $user ) ) ) { |
| 1401 | | $id = $user_by_email->ID; |
| | 1389 | // No user, so bail. |
| | 1390 | if ( null === $user ) { |
| | 1391 | return $args; |
| 1421 | | $avatar_args = array( |
| 1422 | | 'item_id' => $id, |
| 1423 | | 'type' => $type, |
| 1424 | | 'width' => $size, |
| 1425 | | 'height' => $size, |
| 1426 | | 'alt' => $alt, |
| 1427 | | ); |
| 1428 | | |
| 1429 | | // Support new arguments as of WordPress 4.2.0. |
| 1430 | | if ( ! empty( $args['width'] ) ) { |
| 1431 | | $avatar_args['width'] = $args['width']; |
| 1432 | | } |
| 1433 | | if ( ! empty( $args['height'] ) ) { |
| 1434 | | $avatar_args['height'] = $args['height']; |
| 1435 | | } |
| 1436 | | if ( ! empty( $args['class'] ) ) { |
| 1437 | | $avatar_args['class'] = $args['class']; |
| 1438 | | } |
| 1439 | | if ( ! empty( $args['class'] ) ) { |
| 1440 | | $avatar_args['class'] = $args['class']; |
| 1441 | | } |
| 1442 | | if ( ! empty( $args['extra_attr'] ) ) { |
| 1443 | | $avatar_args['extra_attr'] = $args['extra_attr']; |
| 1444 | | } |
| 1445 | | if ( ! empty( $args['scheme'] ) ) { |
| 1446 | | $avatar_args['scheme'] = $args['scheme']; |
| 1447 | | } |
| 1448 | | if ( ! empty( $args['force_default'] ) ) { |
| 1449 | | $avatar_args['force_default'] = $args['force_default']; |
| 1450 | | } |
| 1451 | | if ( ! empty( $args['rating'] ) ) { |
| 1452 | | $avatar_args['rating'] = $args['rating']; |
| 1453 | | } |
| 1454 | | |
| 1455 | | // Let BuddyPress handle the fetching of the avatar. |
| 1456 | | $bp_avatar = bp_core_fetch_avatar( $avatar_args ); |
| 1457 | | |
| 1458 | | // If BuddyPress found an avatar, use it. If not, use the result of get_avatar. |
| 1459 | | return ( !$bp_avatar ) ? $avatar : $bp_avatar; |
| | 1404 | return $args; |