wp/wp-includes/ms-load.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    18 function is_subdomain_install() {
    18 function is_subdomain_install() {
    19 	if ( defined( 'SUBDOMAIN_INSTALL' ) ) {
    19 	if ( defined( 'SUBDOMAIN_INSTALL' ) ) {
    20 		return SUBDOMAIN_INSTALL;
    20 		return SUBDOMAIN_INSTALL;
    21 	}
    21 	}
    22 
    22 
    23 	return ( defined( 'VHOST' ) && VHOST == 'yes' );
    23 	return ( defined( 'VHOST' ) && 'yes' === VHOST );
    24 }
    24 }
    25 
    25 
    26 /**
    26 /**
    27  * Returns array of network plugin files to be included in global scope.
    27  * Returns array of network plugin files to be included in global scope.
    28  *
    28  *
    30  * manually, define `WP_PLUGIN_DIR` and `WP_PLUGIN_URL` in `wp-config.php`.
    30  * manually, define `WP_PLUGIN_DIR` and `WP_PLUGIN_URL` in `wp-config.php`.
    31  *
    31  *
    32  * @access private
    32  * @access private
    33  * @since 3.1.0
    33  * @since 3.1.0
    34  *
    34  *
    35  * @return array Files to include.
    35  * @return string[] Array of absolute paths to files to include.
    36  */
    36  */
    37 function wp_get_active_network_plugins() {
    37 function wp_get_active_network_plugins() {
    38 	$active_plugins = (array) get_site_option( 'active_sitewide_plugins', array() );
    38 	$active_plugins = (array) get_site_option( 'active_sitewide_plugins', array() );
    39 	if ( empty( $active_plugins ) ) {
    39 	if ( empty( $active_plugins ) ) {
    40 		return array();
    40 		return array();
    43 	$plugins        = array();
    43 	$plugins        = array();
    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 			&& '.php' === substr( $plugin, -4 )             // $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 	}
    55 
    55 
    76 	/**
    76 	/**
    77 	 * Filters checking the status of the current blog.
    77 	 * Filters checking the status of the current blog.
    78 	 *
    78 	 *
    79 	 * @since 3.0.0
    79 	 * @since 3.0.0
    80 	 *
    80 	 *
    81 	 * @param bool null Whether to skip the blog status check. Default null.
    81 	 * @param bool|null $check Whether to skip the blog status check. Default null.
    82 	 */
    82 	 */
    83 	$check = apply_filters( 'ms_site_check', null );
    83 	$check = apply_filters( 'ms_site_check', null );
    84 	if ( null !== $check ) {
    84 	if ( null !== $check ) {
    85 		return true;
    85 		return true;
    86 	}
    86 	}
    87 
    87 
    88 	// Allow super admins to see blocked sites
    88 	// Allow super admins to see blocked sites.
    89 	if ( is_super_admin() ) {
    89 	if ( is_super_admin() ) {
    90 		return true;
    90 		return true;
    91 	}
    91 	}
    92 
    92 
    93 	$blog = get_site();
    93 	$blog = get_site();
   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(
   109 				/* translators: %s: admin email link */
       
   110 				sprintf(
   109 				sprintf(
       
   110 					/* translators: %s: Admin email link. */
   111 					__( 'This site has not been activated yet. If you are having problems activating your site, please contact %s.' ),
   111 					__( 'This site has not been activated yet. If you are having problems activating your site, please contact %s.' ),
   112 					sprintf( '<a href="mailto:%1$s">%1$s</a>', $admin_email )
   112 					sprintf( '<a href="mailto:%1$s">%1$s</a>', $admin_email )
   113 				)
   113 				)
   114 			);
   114 			);
   115 		}
   115 		}
   116 	}
   116 	}
   117 
   117 
   118 	if ( $blog->archived == '1' || $blog->spam == '1' ) {
   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 		}
   201 	 * can be found at the requested domain and path. Otherwise, return
   201 	 * can be found at the requested domain and path. Otherwise, return
   202 	 * a site object.
   202 	 * a site object.
   203 	 *
   203 	 *
   204 	 * @since 3.9.0
   204 	 * @since 3.9.0
   205 	 *
   205 	 *
   206 	 * @param null|bool|WP_Site $site     Site value to return by path.
   206 	 * @param null|false|WP_Site $site     Site value to return by path. Default null
   207 	 * @param string            $domain   The requested domain.
   207 	 *                                     to continue retrieving the site.
   208 	 * @param string            $path     The requested path, in full.
   208 	 * @param string             $domain   The requested domain.
   209 	 * @param int|null          $segments The suggested number of paths to consult.
   209 	 * @param string             $path     The requested path, in full.
   210 	 *                                    Default null, meaning the entire path was to be consulted.
   210 	 * @param int|null           $segments The suggested number of paths to consult.
   211 	 * @param array             $paths    The paths to search for, based on $path and $segments.
   211 	 *                                     Default null, meaning the entire path was to be consulted.
       
   212 	 * @param string[]           $paths    The paths to search for, based on $path and $segments.
   212 	 */
   213 	 */
   213 	$pre = apply_filters( 'pre_get_site_by_path', null, $domain, $path, $segments, $paths );
   214 	$pre = apply_filters( 'pre_get_site_by_path', null, $domain, $path, $segments, $paths );
   214 	if ( null !== $pre ) {
   215 	if ( null !== $pre ) {
   215 		if ( false !== $pre && ! $pre instanceof WP_Site ) {
   216 		if ( false !== $pre && ! $pre instanceof WP_Site ) {
   216 			$pre = new WP_Site( $pre );
   217 			$pre = new WP_Site( $pre );
   218 		return $pre;
   219 		return $pre;
   219 	}
   220 	}
   220 
   221 
   221 	/*
   222 	/*
   222 	 * @todo
   223 	 * @todo
   223 	 * caching, etc. Consider alternative optimization routes,
   224 	 * Caching, etc. Consider alternative optimization routes,
   224 	 * perhaps as an opt-in for plugins, rather than using the pre_* filter.
   225 	 * perhaps as an opt-in for plugins, rather than using the pre_* filter.
   225 	 * For example: The segments filter can expand or ignore paths.
   226 	 * For example: The segments filter can expand or ignore paths.
   226 	 * If persistent caching is enabled, we could query the DB for a path <> '/'
   227 	 * If persistent caching is enabled, we could query the DB for a path <> '/'
   227 	 * then cache whether we can just always ignore paths.
   228 	 * then cache whether we can just always ignore paths.
   228 	 */
   229 	 */
   302 		$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;
   303 		$current_site->domain = DOMAIN_CURRENT_SITE;
   304 		$current_site->domain = DOMAIN_CURRENT_SITE;
   304 		$current_site->path   = PATH_CURRENT_SITE;
   305 		$current_site->path   = PATH_CURRENT_SITE;
   305 		if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) {
   306 		if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) {
   306 			$current_site->blog_id = BLOG_ID_CURRENT_SITE;
   307 			$current_site->blog_id = BLOG_ID_CURRENT_SITE;
   307 		} elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) { // deprecated.
   308 		} elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) { // Deprecated.
   308 			$current_site->blog_id = BLOGID_CURRENT_SITE;
   309 			$current_site->blog_id = BLOGID_CURRENT_SITE;
   309 		}
   310 		}
   310 
   311 
   311 		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 ) ) {
   312 			$current_blog = get_site_by_path( $domain, $path );
   313 			$current_blog = get_site_by_path( $domain, $path );
   322 		/*
   323 		/*
   323 		 * A "subdomain" installation can be re-interpreted to mean "can support any domain".
   324 		 * A "subdomain" installation can be re-interpreted to mean "can support any domain".
   324 		 * If we're not dealing with one of these installations, then the important part is determining
   325 		 * If we're not dealing with one of these installations, then the important part is determining
   325 		 * the network first, because we need the network's path to identify any sites.
   326 		 * the network first, because we need the network's path to identify any sites.
   326 		 */
   327 		 */
   327 		if ( ! $current_site = wp_cache_get( 'current_network', 'site-options' ) ) {
   328 		$current_site = wp_cache_get( 'current_network', 'site-options' );
       
   329 		if ( ! $current_site ) {
   328 			// Are there even two networks installed?
   330 			// Are there even two networks installed?
   329 			$networks = get_networks( array( 'number' => 2 ) );
   331 			$networks = get_networks( array( 'number' => 2 ) );
   330 			if ( count( $networks ) === 1 ) {
   332 			if ( count( $networks ) === 1 ) {
   331 				$current_site = array_shift( $networks );
   333 				$current_site = array_shift( $networks );
   332 				wp_cache_add( 'current_network', $current_site, 'site-options' );
   334 				wp_cache_add( 'current_network', $current_site, 'site-options' );
   386 	}
   388 	}
   387 
   389 
   388 	// During activation of a new subdomain, the requested site does not yet exist.
   390 	// During activation of a new subdomain, the requested site does not yet exist.
   389 	if ( empty( $current_blog ) && wp_installing() ) {
   391 	if ( empty( $current_blog ) && wp_installing() ) {
   390 		$current_blog          = new stdClass;
   392 		$current_blog          = new stdClass;
   391 		$current_blog->blog_id = $blog_id = 1;
   393 		$current_blog->blog_id = 1;
       
   394 		$blog_id               = 1;
   392 		$current_blog->public  = 1;
   395 		$current_blog->public  = 1;
   393 	}
   396 	}
   394 
   397 
   395 	// No site has been found, bail.
   398 	// No site has been found, bail.
   396 	if ( empty( $current_blog ) ) {
   399 	if ( empty( $current_blog ) ) {
   414 
   417 
   415 		if ( $subdomain && ! defined( 'NOBLOGREDIRECT' ) ) {
   418 		if ( $subdomain && ! defined( 'NOBLOGREDIRECT' ) ) {
   416 			// For a "subdomain" installation, redirect to the signup form specifically.
   419 			// For a "subdomain" installation, redirect to the signup form specifically.
   417 			$destination .= 'wp-signup.php?new=' . str_replace( '.' . $current_site->domain, '', $domain );
   420 			$destination .= 'wp-signup.php?new=' . str_replace( '.' . $current_site->domain, '', $domain );
   418 		} elseif ( $subdomain ) {
   421 		} elseif ( $subdomain ) {
   419 			// For a "subdomain" installation, the NOBLOGREDIRECT constant
   422 			/*
   420 			// can be used to avoid a redirect to the signup form.
   423 			 * For a "subdomain" installation, the NOBLOGREDIRECT constant
   421 			// Using the ms_site_not_found action is preferred to the constant.
   424 			 * can be used to avoid a redirect to the signup form.
       
   425 			 * Using the ms_site_not_found action is preferred to the constant.
       
   426 			 */
   422 			if ( '%siteurl%' !== NOBLOGREDIRECT ) {
   427 			if ( '%siteurl%' !== NOBLOGREDIRECT ) {
   423 				$destination = NOBLOGREDIRECT;
   428 				$destination = NOBLOGREDIRECT;
   424 			}
   429 			}
   425 		} elseif ( 0 === strcasecmp( $current_site->domain, $domain ) ) {
   430 		} elseif ( 0 === strcasecmp( $current_site->domain, $domain ) ) {
   426 			/*
   431 			/*
   471 	$msg  .= '<p>' . __( 'If your site does not display, please contact the owner of this network.' ) . '';
   476 	$msg  .= '<p>' . __( 'If your site does not display, please contact the owner of this network.' ) . '';
   472 	$msg  .= ' ' . __( 'If you are the owner of this network please check that MySQL is running properly and all tables are error free.' ) . '</p>';
   477 	$msg  .= ' ' . __( 'If you are the owner of this network please check that MySQL is running properly and all tables are error free.' ) . '</p>';
   473 	$query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $wpdb->site ) );
   478 	$query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $wpdb->site ) );
   474 	if ( ! $wpdb->get_var( $query ) ) {
   479 	if ( ! $wpdb->get_var( $query ) ) {
   475 		$msg .= '<p>' . sprintf(
   480 		$msg .= '<p>' . sprintf(
   476 			/* translators: %s: table name */
   481 			/* translators: %s: Table name. */
   477 			__( '<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.' ),
   482 			__( '<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.' ),
   478 			'<code>' . $wpdb->site . '</code>'
   483 			'<code>' . $wpdb->site . '</code>'
   479 		) . '</p>';
   484 		) . '</p>';
   480 	} else {
   485 	} else {
   481 		$msg .= '<p>' . sprintf(
   486 		$msg .= '<p>' . sprintf(
   482 			/* translators: 1: site url, 2: table name, 3: database name */
   487 			/* translators: 1: Site URL, 2: Table name, 3: Database name. */
   483 			__( '<strong>Could not find site %1$s.</strong> Searched for table %2$s in database %3$s. Is that right?' ),
   488 			__( '<strong>Could not find site %1$s.</strong> Searched for table %2$s in database %3$s. Is that right?' ),
   484 			'<code>' . rtrim( $domain . $path, '/' ) . '</code>',
   489 			'<code>' . rtrim( $domain . $path, '/' ) . '</code>',
   485 			'<code>' . $wpdb->blogs . '</code>',
   490 			'<code>' . $wpdb->blogs . '</code>',
   486 			'<code>' . DB_NAME . '</code>'
   491 			'<code>' . DB_NAME . '</code>'
   487 		) . '</p>';
   492 		) . '</p>';
   488 	}
   493 	}
   489 	$msg .= '<p><strong>' . __( 'What do I do now?' ) . '</strong> ';
   494 	$msg .= '<p><strong>' . __( 'What do I do now?' ) . '</strong> ';
   490 	/* translators: %s: Codex URL */
       
   491 	$msg .= sprintf(
   495 	$msg .= sprintf(
   492 		__( 'Read the <a href="%s" target="_blank">bug report</a> page. Some of the guidelines there may help you figure out what went wrong.' ),
   496 		/* translators: %s: Documentation URL. */
   493 		__( 'https://codex.wordpress.org/Debugging_a_WordPress_Network' )
   497 		__( '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.' ),
       
   498 		__( 'https://wordpress.org/support/article/debugging-a-wordpress-network/' )
   494 	);
   499 	);
   495 	$msg .= ' ' . __( 'If you&#8217;re still stuck with this message, then check that your database contains the following tables:' ) . '</p><ul>';
   500 	$msg .= ' ' . __( 'If you&#8217;re still stuck with this message, then check that your database contains the following tables:' ) . '</p><ul>';
   496 	foreach ( $wpdb->tables( 'global' ) as $t => $table ) {
   501 	foreach ( $wpdb->tables( 'global' ) as $t => $table ) {
   497 		if ( 'sitecategories' == $t ) {
   502 		if ( 'sitecategories' === $t ) {
   498 			continue;
   503 			continue;
   499 		}
   504 		}
   500 		$msg .= '<li>' . $table . '</li>';
   505 		$msg .= '<li>' . $table . '</li>';
   501 	}
   506 	}
   502 	$msg .= '</ul>';
   507 	$msg .= '</ul>';