is_blog_installed()

最后更新于:2021-11-27 08:23:50

is_blog_installed()

Determines whether GeChiUI is already installed.

响应

(bool) Whether the site is already installed.

源文件

文件: gc-includes/functions.php

function is_blog_installed() {
	global $gcdb;

	/*
	 * Check cache first. If options table goes away and we have true
	 * cached, oh well.
	 */
	if ( gc_cache_get( 'is_blog_installed' ) ) {
		return true;
	}

	$suppress = $gcdb->suppress_errors();
	if ( ! gc_installing() ) {
		$alloptions = gc_load_alloptions();
	}
	// If siteurl is not set to autoload, check it specifically.
	if ( ! isset( $alloptions['siteurl'] ) ) {
		$installed = $gcdb->get_var( "SELECT option_value FROM $gcdb->options WHERE option_name = 'siteurl'" );
	} else {
		$installed = $alloptions['siteurl'];
	}
	$gcdb->suppress_errors( $suppress );

	$installed = ! empty( $installed );
	gc_cache_set( 'is_blog_installed', $installed );

	if ( $installed ) {
		return true;
	}

	// If visiting repair.php, return true and let it take over.
	if ( defined( 'GC_REPAIRING' ) ) {
		return true;
	}

	$suppress = $gcdb->suppress_errors();

	/*
	 * Loop over the GC tables. If none exist, then scratch installation is allowed.
	 * If one or more exist, suggest table repair since we got here because the
	 * options table could not be accessed.
	 */
	$gc_tables = $gcdb->tables();
	foreach ( $gc_tables as $table ) {
		// The existence of custom user tables shouldn't suggest an unwise state or prevent a clean installation.
		if ( defined( 'CUSTOM_USER_TABLE' ) && CUSTOM_USER_TABLE == $table ) {
			continue;
		}
		if ( defined( 'CUSTOM_USER_META_TABLE' ) && CUSTOM_USER_META_TABLE == $table ) {
			continue;
		}

		$described_table = $gcdb->get_results( "DESCRIBE $table;" );
		if (
			( ! $described_table && empty( $gcdb->last_error ) ) ||
			( is_array( $described_table ) && 0 === count( $described_table ) )
		) {
			continue;
		}

		// One or more tables exist. This is not good.

		gc_load_translations_early();

		// Die with a DB error.
		$gcdb->error = sprintf(
			/* translators: %s: Database repair URL. */
			__( 'One or more database tables are unavailable. The database may need to be <a href="https://docs.gechiui.com/functions/is_blog_installed/%s">repaired</a>.' ),
			'maint/repair.php?referrer=is_blog_installed'
		);

		dead_db();
	}

	$gcdb->suppress_errors( $suppress );

	gc_cache_set( 'is_blog_installed', false );

	return false;
}