Ticket #6622: 6622.02.patch
File 6622.02.patch, 8.9 KB (added by , 9 years ago) |
---|
-
src/bp-core/bp-core-avatars.php
103 103 * locally: 104 104 * add_filter( 'bp_core_fetch_avatar_no_grav', '__return_true' ); 105 105 * 106 * @since 2.4.0 Added 'extra_attr', 'scheme', 'rating' and 'force_default' for $args. 107 * These are inherited from WordPress 4.2.0. See {@link get_avatar()}. 108 * 106 109 * @param array|string $args { 107 110 * An array of arguments. All arguments are technically optional; some 108 111 * will, if not provided, be auto-detected by bp_core_fetch_avatar(). This … … 172 175 * @type bool $html Whether to return an <img> HTML element, vs a raw URL 173 176 * to an avatar. If false, <img>-specific arguments (like 'css_id') 174 177 * will be ignored. Default: true. 178 * @type string $extra_attr HTML attributes to insert in the IMG element. Not sanitized. Default: ''. 179 * @type string $scheme URL scheme to use. See set_url_scheme() for accepted values. 180 * Default null. 181 * @type string $rating What rating to display Gravatars for. Accepts 'G', 'PG', 'R', 'X'. 182 * Default is the value of the 'avatar_rating' option. 183 * @type bool $force_default Used when creating the Gravatar URL. Whether to force the default 184 * image regardless if the Gravatar exists. Default: false. 175 185 * } 176 186 * 177 187 * @return string Formatted HTML <img> element, or raw avatar URL based on $html arg. … … 188 198 189 199 // Set the default variables array and parse it against incoming $args array. 190 200 $params = wp_parse_args( $args, array( 191 'item_id' => false, 192 'object' => 'user', 193 'type' => 'thumb', 194 'avatar_dir' => false, 195 'width' => false, 196 'height' => false, 197 'class' => 'avatar', 198 'css_id' => false, 199 'alt' => '', 200 'email' => false, 201 'no_grav' => false, 202 'html' => true, 203 'title' => '', 201 'item_id' => false, 202 'object' => 'user', 203 'type' => 'thumb', 204 'avatar_dir' => false, 205 'width' => false, 206 'height' => false, 207 'class' => 'avatar', 208 'css_id' => false, 209 'alt' => '', 210 'email' => false, 211 'no_grav' => false, 212 'html' => true, 213 'title' => '', 214 'extra_attr' => '', 215 'scheme' => null, 216 'rating' => get_option( 'avatar_rating' ), 217 'force_default' => false, 204 218 ) ); 205 219 206 220 /** Set item_id ***********************************************************/ … … 346 360 $html_title = ' title="' . esc_attr( $params['title'] ) . '"'; 347 361 } 348 362 363 // Extra attributes 364 $extra_attr = ! empty( $args['extra_attr'] ) ? ' ' . $args['extra_attr'] : ''; 365 349 366 // Set CSS ID and create html string. 350 367 $html_css_id = ''; 351 368 … … 505 522 506 523 // If we found a locally uploaded avatar 507 524 if ( isset( $avatar_url ) ) { 525 // Support custom scheme 526 $avatar_url = set_url_scheme( $avatar_url, $params['scheme'] ); 508 527 509 528 // Return it wrapped in an <img> element 510 529 if ( true === $params['html'] ) { … … 524 543 * @param string $avatar_folder_url Avatar URL path. 525 544 * @param string $avatar_folder_dir Avatar dir path. 526 545 */ 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 );546 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 547 529 548 // ...or only the URL 530 549 } else { … … 579 598 } 580 599 } 581 600 582 $host = '//www.gravatar.com/avatar/';583 584 601 /** 585 602 * Filters the Gravatar email to use. 586 603 * … … 593 610 $params['email'] = apply_filters( 'bp_core_gravatar_email', $params['email'], $params['item_id'], $params['object'] ); 594 611 595 612 /** 596 * Filters the Gravatar URL path.613 * Filters the Gravatar URL host. 597 614 * 598 615 * @since 1.0.2 599 616 * 600 * @param string $value Gravatar URL path.617 * @param string $value Gravatar URL host. 601 618 */ 602 $gravatar = apply_filters( 'bp_gravatar_url', $host ) . md5( strtolower( $params['email'] ) ) . '?d=' . $default_grav . '&s=' . $params['width']; 619 $gravatar = apply_filters( 'bp_gravatar_url', '//www.gravatar.com/avatar/' ); 620 621 // Append email hash to Gravatar 622 $gravatar .= md5( strtolower( $params['email'] ) ); 603 623 604 // Gravatar rating; http://bit.ly/89QxZA 605 $rating = get_option( 'avatar_rating' ); 606 if ( ! empty( $rating ) ) { 607 $gravatar .= "&r={$rating}"; 624 // Main Gravatar URL args 625 $url_args = array( 626 'd' => $default_grav, 627 's' => $params['width'] 628 ); 629 630 // Custom Gravatar URL args 631 if ( ! empty( $args['force_default'] ) ) { 632 $url_args['f'] = 'y'; 633 } 634 if ( ! empty( $args['rating'] ) ) { 635 $url_args['r'] = strtolower( $args['rating'] ); 608 636 } 609 637 638 // Set up the Gravatar URL 639 $gravatar = esc_url( add_query_arg( 640 rawurlencode_deep( array_filter( $url_args ) ), 641 $gravatar 642 ) ); 643 610 644 // No avatar was found, and we've been told not to use a gravatar. 611 645 } else { 612 646 … … 626 660 if ( true === $params['html'] ) { 627 661 628 662 /** 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 );663 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 664 } else { 631 665 632 666 /** This filter is documented in bp-core/bp-core-avatars.php */ … … 1281 1315 /** 1282 1316 * Replace default WordPress avatars with BP avatars, if available. 1283 1317 * 1284 * Filters 'get_avatar'. 1318 * See 'get_avatar' filter description in wp-includes/pluggable.php. 1319 * 1320 * @since 2.4 Added $args parameter to coincide with WordPress 4.2. 1285 1321 * 1286 1322 * @param string $avatar The avatar path passed to 'get_avatar'. 1287 1323 * @param int|string|object $user A user ID, email address, or comment object. 1288 1324 * @param int $size Size of the avatar image ('thumb' or 'full'). 1289 1325 * @param string $default URL to a default image to use if no avatar is available. 1290 1326 * @param string $alt Alternate text to use in image tag. Default: ''. 1327 * @param array $args Arguments passed to get_avatar_data(), after processing. 1291 1328 * 1292 1329 * @return string BP avatar path, if found; else the original avatar path. 1293 1330 */ 1294 function bp_core_fetch_avatar_filter( $avatar, $user, $size, $default, $alt = '' ) {1331 function bp_core_fetch_avatar_filter( $avatar, $user, $size, $default, $alt = '', $args = array() ) { 1295 1332 global $pagenow; 1296 1333 1297 1334 // Do not filter if inside WordPress options page … … 1332 1369 $type = 'full'; 1333 1370 } 1334 1371 1335 // Let BuddyPress handle the fetching of the avatar 1336 $bp_avatar = bp_core_fetch_avatar( array( 1372 $avatar_args = array( 1337 1373 'item_id' => $id, 1338 1374 'type' => $type, 1339 1375 'width' => $size, 1340 1376 'height' => $size, 1341 1377 'alt' => $alt, 1342 ) ); 1378 ); 1379 1380 // Support new arguments as of WordPress 4.2.0 1381 if ( ! empty( $args['width'] ) ) { 1382 $avatar_args['width'] = $args['width']; 1383 } 1384 if ( ! empty( $args['height'] ) ) { 1385 $avatar_args['height'] = $args['height']; 1386 } 1387 if ( ! empty( $args['class'] ) ) { 1388 $avatar_args['class'] = $args['class']; 1389 } 1390 if ( ! empty( $args['class'] ) ) { 1391 $avatar_args['class'] = $args['class']; 1392 } 1393 if ( ! empty( $args['extra_attr'] ) ) { 1394 $avatar_args['extra_attr'] = $args['extra_attr']; 1395 } 1396 if ( ! empty( $args['scheme'] ) ) { 1397 $avatar_args['scheme'] = $args['scheme']; 1398 } 1399 if ( ! empty( $args['force_default'] ) ) { 1400 $avatar_args['force_default'] = $args['force_default']; 1401 } 1402 if ( ! empty( $args['rating'] ) ) { 1403 $avatar_args['rating'] = $args['rating']; 1404 } 1405 1406 // Let BuddyPress handle the fetching of the avatar 1407 $bp_avatar = bp_core_fetch_avatar( $avatar_args ); 1343 1408 1344 1409 // If BuddyPress found an avatar, use it. If not, use the result of get_avatar 1345 1410 return ( !$bp_avatar ) ? $avatar : $bp_avatar; 1346 1411 } 1347 add_filter( 'get_avatar', 'bp_core_fetch_avatar_filter', 10, 5);1412 add_filter( 'get_avatar', 'bp_core_fetch_avatar_filter', 10, 6 ); 1348 1413 1349 1414 /** 1350 1415 * Is the current avatar upload error-free?