|
1 <?php |
|
2 /** |
|
3 * These functions are needed to load Multisite. |
|
4 * |
|
5 * @since 3.0.0 |
|
6 * |
|
7 * @package WordPress |
|
8 * @subpackage Multisite |
|
9 */ |
|
10 |
|
11 /** |
|
12 * Whether a subdomain configuration is enabled. |
|
13 * |
|
14 * @since 3.0.0 |
|
15 * |
|
16 * @return bool True if subdomain configuration is enabled, false otherwise. |
|
17 */ |
|
18 function is_subdomain_install() { |
|
19 if ( defined('SUBDOMAIN_INSTALL') ) |
|
20 return SUBDOMAIN_INSTALL; |
|
21 |
|
22 if ( defined('VHOST') && VHOST == 'yes' ) |
|
23 return true; |
|
24 |
|
25 return false; |
|
26 } |
|
27 |
|
28 /** |
|
29 * Returns array of network plugin files to be included in global scope. |
|
30 * |
|
31 * The default directory is wp-content/plugins. To change the default directory |
|
32 * manually, define <code>WP_PLUGIN_DIR</code> and <code>WP_PLUGIN_URL</code> |
|
33 * in wp-config.php. |
|
34 * |
|
35 * @access private |
|
36 * @since 3.1.0 |
|
37 * @return array Files to include |
|
38 */ |
|
39 function wp_get_active_network_plugins() { |
|
40 $active_plugins = (array) get_site_option( 'active_sitewide_plugins', array() ); |
|
41 if ( empty( $active_plugins ) ) |
|
42 return array(); |
|
43 |
|
44 $plugins = array(); |
|
45 $active_plugins = array_keys( $active_plugins ); |
|
46 sort( $active_plugins ); |
|
47 |
|
48 foreach ( $active_plugins as $plugin ) { |
|
49 if ( ! validate_file( $plugin ) // $plugin must validate as file |
|
50 && '.php' == substr( $plugin, -4 ) // $plugin must end with '.php' |
|
51 && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist |
|
52 ) |
|
53 $plugins[] = WP_PLUGIN_DIR . '/' . $plugin; |
|
54 } |
|
55 return $plugins; |
|
56 } |
|
57 |
|
58 /** |
|
59 * Checks status of current blog. |
|
60 * |
|
61 * Checks if the blog is deleted, inactive, archived, or spammed. |
|
62 * |
|
63 * Dies with a default message if the blog does not pass the check. |
|
64 * |
|
65 * To change the default message when a blog does not pass the check, |
|
66 * use the wp-content/blog-deleted.php, blog-inactive.php and |
|
67 * blog-suspended.php drop-ins. |
|
68 * |
|
69 * @return bool|string Returns true on success, or drop-in file to include. |
|
70 */ |
|
71 function ms_site_check() { |
|
72 global $wpdb, $current_site; |
|
73 |
|
74 $blog = get_blog_details(); |
|
75 |
|
76 /** |
|
77 * Filter checking the status of the current blog. |
|
78 * |
|
79 * @since 1.2.1 |
|
80 * |
|
81 * @param bool null Whether to skip the blog status check. Default null. |
|
82 */ |
|
83 $check = apply_filters( 'ms_site_check', null ); |
|
84 if ( null !== $check ) |
|
85 return true; |
|
86 |
|
87 // Allow super admins to see blocked sites |
|
88 if ( is_super_admin() ) |
|
89 return true; |
|
90 |
|
91 if ( '1' == $blog->deleted ) { |
|
92 if ( file_exists( WP_CONTENT_DIR . '/blog-deleted.php' ) ) |
|
93 return WP_CONTENT_DIR . '/blog-deleted.php'; |
|
94 else |
|
95 wp_die( __( 'This user has elected to delete their account and the content is no longer available.' ), '', array( 'response' => 410 ) ); |
|
96 } |
|
97 |
|
98 if ( '2' == $blog->deleted ) { |
|
99 if ( file_exists( WP_CONTENT_DIR . '/blog-inactive.php' ) ) |
|
100 return WP_CONTENT_DIR . '/blog-inactive.php'; |
|
101 else |
|
102 wp_die( sprintf( __( 'This site has not been activated yet. If you are having problems activating your site, please contact <a href="mailto:%1$s">%1$s</a>.' ), str_replace( '@', ' AT ', get_site_option( 'admin_email', "support@{$current_site->domain}" ) ) ) ); |
|
103 } |
|
104 |
|
105 if ( $blog->archived == '1' || $blog->spam == '1' ) { |
|
106 if ( file_exists( WP_CONTENT_DIR . '/blog-suspended.php' ) ) |
|
107 return WP_CONTENT_DIR . '/blog-suspended.php'; |
|
108 else |
|
109 wp_die( __( 'This site has been archived or suspended.' ), '', array( 'response' => 410 ) ); |
|
110 } |
|
111 |
|
112 return true; |
|
113 } |
|
114 |
|
115 /** |
|
116 * Sets current site name. |
|
117 * |
|
118 * @access private |
|
119 * @since 3.0.0 |
|
120 * @return object $current_site object with site_name |
|
121 */ |
|
122 function get_current_site_name( $current_site ) { |
|
123 global $wpdb; |
|
124 |
|
125 $current_site->site_name = wp_cache_get( $current_site->id . ':site_name', 'site-options' ); |
|
126 if ( ! $current_site->site_name ) { |
|
127 $current_site->site_name = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = %d AND meta_key = 'site_name'", $current_site->id ) ); |
|
128 if ( ! $current_site->site_name ) |
|
129 $current_site->site_name = ucfirst( $current_site->domain ); |
|
130 wp_cache_set( $current_site->id . ':site_name', $current_site->site_name, 'site-options' ); |
|
131 } |
|
132 |
|
133 return $current_site; |
|
134 } |
|
135 |
|
136 /** |
|
137 * Sets current_site object. |
|
138 * |
|
139 * @access private |
|
140 * @since 3.0.0 |
|
141 * @return object $current_site object |
|
142 */ |
|
143 function wpmu_current_site() { |
|
144 global $wpdb, $current_site, $domain, $path, $sites, $cookie_domain; |
|
145 |
|
146 if ( empty( $current_site ) ) |
|
147 $current_site = new stdClass; |
|
148 |
|
149 if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) { |
|
150 $current_site->id = defined( 'SITE_ID_CURRENT_SITE' ) ? SITE_ID_CURRENT_SITE : 1; |
|
151 $current_site->domain = DOMAIN_CURRENT_SITE; |
|
152 $current_site->path = $path = PATH_CURRENT_SITE; |
|
153 if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) |
|
154 $current_site->blog_id = BLOG_ID_CURRENT_SITE; |
|
155 elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) // deprecated. |
|
156 $current_site->blog_id = BLOGID_CURRENT_SITE; |
|
157 if ( DOMAIN_CURRENT_SITE == $domain ) |
|
158 $current_site->cookie_domain = $cookie_domain; |
|
159 elseif ( substr( $current_site->domain, 0, 4 ) == 'www.' ) |
|
160 $current_site->cookie_domain = substr( $current_site->domain, 4 ); |
|
161 else |
|
162 $current_site->cookie_domain = $current_site->domain; |
|
163 |
|
164 wp_load_core_site_options( $current_site->id ); |
|
165 |
|
166 return $current_site; |
|
167 } |
|
168 |
|
169 $current_site = wp_cache_get( 'current_site', 'site-options' ); |
|
170 if ( $current_site ) |
|
171 return $current_site; |
|
172 |
|
173 $sites = $wpdb->get_results( "SELECT * FROM $wpdb->site" ); // usually only one site |
|
174 if ( 1 == count( $sites ) ) { |
|
175 $current_site = $sites[0]; |
|
176 wp_load_core_site_options( $current_site->id ); |
|
177 $path = $current_site->path; |
|
178 $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 ) ); |
|
179 $current_site = get_current_site_name( $current_site ); |
|
180 if ( substr( $current_site->domain, 0, 4 ) == 'www.' ) |
|
181 $current_site->cookie_domain = substr( $current_site->domain, 4 ); |
|
182 wp_cache_set( 'current_site', $current_site, 'site-options' ); |
|
183 return $current_site; |
|
184 } |
|
185 $path = substr( $_SERVER[ 'REQUEST_URI' ], 0, 1 + strpos( $_SERVER[ 'REQUEST_URI' ], '/', 1 ) ); |
|
186 |
|
187 if ( $domain == $cookie_domain ) |
|
188 $current_site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path ) ); |
|
189 else |
|
190 $current_site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->site WHERE domain IN ( %s, %s ) AND path = %s ORDER BY CHAR_LENGTH( domain ) DESC LIMIT 1", $domain, $cookie_domain, $path ) ); |
|
191 |
|
192 if ( ! $current_site ) { |
|
193 if ( $domain == $cookie_domain ) |
|
194 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain ) ); |
|
195 else |
|
196 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain IN ( %s, %s ) AND path = '/' ORDER BY CHAR_LENGTH( domain ) DESC LIMIT 1", $domain, $cookie_domain, $path ) ); |
|
197 } |
|
198 |
|
199 if ( $current_site ) { |
|
200 $path = $current_site->path; |
|
201 $current_site->cookie_domain = $cookie_domain; |
|
202 return $current_site; |
|
203 } |
|
204 |
|
205 if ( is_subdomain_install() ) { |
|
206 $sitedomain = substr( $domain, 1 + strpos( $domain, '.' ) ); |
|
207 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path) ); |
|
208 if ( $current_site ) { |
|
209 $current_site->cookie_domain = $current_site->domain; |
|
210 return $current_site; |
|
211 } |
|
212 |
|
213 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $sitedomain) ); |
|
214 } |
|
215 |
|
216 if ( $current_site || defined( 'WP_INSTALLING' ) ) { |
|
217 $path = '/'; |
|
218 return $current_site; |
|
219 } |
|
220 |
|
221 // Still no dice. |
|
222 wp_load_translations_early(); |
|
223 |
|
224 if ( 1 == count( $sites ) ) |
|
225 wp_die( sprintf( __( 'That site does not exist. Please try <a href="%s">%s</a>.' ), 'http://' . $sites[0]->domain . $sites[0]->path ) ); |
|
226 else |
|
227 wp_die( __( 'No site defined on this host. If you are the owner of this site, please check <a href="http://codex.wordpress.org/Debugging_a_WordPress_Network">Debugging a WordPress Network</a> for help.' ) ); |
|
228 } |
|
229 |
|
230 /** |
|
231 * Displays a failure message. |
|
232 * |
|
233 * Used when a blog's tables do not exist. Checks for a missing $wpdb->site table as well. |
|
234 * |
|
235 * @access private |
|
236 * @since 3.0.0 |
|
237 */ |
|
238 function ms_not_installed() { |
|
239 global $wpdb, $domain, $path; |
|
240 |
|
241 wp_load_translations_early(); |
|
242 |
|
243 $title = __( 'Error establishing a database connection' ); |
|
244 $msg = '<h1>' . $title . '</h1>'; |
|
245 if ( ! is_admin() ) |
|
246 die( $msg ); |
|
247 $msg .= '<p>' . __( 'If your site does not display, please contact the owner of this network.' ) . ''; |
|
248 $msg .= ' ' . __( 'If you are the owner of this network please check that MySQL is running properly and all tables are error free.' ) . '</p>'; |
|
249 if ( ! $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->site'" ) ) |
|
250 $msg .= '<p>' . sprintf( __( '<strong>Database tables are missing.</strong> This means that MySQL is not running, WordPress was not installed properly, or someone deleted <code>%s</code>. You really should look at your database now.' ), $wpdb->site ) . '</p>'; |
|
251 else |
|
252 $msg .= '<p>' . sprintf( __( '<strong>Could not find site <code>%1$s</code>.</strong> Searched for table <code>%2$s</code> in database <code>%3$s</code>. Is that right?' ), rtrim( $domain . $path, '/' ), $wpdb->blogs, DB_NAME ) . '</p>'; |
|
253 $msg .= '<p><strong>' . __( 'What do I do now?' ) . '</strong> '; |
|
254 $msg .= __( 'Read the <a target="_blank" href="http://codex.wordpress.org/Debugging_a_WordPress_Network">bug report</a> page. Some of the guidelines there may help you figure out what went wrong.' ); |
|
255 $msg .= ' ' . __( 'If you’re still stuck with this message, then check that your database contains the following tables:' ) . '</p><ul>'; |
|
256 foreach ( $wpdb->tables('global') as $t => $table ) { |
|
257 if ( 'sitecategories' == $t ) |
|
258 continue; |
|
259 $msg .= '<li>' . $table . '</li>'; |
|
260 } |
|
261 $msg .= '</ul>'; |
|
262 |
|
263 wp_die( $msg, $title ); |
|
264 } |