Advertisements

is_blog_installed

Definition:
function is_blog_installed() {}

Test whether blog is already installed.
The cache will be checked first. If you have a cache plugin, which saves the cache values, then this will work. If you use the default WordPress cache, and the database goes away, then you might have problems.

Return values

returns:Whether blog is already installed.

Source code

function is_blog_installed() {

	global $wpdb;



	// Check cache first. If options table goes away and we have true cached, oh well.

	if ( wp_cache_get( 'is_blog_installed' ) )

		return true;



	$suppress = $wpdb->suppress_errors();

	if ( ! defined( 'WP_INSTALLING' ) ) {

		$alloptions = wp_load_alloptions();

	}

	// If siteurl is not set to autoload, check it specifically

	if ( !isset( $alloptions['siteurl'] ) )

		$installed = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'" );

	else

		$installed = $alloptions['siteurl'];

	$wpdb->suppress_errors( $suppress );



	$installed = !empty( $installed );

	wp_cache_set( 'is_blog_installed', $installed );



	if ( $installed )

		return true;



	// If visiting repair.php, return true and let it take over.

	if ( defined( 'WP_REPAIRING' ) )

		return true;



	$suppress = $wpdb->suppress_errors();



	// Loop over the WP tables.  If none exist, then scratch install is allowed.

	// If one or more exist, suggest table repair since we got here because the options

	// table could not be accessed.

	$wp_tables = $wpdb->tables();

	foreach ( $wp_tables as $table ) {

		// The existence of custom user tables shouldn't suggest an insane state or prevent a clean install.

		if ( defined( 'CUSTOM_USER_TABLE' ) && CUSTOM_USER_TABLE == $table )

			continue;

		if ( defined( 'CUSTOM_USER_META_TABLE' ) && CUSTOM_USER_META_TABLE == $table )

			continue;



		if ( ! $wpdb->get_results( "DESCRIBE $table;" ) )

			continue;



		// One or more tables exist. We are insane.



		// Die with a DB error.

		$wpdb->error = sprintf( /*WP_I18N_NO_TABLES*/'One or more database tables are unavailable.  The database may need to be <a href="%s">repaired</a>.'/*/WP_I18N_NO_TABLES*/, 'maint/repair.php?referrer=is_blog_installed' );

		dead_db();

	}



	$wpdb->suppress_errors( $suppress );



	wp_cache_set( 'is_blog_installed', false );



	return false;

}

2095

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: