is_blog_installed

Test whether WordPress is already installed.

Description

is_blog_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.

Checks for the siteurl option for whether WordPress is installed.


Usage

  1. if ( !function_exists( 'is_blog_installed' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = is_blog_installed(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/functions.php  
  1. function is_blog_installed() { 
  2. global $wpdb; 
  3.  
  4. /** 
  5. * Check cache first. If options table goes away and we have true 
  6. * cached, oh well. 
  7. */ 
  8. if ( wp_cache_get( 'is_blog_installed' ) ) 
  9. return true; 
  10.  
  11. $suppress = $wpdb->suppress_errors(); 
  12. if ( ! wp_installing() ) { 
  13. $alloptions = wp_load_alloptions(); 
  14. // If siteurl is not set to autoload, check it specifically 
  15. if ( !isset( $alloptions['siteurl'] ) ) 
  16. $installed = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'" ); 
  17. else 
  18. $installed = $alloptions['siteurl']; 
  19. $wpdb->suppress_errors( $suppress ); 
  20.  
  21. $installed = !empty( $installed ); 
  22. wp_cache_set( 'is_blog_installed', $installed ); 
  23.  
  24. if ( $installed ) 
  25. return true; 
  26.  
  27. // If visiting repair.php, return true and let it take over. 
  28. if ( defined( 'WP_REPAIRING' ) ) 
  29. return true; 
  30.  
  31. $suppress = $wpdb->suppress_errors(); 
  32.  
  33. /** 
  34. * Loop over the WP tables. If none exist, then scratch install is allowed. 
  35. * If one or more exist, suggest table repair since we got here because the 
  36. * options table could not be accessed. 
  37. */ 
  38. $wp_tables = $wpdb->tables(); 
  39. foreach ( $wp_tables as $table ) { 
  40. // The existence of custom user tables shouldn't suggest an insane state or prevent a clean install. 
  41. if ( defined( 'CUSTOM_USER_TABLE' ) && CUSTOM_USER_TABLE == $table ) 
  42. continue; 
  43. if ( defined( 'CUSTOM_USER_META_TABLE' ) && CUSTOM_USER_META_TABLE == $table ) 
  44. continue; 
  45.  
  46. if ( ! $wpdb->get_results( "DESCRIBE $table;" ) ) 
  47. continue; 
  48.  
  49. // One or more tables exist. We are insane. 
  50.  
  51.  
  52. // Die with a DB error. 
  53. $wpdb->error = sprintf( 
  54. /** translators: %s: database repair URL */ 
  55. __( 'One or more database tables are unavailable. The database may need to be <a href="%s">repaired</a>.' ),  
  56. 'maint/repair.php?referrer=is_blog_installed' 
  57. ); 
  58.  
  59. dead_db(); 
  60.  
  61. $wpdb->suppress_errors( $suppress ); 
  62.  
  63. wp_cache_set( 'is_blog_installed', false ); 
  64.  
  65. return false;