/wp-includes/ms-settings.php

https://github.com/meanlumberjack/First-Estate · PHP · 132 lines · 101 code · 17 blank · 14 comment · 45 complexity · 107eb4a57e8214d9dd02178848ba509b MD5 · raw file

  1. <?php
  2. /**
  3. * Used to set up and fix common variables and include
  4. * the Multisite procedural and class library.
  5. *
  6. * Allows for some configuration in wp-config.php (see ms-default-constants.php)
  7. *
  8. * @package WordPress
  9. * @subpackage Multisite
  10. * @since 3.0.0
  11. */
  12. /** Include Multisite initialization functions */
  13. require( ABSPATH . WPINC . '/ms-load.php' );
  14. require( ABSPATH . WPINC . '/ms-default-constants.php' );
  15. if ( defined( 'SUNRISE' ) )
  16. include_once( WP_CONTENT_DIR . '/sunrise.php' );
  17. /** Check for and define SUBDOMAIN_INSTALL and the deprecated VHOST constant. */
  18. ms_subdomain_constants();
  19. if ( !isset( $current_site ) || !isset( $current_blog ) ) {
  20. $domain = addslashes( $_SERVER['HTTP_HOST'] );
  21. if ( false !== strpos( $domain, ':' ) ) {
  22. if ( substr( $domain, -3 ) == ':80' ) {
  23. $domain = substr( $domain, 0, -3 );
  24. $_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -3 );
  25. } elseif ( substr( $domain, -4 ) == ':443' ) {
  26. $domain = substr( $domain, 0, -4 );
  27. $_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -4 );
  28. } else {
  29. wp_die( /*WP_I18N_NO_PORT_NUMBER*/'Multisite werkt alleen zonder poortnummer in de URL.'/*/WP_I18N_NO_PORT_NUMBER*/ );
  30. }
  31. }
  32. $domain = rtrim( $domain, '.' );
  33. $cookie_domain = $domain;
  34. if ( substr( $cookie_domain, 0, 4 ) == 'www.' )
  35. $cookie_domain = substr( $cookie_domain, 4 );
  36. $path = preg_replace( '|([a-z0-9-]+.php.*)|', '', $_SERVER['REQUEST_URI'] );
  37. $path = str_replace ( '/wp-admin/', '/', $path );
  38. $path = preg_replace( '|(/[a-z0-9-]+?/).*|', '$1', $path );
  39. $current_site = wpmu_current_site();
  40. if ( ! isset( $current_site->blog_id ) )
  41. $current_site->blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s", $current_site->domain, $current_site->path ) );
  42. if ( is_subdomain_install() ) {
  43. $current_blog = wp_cache_get( 'current_blog_' . $domain, 'site-options' );
  44. if ( !$current_blog ) {
  45. $current_blog = get_blog_details( array( 'domain' => $domain ), false );
  46. if ( $current_blog )
  47. wp_cache_set( 'current_blog_' . $domain, $current_blog, 'site-options' );
  48. }
  49. if ( $current_blog && $current_blog->site_id != $current_site->id ) {
  50. $current_site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->site WHERE id = %d", $current_blog->site_id ) );
  51. if ( ! isset( $current_site->blog_id ) )
  52. $current_site->blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s", $current_site->domain, $current_site->path ) );
  53. } else
  54. $blogname = substr( $domain, 0, strpos( $domain, '.' ) );
  55. } else {
  56. $blogname = htmlspecialchars( substr( $_SERVER[ 'REQUEST_URI' ], strlen( $path ) ) );
  57. if ( false !== strpos( $blogname, '/' ) )
  58. $blogname = substr( $blogname, 0, strpos( $blogname, '/' ) );
  59. if ( false !== strpos( $blogname, '?' ) )
  60. $blogname = substr( $blogname, 0, strpos( $blogname, '?' ) );
  61. $reserved_blognames = array( 'page', 'comments', 'blog', 'wp-admin', 'wp-includes', 'wp-content', 'files', 'feed' );
  62. if ( $blogname != '' && ! in_array( $blogname, $reserved_blognames ) && ! is_file( $blogname ) )
  63. $path .= $blogname . '/';
  64. $current_blog = wp_cache_get( 'current_blog_' . $domain . $path, 'site-options' );
  65. if ( ! $current_blog ) {
  66. $current_blog = get_blog_details( array( 'domain' => $domain, 'path' => $path ), false );
  67. if ( $current_blog )
  68. wp_cache_set( 'current_blog_' . $domain . $path, $current_blog, 'site-options' );
  69. }
  70. unset($reserved_blognames);
  71. }
  72. if ( ! defined( 'WP_INSTALLING' ) && is_subdomain_install() && ! is_object( $current_blog ) ) {
  73. if ( defined( 'NOBLOGREDIRECT' ) ) {
  74. $destination = NOBLOGREDIRECT;
  75. if ( '%siteurl%' == $destination )
  76. $destination = "http://" . $current_site->domain . $current_site->path;
  77. } else {
  78. $destination = 'http://' . $current_site->domain . $current_site->path . 'wp-signup.php?new=' . str_replace( '.' . $current_site->domain, '', $domain );
  79. }
  80. header( 'Location: ' . $destination );
  81. die();
  82. }
  83. if ( ! defined( 'WP_INSTALLING' ) ) {
  84. if ( $current_site && ! $current_blog ) {
  85. if ( $current_site->domain != $_SERVER[ 'HTTP_HOST' ] ) {
  86. header( 'Location: http://' . $current_site->domain . $current_site->path );
  87. exit;
  88. }
  89. $current_blog = get_blog_details( array( 'domain' => $current_site->domain, 'path' => $current_site->path ), false );
  90. }
  91. if ( ! $current_blog || ! $current_site )
  92. ms_not_installed();
  93. }
  94. $blog_id = $current_blog->blog_id;
  95. $public = $current_blog->public;
  96. if ( empty( $current_blog->site_id ) )
  97. $current_blog->site_id = 1;
  98. $site_id = $current_blog->site_id;
  99. $current_site = get_current_site_name( $current_site );
  100. if ( ! $blog_id ) {
  101. if ( defined( 'WP_INSTALLING' ) ) {
  102. $current_blog->blog_id = $blog_id = 1;
  103. } else {
  104. $msg = ! $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->site'" ) ? ' ' . /*WP_I18N_TABLES_MISSING*/'De database tabellen ontbreken.'/*/WP_I18N_TABLES_MISSING*/ : '';
  105. wp_die( /*WP_I18N_NO_BLOG*/'Geen website met deze naam bekend in ons systeem.'/*/WP_I18N_NO_BLOG*/ . $msg );
  106. }
  107. }
  108. }
  109. $wpdb->set_prefix( $table_prefix, false ); // $table_prefix can be set in sunrise.php
  110. $wpdb->set_blog_id( $current_blog->blog_id, $current_blog->site_id );
  111. $table_prefix = $wpdb->get_blog_prefix();
  112. // need to init cache again after blog_id is set
  113. wp_start_object_cache();
  114. // Define upload directory constants
  115. ms_upload_constants();