Get it All
Together

Summary: Toggles all settings to a different blog’s settings, thus allowing you to perform functions as though you were on that blog. Stores the current blog’s settings in a temporary array, so they can be restored when desired.

Detail: This function switches all the settings in the $wpdb object to the new blog ($new_blog), while also updating the current user’s role as per the new blog. The end result is that all operations performed after using the switch_to_blog function will behave as you would anticipate if you were on that new blog. You would presumably use this function along with the restore_blog() function.

This is probably the single most important and strangely, least-used function in the WPMU platform. The advantages of using switch_to_blog are many. For one, it saves you the trouble of having to rewrite the database blog prefix (wp_24_posts, for example), and instead let’s you query the dB using the same pseudonyms you would use in any WordPress setting ($wpdb->posts). For another, you can use all the standard, built in WordPress functions such as get_permalink() exactly as you would in any other setting. Best of all, because it stores all the current blog’s settings in a temporary array, you can quickly restore the settings without a lot of complex coding.

Additionally, since the user’s roles are carried over, and because you’re using the standard WordPress functions, information normally not visible to a user remains invisible without complex coding. For example, if you want to display the most recent posts from a given blog, you can simply switch to that blog, use the get_posts() function to perform whatever tasks you’d like, and switch back. In doing this, you can avoid showing posts from private, spam or adult blogs. Moreover, on each blog, you can eliminate the possibility that visitors could see private or unpublished posts, or that posts set to be visible only to certain user levels. However, users who do have the proper privileges on that second blog will be able to see those additional posts. Thus you can write supple, flexible plugins that play ball with most available plugins on all public blogs. No additional coding is required, nor are lengthy database queries.

A word of warning: do not attempt to use this function to iterate over a variety of blog ID’s hoping to restore the original blog’s ID at the end, unless you switch back to the original blog in between. At first, I thought that this would be possible, but it is not. Thus, swapping back and forth between several blogs would need to be done like this pseudo-code:

switch_to_blog(4)
. . . do some stuff . . .
restore_blog()
switch_to_blog(5)
. . . do some stuff . . .
restore_blog()

This plugin no longer supported by the developer.

Download Here

The WPMU Site-Wide Latest plugin provides two widgets for your site. The first, labeled “Newest Post,” creates an 80-word teaser of the single most recently published blog post on any public blog across the entire site. The second, called “Recent Posts,” creates a list of the most recently updated blogs with their most recent posts, one post per blog. Both plugins provide a vehicle for those using the standard Gravatar plugin to obtain and display the Gravatar of the post author in each case.

The teaser widget takes the post title as the title of the widget, whereas the listing widget allows you to set your own title. Both allow you to ignore blogs, if you wish. The list widget also allows you to specify how many blogs you want to display and an offset. This is in case you use both together, that way the most recent comment is in the “Newest Post” widget and the next most recent begins the list in the “Recent Posts” widget.

The plugin also uses the WP-Cache, and both widgets allow you to set a time-out.

WP-Functions Used in This Plugin:

switch_to_blog()
restore_blog()
wp_cache_set()
wp_cache_get()
get_permalink()

Installation:

Unzip, upload (to either /mu-plugins or /plugins, your preference), activate and configure. Simple as that!

Summary: High-level function that creates a new blog with the given parameters

Detail:  This function is a high-level function that combines a number of other functions to create a new blog.  It uses the install_blog(), install_blog_defaults() and add_user_to_blog() to set all the needed values in the database.  This would be the preferred function to use when creating a new blog, rather than all the lower-level functions.

Summary:  Installs the default values of a WP blog during the creation of a new blog

Details:  This function does a lot, and depending on how you want your blogs setup, may be useful to modify.  It sets up default values for such things as the blogroll, the first post, the first comment, the default category.  Of these options, only the default post can be set in Blog Options, so for finer tuning of the end-user experience, editing this file might be helpful.

Summary:  Creates a new blog with the id $blog_id and the title $blog_title

Detail:  This is a very complex function that involves calling the upgrade-functions.php file and using a bunch of it’s functions to complete its task.  This is definitely a function which – in the absence of a specific need – is better off left on its own and accessed through the API.

Summary:  Creates an entry in the wp_blogs table (or equivalent) for a new blog with the domain $domain, the path $path and within the site $site_id.

Detail:  This is one of the functions called when a new blog is created.  It’s not the whole process, and unless you have a specific reason for calling it, is probably best left to itself.  It only really performs two functions, the first being the insertion of the new blog into the database, and the second being a refresh on the wp_cache to include the new blog.

Summary:  Returns the number of blogs that exist on either the current domain or the domain $id.

Detail:  This function counts the number of blogs on a give domain.  By default, it checks the current domain, but if $id is set, another domain can be checked as well.  The number of blogs is cached in the dB for 60 seconds, but queries after that 60 seconds elicit another query of the dB.