10 /** |
10 /** |
11 * Gets the network's site and user counts. |
11 * Gets the network's site and user counts. |
12 * |
12 * |
13 * @since MU (3.0.0) |
13 * @since MU (3.0.0) |
14 * |
14 * |
15 * @return array Site and user count for the network. |
15 * @return int[] { |
|
16 * Site and user count for the network. |
|
17 * |
|
18 * @type int $blogs Number of sites on the network. |
|
19 * @type int $users Number of users on the network. |
|
20 * } |
16 */ |
21 */ |
17 function get_sitestats() { |
22 function get_sitestats() { |
18 $stats = array( |
23 $stats = array( |
19 'blogs' => get_blog_count(), |
24 'blogs' => get_blog_count(), |
20 'users' => get_user_count(), |
25 'users' => get_user_count(), |
55 $primary = get_site( $first_blog->userblog_id ); |
60 $primary = get_site( $first_blog->userblog_id ); |
56 } else { |
61 } else { |
57 $primary = get_site( $primary_blog ); |
62 $primary = get_site( $primary_blog ); |
58 } |
63 } |
59 } else { |
64 } else { |
60 //TODO Review this call to add_user_to_blog too - to get here the user must have a role on this blog? |
65 // TODO: Review this call to add_user_to_blog too - to get here the user must have a role on this blog? |
61 $result = add_user_to_blog( $first_blog->userblog_id, $user_id, 'subscriber' ); |
66 $result = add_user_to_blog( $first_blog->userblog_id, $user_id, 'subscriber' ); |
62 |
67 |
63 if ( ! is_wp_error( $result ) ) { |
68 if ( ! is_wp_error( $result ) ) { |
64 update_user_meta( $user_id, 'primary_blog', $first_blog->userblog_id ); |
69 update_user_meta( $user_id, 'primary_blog', $first_blog->userblog_id ); |
65 $primary = $first_blog; |
70 $primary = $first_blog; |
66 } |
71 } |
67 } |
72 } |
68 |
73 |
69 if ( ( ! is_object( $primary ) ) || ( $primary->archived == 1 || $primary->spam == 1 || $primary->deleted == 1 ) ) { |
74 if ( ( ! is_object( $primary ) ) || ( 1 == $primary->archived || 1 == $primary->spam || 1 == $primary->deleted ) ) { |
70 $blogs = get_blogs_of_user( $user_id, true ); // if a user's primary blog is shut down, check their other blogs. |
75 $blogs = get_blogs_of_user( $user_id, true ); // If a user's primary blog is shut down, check their other blogs. |
71 $ret = false; |
76 $ret = false; |
72 if ( is_array( $blogs ) && count( $blogs ) > 0 ) { |
77 if ( is_array( $blogs ) && count( $blogs ) > 0 ) { |
73 foreach ( (array) $blogs as $blog_id => $blog ) { |
78 foreach ( (array) $blogs as $blog_id => $blog ) { |
74 if ( $blog->site_id != get_current_network_id() ) { |
79 if ( get_current_network_id() != $blog->site_id ) { |
75 continue; |
80 continue; |
76 } |
81 } |
77 $details = get_site( $blog_id ); |
82 $details = get_site( $blog_id ); |
78 if ( is_object( $details ) && $details->archived == 0 && $details->spam == 0 && $details->deleted == 0 ) { |
83 if ( is_object( $details ) && 0 == $details->archived && 0 == $details->spam && 0 == $details->deleted ) { |
79 $ret = $details; |
84 $ret = $details; |
80 if ( get_user_meta( $user_id, 'primary_blog', true ) != $blog_id ) { |
85 if ( get_user_meta( $user_id, 'primary_blog', true ) != $blog_id ) { |
81 update_user_meta( $user_id, 'primary_blog', $blog_id ); |
86 update_user_meta( $user_id, 'primary_blog', $blog_id ); |
82 } |
87 } |
83 if ( ! get_user_meta( $user_id, 'source_domain', true ) ) { |
88 if ( ! get_user_meta( $user_id, 'source_domain', true ) ) { |
125 function get_blog_count( $network_id = null ) { |
130 function get_blog_count( $network_id = null ) { |
126 return get_network_option( $network_id, 'blog_count' ); |
131 return get_network_option( $network_id, 'blog_count' ); |
127 } |
132 } |
128 |
133 |
129 /** |
134 /** |
130 * Get a blog post from any site on the network. |
135 * Gets a blog post from any site on the network. |
|
136 * |
|
137 * This function is similar to get_post(), except that it can retrieve a post |
|
138 * from any site on the network, not just the current site. |
131 * |
139 * |
132 * @since MU (3.0.0) |
140 * @since MU (3.0.0) |
133 * |
141 * |
134 * @param int $blog_id ID of the blog. |
142 * @param int $blog_id ID of the blog. |
135 * @param int $post_id ID of the post you're looking for. |
143 * @param int $post_id ID of the post being looked for. |
136 * @return WP_Post|null WP_Post on success or null on failure |
144 * @return WP_Post|null WP_Post object on success, null on failure |
137 */ |
145 */ |
138 function get_blog_post( $blog_id, $post_id ) { |
146 function get_blog_post( $blog_id, $post_id ) { |
139 switch_to_blog( $blog_id ); |
147 switch_to_blog( $blog_id ); |
140 $post = get_post( $post_id ); |
148 $post = get_post( $post_id ); |
141 restore_current_blog(); |
149 restore_current_blog(); |
142 |
150 |
143 return $post; |
151 return $post; |
144 } |
152 } |
145 |
153 |
146 /** |
154 /** |
147 * Adds a user to a blog. |
155 * Adds a user to a blog, along with specifying the user's role. |
148 * |
156 * |
149 * Use the {@see 'add_user_to_blog'} action to fire an event when users are added to a blog. |
157 * Use the {@see 'add_user_to_blog'} action to fire an event when users are added to a blog. |
150 * |
158 * |
151 * @since MU (3.0.0) |
159 * @since MU (3.0.0) |
152 * |
160 * |
153 * @param int $blog_id ID of the blog you're adding the user to. |
161 * @param int $blog_id ID of the blog the user is being added to. |
154 * @param int $user_id ID of the user you're adding. |
162 * @param int $user_id ID of the user being added. |
155 * @param string $role The role you want the user to have |
163 * @param string $role The role you want the user to have. |
156 * @return true|WP_Error |
164 * @return true|WP_Error True on success or a WP_Error object if the user doesn't exist |
|
165 * or could not be added. |
157 */ |
166 */ |
158 function add_user_to_blog( $blog_id, $user_id, $role ) { |
167 function add_user_to_blog( $blog_id, $user_id, $role ) { |
159 switch_to_blog( $blog_id ); |
168 switch_to_blog( $blog_id ); |
160 |
169 |
161 $user = get_userdata( $user_id ); |
170 $user = get_userdata( $user_id ); |
168 /** |
177 /** |
169 * Filters whether a user should be added to a site. |
178 * Filters whether a user should be added to a site. |
170 * |
179 * |
171 * @since 4.9.0 |
180 * @since 4.9.0 |
172 * |
181 * |
173 * @param bool|WP_Error $retval True if the user should be added to the site, false |
182 * @param true|WP_Error $retval True if the user should be added to the site, error |
174 * or error object otherwise. |
183 * object otherwise. |
175 * @param int $user_id User ID. |
184 * @param int $user_id User ID. |
176 * @param string $role User role. |
185 * @param string $role User role. |
177 * @param int $blog_id Site ID. |
186 * @param int $blog_id Site ID. |
178 */ |
187 */ |
179 $can_add_user = apply_filters( 'can_add_user_to_blog', true, $user_id, $role, $blog_id ); |
188 $can_add_user = apply_filters( 'can_add_user_to_blog', true, $user_id, $role, $blog_id ); |
204 * @param int $user_id User ID. |
213 * @param int $user_id User ID. |
205 * @param string $role User role. |
214 * @param string $role User role. |
206 * @param int $blog_id Blog ID. |
215 * @param int $blog_id Blog ID. |
207 */ |
216 */ |
208 do_action( 'add_user_to_blog', $user_id, $role, $blog_id ); |
217 do_action( 'add_user_to_blog', $user_id, $role, $blog_id ); |
209 wp_cache_delete( $user_id, 'users' ); |
218 |
|
219 clean_user_cache( $user_id ); |
210 wp_cache_delete( $blog_id . '_user_count', 'blog-details' ); |
220 wp_cache_delete( $blog_id . '_user_count', 'blog-details' ); |
|
221 |
211 restore_current_blog(); |
222 restore_current_blog(); |
|
223 |
212 return true; |
224 return true; |
213 } |
225 } |
214 |
226 |
215 /** |
227 /** |
216 * Remove a user from a blog. |
228 * Remove a user from a blog. |
223 * |
235 * |
224 * @since MU (3.0.0) |
236 * @since MU (3.0.0) |
225 * |
237 * |
226 * @global wpdb $wpdb WordPress database abstraction object. |
238 * @global wpdb $wpdb WordPress database abstraction object. |
227 * |
239 * |
228 * @param int $user_id ID of the user you're removing. |
240 * @param int $user_id ID of the user being removed. |
229 * @param int $blog_id ID of the blog you're removing the user from. |
241 * @param int $blog_id Optional. ID of the blog the user is being removed from. Default 0. |
230 * @param string $reassign Optional. A user to whom to reassign posts. |
242 * @param int $reassign Optional. ID of the user to whom to reassign posts. Default 0. |
231 * @return true|WP_Error |
243 * @return true|WP_Error True on success or a WP_Error object if the user doesn't exist. |
232 */ |
244 */ |
233 function remove_user_from_blog( $user_id, $blog_id = '', $reassign = '' ) { |
245 function remove_user_from_blog( $user_id, $blog_id = 0, $reassign = 0 ) { |
234 global $wpdb; |
246 global $wpdb; |
|
247 |
235 switch_to_blog( $blog_id ); |
248 switch_to_blog( $blog_id ); |
236 $user_id = (int) $user_id; |
249 $user_id = (int) $user_id; |
|
250 |
237 /** |
251 /** |
238 * Fires before a user is removed from a site. |
252 * Fires before a user is removed from a site. |
239 * |
253 * |
240 * @since MU (3.0.0) |
254 * @since MU (3.0.0) |
241 * |
255 * @since 5.4.0 Added the `$reassign` parameter. |
242 * @param int $user_id User ID. |
256 * |
243 * @param int $blog_id Blog ID. |
257 * @param int $user_id ID of the user being removed. |
244 */ |
258 * @param int $blog_id ID of the blog the user is being removed from. |
245 do_action( 'remove_user_from_blog', $user_id, $blog_id ); |
259 * @param int $reassign ID of the user to whom to reassign posts. |
246 |
260 */ |
247 // If being removed from the primary blog, set a new primary if the user is assigned |
261 do_action( 'remove_user_from_blog', $user_id, $blog_id, $reassign ); |
248 // to multiple blogs. |
262 |
|
263 // If being removed from the primary blog, set a new primary |
|
264 // if the user is assigned to multiple blogs. |
249 $primary_blog = get_user_meta( $user_id, 'primary_blog', true ); |
265 $primary_blog = get_user_meta( $user_id, 'primary_blog', true ); |
250 if ( $primary_blog == $blog_id ) { |
266 if ( $primary_blog == $blog_id ) { |
251 $new_id = ''; |
267 $new_id = ''; |
252 $new_domain = ''; |
268 $new_domain = ''; |
253 $blogs = get_blogs_of_user( $user_id ); |
269 $blogs = get_blogs_of_user( $user_id ); |
262 |
278 |
263 update_user_meta( $user_id, 'primary_blog', $new_id ); |
279 update_user_meta( $user_id, 'primary_blog', $new_id ); |
264 update_user_meta( $user_id, 'source_domain', $new_domain ); |
280 update_user_meta( $user_id, 'source_domain', $new_domain ); |
265 } |
281 } |
266 |
282 |
267 // wp_revoke_user($user_id); |
283 // wp_revoke_user( $user_id ); |
268 $user = get_userdata( $user_id ); |
284 $user = get_userdata( $user_id ); |
269 if ( ! $user ) { |
285 if ( ! $user ) { |
270 restore_current_blog(); |
286 restore_current_blog(); |
271 return new WP_Error( 'user_does_not_exist', __( 'That user does not exist.' ) ); |
287 return new WP_Error( 'user_does_not_exist', __( 'That user does not exist.' ) ); |
272 } |
288 } |
277 if ( count( $blogs ) == 0 ) { |
293 if ( count( $blogs ) == 0 ) { |
278 update_user_meta( $user_id, 'primary_blog', '' ); |
294 update_user_meta( $user_id, 'primary_blog', '' ); |
279 update_user_meta( $user_id, 'source_domain', '' ); |
295 update_user_meta( $user_id, 'source_domain', '' ); |
280 } |
296 } |
281 |
297 |
282 if ( $reassign != '' ) { |
298 if ( $reassign ) { |
283 $reassign = (int) $reassign; |
299 $reassign = (int) $reassign; |
284 $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $user_id ) ); |
300 $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $user_id ) ); |
285 $link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $user_id ) ); |
301 $link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $user_id ) ); |
286 |
302 |
287 if ( ! empty( $post_ids ) ) { |
303 if ( ! empty( $post_ids ) ) { |
336 function get_blog_id_from_url( $domain, $path = '/' ) { |
352 function get_blog_id_from_url( $domain, $path = '/' ) { |
337 $domain = strtolower( $domain ); |
353 $domain = strtolower( $domain ); |
338 $path = strtolower( $path ); |
354 $path = strtolower( $path ); |
339 $id = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' ); |
355 $id = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' ); |
340 |
356 |
341 if ( $id == -1 ) { // blog does not exist |
357 if ( -1 == $id ) { // Blog does not exist. |
342 return 0; |
358 return 0; |
343 } elseif ( $id ) { |
359 } elseif ( $id ) { |
344 return (int) $id; |
360 return (int) $id; |
345 } |
361 } |
346 |
362 |
375 * bypasses this check. |
393 * bypasses this check. |
376 * |
394 * |
377 * @since MU (3.0.0) |
395 * @since MU (3.0.0) |
378 * |
396 * |
379 * @param string $user_email The email provided by the user at registration. |
397 * @param string $user_email The email provided by the user at registration. |
380 * @return bool Returns true when the email address is banned. |
398 * @return bool True when the email address is banned, false otherwise. |
381 */ |
399 */ |
382 function is_email_address_unsafe( $user_email ) { |
400 function is_email_address_unsafe( $user_email ) { |
383 $banned_names = get_site_option( 'banned_email_domains' ); |
401 $banned_names = get_site_option( 'banned_email_domains' ); |
384 if ( $banned_names && ! is_array( $banned_names ) ) { |
402 if ( $banned_names && ! is_array( $banned_names ) ) { |
385 $banned_names = explode( "\n", $banned_names ); |
403 $banned_names = explode( "\n", $banned_names ); |
424 |
442 |
425 /** |
443 /** |
426 * Sanitize and validate data required for a user sign-up. |
444 * Sanitize and validate data required for a user sign-up. |
427 * |
445 * |
428 * Verifies the validity and uniqueness of user names and user email addresses, |
446 * Verifies the validity and uniqueness of user names and user email addresses, |
429 * and checks email addresses against admin-provided domain whitelists and blacklists. |
447 * and checks email addresses against allowed and disallowed domains provided by |
|
448 * administrators. |
430 * |
449 * |
431 * The {@see 'wpmu_validate_user_signup'} hook provides an easy way to modify the sign-up |
450 * The {@see 'wpmu_validate_user_signup'} hook provides an easy way to modify the sign-up |
432 * process. The value $result, which is passed to the hook, contains both the user-provided |
451 * process. The value $result, which is passed to the hook, contains both the user-provided |
433 * info and the error messages created by the function. {@see 'wpmu_validate_user_signup'} |
452 * info and the error messages created by the function. {@see 'wpmu_validate_user_signup'} |
434 * allows you to process the data in any way you'd like, and unset the relevant errors if |
453 * allows you to process the data in any way you'd like, and unset the relevant errors if |
438 * |
457 * |
439 * @global wpdb $wpdb WordPress database abstraction object. |
458 * @global wpdb $wpdb WordPress database abstraction object. |
440 * |
459 * |
441 * @param string $user_name The login name provided by the user. |
460 * @param string $user_name The login name provided by the user. |
442 * @param string $user_email The email provided by the user. |
461 * @param string $user_email The email provided by the user. |
443 * @return array Contains username, email, and error messages. |
462 * @return array { |
|
463 * The array of user name, email, and the error messages. |
|
464 * |
|
465 * @type string $user_name Sanitized and unique username. |
|
466 * @type string $orig_username Original username. |
|
467 * @type string $user_email User email address. |
|
468 * @type WP_Error $errors WP_Error object containing any errors found. |
|
469 * } |
444 */ |
470 */ |
445 function wpmu_validate_user_signup( $user_name, $user_email ) { |
471 function wpmu_validate_user_signup( $user_name, $user_email ) { |
446 global $wpdb; |
472 global $wpdb; |
447 |
473 |
448 $errors = new WP_Error(); |
474 $errors = new WP_Error(); |
464 $illegal_names = get_site_option( 'illegal_names' ); |
490 $illegal_names = get_site_option( 'illegal_names' ); |
465 if ( ! is_array( $illegal_names ) ) { |
491 if ( ! is_array( $illegal_names ) ) { |
466 $illegal_names = array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' ); |
492 $illegal_names = array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' ); |
467 add_site_option( 'illegal_names', $illegal_names ); |
493 add_site_option( 'illegal_names', $illegal_names ); |
468 } |
494 } |
469 if ( in_array( $user_name, $illegal_names ) ) { |
495 if ( in_array( $user_name, $illegal_names, true ) ) { |
470 $errors->add( 'user_name', __( 'Sorry, that username is not allowed.' ) ); |
496 $errors->add( 'user_name', __( 'Sorry, that username is not allowed.' ) ); |
471 } |
497 } |
472 |
498 |
473 /** This filter is documented in wp-includes/user.php */ |
499 /** This filter is documented in wp-includes/user.php */ |
474 $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
500 $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
475 |
501 |
476 if ( in_array( strtolower( $user_name ), array_map( 'strtolower', $illegal_logins ) ) ) { |
502 if ( in_array( strtolower( $user_name ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
477 $errors->add( 'user_name', __( 'Sorry, that username is not allowed.' ) ); |
503 $errors->add( 'user_name', __( 'Sorry, that username is not allowed.' ) ); |
478 } |
504 } |
479 |
505 |
480 if ( ! is_email( $user_email ) ) { |
506 if ( ! is_email( $user_email ) ) { |
481 $errors->add( 'user_email', __( 'Please enter a valid email address.' ) ); |
507 $errors->add( 'user_email', __( 'Please enter a valid email address.' ) ); |
489 |
515 |
490 if ( strlen( $user_name ) > 60 ) { |
516 if ( strlen( $user_name ) > 60 ) { |
491 $errors->add( 'user_name', __( 'Username may not be longer than 60 characters.' ) ); |
517 $errors->add( 'user_name', __( 'Username may not be longer than 60 characters.' ) ); |
492 } |
518 } |
493 |
519 |
494 // all numeric? |
520 // All numeric? |
495 if ( preg_match( '/^[0-9]*$/', $user_name ) ) { |
521 if ( preg_match( '/^[0-9]*$/', $user_name ) ) { |
496 $errors->add( 'user_name', __( 'Sorry, usernames must have letters too!' ) ); |
522 $errors->add( 'user_name', __( 'Sorry, usernames must have letters too!' ) ); |
497 } |
523 } |
498 |
524 |
499 $limited_email_domains = get_site_option( 'limited_email_domains' ); |
525 $limited_email_domains = get_site_option( 'limited_email_domains' ); |
515 $errors->add( 'user_email', __( 'Sorry, that email address is already used!' ) ); |
541 $errors->add( 'user_email', __( 'Sorry, that email address is already used!' ) ); |
516 } |
542 } |
517 |
543 |
518 // Has someone already signed up for this username? |
544 // Has someone already signed up for this username? |
519 $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE user_login = %s", $user_name ) ); |
545 $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE user_login = %s", $user_name ) ); |
520 if ( $signup != null ) { |
546 if ( null != $signup ) { |
521 $registered_at = mysql2date( 'U', $signup->registered ); |
547 $registered_at = mysql2date( 'U', $signup->registered ); |
522 $now = time(); |
548 $now = time(); |
523 $diff = $now - $registered_at; |
549 $diff = $now - $registered_at; |
524 // If registered more than two days ago, cancel registration and let this signup go through. |
550 // If registered more than two days ago, cancel registration and let this signup go through. |
525 if ( $diff > 2 * DAY_IN_SECONDS ) { |
551 if ( $diff > 2 * DAY_IN_SECONDS ) { |
528 $errors->add( 'user_name', __( 'That username is currently reserved but may be available in a couple of days.' ) ); |
554 $errors->add( 'user_name', __( 'That username is currently reserved but may be available in a couple of days.' ) ); |
529 } |
555 } |
530 } |
556 } |
531 |
557 |
532 $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE user_email = %s", $user_email ) ); |
558 $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE user_email = %s", $user_email ) ); |
533 if ( $signup != null ) { |
559 if ( null != $signup ) { |
534 $diff = time() - mysql2date( 'U', $signup->registered ); |
560 $diff = time() - mysql2date( 'U', $signup->registered ); |
535 // If registered more than two days ago, cancel registration and let this signup go through. |
561 // If registered more than two days ago, cancel registration and let this signup go through. |
536 if ( $diff > 2 * DAY_IN_SECONDS ) { |
562 if ( $diff > 2 * DAY_IN_SECONDS ) { |
537 $wpdb->delete( $wpdb->signups, array( 'user_email' => $user_email ) ); |
563 $wpdb->delete( $wpdb->signups, array( 'user_email' => $user_email ) ); |
538 } else { |
564 } else { |
554 * registration. The values are solely used for validation and error handling. |
580 * registration. The values are solely used for validation and error handling. |
555 * |
581 * |
556 * @since MU (3.0.0) |
582 * @since MU (3.0.0) |
557 * |
583 * |
558 * @param array $result { |
584 * @param array $result { |
559 * The array of user name, email and the error messages. |
585 * The array of user name, email, and the error messages. |
560 * |
586 * |
561 * @type string $user_name Sanitized and unique username. |
587 * @type string $user_name Sanitized and unique username. |
562 * @type string $orig_username Original username. |
588 * @type string $orig_username Original username. |
563 * @type string $user_email User email address. |
589 * @type string $user_email User email address. |
564 * @type WP_Error $errors WP_Error object containing any errors found. |
590 * @type WP_Error $errors WP_Error object containing any errors found. |
581 * Filter {@see 'wpmu_validate_blog_signup'} if you want to modify |
607 * Filter {@see 'wpmu_validate_blog_signup'} if you want to modify |
582 * the way that WordPress validates new site signups. |
608 * the way that WordPress validates new site signups. |
583 * |
609 * |
584 * @since MU (3.0.0) |
610 * @since MU (3.0.0) |
585 * |
611 * |
586 * @global wpdb $wpdb |
612 * @global wpdb $wpdb WordPress database abstraction object. |
587 * @global string $domain |
613 * @global string $domain |
588 * |
614 * |
589 * @param string $blogname The blog name provided by the user. Must be unique. |
615 * @param string $blogname The blog name provided by the user. Must be unique. |
590 * @param string $blog_title The blog title provided by the user. |
616 * @param string $blog_title The blog title provided by the user. |
591 * @param WP_User|string $user Optional. The user object to check against the new site name. |
617 * @param WP_User|string $user Optional. The user object to check against the new site name. |
592 * @return array Contains the new site data and error messages. |
618 * @return array { |
|
619 * Array of domain, path, blog name, blog title, user and error messages. |
|
620 * |
|
621 * @type string $domain Domain for the site. |
|
622 * @type string $path Path for the site. Used in subdirectory installations. |
|
623 * @type string $blogname The unique site name (slug). |
|
624 * @type string $blog_title Blog title. |
|
625 * @type string|WP_User $user By default, an empty string. A user object if provided. |
|
626 * @type WP_Error $errors WP_Error containing any errors found. |
|
627 * } |
593 */ |
628 */ |
594 function wpmu_validate_blog_signup( $blogname, $blog_title, $user = '' ) { |
629 function wpmu_validate_blog_signup( $blogname, $blog_title, $user = '' ) { |
595 global $wpdb, $domain; |
630 global $wpdb, $domain; |
596 |
631 |
597 $current_network = get_network(); |
632 $current_network = get_network(); |
599 |
634 |
600 $blog_title = strip_tags( $blog_title ); |
635 $blog_title = strip_tags( $blog_title ); |
601 |
636 |
602 $errors = new WP_Error(); |
637 $errors = new WP_Error(); |
603 $illegal_names = get_site_option( 'illegal_names' ); |
638 $illegal_names = get_site_option( 'illegal_names' ); |
604 if ( $illegal_names == false ) { |
639 if ( false == $illegal_names ) { |
605 $illegal_names = array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' ); |
640 $illegal_names = array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' ); |
606 add_site_option( 'illegal_names', $illegal_names ); |
641 add_site_option( 'illegal_names', $illegal_names ); |
607 } |
642 } |
608 |
643 |
609 /* |
644 /* |
620 |
655 |
621 if ( preg_match( '/[^a-z0-9]+/', $blogname ) ) { |
656 if ( preg_match( '/[^a-z0-9]+/', $blogname ) ) { |
622 $errors->add( 'blogname', __( 'Site names can only contain lowercase letters (a-z) and numbers.' ) ); |
657 $errors->add( 'blogname', __( 'Site names can only contain lowercase letters (a-z) and numbers.' ) ); |
623 } |
658 } |
624 |
659 |
625 if ( in_array( $blogname, $illegal_names ) ) { |
660 if ( in_array( $blogname, $illegal_names, true ) ) { |
626 $errors->add( 'blogname', __( 'That name is not allowed.' ) ); |
661 $errors->add( 'blogname', __( 'That name is not allowed.' ) ); |
627 } |
662 } |
628 |
663 |
629 /** |
664 /** |
630 * Filters the minimum site name length required when validating a site signup. |
665 * Filters the minimum site name length required when validating a site signup. |
634 * @param int $length The minimum site name length. Default 4. |
669 * @param int $length The minimum site name length. Default 4. |
635 */ |
670 */ |
636 $minimum_site_name_length = apply_filters( 'minimum_site_name_length', 4 ); |
671 $minimum_site_name_length = apply_filters( 'minimum_site_name_length', 4 ); |
637 |
672 |
638 if ( strlen( $blogname ) < $minimum_site_name_length ) { |
673 if ( strlen( $blogname ) < $minimum_site_name_length ) { |
639 /* translators: %s: minimum site name length */ |
674 /* translators: %s: Minimum site name length. */ |
640 $errors->add( 'blogname', sprintf( _n( 'Site name must be at least %s character.', 'Site name must be at least %s characters.', $minimum_site_name_length ), number_format_i18n( $minimum_site_name_length ) ) ); |
675 $errors->add( 'blogname', sprintf( _n( 'Site name must be at least %s character.', 'Site name must be at least %s characters.', $minimum_site_name_length ), number_format_i18n( $minimum_site_name_length ) ) ); |
641 } |
676 } |
642 |
677 |
643 // do not allow users to create a blog that conflicts with a page on the main blog. |
678 // Do not allow users to create a blog that conflicts with a page on the main blog. |
644 if ( ! is_subdomain_install() && $wpdb->get_var( $wpdb->prepare( 'SELECT post_name FROM ' . $wpdb->get_blog_prefix( $current_network->site_id ) . "posts WHERE post_type = 'page' AND post_name = %s", $blogname ) ) ) { |
679 if ( ! is_subdomain_install() && $wpdb->get_var( $wpdb->prepare( 'SELECT post_name FROM ' . $wpdb->get_blog_prefix( $current_network->site_id ) . "posts WHERE post_type = 'page' AND post_name = %s", $blogname ) ) ) { |
645 $errors->add( 'blogname', __( 'Sorry, you may not use that site name.' ) ); |
680 $errors->add( 'blogname', __( 'Sorry, you may not use that site name.' ) ); |
646 } |
681 } |
647 |
682 |
648 // all numeric? |
683 // All numeric? |
649 if ( preg_match( '/^[0-9]*$/', $blogname ) ) { |
684 if ( preg_match( '/^[0-9]*$/', $blogname ) ) { |
650 $errors->add( 'blogname', __( 'Sorry, site names must have letters too!' ) ); |
685 $errors->add( 'blogname', __( 'Sorry, site names must have letters too!' ) ); |
651 } |
686 } |
652 |
687 |
653 /** |
688 /** |
685 $errors->add( 'blogname', __( 'Sorry, that site is reserved!' ) ); |
720 $errors->add( 'blogname', __( 'Sorry, that site is reserved!' ) ); |
686 } |
721 } |
687 } |
722 } |
688 |
723 |
689 // Has someone already signed up for this domain? |
724 // Has someone already signed up for this domain? |
690 $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE domain = %s AND path = %s", $mydomain, $path ) ); // TODO: Check email too? |
725 // TODO: Check email too? |
|
726 $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE domain = %s AND path = %s", $mydomain, $path ) ); |
691 if ( ! empty( $signup ) ) { |
727 if ( ! empty( $signup ) ) { |
692 $diff = time() - mysql2date( 'U', $signup->registered ); |
728 $diff = time() - mysql2date( 'U', $signup->registered ); |
693 // If registered more than two days ago, cancel registration and let this signup go through. |
729 // If registered more than two days ago, cancel registration and let this signup go through. |
694 if ( $diff > 2 * DAY_IN_SECONDS ) { |
730 if ( $diff > 2 * DAY_IN_SECONDS ) { |
695 $wpdb->delete( |
731 $wpdb->delete( |
813 * @param array $meta Optional. Signup meta data. Default empty array. |
849 * @param array $meta Optional. Signup meta data. Default empty array. |
814 */ |
850 */ |
815 function wpmu_signup_user( $user, $user_email, $meta = array() ) { |
851 function wpmu_signup_user( $user, $user_email, $meta = array() ) { |
816 global $wpdb; |
852 global $wpdb; |
817 |
853 |
818 // Format data |
854 // Format data. |
819 $user = preg_replace( '/\s+/', '', sanitize_user( $user, true ) ); |
855 $user = preg_replace( '/\s+/', '', sanitize_user( $user, true ) ); |
820 $user_email = sanitize_email( $user_email ); |
856 $user_email = sanitize_email( $user_email ); |
821 $key = substr( md5( time() . wp_rand() . $user_email ), 0, 16 ); |
857 $key = substr( md5( time() . wp_rand() . $user_email ), 0, 16 ); |
822 |
858 |
823 /** |
859 /** |
906 |
942 |
907 // Send email with activation link. |
943 // Send email with activation link. |
908 if ( ! is_subdomain_install() || get_current_network_id() != 1 ) { |
944 if ( ! is_subdomain_install() || get_current_network_id() != 1 ) { |
909 $activate_url = network_site_url( "wp-activate.php?key=$key" ); |
945 $activate_url = network_site_url( "wp-activate.php?key=$key" ); |
910 } else { |
946 } else { |
911 $activate_url = "http://{$domain}{$path}wp-activate.php?key=$key"; // @todo use *_url() API |
947 $activate_url = "http://{$domain}{$path}wp-activate.php?key=$key"; // @todo Use *_url() API. |
912 } |
948 } |
913 |
949 |
914 $activate_url = esc_url( $activate_url ); |
950 $activate_url = esc_url( $activate_url ); |
915 $admin_email = get_site_option( 'admin_email' ); |
951 |
916 if ( $admin_email == '' ) { |
952 $admin_email = get_site_option( 'admin_email' ); |
917 $admin_email = 'support@' . $_SERVER['SERVER_NAME']; |
953 |
918 } |
954 if ( '' === $admin_email ) { |
919 $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) ); |
955 $admin_email = 'support@' . wp_parse_url( network_home_url(), PHP_URL_HOST ); |
|
956 } |
|
957 |
|
958 $from_name = ( '' !== get_site_option( 'site_name' ) ) ? esc_html( get_site_option( 'site_name' ) ) : 'WordPress'; |
920 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n"; |
959 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n"; |
921 |
960 |
922 $user = get_user_by( 'login', $user_login ); |
961 $user = get_user_by( 'login', $user_login ); |
923 $switched_locale = switch_to_locale( get_user_locale( $user ) ); |
962 $switched_locale = switch_to_locale( get_user_locale( $user ) ); |
924 |
963 |
939 * @param string $key Activation key created in wpmu_signup_blog(). |
978 * @param string $key Activation key created in wpmu_signup_blog(). |
940 * @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id. |
979 * @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id. |
941 */ |
980 */ |
942 apply_filters( |
981 apply_filters( |
943 'wpmu_signup_blog_notification_email', |
982 'wpmu_signup_blog_notification_email', |
|
983 /* translators: New site notification email. 1: Activation URL, 2: New site URL. */ |
944 __( "To activate your blog, please click the following link:\n\n%1\$s\n\nAfter you activate, you will receive *another email* with your login.\n\nAfter you activate, you can visit your site here:\n\n%2\$s" ), |
984 __( "To activate your blog, please click the following link:\n\n%1\$s\n\nAfter you activate, you will receive *another email* with your login.\n\nAfter you activate, you can visit your site here:\n\n%2\$s" ), |
945 $domain, |
985 $domain, |
946 $path, |
986 $path, |
947 $title, |
987 $title, |
948 $user_login, |
988 $user_login, |
970 * @param string $key Activation key created in wpmu_signup_blog(). |
1010 * @param string $key Activation key created in wpmu_signup_blog(). |
971 * @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id. |
1011 * @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id. |
972 */ |
1012 */ |
973 apply_filters( |
1013 apply_filters( |
974 'wpmu_signup_blog_notification_subject', |
1014 'wpmu_signup_blog_notification_subject', |
975 /* translators: New site notification email subject. 1: Network name, 2: New site URL */ |
1015 /* translators: New site notification email subject. 1: Network title, 2: New site URL. */ |
976 _x( '[%1$s] Activate %2$s', 'New site notification email subject' ), |
1016 _x( '[%1$s] Activate %2$s', 'New site notification email subject' ), |
977 $domain, |
1017 $domain, |
978 $path, |
1018 $path, |
979 $title, |
1019 $title, |
980 $user_login, |
1020 $user_login, |
1034 $user = get_user_by( 'login', $user_login ); |
1075 $user = get_user_by( 'login', $user_login ); |
1035 $switched_locale = switch_to_locale( get_user_locale( $user ) ); |
1076 $switched_locale = switch_to_locale( get_user_locale( $user ) ); |
1036 |
1077 |
1037 // Send email with activation link. |
1078 // Send email with activation link. |
1038 $admin_email = get_site_option( 'admin_email' ); |
1079 $admin_email = get_site_option( 'admin_email' ); |
1039 if ( $admin_email == '' ) { |
1080 |
1040 $admin_email = 'support@' . $_SERVER['SERVER_NAME']; |
1081 if ( '' === $admin_email ) { |
1041 } |
1082 $admin_email = 'support@' . wp_parse_url( network_home_url(), PHP_URL_HOST ); |
1042 $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) ); |
1083 } |
|
1084 |
|
1085 $from_name = ( '' !== get_site_option( 'site_name' ) ) ? esc_html( get_site_option( 'site_name' ) ) : 'WordPress'; |
1043 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n"; |
1086 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n"; |
1044 $message = sprintf( |
1087 $message = sprintf( |
1045 /** |
1088 /** |
1046 * Filters the content of the notification email for new user sign-up. |
1089 * Filters the content of the notification email for new user sign-up. |
1047 * |
1090 * |
1055 * @param string $key Activation key created in wpmu_signup_user(). |
1098 * @param string $key Activation key created in wpmu_signup_user(). |
1056 * @param array $meta Signup meta data. Default empty array. |
1099 * @param array $meta Signup meta data. Default empty array. |
1057 */ |
1100 */ |
1058 apply_filters( |
1101 apply_filters( |
1059 'wpmu_signup_user_notification_email', |
1102 'wpmu_signup_user_notification_email', |
|
1103 /* translators: New user notification email. %s: Activation URL. */ |
1060 __( "To activate your user, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login." ), |
1104 __( "To activate your user, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login." ), |
1061 $user_login, |
1105 $user_login, |
1062 $user_email, |
1106 $user_email, |
1063 $key, |
1107 $key, |
1064 $meta |
1108 $meta |
1065 ), |
1109 ), |
1066 site_url( "wp-activate.php?key=$key" ) |
1110 site_url( "wp-activate.php?key=$key" ) |
1067 ); |
1111 ); |
1068 // TODO: Don't hard code activation link. |
1112 |
1069 $subject = sprintf( |
1113 $subject = sprintf( |
1070 /** |
1114 /** |
1071 * Filters the subject of the notification email of new user signup. |
1115 * Filters the subject of the notification email of new user signup. |
1072 * |
1116 * |
1073 * @since MU (3.0.0) |
1117 * @since MU (3.0.0) |
1078 * @param string $key Activation key created in wpmu_signup_user(). |
1122 * @param string $key Activation key created in wpmu_signup_user(). |
1079 * @param array $meta Signup meta data. Default empty array. |
1123 * @param array $meta Signup meta data. Default empty array. |
1080 */ |
1124 */ |
1081 apply_filters( |
1125 apply_filters( |
1082 'wpmu_signup_user_notification_subject', |
1126 'wpmu_signup_user_notification_subject', |
1083 /* translators: New user notification email subject. 1: Network name, 2: New user login */ |
1127 /* translators: New user notification email subject. 1: Network title, 2: New user login. */ |
1084 _x( '[%1$s] Activate %2$s', 'New user notification email subject' ), |
1128 _x( '[%1$s] Activate %2$s', 'New user notification email subject' ), |
1085 $user_login, |
1129 $user_login, |
1086 $user_email, |
1130 $user_email, |
1087 $key, |
1131 $key, |
1088 $meta |
1132 $meta |
1089 ), |
1133 ), |
1090 $from_name, |
1134 $from_name, |
1091 $user_login |
1135 $user_login |
1092 ); |
1136 ); |
|
1137 |
1093 wp_mail( $user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); |
1138 wp_mail( $user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); |
1094 |
1139 |
1095 if ( $switched_locale ) { |
1140 if ( $switched_locale ) { |
1096 restore_previous_locale(); |
1141 restore_previous_locale(); |
1097 } |
1142 } |
1165 /** |
1210 /** |
1166 * Fires immediately after a new user is activated. |
1211 * Fires immediately after a new user is activated. |
1167 * |
1212 * |
1168 * @since MU (3.0.0) |
1213 * @since MU (3.0.0) |
1169 * |
1214 * |
1170 * @param int $user_id User ID. |
1215 * @param int $user_id User ID. |
1171 * @param int $password User password. |
1216 * @param string $password User password. |
1172 * @param array $meta Signup meta data. |
1217 * @param array $meta Signup meta data. |
1173 */ |
1218 */ |
1174 do_action( 'wpmu_activate_user', $user_id, $password, $meta ); |
1219 do_action( 'wpmu_activate_user', $user_id, $password, $meta ); |
|
1220 |
1175 return array( |
1221 return array( |
1176 'user_id' => $user_id, |
1222 'user_id' => $user_id, |
1177 'password' => $password, |
1223 'password' => $password, |
1178 'meta' => $meta, |
1224 'meta' => $meta, |
1179 ); |
1225 ); |
1181 |
1227 |
1182 $blog_id = wpmu_create_blog( $signup->domain, $signup->path, $signup->title, $user_id, $meta, get_current_network_id() ); |
1228 $blog_id = wpmu_create_blog( $signup->domain, $signup->path, $signup->title, $user_id, $meta, get_current_network_id() ); |
1183 |
1229 |
1184 // TODO: What to do if we create a user but cannot create a blog? |
1230 // TODO: What to do if we create a user but cannot create a blog? |
1185 if ( is_wp_error( $blog_id ) ) { |
1231 if ( is_wp_error( $blog_id ) ) { |
1186 // If blog is taken, that means a previous attempt to activate this blog failed in between creating the blog and |
1232 /* |
1187 // setting the activation flag. Let's just set the active flag and instruct the user to reset their password. |
1233 * If blog is taken, that means a previous attempt to activate this blog |
1188 if ( 'blog_taken' == $blog_id->get_error_code() ) { |
1234 * failed in between creating the blog and setting the activation flag. |
|
1235 * Let's just set the active flag and instruct the user to reset their password. |
|
1236 */ |
|
1237 if ( 'blog_taken' === $blog_id->get_error_code() ) { |
1189 $blog_id->add_data( $signup ); |
1238 $blog_id->add_data( $signup ); |
1190 $wpdb->update( |
1239 $wpdb->update( |
1191 $wpdb->signups, |
1240 $wpdb->signups, |
1192 array( |
1241 array( |
1193 'active' => 1, |
1242 'active' => 1, |
1225 'user_id' => $user_id, |
1275 'user_id' => $user_id, |
1226 'password' => $password, |
1276 'password' => $password, |
1227 'title' => $signup->title, |
1277 'title' => $signup->title, |
1228 'meta' => $meta, |
1278 'meta' => $meta, |
1229 ); |
1279 ); |
|
1280 } |
|
1281 |
|
1282 /** |
|
1283 * Deletes am associated signup entry when a user is deleted from the database. |
|
1284 * |
|
1285 * @since 5.5.0 |
|
1286 * |
|
1287 * @param int $id ID of the user to delete. |
|
1288 * @param int|null $reassign ID of the user to reassign posts and links to. |
|
1289 * @param WP_User $user User object. |
|
1290 */ |
|
1291 function wp_delete_signup_on_user_delete( $id, $reassign, $user ) { |
|
1292 global $wpdb; |
|
1293 |
|
1294 $wpdb->delete( $wpdb->signups, array( 'user_login' => $user->user_login ) ); |
1230 } |
1295 } |
1231 |
1296 |
1232 /** |
1297 /** |
1233 * Create a user. |
1298 * Create a user. |
1234 * |
1299 * |
1310 |
1375 |
1311 if ( ! wp_installing() ) { |
1376 if ( ! wp_installing() ) { |
1312 wp_installing( true ); |
1377 wp_installing( true ); |
1313 } |
1378 } |
1314 |
1379 |
1315 $site_data_whitelist = array( 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' ); |
1380 $allowed_data_fields = array( 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' ); |
1316 |
1381 |
1317 $site_data = array_merge( |
1382 $site_data = array_merge( |
1318 array( |
1383 array( |
1319 'domain' => $domain, |
1384 'domain' => $domain, |
1320 'path' => $path, |
1385 'path' => $path, |
1321 'network_id' => $network_id, |
1386 'network_id' => $network_id, |
1322 ), |
1387 ), |
1323 array_intersect_key( $options, array_flip( $site_data_whitelist ) ) |
1388 array_intersect_key( $options, array_flip( $allowed_data_fields ) ) |
1324 ); |
1389 ); |
1325 |
1390 |
1326 // Data to pass to wp_initialize_site(). |
1391 // Data to pass to wp_initialize_site(). |
1327 $site_initialization_data = array( |
1392 $site_initialization_data = array( |
1328 'title' => $title, |
1393 'title' => $title, |
1329 'user_id' => $user_id, |
1394 'user_id' => $user_id, |
1330 'options' => array_diff_key( $options, array_flip( $site_data_whitelist ) ), |
1395 'options' => array_diff_key( $options, array_flip( $allowed_data_fields ) ), |
1331 ); |
1396 ); |
1332 |
1397 |
1333 $blog_id = wp_insert_site( array_merge( $site_data, $site_initialization_data ) ); |
1398 $blog_id = wp_insert_site( array_merge( $site_data, $site_initialization_data ) ); |
1334 |
1399 |
1335 if ( is_wp_error( $blog_id ) ) { |
1400 if ( is_wp_error( $blog_id ) ) { |
1357 function newblog_notify_siteadmin( $blog_id, $deprecated = '' ) { |
1422 function newblog_notify_siteadmin( $blog_id, $deprecated = '' ) { |
1358 if ( is_object( $blog_id ) ) { |
1423 if ( is_object( $blog_id ) ) { |
1359 $blog_id = $blog_id->blog_id; |
1424 $blog_id = $blog_id->blog_id; |
1360 } |
1425 } |
1361 |
1426 |
1362 if ( get_site_option( 'registrationnotification' ) != 'yes' ) { |
1427 if ( 'yes' !== get_site_option( 'registrationnotification' ) ) { |
1363 return false; |
1428 return false; |
1364 } |
1429 } |
1365 |
1430 |
1366 $email = get_site_option( 'admin_email' ); |
1431 $email = get_site_option( 'admin_email' ); |
|
1432 |
1367 if ( is_email( $email ) == false ) { |
1433 if ( is_email( $email ) == false ) { |
1368 return false; |
1434 return false; |
1369 } |
1435 } |
1370 |
1436 |
1371 $options_site_url = esc_url( network_admin_url( 'settings.php' ) ); |
1437 $options_site_url = esc_url( network_admin_url( 'settings.php' ) ); |
1373 switch_to_blog( $blog_id ); |
1439 switch_to_blog( $blog_id ); |
1374 $blogname = get_option( 'blogname' ); |
1440 $blogname = get_option( 'blogname' ); |
1375 $siteurl = site_url(); |
1441 $siteurl = site_url(); |
1376 restore_current_blog(); |
1442 restore_current_blog(); |
1377 |
1443 |
1378 /* translators: New site notification email. 1: Site URL, 2: User IP address, 3: Settings screen URL */ |
|
1379 $msg = sprintf( |
1444 $msg = sprintf( |
|
1445 /* translators: New site notification email. 1: Site URL, 2: User IP address, 3: URL to Network Settings screen. */ |
1380 __( |
1446 __( |
1381 'New Site: %1$s |
1447 'New Site: %1$s |
1382 URL: %2$s |
1448 URL: %2$s |
1383 Remote IP address: %3$s |
1449 Remote IP address: %3$s |
1384 |
1450 |
1392 /** |
1458 /** |
1393 * Filters the message body of the new site activation email sent |
1459 * Filters the message body of the new site activation email sent |
1394 * to the network administrator. |
1460 * to the network administrator. |
1395 * |
1461 * |
1396 * @since MU (3.0.0) |
1462 * @since MU (3.0.0) |
1397 * |
1463 * @since 5.4.0 The `$blog_id` parameter was added. |
1398 * @param string $msg Email body. |
1464 * |
1399 */ |
1465 * @param string $msg Email body. |
1400 $msg = apply_filters( 'newblog_notify_siteadmin', $msg ); |
1466 * @param int $blog_id The new site's ID. |
1401 |
1467 */ |
|
1468 $msg = apply_filters( 'newblog_notify_siteadmin', $msg, $blog_id ); |
|
1469 |
|
1470 /* translators: New site notification email subject. %s: New site URL. */ |
1402 wp_mail( $email, sprintf( __( 'New Site Registration: %s' ), $siteurl ), $msg ); |
1471 wp_mail( $email, sprintf( __( 'New Site Registration: %s' ), $siteurl ), $msg ); |
|
1472 |
1403 return true; |
1473 return true; |
1404 } |
1474 } |
1405 |
1475 |
1406 /** |
1476 /** |
1407 * Notifies the network admin that a new user has been activated. |
1477 * Notifies the network admin that a new user has been activated. |
1426 } |
1496 } |
1427 |
1497 |
1428 $user = get_userdata( $user_id ); |
1498 $user = get_userdata( $user_id ); |
1429 |
1499 |
1430 $options_site_url = esc_url( network_admin_url( 'settings.php' ) ); |
1500 $options_site_url = esc_url( network_admin_url( 'settings.php' ) ); |
1431 /* translators: New user notification email. 1: User login, 2: User IP address, 3: Settings screen URL */ |
1501 |
1432 $msg = sprintf( |
1502 $msg = sprintf( |
|
1503 /* translators: New user notification email. 1: User login, 2: User IP address, 3: URL to Network Settings screen. */ |
1433 __( |
1504 __( |
1434 'New User: %1$s |
1505 'New User: %1$s |
1435 Remote IP address: %2$s |
1506 Remote IP address: %2$s |
1436 |
1507 |
1437 Disable these notifications: %3$s' |
1508 Disable these notifications: %3$s' |
1449 * |
1520 * |
1450 * @param string $msg Email body. |
1521 * @param string $msg Email body. |
1451 * @param WP_User $user WP_User instance of the new user. |
1522 * @param WP_User $user WP_User instance of the new user. |
1452 */ |
1523 */ |
1453 $msg = apply_filters( 'newuser_notify_siteadmin', $msg, $user ); |
1524 $msg = apply_filters( 'newuser_notify_siteadmin', $msg, $user ); |
|
1525 |
|
1526 /* translators: New user notification email subject. %s: User login. */ |
1454 wp_mail( $email, sprintf( __( 'New User Registration: %s' ), $user->user_login ), $msg ); |
1527 wp_mail( $email, sprintf( __( 'New User Registration: %s' ), $user->user_login ), $msg ); |
|
1528 |
1455 return true; |
1529 return true; |
1456 } |
1530 } |
1457 |
1531 |
1458 /** |
1532 /** |
1459 * Checks whether a site name is already taken. |
1533 * Checks whether a site name is already taken. |
1540 $user = get_userdata( $user_id ); |
1614 $user = get_userdata( $user_id ); |
1541 |
1615 |
1542 $switched_locale = switch_to_locale( get_user_locale( $user ) ); |
1616 $switched_locale = switch_to_locale( get_user_locale( $user ) ); |
1543 |
1617 |
1544 $welcome_email = get_site_option( 'welcome_email' ); |
1618 $welcome_email = get_site_option( 'welcome_email' ); |
1545 if ( $welcome_email == false ) { |
1619 if ( false == $welcome_email ) { |
1546 /* translators: Do not translate USERNAME, SITE_NAME, BLOG_URL, PASSWORD: those are placeholders. */ |
1620 /* translators: Do not translate USERNAME, SITE_NAME, BLOG_URL, PASSWORD: those are placeholders. */ |
1547 $welcome_email = __( |
1621 $welcome_email = __( |
1548 'Howdy USERNAME, |
1622 'Howdy USERNAME, |
1549 |
1623 |
1550 Your new SITE_NAME site has been successfully set up at: |
1624 Your new SITE_NAME site has been successfully set up at: |
1583 * @param string $password User password. |
1657 * @param string $password User password. |
1584 * @param string $title Site title. |
1658 * @param string $title Site title. |
1585 * @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id. |
1659 * @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id. |
1586 */ |
1660 */ |
1587 $welcome_email = apply_filters( 'update_welcome_email', $welcome_email, $blog_id, $user_id, $password, $title, $meta ); |
1661 $welcome_email = apply_filters( 'update_welcome_email', $welcome_email, $blog_id, $user_id, $password, $title, $meta ); |
1588 $admin_email = get_site_option( 'admin_email' ); |
1662 |
1589 |
1663 $admin_email = get_site_option( 'admin_email' ); |
1590 if ( $admin_email == '' ) { |
1664 |
1591 $admin_email = 'support@' . $_SERVER['SERVER_NAME']; |
1665 if ( '' === $admin_email ) { |
1592 } |
1666 $admin_email = 'support@' . wp_parse_url( network_home_url(), PHP_URL_HOST ); |
1593 |
1667 } |
1594 $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) ); |
1668 |
|
1669 $from_name = ( '' !== get_site_option( 'site_name' ) ) ? esc_html( get_site_option( 'site_name' ) ) : 'WordPress'; |
1595 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n"; |
1670 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n"; |
1596 $message = $welcome_email; |
1671 $message = $welcome_email; |
1597 |
1672 |
1598 if ( empty( $current_network->site_name ) ) { |
1673 if ( empty( $current_network->site_name ) ) { |
1599 $current_network->site_name = 'WordPress'; |
1674 $current_network->site_name = 'WordPress'; |
1600 } |
1675 } |
1601 |
1676 |
1602 /* translators: New site notification email subject. 1: Network name, 2: New site name */ |
1677 /* translators: New site notification email subject. 1: Network title, 2: New site title. */ |
1603 $subject = __( 'New %1$s Site: %2$s' ); |
1678 $subject = __( 'New %1$s Site: %2$s' ); |
1604 |
1679 |
1605 /** |
1680 /** |
1606 * Filters the subject of the welcome email after site activation. |
1681 * Filters the subject of the welcome email after site activation. |
1607 * |
1682 * |
1608 * @since MU (3.0.0) |
1683 * @since MU (3.0.0) |
1609 * |
1684 * |
1610 * @param string $subject Subject of the email. |
1685 * @param string $subject Subject of the email. |
1611 */ |
1686 */ |
1612 $subject = apply_filters( 'update_welcome_subject', sprintf( $subject, $current_network->site_name, wp_unslash( $title ) ) ); |
1687 $subject = apply_filters( 'update_welcome_subject', sprintf( $subject, $current_network->site_name, wp_unslash( $title ) ) ); |
|
1688 |
1613 wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); |
1689 wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); |
1614 |
1690 |
1615 if ( $switched_locale ) { |
1691 if ( $switched_locale ) { |
1616 restore_previous_locale(); |
1692 restore_previous_locale(); |
1617 } |
1693 } |
1676 $welcome_email = str_replace( 'PASSWORD', $password, $welcome_email ); |
1752 $welcome_email = str_replace( 'PASSWORD', $password, $welcome_email ); |
1677 $welcome_email = str_replace( 'LOGINLINK', wp_login_url(), $welcome_email ); |
1753 $welcome_email = str_replace( 'LOGINLINK', wp_login_url(), $welcome_email ); |
1678 |
1754 |
1679 $admin_email = get_site_option( 'admin_email' ); |
1755 $admin_email = get_site_option( 'admin_email' ); |
1680 |
1756 |
1681 if ( $admin_email == '' ) { |
1757 if ( '' === $admin_email ) { |
1682 $admin_email = 'support@' . $_SERVER['SERVER_NAME']; |
1758 $admin_email = 'support@' . wp_parse_url( network_home_url(), PHP_URL_HOST ); |
1683 } |
1759 } |
1684 |
1760 |
1685 $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) ); |
1761 $from_name = ( '' !== get_site_option( 'site_name' ) ) ? esc_html( get_site_option( 'site_name' ) ) : 'WordPress'; |
1686 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n"; |
1762 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n"; |
1687 $message = $welcome_email; |
1763 $message = $welcome_email; |
1688 |
1764 |
1689 if ( empty( $current_network->site_name ) ) { |
1765 if ( empty( $current_network->site_name ) ) { |
1690 $current_network->site_name = 'WordPress'; |
1766 $current_network->site_name = 'WordPress'; |
1691 } |
1767 } |
1692 |
1768 |
1693 /* translators: New user notification email subject. 1: Network name, 2: New user login */ |
1769 /* translators: New user notification email subject. 1: Network title, 2: New user login. */ |
1694 $subject = __( 'New %1$s User: %2$s' ); |
1770 $subject = __( 'New %1$s User: %2$s' ); |
1695 |
1771 |
1696 /** |
1772 /** |
1697 * Filters the subject of the welcome email after user activation. |
1773 * Filters the subject of the welcome email after user activation. |
1698 * |
1774 * |
1699 * @since MU (3.0.0) |
1775 * @since MU (3.0.0) |
1700 * |
1776 * |
1701 * @param string $subject Subject of the email. |
1777 * @param string $subject Subject of the email. |
1702 */ |
1778 */ |
1703 $subject = apply_filters( 'update_welcome_user_subject', sprintf( $subject, $current_network->site_name, $user->user_login ) ); |
1779 $subject = apply_filters( 'update_welcome_user_subject', sprintf( $subject, $current_network->site_name, $user->user_login ) ); |
|
1780 |
1704 wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); |
1781 wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); |
1705 |
1782 |
1706 if ( $switched_locale ) { |
1783 if ( $switched_locale ) { |
1707 restore_previous_locale(); |
1784 restore_previous_locale(); |
1708 } |
1785 } |
1747 |
1824 |
1748 $user_blogs = get_blogs_of_user( (int) $user_id ); |
1825 $user_blogs = get_blogs_of_user( (int) $user_id ); |
1749 $most_recent_post = array(); |
1826 $most_recent_post = array(); |
1750 |
1827 |
1751 // Walk through each blog and get the most recent post |
1828 // Walk through each blog and get the most recent post |
1752 // published by $user_id |
1829 // published by $user_id. |
1753 foreach ( (array) $user_blogs as $blog ) { |
1830 foreach ( (array) $user_blogs as $blog ) { |
1754 $prefix = $wpdb->get_blog_prefix( $blog->userblog_id ); |
1831 $prefix = $wpdb->get_blog_prefix( $blog->userblog_id ); |
1755 $recent_post = $wpdb->get_row( $wpdb->prepare( "SELECT ID, post_date_gmt FROM {$prefix}posts WHERE post_author = %d AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1", $user_id ), ARRAY_A ); |
1832 $recent_post = $wpdb->get_row( $wpdb->prepare( "SELECT ID, post_date_gmt FROM {$prefix}posts WHERE post_author = %d AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1", $user_id ), ARRAY_A ); |
1756 |
1833 |
1757 // Make sure we found a post |
1834 // Make sure we found a post. |
1758 if ( isset( $recent_post['ID'] ) ) { |
1835 if ( isset( $recent_post['ID'] ) ) { |
1759 $post_gmt_ts = strtotime( $recent_post['post_date_gmt'] ); |
1836 $post_gmt_ts = strtotime( $recent_post['post_date_gmt'] ); |
1760 |
1837 |
1761 // If this is the first post checked or if this post is |
1838 /* |
1762 // newer than the current recent post, make it the new |
1839 * If this is the first post checked |
1763 // most recent post. |
1840 * or if this post is newer than the current recent post, |
|
1841 * make it the new most recent post. |
|
1842 */ |
1764 if ( ! isset( $most_recent_post['post_gmt_ts'] ) || ( $post_gmt_ts > $most_recent_post['post_gmt_ts'] ) ) { |
1843 if ( ! isset( $most_recent_post['post_gmt_ts'] ) || ( $post_gmt_ts > $most_recent_post['post_gmt_ts'] ) ) { |
1765 $most_recent_post = array( |
1844 $most_recent_post = array( |
1766 'blog_id' => $blog->userblog_id, |
1845 'blog_id' => $blog->userblog_id, |
1767 'post_id' => $recent_post['ID'], |
1846 'post_id' => $recent_post['ID'], |
1768 'post_date_gmt' => $recent_post['post_date_gmt'], |
1847 'post_date_gmt' => $recent_post['post_date_gmt'], |
1773 } |
1852 } |
1774 |
1853 |
1775 return $most_recent_post; |
1854 return $most_recent_post; |
1776 } |
1855 } |
1777 |
1856 |
1778 // Misc functions |
1857 // |
1779 |
1858 // Misc functions. |
1780 /** |
1859 // |
1781 * Check an array of MIME types against a whitelist. |
1860 |
|
1861 /** |
|
1862 * Check an array of MIME types against a list of allowed types. |
1782 * |
1863 * |
1783 * WordPress ships with a set of allowed upload filetypes, |
1864 * WordPress ships with a set of allowed upload filetypes, |
1784 * which is defined in wp-includes/functions.php in |
1865 * which is defined in wp-includes/functions.php in |
1785 * get_allowed_mime_types(). This function is used to filter |
1866 * get_allowed_mime_types(). This function is used to filter |
1786 * that list against the filetype whitelist provided by Multisite |
1867 * that list against the filetypes allowed provided by Multisite |
1787 * Super Admins at wp-admin/network/settings.php. |
1868 * Super Admins at wp-admin/network/settings.php. |
1788 * |
1869 * |
1789 * @since MU (3.0.0) |
1870 * @since MU (3.0.0) |
1790 * |
1871 * |
1791 * @param array $mimes |
1872 * @param array $mimes |
1794 function check_upload_mimes( $mimes ) { |
1875 function check_upload_mimes( $mimes ) { |
1795 $site_exts = explode( ' ', get_site_option( 'upload_filetypes', 'jpg jpeg png gif' ) ); |
1876 $site_exts = explode( ' ', get_site_option( 'upload_filetypes', 'jpg jpeg png gif' ) ); |
1796 $site_mimes = array(); |
1877 $site_mimes = array(); |
1797 foreach ( $site_exts as $ext ) { |
1878 foreach ( $site_exts as $ext ) { |
1798 foreach ( $mimes as $ext_pattern => $mime ) { |
1879 foreach ( $mimes as $ext_pattern => $mime ) { |
1799 if ( $ext != '' && strpos( $ext_pattern, $ext ) !== false ) { |
1880 if ( '' !== $ext && false !== strpos( $ext_pattern, $ext ) ) { |
1800 $site_mimes[ $ext_pattern ] = $mime; |
1881 $site_mimes[ $ext_pattern ] = $mime; |
1801 } |
1882 } |
1802 } |
1883 } |
1803 } |
1884 } |
1804 return $site_mimes; |
1885 return $site_mimes; |
1879 |
1959 |
1880 if ( ! global_terms_enabled() ) { |
1960 if ( ! global_terms_enabled() ) { |
1881 return $term_id; |
1961 return $term_id; |
1882 } |
1962 } |
1883 |
1963 |
1884 // prevent a race condition |
1964 // Prevent a race condition. |
1885 $recurse_start = false; |
1965 $recurse_start = false; |
1886 if ( $global_terms_recurse === null ) { |
1966 if ( null === $global_terms_recurse ) { |
1887 $recurse_start = true; |
1967 $recurse_start = true; |
1888 $global_terms_recurse = 1; |
1968 $global_terms_recurse = 1; |
1889 } elseif ( 10 < $global_terms_recurse++ ) { |
1969 } elseif ( 10 < $global_terms_recurse++ ) { |
1890 return $term_id; |
1970 return $term_id; |
1891 } |
1971 } |
1892 |
1972 |
1893 $term_id = intval( $term_id ); |
1973 $term_id = intval( $term_id ); |
1894 $c = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->terms WHERE term_id = %d", $term_id ) ); |
1974 $c = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->terms WHERE term_id = %d", $term_id ) ); |
1895 |
1975 |
1896 $global_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM $wpdb->sitecategories WHERE category_nicename = %s", $c->slug ) ); |
1976 $global_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM $wpdb->sitecategories WHERE category_nicename = %s", $c->slug ) ); |
1897 if ( $global_id == null ) { |
1977 if ( null == $global_id ) { |
1898 $used_global_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM $wpdb->sitecategories WHERE cat_ID = %d", $c->term_id ) ); |
1978 $used_global_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM $wpdb->sitecategories WHERE cat_ID = %d", $c->term_id ) ); |
1899 if ( null == $used_global_id ) { |
1979 if ( null == $used_global_id ) { |
1900 $wpdb->insert( |
1980 $wpdb->insert( |
1901 $wpdb->sitecategories, |
1981 $wpdb->sitecategories, |
1902 array( |
1982 array( |
1978 if ( ! is_array( $upload ) || defined( 'WP_IMPORTING' ) || get_site_option( 'upload_space_check_disabled' ) ) { |
2062 if ( ! is_array( $upload ) || defined( 'WP_IMPORTING' ) || get_site_option( 'upload_space_check_disabled' ) ) { |
1979 return $upload; |
2063 return $upload; |
1980 } |
2064 } |
1981 |
2065 |
1982 if ( strlen( $upload['bits'] ) > ( KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ) ) ) { |
2066 if ( strlen( $upload['bits'] ) > ( KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ) ) ) { |
1983 /* translators: %s: maximum allowed file size in kilobytes */ |
2067 /* translators: %s: Maximum allowed file size in kilobytes. */ |
1984 return sprintf( __( 'This file is too big. Files must be less than %s KB in size.' ) . '<br />', get_site_option( 'fileupload_maxk', 1500 ) ); |
2068 return sprintf( __( 'This file is too big. Files must be less than %s KB in size.' ) . '<br />', get_site_option( 'fileupload_maxk', 1500 ) ); |
1985 } |
2069 } |
1986 |
2070 |
1987 return $upload; |
2071 return $upload; |
1988 } |
2072 } |
2022 * Correct 404 redirects when NOBLOGREDIRECT is defined. |
2106 * Correct 404 redirects when NOBLOGREDIRECT is defined. |
2023 * |
2107 * |
2024 * @since MU (3.0.0) |
2108 * @since MU (3.0.0) |
2025 */ |
2109 */ |
2026 function maybe_redirect_404() { |
2110 function maybe_redirect_404() { |
2027 /** |
2111 if ( is_main_site() && is_404() && defined( 'NOBLOGREDIRECT' ) ) { |
2028 * Filters the redirect URL for 404s on the main site. |
2112 /** |
2029 * |
2113 * Filters the redirect URL for 404s on the main site. |
2030 * The filter is only evaluated if the NOBLOGREDIRECT constant is defined. |
2114 * |
2031 * |
2115 * The filter is only evaluated if the NOBLOGREDIRECT constant is defined. |
2032 * @since 3.0.0 |
2116 * |
2033 * |
2117 * @since 3.0.0 |
2034 * @param string $no_blog_redirect The redirect URL defined in NOBLOGREDIRECT. |
2118 * |
2035 */ |
2119 * @param string $no_blog_redirect The redirect URL defined in NOBLOGREDIRECT. |
2036 if ( is_main_site() && is_404() && defined( 'NOBLOGREDIRECT' ) && ( $destination = apply_filters( 'blog_redirect_404', NOBLOGREDIRECT ) ) ) { |
2120 */ |
2037 if ( $destination == '%siteurl%' ) { |
2121 $destination = apply_filters( 'blog_redirect_404', NOBLOGREDIRECT ); |
2038 $destination = network_home_url(); |
2122 |
|
2123 if ( $destination ) { |
|
2124 if ( '%siteurl%' === $destination ) { |
|
2125 $destination = network_home_url(); |
|
2126 } |
|
2127 |
|
2128 wp_redirect( $destination ); |
|
2129 exit; |
2039 } |
2130 } |
2040 wp_redirect( $destination ); |
|
2041 exit(); |
|
2042 } |
2131 } |
2043 } |
2132 } |
2044 |
2133 |
2045 /** |
2134 /** |
2046 * Add a new user to a blog by visiting /newbloguser/{key}/. |
2135 * Add a new user to a blog by visiting /newbloguser/{key}/. |
2057 } |
2146 } |
2058 |
2147 |
2059 $parts = explode( '/', $_SERVER['REQUEST_URI'] ); |
2148 $parts = explode( '/', $_SERVER['REQUEST_URI'] ); |
2060 $key = array_pop( $parts ); |
2149 $key = array_pop( $parts ); |
2061 |
2150 |
2062 if ( $key == '' ) { |
2151 if ( '' === $key ) { |
2063 $key = array_pop( $parts ); |
2152 $key = array_pop( $parts ); |
2064 } |
2153 } |
2065 |
2154 |
2066 $details = get_option( 'new_user_' . $key ); |
2155 $details = get_option( 'new_user_' . $key ); |
2067 if ( ! empty( $details ) ) { |
2156 if ( ! empty( $details ) ) { |
2068 delete_option( 'new_user_' . $key ); |
2157 delete_option( 'new_user_' . $key ); |
2069 } |
2158 } |
2070 |
2159 |
2071 if ( empty( $details ) || is_wp_error( add_existing_user_to_blog( $details ) ) ) { |
2160 if ( empty( $details ) || is_wp_error( add_existing_user_to_blog( $details ) ) ) { |
2072 wp_die( sprintf( __( 'An error occurred adding you to this site. Back to the <a href="%s">homepage</a>.' ), home_url() ) ); |
2161 wp_die( |
2073 } |
2162 sprintf( |
2074 |
2163 /* translators: %s: Home URL. */ |
2075 wp_die( sprintf( __( 'You have been added to this site. Please visit the <a href="%1$s">homepage</a> or <a href="%2$s">log in</a> using your username and password.' ), home_url(), admin_url() ), __( 'WordPress › Success' ), array( 'response' => 200 ) ); |
2164 __( 'An error occurred adding you to this site. Back to the <a href="%s">homepage</a>.' ), |
|
2165 home_url() |
|
2166 ) |
|
2167 ); |
|
2168 } |
|
2169 |
|
2170 wp_die( |
|
2171 sprintf( |
|
2172 /* translators: 1: Home URL, 2: Admin URL. */ |
|
2173 __( 'You have been added to this site. Please visit the <a href="%1$s">homepage</a> or <a href="%2$s">log in</a> using your username and password.' ), |
|
2174 home_url(), |
|
2175 admin_url() |
|
2176 ), |
|
2177 __( 'WordPress › Success' ), |
|
2178 array( 'response' => 200 ) |
|
2179 ); |
2076 } |
2180 } |
2077 |
2181 |
2078 /** |
2182 /** |
2079 * Add a user to a blog based on details from maybe_add_existing_user_to_blog(). |
2183 * Add a user to a blog based on details from maybe_add_existing_user_to_blog(). |
2080 * |
2184 * |
2081 * @since MU (3.0.0) |
2185 * @since MU (3.0.0) |
2082 * |
2186 * |
2083 * @param array $details |
2187 * @param array $details { |
2084 * @return true|WP_Error|void |
2188 * User details. Must at least contain values for the keys listed below. |
|
2189 * |
|
2190 * @type int $user_id The ID of the user being added to the current blog. |
|
2191 * @type string $role The role to be assigned to the user. |
|
2192 * } |
|
2193 * @return true|WP_Error|void True on success or a WP_Error object if the user doesn't exist |
|
2194 * or could not be added. Void if $details array was not provided. |
2085 */ |
2195 */ |
2086 function add_existing_user_to_blog( $details = false ) { |
2196 function add_existing_user_to_blog( $details = false ) { |
2087 if ( is_array( $details ) ) { |
2197 if ( is_array( $details ) ) { |
2088 $blog_id = get_current_blog_id(); |
2198 $blog_id = get_current_blog_id(); |
2089 $result = add_user_to_blog( $blog_id, $details['user_id'], $details['role'] ); |
2199 $result = add_user_to_blog( $blog_id, $details['user_id'], $details['role'] ); |
2091 /** |
2201 /** |
2092 * Fires immediately after an existing user is added to a site. |
2202 * Fires immediately after an existing user is added to a site. |
2093 * |
2203 * |
2094 * @since MU (3.0.0) |
2204 * @since MU (3.0.0) |
2095 * |
2205 * |
2096 * @param int $user_id User ID. |
2206 * @param int $user_id User ID. |
2097 * @param mixed $result True on success or a WP_Error object if the user doesn't exist |
2207 * @param true|WP_Error $result True on success or a WP_Error object if the user doesn't exist |
2098 * or could not be added. |
2208 * or could not be added. |
2099 */ |
2209 */ |
2100 do_action( 'added_existing_user', $details['user_id'], $result ); |
2210 do_action( 'added_existing_user', $details['user_id'], $result ); |
2101 |
2211 |
2102 return $result; |
2212 return $result; |
2103 } |
2213 } |
2108 * |
2218 * |
2109 * To add a user in general, use add_user_to_blog(). This function |
2219 * To add a user in general, use add_user_to_blog(). This function |
2110 * is specifically hooked into the {@see 'wpmu_activate_user'} action. |
2220 * is specifically hooked into the {@see 'wpmu_activate_user'} action. |
2111 * |
2221 * |
2112 * @since MU (3.0.0) |
2222 * @since MU (3.0.0) |
|
2223 * |
2113 * @see add_user_to_blog() |
2224 * @see add_user_to_blog() |
2114 * |
2225 * |
2115 * @param int $user_id |
2226 * @param int $user_id User ID. |
2116 * @param mixed $password Ignored. |
2227 * @param string $password User password. Ignored. |
2117 * @param array $meta |
2228 * @param array $meta Signup meta data. |
2118 */ |
2229 */ |
2119 function add_new_user_to_blog( $user_id, $password, $meta ) { |
2230 function add_new_user_to_blog( $user_id, $password, $meta ) { |
2120 if ( ! empty( $meta['add_to_blog'] ) ) { |
2231 if ( ! empty( $meta['add_to_blog'] ) ) { |
2121 $blog_id = $meta['add_to_blog']; |
2232 $blog_id = $meta['add_to_blog']; |
2122 $role = $meta['new_role']; |
2233 $role = $meta['new_role']; |
2123 remove_user_from_blog( $user_id, get_network()->site_id ); // remove user from main blog. |
2234 remove_user_from_blog( $user_id, get_network()->site_id ); // Remove user from main blog. |
2124 |
2235 |
2125 $result = add_user_to_blog( $blog_id, $user_id, $role ); |
2236 $result = add_user_to_blog( $blog_id, $user_id, $role ); |
2126 |
2237 |
2127 if ( ! is_wp_error( $result ) ) { |
2238 if ( ! is_wp_error( $result ) ) { |
2128 update_user_meta( $user_id, 'primary_blog', $blog_id ); |
2239 update_user_meta( $user_id, 'primary_blog', $blog_id ); |
2223 /** |
2334 /** |
2224 * Whether to force SSL on content. |
2335 * Whether to force SSL on content. |
2225 * |
2336 * |
2226 * @since 2.8.5 |
2337 * @since 2.8.5 |
2227 * |
2338 * |
2228 * @staticvar bool $forced_content |
|
2229 * |
|
2230 * @param bool $force |
2339 * @param bool $force |
2231 * @return bool True if forced, false if not forced. |
2340 * @return bool True if forced, false if not forced. |
2232 */ |
2341 */ |
2233 function force_ssl_content( $force = '' ) { |
2342 function force_ssl_content( $force = '' ) { |
2234 static $forced_content = false; |
2343 static $forced_content = false; |
2235 |
2344 |
2236 if ( '' != $force ) { |
2345 if ( ! $force ) { |
2237 $old_forced = $forced_content; |
2346 $old_forced = $forced_content; |
2238 $forced_content = $force; |
2347 $forced_content = $force; |
2239 return $old_forced; |
2348 return $old_forced; |
2240 } |
2349 } |
2241 |
2350 |
2250 * @since 2.8.5 |
2359 * @since 2.8.5 |
2251 * |
2360 * |
2252 * @param string $url URL |
2361 * @param string $url URL |
2253 * @return string URL with https as the scheme |
2362 * @return string URL with https as the scheme |
2254 */ |
2363 */ |
2255 function filter_SSL( $url ) { |
2364 function filter_SSL( $url ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid |
2256 if ( ! is_string( $url ) ) { |
2365 if ( ! is_string( $url ) ) { |
2257 return get_bloginfo( 'url' ); // Return home blog url with proper scheme |
2366 return get_bloginfo( 'url' ); // Return home blog URL with proper scheme. |
2258 } |
2367 } |
2259 |
2368 |
2260 if ( force_ssl_content() && is_ssl() ) { |
2369 if ( force_ssl_content() && is_ssl() ) { |
2261 $url = set_url_scheme( $url, 'https' ); |
2370 $url = set_url_scheme( $url, 'https' ); |
2262 } |
2371 } |
2389 $count = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" ); |
2498 $count = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" ); |
2390 update_network_option( $network_id, 'user_count', $count ); |
2499 update_network_option( $network_id, 'user_count', $count ); |
2391 } |
2500 } |
2392 |
2501 |
2393 /** |
2502 /** |
2394 * Returns the space used by the current blog. |
2503 * Returns the space used by the current site. |
2395 * |
2504 * |
2396 * @since 3.5.0 |
2505 * @since 3.5.0 |
2397 * |
2506 * |
2398 * @return int Used space in megabytes |
2507 * @return int Used space in megabytes. |
2399 */ |
2508 */ |
2400 function get_space_used() { |
2509 function get_space_used() { |
2401 /** |
2510 /** |
2402 * Filters the amount of storage space used by the current site. |
2511 * Filters the amount of storage space used by the current site, in megabytes. |
2403 * |
2512 * |
2404 * @since 3.5.0 |
2513 * @since 3.5.0 |
2405 * |
2514 * |
2406 * @param int|bool $space_used The amount of used space, in megabytes. Default false. |
2515 * @param int|false $space_used The amount of used space, in megabytes. Default false. |
2407 */ |
2516 */ |
2408 $space_used = apply_filters( 'pre_get_space_used', false ); |
2517 $space_used = apply_filters( 'pre_get_space_used', false ); |
2409 if ( false === $space_used ) { |
2518 if ( false === $space_used ) { |
2410 $upload_dir = wp_upload_dir(); |
2519 $upload_dir = wp_upload_dir(); |
2411 $space_used = get_dirsize( $upload_dir['basedir'] ) / MB_IN_BYTES; |
2520 $space_used = get_dirsize( $upload_dir['basedir'] ) / MB_IN_BYTES; |
2485 /** |
2594 /** |
2486 * Filters the maximum upload file size allowed, in bytes. |
2595 * Filters the maximum upload file size allowed, in bytes. |
2487 * |
2596 * |
2488 * @since 3.0.0 |
2597 * @since 3.0.0 |
2489 * |
2598 * |
2490 * @param int $size Upload size limit in bytes. |
2599 * @param int $size Upload size limit in bytes. |
2491 * @return int Upload size limit in bytes. |
2600 * @return int Upload size limit in bytes. |
2492 */ |
2601 */ |
2493 function upload_size_limit_filter( $size ) { |
2602 function upload_size_limit_filter( $size ) { |
2494 $fileupload_maxk = KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ); |
2603 $fileupload_maxk = KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ); |
2495 if ( get_site_option( 'upload_space_check_disabled' ) ) { |
2604 if ( get_site_option( 'upload_space_check_disabled' ) ) { |
2496 return min( $size, $fileupload_maxk ); |
2605 return min( $size, $fileupload_maxk ); |
2533 */ |
2642 */ |
2534 return apply_filters( 'wp_is_large_network', $count > 10000, 'users', $count, $network_id ); |
2643 return apply_filters( 'wp_is_large_network', $count > 10000, 'users', $count, $network_id ); |
2535 } |
2644 } |
2536 |
2645 |
2537 $count = get_blog_count( $network_id ); |
2646 $count = get_blog_count( $network_id ); |
|
2647 |
2538 /** This filter is documented in wp-includes/ms-functions.php */ |
2648 /** This filter is documented in wp-includes/ms-functions.php */ |
2539 return apply_filters( 'wp_is_large_network', $count > 10000, 'sites', $count, $network_id ); |
2649 return apply_filters( 'wp_is_large_network', $count > 10000, 'sites', $count, $network_id ); |
2540 } |
2650 } |
2541 |
2651 |
2542 /** |
2652 /** |
2543 * Retrieves a list of reserved site on a sub-directory Multisite installation. |
2653 * Retrieves a list of reserved site on a sub-directory Multisite installation. |
2544 * |
2654 * |
2545 * @since 4.4.0 |
2655 * @since 4.4.0 |
2546 * |
2656 * |
2547 * @return array $names Array of reserved subdirectory names. |
2657 * @return string[] Array of reserved names. |
2548 */ |
2658 */ |
2549 function get_subdirectory_reserved_names() { |
2659 function get_subdirectory_reserved_names() { |
2550 $names = array( |
2660 $names = array( |
2551 'page', |
2661 'page', |
2552 'comments', |
2662 'comments', |
2565 * |
2675 * |
2566 * @since 3.0.0 |
2676 * @since 3.0.0 |
2567 * @since 4.4.0 'wp-admin', 'wp-content', 'wp-includes', 'wp-json', and 'embed' were added |
2677 * @since 4.4.0 'wp-admin', 'wp-content', 'wp-includes', 'wp-json', and 'embed' were added |
2568 * to the reserved names list. |
2678 * to the reserved names list. |
2569 * |
2679 * |
2570 * @param array $subdirectory_reserved_names Array of reserved names. |
2680 * @param string[] $subdirectory_reserved_names Array of reserved names. |
2571 */ |
2681 */ |
2572 return apply_filters( 'subdirectory_reserved_names', $names ); |
2682 return apply_filters( 'subdirectory_reserved_names', $names ); |
2573 } |
2683 } |
2574 |
2684 |
2575 /** |
2685 /** |
2581 * |
2691 * |
2582 * @param string $old_value The old network admin email address. |
2692 * @param string $old_value The old network admin email address. |
2583 * @param string $value The proposed new network admin email address. |
2693 * @param string $value The proposed new network admin email address. |
2584 */ |
2694 */ |
2585 function update_network_option_new_admin_email( $old_value, $value ) { |
2695 function update_network_option_new_admin_email( $old_value, $value ) { |
2586 if ( $value == get_site_option( 'admin_email' ) || ! is_email( $value ) ) { |
2696 if ( get_site_option( 'admin_email' ) === $value || ! is_email( $value ) ) { |
2587 return; |
2697 return; |
2588 } |
2698 } |
2589 |
2699 |
2590 $hash = md5( $value . time() . mt_rand() ); |
2700 $hash = md5( $value . time() . mt_rand() ); |
2591 $new_admin_email = array( |
2701 $new_admin_email = array( |
2643 $content = str_replace( '###ADMIN_URL###', esc_url( network_admin_url( 'settings.php?network_admin_hash=' . $hash ) ), $content ); |
2753 $content = str_replace( '###ADMIN_URL###', esc_url( network_admin_url( 'settings.php?network_admin_hash=' . $hash ) ), $content ); |
2644 $content = str_replace( '###EMAIL###', $value, $content ); |
2754 $content = str_replace( '###EMAIL###', $value, $content ); |
2645 $content = str_replace( '###SITENAME###', wp_specialchars_decode( get_site_option( 'site_name' ), ENT_QUOTES ), $content ); |
2755 $content = str_replace( '###SITENAME###', wp_specialchars_decode( get_site_option( 'site_name' ), ENT_QUOTES ), $content ); |
2646 $content = str_replace( '###SITEURL###', network_home_url(), $content ); |
2756 $content = str_replace( '###SITEURL###', network_home_url(), $content ); |
2647 |
2757 |
2648 /* translators: Email change notification email subject. %s: Network title */ |
2758 wp_mail( |
2649 wp_mail( $value, sprintf( __( '[%s] Network Admin Email Change Request' ), wp_specialchars_decode( get_site_option( 'site_name' ), ENT_QUOTES ) ), $content ); |
2759 $value, |
|
2760 sprintf( |
|
2761 /* translators: Email change notification email subject. %s: Network title. */ |
|
2762 __( '[%s] Network Admin Email Change Request' ), |
|
2763 wp_specialchars_decode( get_site_option( 'site_name' ), ENT_QUOTES ) |
|
2764 ), |
|
2765 $content |
|
2766 ); |
2650 |
2767 |
2651 if ( $switched_locale ) { |
2768 if ( $switched_locale ) { |
2652 restore_previous_locale(); |
2769 restore_previous_locale(); |
2653 } |
2770 } |
2654 } |
2771 } |
2702 ###SITEURL###' |
2819 ###SITEURL###' |
2703 ); |
2820 ); |
2704 |
2821 |
2705 $email_change_email = array( |
2822 $email_change_email = array( |
2706 'to' => $old_email, |
2823 'to' => $old_email, |
2707 /* translators: Network admin email change notification email subject. %s: Network title */ |
2824 /* translators: Network admin email change notification email subject. %s: Network title. */ |
2708 'subject' => __( '[%s] Network Admin Email Changed' ), |
2825 'subject' => __( '[%s] Network Admin Email Changed' ), |
2709 'message' => $email_change_text, |
2826 'message' => $email_change_text, |
2710 'headers' => '', |
2827 'headers' => '', |
2711 ); |
2828 ); |
2712 // get network name |
2829 // Get network name. |
2713 $network_name = wp_specialchars_decode( get_site_option( 'site_name' ), ENT_QUOTES ); |
2830 $network_name = wp_specialchars_decode( get_site_option( 'site_name' ), ENT_QUOTES ); |
2714 |
2831 |
2715 /** |
2832 /** |
2716 * Filters the contents of the email notification sent when the network admin email address is changed. |
2833 * Filters the contents of the email notification sent when the network admin email address is changed. |
2717 * |
2834 * |