wp/wp-includes/ms-load.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
    44 	$active_plugins = array_keys( $active_plugins );
    44 	$active_plugins = array_keys( $active_plugins );
    45 	sort( $active_plugins );
    45 	sort( $active_plugins );
    46 
    46 
    47 	foreach ( $active_plugins as $plugin ) {
    47 	foreach ( $active_plugins as $plugin ) {
    48 		if ( ! validate_file( $plugin )                     // $plugin must validate as file.
    48 		if ( ! validate_file( $plugin )                     // $plugin must validate as file.
    49 			&& '.php' === substr( $plugin, -4 )             // $plugin must end with '.php'.
    49 			&& str_ends_with( $plugin, '.php' )             // $plugin must end with '.php'.
    50 			&& file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist.
    50 			&& file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist.
    51 			) {
    51 			) {
    52 			$plugins[] = WP_PLUGIN_DIR . '/' . $plugin;
    52 			$plugins[] = WP_PLUGIN_DIR . '/' . $plugin;
    53 		}
    53 		}
    54 	}
    54 	}
    90 		return true;
    90 		return true;
    91 	}
    91 	}
    92 
    92 
    93 	$blog = get_site();
    93 	$blog = get_site();
    94 
    94 
    95 	if ( '1' == $blog->deleted ) {
    95 	if ( '1' === $blog->deleted ) {
    96 		if ( file_exists( WP_CONTENT_DIR . '/blog-deleted.php' ) ) {
    96 		if ( file_exists( WP_CONTENT_DIR . '/blog-deleted.php' ) ) {
    97 			return WP_CONTENT_DIR . '/blog-deleted.php';
    97 			return WP_CONTENT_DIR . '/blog-deleted.php';
    98 		} else {
    98 		} else {
    99 			wp_die( __( 'This site is no longer available.' ), '', array( 'response' => 410 ) );
    99 			wp_die( __( 'This site is no longer available.' ), '', array( 'response' => 410 ) );
   100 		}
   100 		}
   101 	}
   101 	}
   102 
   102 
   103 	if ( '2' == $blog->deleted ) {
   103 	if ( '2' === $blog->deleted ) {
   104 		if ( file_exists( WP_CONTENT_DIR . '/blog-inactive.php' ) ) {
   104 		if ( file_exists( WP_CONTENT_DIR . '/blog-inactive.php' ) ) {
   105 			return WP_CONTENT_DIR . '/blog-inactive.php';
   105 			return WP_CONTENT_DIR . '/blog-inactive.php';
   106 		} else {
   106 		} else {
   107 			$admin_email = str_replace( '@', ' AT ', get_site_option( 'admin_email', 'support@' . get_network()->domain ) );
   107 			$admin_email = str_replace( '@', ' AT ', get_site_option( 'admin_email', 'support@' . get_network()->domain ) );
   108 			wp_die(
   108 			wp_die(
   113 				)
   113 				)
   114 			);
   114 			);
   115 		}
   115 		}
   116 	}
   116 	}
   117 
   117 
   118 	if ( '1' == $blog->archived || '1' == $blog->spam ) {
   118 	if ( '1' === $blog->archived || '1' === $blog->spam ) {
   119 		if ( file_exists( WP_CONTENT_DIR . '/blog-suspended.php' ) ) {
   119 		if ( file_exists( WP_CONTENT_DIR . '/blog-suspended.php' ) ) {
   120 			return WP_CONTENT_DIR . '/blog-suspended.php';
   120 			return WP_CONTENT_DIR . '/blog-suspended.php';
   121 		} else {
   121 		} else {
   122 			wp_die( __( 'This site has been archived or suspended.' ), '', array( 'response' => 410 ) );
   122 			wp_die( __( 'This site has been archived or suspended.' ), '', array( 'response' => 410 ) );
   123 		}
   123 		}
   224 	 * For example: The segments filter can expand or ignore paths.
   224 	 * For example: The segments filter can expand or ignore paths.
   225 	 * If persistent caching is enabled, we could query the DB for a path <> '/'
   225 	 * If persistent caching is enabled, we could query the DB for a path <> '/'
   226 	 * then cache whether we can just always ignore paths.
   226 	 * then cache whether we can just always ignore paths.
   227 	 */
   227 	 */
   228 
   228 
   229 	// Either www or non-www is supported, not both. If a www domain is requested,
   229 	/*
   230 	// query for both to provide the proper redirect.
   230 	 * Either www or non-www is supported, not both. If a www domain is requested,
       
   231 	 * query for both to provide the proper redirect.
       
   232 	 */
   231 	$domains = array( $domain );
   233 	$domains = array( $domain );
   232 	if ( 'www.' === substr( $domain, 0, 4 ) ) {
   234 	if ( str_starts_with( $domain, 'www.' ) ) {
   233 		$domains[] = substr( $domain, 4 );
   235 		$domains[] = substr( $domain, 4 );
   234 	}
   236 	}
   235 
   237 
   236 	$args = array(
   238 	$args = array(
   237 		'number'                 => 1,
   239 		'number'                 => 1,
   295 function ms_load_current_site_and_network( $domain, $path, $subdomain = false ) {
   297 function ms_load_current_site_and_network( $domain, $path, $subdomain = false ) {
   296 	global $current_site, $current_blog;
   298 	global $current_site, $current_blog;
   297 
   299 
   298 	// If the network is defined in wp-config.php, we can simply use that.
   300 	// If the network is defined in wp-config.php, we can simply use that.
   299 	if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) {
   301 	if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) {
   300 		$current_site         = new stdClass;
   302 		$current_site         = new stdClass();
   301 		$current_site->id     = defined( 'SITE_ID_CURRENT_SITE' ) ? SITE_ID_CURRENT_SITE : 1;
   303 		$current_site->id     = defined( 'SITE_ID_CURRENT_SITE' ) ? SITE_ID_CURRENT_SITE : 1;
   302 		$current_site->domain = DOMAIN_CURRENT_SITE;
   304 		$current_site->domain = DOMAIN_CURRENT_SITE;
   303 		$current_site->path   = PATH_CURRENT_SITE;
   305 		$current_site->path   = PATH_CURRENT_SITE;
   304 		if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) {
   306 		if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) {
   305 			$current_site->blog_id = BLOG_ID_CURRENT_SITE;
   307 			$current_site->blog_id = BLOG_ID_CURRENT_SITE;
   308 		}
   310 		}
   309 
   311 
   310 		if ( 0 === strcasecmp( $current_site->domain, $domain ) && 0 === strcasecmp( $current_site->path, $path ) ) {
   312 		if ( 0 === strcasecmp( $current_site->domain, $domain ) && 0 === strcasecmp( $current_site->path, $path ) ) {
   311 			$current_blog = get_site_by_path( $domain, $path );
   313 			$current_blog = get_site_by_path( $domain, $path );
   312 		} elseif ( '/' !== $current_site->path && 0 === strcasecmp( $current_site->domain, $domain ) && 0 === stripos( $path, $current_site->path ) ) {
   314 		} elseif ( '/' !== $current_site->path && 0 === strcasecmp( $current_site->domain, $domain ) && 0 === stripos( $path, $current_site->path ) ) {
   313 			// If the current network has a path and also matches the domain and path of the request,
   315 			/*
   314 			// we need to look for a site using the first path segment following the network's path.
   316 			 * If the current network has a path and also matches the domain and path of the request,
       
   317 			 * we need to look for a site using the first path segment following the network's path.
       
   318 			 */
   315 			$current_blog = get_site_by_path( $domain, $path, 1 + count( explode( '/', trim( $current_site->path, '/' ) ) ) );
   319 			$current_blog = get_site_by_path( $domain, $path, 1 + count( explode( '/', trim( $current_site->path, '/' ) ) ) );
   316 		} else {
   320 		} else {
   317 			// Otherwise, use the first path segment (as usual).
   321 			// Otherwise, use the first path segment (as usual).
   318 			$current_blog = get_site_by_path( $domain, $path, 1 );
   322 			$current_blog = get_site_by_path( $domain, $path, 1 );
   319 		}
   323 		}
   371 			$current_site = WP_Network::get_by_path( $domain, $path, 1 );
   375 			$current_site = WP_Network::get_by_path( $domain, $path, 1 );
   372 		}
   376 		}
   373 	}
   377 	}
   374 
   378 
   375 	// The network declared by the site trumps any constants.
   379 	// The network declared by the site trumps any constants.
   376 	if ( $current_blog && $current_blog->site_id != $current_site->id ) {
   380 	if ( $current_blog && (int) $current_blog->site_id !== $current_site->id ) {
   377 		$current_site = WP_Network::get_instance( $current_blog->site_id );
   381 		$current_site = WP_Network::get_instance( $current_blog->site_id );
   378 	}
   382 	}
   379 
   383 
   380 	// No network has been found, bail.
   384 	// No network has been found, bail.
   381 	if ( empty( $current_site ) ) {
   385 	if ( empty( $current_site ) ) {
   385 		return false;
   389 		return false;
   386 	}
   390 	}
   387 
   391 
   388 	// During activation of a new subdomain, the requested site does not yet exist.
   392 	// During activation of a new subdomain, the requested site does not yet exist.
   389 	if ( empty( $current_blog ) && wp_installing() ) {
   393 	if ( empty( $current_blog ) && wp_installing() ) {
   390 		$current_blog          = new stdClass;
   394 		$current_blog          = new stdClass();
   391 		$current_blog->blog_id = 1;
   395 		$current_blog->blog_id = 1;
   392 		$blog_id               = 1;
   396 		$blog_id               = 1;
   393 		$current_blog->public  = 1;
   397 		$current_blog->public  = 1;
   394 	}
   398 	}
   395 
   399 
   470 
   474 
   471 	$title = __( 'Error establishing a database connection' );
   475 	$title = __( 'Error establishing a database connection' );
   472 
   476 
   473 	$msg   = '<h1>' . $title . '</h1>';
   477 	$msg   = '<h1>' . $title . '</h1>';
   474 	$msg  .= '<p>' . __( 'If your site does not display, please contact the owner of this network.' ) . '';
   478 	$msg  .= '<p>' . __( 'If your site does not display, please contact the owner of this network.' ) . '';
   475 	$msg  .= ' ' . __( 'If you are the owner of this network please check that MySQL is running properly and all tables are error free.' ) . '</p>';
   479 	$msg  .= ' ' . __( 'If you are the owner of this network please check that your host&#8217;s database server is running properly and all tables are error free.' ) . '</p>';
   476 	$query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $wpdb->site ) );
   480 	$query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $wpdb->site ) );
   477 	if ( ! $wpdb->get_var( $query ) ) {
   481 	if ( ! $wpdb->get_var( $query ) ) {
   478 		$msg .= '<p>' . sprintf(
   482 		$msg .= '<p>' . sprintf(
   479 			/* translators: %s: Table name. */
   483 			/* translators: %s: Table name. */
   480 			__( '<strong>Database tables are missing.</strong> This means that MySQL is not running, WordPress was not installed properly, or someone deleted %s. You really should look at your database now.' ),
   484 			__( '<strong>Database tables are missing.</strong> This means that your host&#8217;s database server is not running, WordPress was not installed properly, or someone deleted %s. You really should look at your database now.' ),
   481 			'<code>' . $wpdb->site . '</code>'
   485 			'<code>' . $wpdb->site . '</code>'
   482 		) . '</p>';
   486 		) . '</p>';
   483 	} else {
   487 	} else {
   484 		$msg .= '<p>' . sprintf(
   488 		$msg .= '<p>' . sprintf(
   485 			/* translators: 1: Site URL, 2: Table name, 3: Database name. */
   489 			/* translators: 1: Site URL, 2: Table name, 3: Database name. */
   491 	}
   495 	}
   492 	$msg .= '<p><strong>' . __( 'What do I do now?' ) . '</strong> ';
   496 	$msg .= '<p><strong>' . __( 'What do I do now?' ) . '</strong> ';
   493 	$msg .= sprintf(
   497 	$msg .= sprintf(
   494 		/* translators: %s: Documentation URL. */
   498 		/* translators: %s: Documentation URL. */
   495 		__( 'Read the <a href="%s" target="_blank">Debugging a WordPress Network</a> article. Some of the suggestions there may help you figure out what went wrong.' ),
   499 		__( 'Read the <a href="%s" target="_blank">Debugging a WordPress Network</a> article. Some of the suggestions there may help you figure out what went wrong.' ),
   496 		__( 'https://wordpress.org/support/article/debugging-a-wordpress-network/' )
   500 		__( 'https://developer.wordpress.org/advanced-administration/debug/debug-network/' )
   497 	);
   501 	);
   498 	$msg .= ' ' . __( 'If you are still stuck with this message, then check that your database contains the following tables:' ) . '</p><ul>';
   502 	$msg .= ' ' . __( 'If you are still stuck with this message, then check that your database contains the following tables:' ) . '</p><ul>';
   499 	foreach ( $wpdb->tables( 'global' ) as $t => $table ) {
   503 	foreach ( $wpdb->tables( 'global' ) as $t => $table ) {
   500 		if ( 'sitecategories' === $t ) {
   504 		if ( 'sitecategories' === $t ) {
   501 			continue;
   505 			continue;