bp_blogs_get_site_icon_url( integer $blog_id, integer $size = 512 )

Gets the site icon URL even when BuddyPress is not network activated.


Parameters Parameters

$blog_id

(integer) (Required) The ID of the blog to get the site icon URL for.

$size

(integer) (Optional) The size of the site icon.

Default value: 512


Top ↑

Return Return

(string) The site icon URL


Source Source

File: bp-blogs/bp-blogs-functions.php

function bp_blogs_get_site_icon_url( $blog_id = 0, $size = 512 ) {
	if ( is_multisite() && ! bp_is_network_activated() && ! bp_is_root_blog( $blog_id ) ) {
		$switched_blog = false;
		$url           = '';

		if ( $blog_id && get_current_blog_id() !== (int) $blog_id ) {
			switch_to_blog( $blog_id );
			$switched_blog = true;
		}

		$site_icon_id = get_option( 'site_icon' );

		if ( $site_icon_id ) {
			$site_icon_data = wp_get_attachment_metadata( $site_icon_id );
			$sizes          = wp_list_pluck( $site_icon_data['sizes'], 'width' );

			sort( $sizes );
			$closest = 'full';

			foreach ( $sizes as $width ) {
				$closest = array( $width, $width );

				if ( (int) $size < (int) $width ) {
					break;
				}
			}

			$url = wp_get_attachment_image_url( $site_icon_id, $closest );
		}

		if ( $switched_blog ) {
			restore_current_blog();
		}

		return $url;
	}

	return get_site_icon_url( $size, '', $blog_id );
}


Top ↑

Changelog Changelog

Changelog
Version Description
7.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.