bp_get_blog_avatar

Get a blog's avatar.

Description

(string) bp_get_blog_avatar( (string) $args = '' ); 

At the moment, blog avatars are simply the user avatars of the blog admin. Filter bp_get_blog_avatar_ . $blog_id to customize.

Returns (string)

User avatar string.

Parameters (1)

0. $args — Optional. (string) => ''
The args.

Options

    ;        


    Usage

    1. if ( !function_exists( 'bp_get_blog_avatar' ) ) { 
    2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-blogs/bp-blogs-template.php'; 
    3.  
    4. // The args. 
    5. $args = ''; 
    6.  
    7. // NOTICE! Understand what this does before running. 
    8. $result = bp_get_blog_avatar($args); 
    9.  

    Defined (1)

    The function is defined in the following location(s).

    /bp-blogs/bp-blogs-template.php  
    1. function bp_get_blog_avatar( $args = '' ) { 
    2. global $blogs_template; 
    3.  
    4. // Bail if avatars are turned off 
    5. // @todo Should we maybe still filter this? 
    6. if ( !buddypress)->avatar->show_avatars ) { 
    7. return false; 
    8.  
    9. $author_displayname = bp_core_get_user_displayname( $blogs_template->blog->admin_user_id ); 
    10.  
    11. // Parse the arguments. 
    12. $r = bp_parse_args( $args, array( 
    13. 'type' => 'full',  
    14. 'width' => false,  
    15. 'height' => false,  
    16. 'class' => 'avatar',  
    17. 'id' => false,  
    18. 'alt' => sprintf( __( 'Profile picture of site author %s', buddypress ), esc_attr( $author_displayname ) ),  
    19. 'no_grav' => true,  
    20. ) ); 
    21.  
    22. // Use site icon if available. 
    23. $avatar = ''; 
    24. if ( bp_is_active( 'blogs', 'site-icon' ) && function_exists( 'has_site_icon' ) ) { 
    25. $site_icon = bp_blogs_get_blogmeta( bp_get_blog_id(), "site_icon_url_{$r['type']}" ); 
    26.  
    27. // Never attempted to fetch site icon before; do it now! 
    28. if ( '' === $site_icon ) { 
    29.  
    30. // Fetch the other size first. 
    31. if ( 'full' === $r['type'] ) { 
    32. $save_size = 'thumb'; 
    33. } else { 
    34. $save_size = 'full'; 
    35.  
    36. $site_icon = get_site_icon_url( $size ); 
    37. // Empty site icons get saved as integer 0. 
    38. if ( empty( $site_icon ) ) { 
    39. $site_icon = 0; 
    40.  
    41. // Sync site icon for other size to blogmeta. 
    42. bp_blogs_update_blogmeta( bp_get_blog_id(), "site_icon_url_{$save_size}", $site_icon ); 
    43.  
    44. // Now, fetch the size we want. 
    45. if ( 0 !== $site_icon ) { 
    46. $size = 'full' === $r['type'] ? bp_core_avatar_full_width() : bp_core_avatar_thumb_width(); 
    47. $site_icon = get_site_icon_url( $size ); 
    48.  
    49. // Sync site icon to blogmeta. 
    50. bp_blogs_update_blogmeta( bp_get_blog_id(), "site_icon_url_{$r['type']}", $site_icon ); 
    51.  
    52.  
    53. // We have a site icon. 
    54. if ( ! is_numeric( $site_icon ) ) { 
    55. if ( empty( $r['width'] ) && ! isset( $size ) ) { 
    56. $size = 'full' === $r['type'] ? bp_core_avatar_full_width() : bp_core_avatar_thumb_width(); 
    57. } else { 
    58. $size = (int) $r['width']; 
    59.  
    60. $avatar = sprintf( '<img src="%1$s" class="%2$s" width="%3$s" height="%3$s" alt="%4$s" />',  
    61. esc_url( $site_icon ),  
    62. esc_attr( "{$r['class']} avatar-{$size}" ),  
    63. esc_attr( $size ),  
    64. sprintf( esc_attr__( 'Site icon for %s', buddypress ), bp_get_blog_name() ) 
    65. ); 
    66.  
    67. // Fallback to user ID avatar. 
    68. if ( '' === $avatar ) { 
    69. $avatar = bp_core_fetch_avatar( array( 
    70. 'item_id' => $blogs_template->blog->admin_user_id,  
    71. // 'avatar_dir' => 'blog-avatars',  
    72. // 'object' => 'blog',  
    73. 'type' => $r['type'],  
    74. 'alt' => $r['alt'],  
    75. 'css_id' => $r['id'],  
    76. 'class' => $r['class'],  
    77. 'width' => $r['width'],  
    78. 'height' => $r['height'] 
    79. ) ); 
    80.  
    81. /** 
    82. * In future BuddyPress versions you will be able to set the avatar for a blog. 
    83. * Right now you can use a filter with the ID of the blog to change it if you wish. 
    84. * By default it will return the avatar for the primary blog admin. 
    85. * This filter is deprecated as of BuddyPress 1.5 and may be removed in a future version. 
    86. * Use the 'bp_get_blog_avatar' filter instead. 
    87. */ 
    88. $avatar = apply_filters( 'bp_get_blog_avatar_' . $blogs_template->blog->blog_id, $avatar ); 
    89.  
    90. /** 
    91. * Filters a blog's avatar. 
    92. * @since 1.5.0 
    93. * @param string $avatar Formatted HTML <img> element, or raw avatar 
    94. * URL based on $html arg. 
    95. * @param int $blog_id ID of the blog whose avatar is being displayed. 
    96. * @param array $r Array of arguments used when fetching avatar. 
    97. */ 
    98. return apply_filters( 'bp_get_blog_avatar', $avatar, $blogs_template->blog->blog_id, $r );