wp/wp-includes/ms-load.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    14  * @since 3.0.0
    14  * @since 3.0.0
    15  *
    15  *
    16  * @return bool True if subdomain configuration is enabled, false otherwise.
    16  * @return bool True if subdomain configuration is enabled, false otherwise.
    17  */
    17  */
    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 	return ( defined( 'VHOST' ) && VHOST == 'yes' );
    23 	return ( defined( 'VHOST' ) && VHOST == 'yes' );
    23 }
    24 }
    24 
    25 
    25 /**
    26 /**
    33  *
    34  *
    34  * @return array Files to include.
    35  * @return array Files to include.
    35  */
    36  */
    36 function wp_get_active_network_plugins() {
    37 function wp_get_active_network_plugins() {
    37 	$active_plugins = (array) get_site_option( 'active_sitewide_plugins', array() );
    38 	$active_plugins = (array) get_site_option( 'active_sitewide_plugins', array() );
    38 	if ( empty( $active_plugins ) )
    39 	if ( empty( $active_plugins ) ) {
    39 		return array();
    40 		return array();
    40 
    41 	}
    41 	$plugins = array();
    42 
       
    43 	$plugins        = array();
    42 	$active_plugins = array_keys( $active_plugins );
    44 	$active_plugins = array_keys( $active_plugins );
    43 	sort( $active_plugins );
    45 	sort( $active_plugins );
    44 
    46 
    45 	foreach ( $active_plugins as $plugin ) {
    47 	foreach ( $active_plugins as $plugin ) {
    46 		if ( ! validate_file( $plugin ) // $plugin must validate as file
    48 		if ( ! validate_file( $plugin ) // $plugin must validate as file
    47 			&& '.php' == substr( $plugin, -4 ) // $plugin must end with '.php'
    49 			&& '.php' == substr( $plugin, -4 ) // $plugin must end with '.php'
    48 			&& file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist
    50 			&& file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist
    49 			)
    51 			) {
    50 		$plugins[] = WP_PLUGIN_DIR . '/' . $plugin;
    52 			$plugins[] = WP_PLUGIN_DIR . '/' . $plugin;
    51 	}
    53 		}
       
    54 	}
       
    55 
    52 	return $plugins;
    56 	return $plugins;
    53 }
    57 }
    54 
    58 
    55 /**
    59 /**
    56  * Checks status of current blog.
    60  * Checks status of current blog.
    73 	 * Filters checking the status of the current blog.
    77 	 * Filters checking the status of the current blog.
    74 	 *
    78 	 *
    75 	 * @since 3.0.0
    79 	 * @since 3.0.0
    76 	 *
    80 	 *
    77 	 * @param bool null Whether to skip the blog status check. Default null.
    81 	 * @param bool null Whether to skip the blog status check. Default null.
    78 	*/
    82 	 */
    79 	$check = apply_filters( 'ms_site_check', null );
    83 	$check = apply_filters( 'ms_site_check', null );
    80 	if ( null !== $check )
    84 	if ( null !== $check ) {
    81 		return true;
    85 		return true;
       
    86 	}
    82 
    87 
    83 	// Allow super admins to see blocked sites
    88 	// Allow super admins to see blocked sites
    84 	if ( is_super_admin() )
    89 	if ( is_super_admin() ) {
    85 		return true;
    90 		return true;
       
    91 	}
    86 
    92 
    87 	$blog = get_site();
    93 	$blog = get_site();
    88 
    94 
    89 	if ( '1' == $blog->deleted ) {
    95 	if ( '1' == $blog->deleted ) {
    90 		if ( file_exists( WP_CONTENT_DIR . '/blog-deleted.php' ) )
    96 		if ( file_exists( WP_CONTENT_DIR . '/blog-deleted.php' ) ) {
    91 			return WP_CONTENT_DIR . '/blog-deleted.php';
    97 			return WP_CONTENT_DIR . '/blog-deleted.php';
    92 		else
    98 		} else {
    93 			wp_die( __( 'This site is no longer available.' ), '', array( 'response' => 410 ) );
    99 			wp_die( __( 'This site is no longer available.' ), '', array( 'response' => 410 ) );
       
   100 		}
    94 	}
   101 	}
    95 
   102 
    96 	if ( '2' == $blog->deleted ) {
   103 	if ( '2' == $blog->deleted ) {
    97 		if ( file_exists( WP_CONTENT_DIR . '/blog-inactive.php' ) ) {
   104 		if ( file_exists( WP_CONTENT_DIR . '/blog-inactive.php' ) ) {
    98 			return WP_CONTENT_DIR . '/blog-inactive.php';
   105 			return WP_CONTENT_DIR . '/blog-inactive.php';
    99 		} else {
   106 		} else {
   100 			$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 ) );
   101 			wp_die(
   108 			wp_die(
   102 				/* translators: %s: admin email link */
   109 				/* translators: %s: admin email link */
   103 				sprintf( __( 'This site has not been activated yet. If you are having problems activating your site, please contact %s.' ),
   110 				sprintf(
   104 					sprintf( '<a href="mailto:%s">%s</a>', $admin_email )
   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 )
   105 				)
   113 				)
   106 			);
   114 			);
   107 		}
   115 		}
   108 	}
   116 	}
   109 
   117 
   110 	if ( $blog->archived == '1' || $blog->spam == '1' ) {
   118 	if ( $blog->archived == '1' || $blog->spam == '1' ) {
   111 		if ( file_exists( WP_CONTENT_DIR . '/blog-suspended.php' ) )
   119 		if ( file_exists( WP_CONTENT_DIR . '/blog-suspended.php' ) ) {
   112 			return WP_CONTENT_DIR . '/blog-suspended.php';
   120 			return WP_CONTENT_DIR . '/blog-suspended.php';
   113 		else
   121 		} else {
   114 			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 		}
   115 	}
   124 	}
   116 
   125 
   117 	return true;
   126 	return true;
   118 }
   127 }
   119 
   128 
   224 	if ( 'www.' === substr( $domain, 0, 4 ) ) {
   233 	if ( 'www.' === substr( $domain, 0, 4 ) ) {
   225 		$domains[] = substr( $domain, 4 );
   234 		$domains[] = substr( $domain, 4 );
   226 	}
   235 	}
   227 
   236 
   228 	$args = array(
   237 	$args = array(
   229 		'domain__in' => $domains,
   238 		'number'                 => 1,
   230 		'path__in' => $paths,
   239 		'update_site_meta_cache' => false,
   231 		'number' => 1,
       
   232 	);
   240 	);
   233 
   241 
   234 	if ( count( $domains ) > 1 ) {
   242 	if ( count( $domains ) > 1 ) {
       
   243 		$args['domain__in']               = $domains;
   235 		$args['orderby']['domain_length'] = 'DESC';
   244 		$args['orderby']['domain_length'] = 'DESC';
       
   245 	} else {
       
   246 		$args['domain'] = array_shift( $domains );
   236 	}
   247 	}
   237 
   248 
   238 	if ( count( $paths ) > 1 ) {
   249 	if ( count( $paths ) > 1 ) {
       
   250 		$args['path__in']               = $paths;
   239 		$args['orderby']['path_length'] = 'DESC';
   251 		$args['orderby']['path_length'] = 'DESC';
       
   252 	} else {
       
   253 		$args['path'] = array_shift( $paths );
   240 	}
   254 	}
   241 
   255 
   242 	$result = get_sites( $args );
   256 	$result = get_sites( $args );
   243 	$site = array_shift( $result );
   257 	$site   = array_shift( $result );
   244 
   258 
   245 	if ( $site ) {
   259 	if ( $site ) {
   246 		return $site;
   260 		return $site;
   247 	}
   261 	}
   248 
   262 
   282 function ms_load_current_site_and_network( $domain, $path, $subdomain = false ) {
   296 function ms_load_current_site_and_network( $domain, $path, $subdomain = false ) {
   283 	global $current_site, $current_blog;
   297 	global $current_site, $current_blog;
   284 
   298 
   285 	// If the network is defined in wp-config.php, we can simply use that.
   299 	// If the network is defined in wp-config.php, we can simply use that.
   286 	if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) {
   300 	if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) {
   287 		$current_site = new stdClass;
   301 		$current_site         = new stdClass;
   288 		$current_site->id = defined( 'SITE_ID_CURRENT_SITE' ) ? SITE_ID_CURRENT_SITE : 1;
   302 		$current_site->id     = defined( 'SITE_ID_CURRENT_SITE' ) ? SITE_ID_CURRENT_SITE : 1;
   289 		$current_site->domain = DOMAIN_CURRENT_SITE;
   303 		$current_site->domain = DOMAIN_CURRENT_SITE;
   290 		$current_site->path = PATH_CURRENT_SITE;
   304 		$current_site->path   = PATH_CURRENT_SITE;
   291 		if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) {
   305 		if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) {
   292 			$current_site->blog_id = BLOG_ID_CURRENT_SITE;
   306 			$current_site->blog_id = BLOG_ID_CURRENT_SITE;
   293 		} elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) { // deprecated.
   307 		} elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) { // deprecated.
   294 			$current_site->blog_id = BLOGID_CURRENT_SITE;
   308 			$current_site->blog_id = BLOGID_CURRENT_SITE;
   295 		}
   309 		}
   302 			$current_blog = get_site_by_path( $domain, $path, 1 + count( explode( '/', trim( $current_site->path, '/' ) ) ) );
   316 			$current_blog = get_site_by_path( $domain, $path, 1 + count( explode( '/', trim( $current_site->path, '/' ) ) ) );
   303 		} else {
   317 		} else {
   304 			// Otherwise, use the first path segment (as usual).
   318 			// Otherwise, use the first path segment (as usual).
   305 			$current_blog = get_site_by_path( $domain, $path, 1 );
   319 			$current_blog = get_site_by_path( $domain, $path, 1 );
   306 		}
   320 		}
   307 
       
   308 	} elseif ( ! $subdomain ) {
   321 	} elseif ( ! $subdomain ) {
   309 		/*
   322 		/*
   310 		 * A "subdomain" installation can be re-interpreted to mean "can support any domain".
   323 		 * A "subdomain" installation can be re-interpreted to mean "can support any domain".
   311 		 * If we're not dealing with one of these installations, then the important part is determining
   324 		 * If we're not dealing with one of these installations, then the important part is determining
   312 		 * the network first, because we need the network's path to identify any sites.
   325 		 * the network first, because we need the network's path to identify any sites.
   372 		return false;
   385 		return false;
   373 	}
   386 	}
   374 
   387 
   375 	// During activation of a new subdomain, the requested site does not yet exist.
   388 	// During activation of a new subdomain, the requested site does not yet exist.
   376 	if ( empty( $current_blog ) && wp_installing() ) {
   389 	if ( empty( $current_blog ) && wp_installing() ) {
   377 		$current_blog = new stdClass;
   390 		$current_blog          = new stdClass;
   378 		$current_blog->blog_id = $blog_id = 1;
   391 		$current_blog->blog_id = $blog_id = 1;
   379 		$current_blog->public = 1;
   392 		$current_blog->public  = 1;
   380 	}
   393 	}
   381 
   394 
   382 	// No site has been found, bail.
   395 	// No site has been found, bail.
   383 	if ( empty( $current_blog ) ) {
   396 	if ( empty( $current_blog ) ) {
   384 		// We're going to redirect to the network URL, with some possible modifications.
   397 		// We're going to redirect to the network URL, with some possible modifications.
   385 		$scheme = is_ssl() ? 'https' : 'http';
   398 		$scheme      = is_ssl() ? 'https' : 'http';
   386 		$destination = "$scheme://{$current_site->domain}{$current_site->path}";
   399 		$destination = "$scheme://{$current_site->domain}{$current_site->path}";
   387 
   400 
   388 		/**
   401 		/**
   389 		 * Fires when a network can be determined but a site cannot.
   402 		 * Fires when a network can be determined but a site cannot.
   390 		 *
   403 		 *
   452 
   465 
   453 	wp_load_translations_early();
   466 	wp_load_translations_early();
   454 
   467 
   455 	$title = __( 'Error establishing a database connection' );
   468 	$title = __( 'Error establishing a database connection' );
   456 
   469 
   457 	$msg  = '<h1>' . $title . '</h1>';
   470 	$msg   = '<h1>' . $title . '</h1>';
   458 	$msg .= '<p>' . __( 'If your site does not display, please contact the owner of this network.' ) . '';
   471 	$msg  .= '<p>' . __( 'If your site does not display, please contact the owner of this network.' ) . '';
   459 	$msg .= ' ' . __( 'If you are the owner of this network please check that MySQL is running properly and all tables are error free.' ) . '</p>';
   472 	$msg  .= ' ' . __( 'If you are the owner of this network please check that MySQL is running properly and all tables are error free.' ) . '</p>';
   460 	$query = $wpdb->prepare( "SHOW TABLES LIKE %s", $wpdb->esc_like( $wpdb->site ) );
   473 	$query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $wpdb->site ) );
   461 	if ( ! $wpdb->get_var( $query ) ) {
   474 	if ( ! $wpdb->get_var( $query ) ) {
   462 		$msg .= '<p>' . sprintf(
   475 		$msg .= '<p>' . sprintf(
   463 			/* translators: %s: table name */
   476 			/* translators: %s: table name */
   464 			__( '<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.' ),
   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.' ),
   465 			'<code>' . $wpdb->site . '</code>'
   478 			'<code>' . $wpdb->site . '</code>'
   473 			'<code>' . DB_NAME . '</code>'
   486 			'<code>' . DB_NAME . '</code>'
   474 		) . '</p>';
   487 		) . '</p>';
   475 	}
   488 	}
   476 	$msg .= '<p><strong>' . __( 'What do I do now?' ) . '</strong> ';
   489 	$msg .= '<p><strong>' . __( 'What do I do now?' ) . '</strong> ';
   477 	/* translators: %s: Codex URL */
   490 	/* translators: %s: Codex URL */
   478 	$msg .= sprintf( __( 'Read the <a href="%s" target="_blank">bug report</a> page. Some of the guidelines there may help you figure out what went wrong.' ),
   491 	$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.' ),
   479 		__( 'https://codex.wordpress.org/Debugging_a_WordPress_Network' )
   493 		__( 'https://codex.wordpress.org/Debugging_a_WordPress_Network' )
   480 	);
   494 	);
   481 	$msg .= ' ' . __( 'If you&#8217;re still stuck with this message, then check that your database contains the following tables:' ) . '</p><ul>';
   495 	$msg .= ' ' . __( 'If you&#8217;re still stuck with this message, then check that your database contains the following tables:' ) . '</p><ul>';
   482 	foreach ( $wpdb->tables('global') as $t => $table ) {
   496 	foreach ( $wpdb->tables( 'global' ) as $t => $table ) {
   483 		if ( 'sitecategories' == $t )
   497 		if ( 'sitecategories' == $t ) {
   484 			continue;
   498 			continue;
       
   499 		}
   485 		$msg .= '<li>' . $table . '</li>';
   500 		$msg .= '<li>' . $table . '</li>';
   486 	}
   501 	}
   487 	$msg .= '</ul>';
   502 	$msg .= '</ul>';
   488 
   503 
   489 	wp_die( $msg, $title, array( 'response' => 500 ) );
   504 	wp_die( $msg, $title, array( 'response' => 500 ) );