bp_get_blog_avatar( array|string $args = '' )
Get a blog’s avatar.
Contents
Description Description
At the moment, unless the blog has a site icon, the blog’s avatar defaults to the /bp-core/images/mystery-blog.png image or the Blog’s Admin user avatar if the admin_user_id
argument contains the Blog’s Admin user ID.
See also See also
- bp_core_fetch_avatar(): For a description of arguments and return values.
Parameters Parameters
- $args
-
(array|string) (Optional) Arguments are listed here with an explanation of their defaults. For more information about the arguments, see bp_core_fetch_avatar().
- 'alt'
(string) Default: 'Profile picture of site author [user name]'. - 'class'
(string) Default: 'avatar'. - 'type'
(string) Default: 'full'. - 'width'
(int|bool) Default: false. - 'height'
(int|bool) Default: false. - 'id'
(bool) Currently unused. - 'no_grav'
(bool) Default: false. - 'blog_id'
(int) The blog ID. Default: O. - 'admin_user_id'
(int) The Blog Admin user ID. Default: 0. - 'html'
(bool) Default: true.
Default value: ''
- 'alt'
Return Return
(string) User avatar string.
Source Source
File: bp-blogs/bp-blogs-template.php
function bp_get_blog_avatar( $args = '' ) { global $blogs_template; // Bail if avatars are turned off // @todo Should we maybe still filter this? if ( ! buddypress()->avatar->show_avatars ) { return false; } // Set default value for the `alt` attribute. $alt_attribute = __( 'Site icon for the blog', 'buddypress' ); if ( ! $blogs_template && isset( $args['blog_id'] ) && $args['blog_id'] ) { $blog_id = (int) $args['blog_id']; } else { $blog_id = bp_get_blog_id(); /* translators: %s is the blog name */ $alt_attribute = sprintf( __( 'Site icon for %s', 'buddypress' ), bp_get_blog_name() ); } // Parse the arguments. $r = bp_parse_args( $args, array( 'item_id' => $blog_id, 'avatar_dir' => 'blog-avatars', 'object' => 'blog', 'type' => 'full', 'width' => false, 'height' => false, 'class' => 'avatar', 'id' => false, 'alt' => $alt_attribute, 'no_grav' => false, 'html' => true, ), 'blog_avatar' ); /** * If the `admin_user_id` was provided, make the Blog avatar * defaults to the Blog's Admin user one. */ if ( isset( $r['admin_user_id'] ) && $r['admin_user_id'] ) { $r['item_id'] = (int) $r['admin_user_id']; $r['avatar_dir'] = 'avatars'; $r['object'] = 'user'; } elseif ( ! $r['no_grav'] ) { $r['no_grav'] = true; } // Use site icon if available. $avatar = ''; if ( bp_is_active( 'blogs', 'site-icon' ) ) { $site_icon = bp_blogs_get_blogmeta( $blog_id, "site_icon_url_{$r['type']}" ); // Never attempted to fetch site icon before; do it now! if ( '' === $site_icon ) { // Fetch the other size first. if ( 'full' === $r['type'] ) { $size = bp_core_avatar_thumb_width(); $save_size = 'thumb'; } else { $size = bp_core_avatar_full_width(); $save_size = 'full'; } $site_icon = bp_blogs_get_site_icon_url( $blog_id, $size ); // Empty site icons get saved as integer 0. if ( empty( $site_icon ) ) { $site_icon = 0; } // Sync site icon for other size to blogmeta. bp_blogs_update_blogmeta( $blog_id, "site_icon_url_{$save_size}", $site_icon ); // Now, fetch the size we want. if ( 0 !== $site_icon ) { $size = 'full' === $r['type'] ? bp_core_avatar_full_width() : bp_core_avatar_thumb_width(); $site_icon = bp_blogs_get_site_icon_url( $blog_id, $size ); } // Sync site icon to blogmeta. bp_blogs_update_blogmeta( $blog_id, "site_icon_url_{$r['type']}", $site_icon ); } // We have a site icon. if ( ! is_numeric( $site_icon ) ) { // Just return the raw url of the Site Icon. if ( ! $r['html'] ) { return esc_url_raw( $site_icon ); } if ( empty( $r['width'] ) && ! isset( $size ) ) { $size = 'full' === $r['type'] ? bp_core_avatar_full_width() : bp_core_avatar_thumb_width(); } else { $size = (int) $r['width']; } $avatar = sprintf( '<img src="%1$s" class="%2$s" width="%3$s" height="%3$s" alt="%4$s" />', esc_url( $site_icon ), esc_attr( "{$r['class']} avatar-{$size}" ), esc_attr( $size ), esc_attr( $alt_attribute ) ); } } // Fallback to Default blog avatar. if ( '' === $avatar ) { $avatar = bp_core_fetch_avatar( $r ); } /** * Filters a blog's avatar. * * @since 1.5.0 * * @param string $avatar Formatted HTML <img> element, or raw avatar * URL based on $html arg. * @param int $blog_id ID of the blog whose avatar is being displayed. * @param array $r Array of arguments used when fetching avatar. */ return apply_filters( 'bp_get_blog_avatar', $avatar, $blog_id, $r ); }
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
7.0.0 | Introduced the Blog's default avatar bp_blogs_default_avatar(). Removed the 'bp_get_blog_avatar_' . $blog_id filter (it was deprecated since 1.5). |
6.0.0 | Introduced the $blog_id , $admin_user_id and html arguments. |
2.4.0 | Introduced. |