返回介绍

is_blog_installed()

发布于 2017-09-11 01:11:50 字数 3884 浏览 933 评论 0 收藏 0

is_blog_installed()

Test whether WordPress is already installed.


description

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.

Checks for the ‘siteurl’ option for whether WordPress is installed.


返回值

(bool) Whether the site is already installed.


源代码

File: wp-includes/functions.php

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 ( ! 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.

		wp_load_translations_early();

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

		dead_db();
	}

	$wpdb->suppress_errors( $suppress );

	wp_cache_set( 'is_blog_installed', false );

	return false;
}

更新日志

Versiondescription
2.1.0Introduced.

相关函数

Uses

  • wp-includes/load.php: wp_installing()
  • wp-includes/cache.php: wp_cache_get()
  • wp-includes/cache.php: wp_cache_set()
  • wp-includes/l10n.php: __()
  • wp-includes/load.php: wp_load_translations_early()
  • wp-includes/functions.php: dead_db()
  • wp-includes/option.php: wp_load_alloptions()
  • wp-includes/wp-db.php: wpdb::get_var()
  • wp-includes/wp-db.php: wpdb::get_results()
  • wp-includes/wp-db.php: wpdb::suppress_errors()
  • wp-includes/wp-db.php: wpdb::tables()
  • Show 6 more uses Hide more uses

Used By

  • wp-admin/includes/upgrade.php: wp_upgrade()
  • wp-includes/load.php: wp_not_installed()
  • wp-includes/widgets.php: wp_widgets_init()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文