get_blog_id_from_url

Definition:
function get_blog_id_from_url( $domain, $path = '/' ) {}

Get a blog’s numeric ID from its URL.
On a subdirectory installation like example.com/blog1/, $domain will be the root ‘example.com’ and $path the subdirectory ‘/blog1/’. With subdomains like blog1.example.com, $domain is ‘blog1.example.com’ and $path is ‘/’.

Parameters

  • string $domain
  • string $path: Optional. Not required for subdomain installations.

Source code

function get_blog_id_from_url( $domain, $path = '/' ) {

	global $wpdb;



	$domain = strtolower( $wpdb->escape( $domain ) );

	$path = strtolower( $wpdb->escape( $path ) );

	$id = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' );



	if ( $id == -1 ) { // blog does not exist

		return 0;

	} elseif ( $id ) {

		return (int)$id;

	}



	$id = $wpdb->get_var( "SELECT blog_id FROM $wpdb->blogs WHERE domain = '$domain' and path = '$path' /* get_blog_id_from_url */" );



	if ( !$id ) {

		wp_cache_set( md5( $domain . $path ), -1, 'blog-id-cache' );

		return false;

	}

	wp_cache_set( md5( $domain . $path ), $id, 'blog-id-cache' );



	return $id;

}

1210

get_blog_details

Definition:
function get_blog_details( $fields, $get_all = true ) {}

Retrieve the details for a blog from the blogs table and blog options.

Parameters

  • int|string|array $fields: A blog ID, a blog name, or an array of fields to query against.
  • bool $get_all: Whether to retrieve all details or only the details in the blogs table. Default is true.

Return values

returns:details.

Defined filters

  • blog_details
    apply_filters( 'blog_details', $details )

Source code

function get_blog_details( $fields, $get_all = true ) {

	global $wpdb;



	if ( is_array($fields ) ) {

		if ( isset($fields['blog_id']) ) {

			$blog_id = $fields['blog_id'];

		} elseif ( isset($fields['domain']) && isset($fields['path']) ) {

			$key = md5( $fields['domain'] . $fields['path'] );

			$blog = wp_cache_get($key, 'blog-lookup');

			if ( false !== $blog )

				return $blog;

			if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) {

				$nowww = substr( $fields['domain'], 4 );

				$blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) AND path = %s ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'], $fields['path'] ) );

			} else {

				$blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $fields['domain'], $fields['path'] ) );

			}

			if ( $blog ) {

				wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details');

				$blog_id = $blog->blog_id;

			} else {

				return false;

			}

		} elseif ( isset($fields['domain']) && is_subdomain_install() ) {

			$key = md5( $fields['domain'] );

			$blog = wp_cache_get($key, 'blog-lookup');

			if ( false !== $blog )

				return $blog;

			if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) {

				$nowww = substr( $fields['domain'], 4 );

				$blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'] ) );

			} else {

				$blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $fields['domain'] ) );

			}

			if ( $blog ) {

				wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details');

				$blog_id = $blog->blog_id;

			} else {

				return false;

			}

		} else {

			return false;

		}

	} else {

		if ( !is_numeric( $fields ) )

			$blog_id = get_id_from_blogname( $fields );

		else

			$blog_id = $fields;

	}



	$blog_id = (int) $blog_id;



	$all = $get_all == true ? '' : 'short';

	$details = wp_cache_get( $blog_id . $all, 'blog-details' );



	if ( $details ) {

		if ( ! is_object( $details ) ) {

			if ( $details == -1 ) {

				return false;

			} else {

				// Clear old pre-serialized objects. Cache clients do better with that.

				wp_cache_delete( $blog_id . $all, 'blog-details' );

				unset($details);

			}

		} else {

			return $details;

		}

	}



	// Try the other cache.

	if ( $get_all ) {

		$details = wp_cache_get( $blog_id . 'short', 'blog-details' );

	} else {

		$details = wp_cache_get( $blog_id, 'blog-details' );

		// If short was requested and full cache is set, we can return.

		if ( $details ) {

			if ( ! is_object( $details ) ) {

				if ( $details == -1 ) {

					return false;

				} else {

					// Clear old pre-serialized objects. Cache clients do better with that.

					wp_cache_delete( $blog_id, 'blog-details' );

					unset($details);

				}

			} else {

				return $details;

			}

		}

	}



	if ( empty($details) ) {

		$details = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE blog_id = %d /* get_blog_details */", $blog_id ) );

		if ( ! $details ) {

			// Set the full cache.

			wp_cache_set( $blog_id, -1, 'blog-details' );

			return false;

		}

	}



	if ( ! $get_all ) {

		wp_cache_set( $blog_id . $all, $details, 'blog-details' );

		return $details;

	}



	$details->blogname		= get_blog_option( $blog_id, 'blogname' );

	$details->siteurl		= get_blog_option( $blog_id, 'siteurl' );

	$details->post_count	= get_blog_option( $blog_id, 'post_count' );



	$details = apply_filters( 'blog_details', $details );



	wp_cache_set( $blog_id . $all, $details, 'blog-details' );



	$key = md5( $details->domain . $details->path );

	wp_cache_set( $key, $details, 'blog-lookup' );



	return $details;

}

1208

get_blog_count

Definition:
function get_blog_count( $id = 0 ) {}

The number of active sites on your installation.
The count is cached and updated twice daily. This is not a live count.

Parameters

  • int $id: Optional. A site_id.

Source code

function get_blog_count( $id = 0 ) {

	return get_site_option( 'blog_count' );

}

1206

get_blogs_of_user

Definition:
function get_blogs_of_user( $id, $all = false ) {}

Parameters

  • $id
  • $all

Defined filters

  • get_blogs_of_user
    apply_filters( 'get_blogs_of_user', $return, $id, $all )
  • get_blogs_of_user
    apply_filters( 'get_blogs_of_user', $blogs, $id, $all )

Source code

function get_blogs_of_user( $id, $all = false ) {

	global $wpdb;



	$cache_suffix = $all ? '_all' : '_short';

	$return = wp_cache_get( 'blogs_of_user_' . $id . $cache_suffix, 'users' );

	if ( $return )

		return apply_filters( 'get_blogs_of_user', $return, $id, $all );



	$user = get_userdata( (int) $id );

	if ( !$user )

		return false;



	$blogs = $match = array();

	$prefix_length = strlen($wpdb->base_prefix);

	foreach ( (array) $user as $key => $value ) {

		if ( $prefix_length && substr($key, 0, $prefix_length) != $wpdb->base_prefix )

			continue;

		if ( substr($key, -12, 12) != 'capabilities' )

			continue;

		if ( preg_match( '/^' . $wpdb->base_prefix . '((\d+)_)?capabilities$/', $key, $match ) ) {

			if ( count( $match ) > 2 )

				$blog_id = $match[ 2 ];

			else

				$blog_id = 1;

			$blog = get_blog_details( $blog_id );

			if ( $blog && isset( $blog->domain ) && ( $all == true || $all == false && ( $blog->archived == 0 && $blog->spam == 0 && $blog->deleted == 0 ) ) ) {

				$blogs[ $blog_id ]->userblog_id	= $blog_id;

				$blogs[ $blog_id ]->blogname		= $blog->blogname;

				$blogs[ $blog_id ]->domain		= $blog->domain;

				$blogs[ $blog_id ]->path			= $blog->path;

				$blogs[ $blog_id ]->site_id		= $blog->site_id;

				$blogs[ $blog_id ]->siteurl		= $blog->siteurl;

			}

		}

	}



	wp_cache_add( 'blogs_of_user_' . $id . $cache_suffix, $blogs, 'users', 5 );

	return apply_filters( 'get_blogs_of_user', $blogs, $id, $all );

}

1204

get_bloginfo_rss

Definition:
function get_bloginfo_rss($show = '') {}

RSS container for the bloginfo function.
You can retrieve anything that you can using the get_bloginfo() function. Everything will be stripped of tags and characters converted, when the values are retrieved for use in the feeds.

Parameters

  • string $show: See get_bloginfo() for possible values.

Defined filters

  • get_bloginfo_rss
    apply_filters('get_bloginfo_rss', convert_chars($info)

Source code

function get_bloginfo_rss($show = '') {

	$info = strip_tags(get_bloginfo($show));

	return apply_filters('get_bloginfo_rss', convert_chars($info), $show);

}

1202