| 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 string $retval The URL of the avatar. |
| | 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 | * @param array $args Arguments passed to get_avatar_data(), after processing. |
| | 1372 | * @return string |
| 1379 | | function bp_core_fetch_avatar_filter( $avatar, $user, $size, $default, $alt = '', $args = array() ) { |
| 1380 | | global $pagenow; |
| 1381 | | |
| 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; |
| 1385 | | } |
| 1386 | | |
| 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; |
| 1402 | | } |
| 1403 | | |
| 1404 | | // If somehow $id hasn't been assigned, return the result of get_avatar. |
| 1405 | | if ( empty( $id ) ) { |
| 1406 | | return !empty( $avatar ) ? $avatar : $default; |
| 1407 | | } |
| 1408 | | |
| 1409 | | // Image alt tag. |
| 1410 | | if ( empty( $alt ) ) { |
| 1411 | | $alt = sprintf( __( 'Profile photo of %s', 'buddypress' ), bp_core_get_user_displayname( $id ) ); |
| 1412 | | } |
| 1413 | | |
| 1414 | | // Use the 'thumb' type, unless the requested width is bigger than |
| 1415 | | // BP's thumb width. |
| 1416 | | $type = 'thumb'; |
| 1417 | | if ( (int) $size > bp_core_avatar_thumb_width() ) { |
| 1418 | | $type = 'full'; |
| | 1374 | function bp_core_get_avatar_data_url_filter( $retval, $id_or_email, $args ) { |
| | 1375 | $user = null; |
| | 1376 | |
| | 1377 | // Ugh, hate duplicating code; process the user identifier. |
| | 1378 | if ( is_numeric( $id_or_email ) ) { |
| | 1379 | $user = get_user_by( 'id', absint( $id_or_email ) ); |
| | 1380 | } elseif ( $id_or_email instanceof WP_User ) { |
| | 1381 | // User Object |
| | 1382 | $user = $id_or_email; |
| | 1383 | } elseif ( $id_or_email instanceof WP_Post ) { |
| | 1384 | // Post Object |
| | 1385 | $user = get_user_by( 'id', (int) $id_or_email->post_author ); |
| | 1386 | } elseif ( $id_or_email instanceof WP_Comment && ! empty( $id_or_email->user_id ) ) { |
| | 1387 | $user = get_user_by( 'id', (int) $id_or_email->user_id ); |
| | 1388 | } |
| | 1389 | |
| | 1390 | // No user, so bail. |
| | 1391 | if ( null === $user ) { |
| | 1392 | return $retval; |
| 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']; |
| | 1399 | // Get the BuddyPress avatar URL. |
| | 1400 | if ( $bp_avatar = bp_core_fetch_avatar( $args ) ) { |
| | 1401 | return $bp_avatar; |
| 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 ); |