150 * |
150 * |
151 * @since MU 1.0 |
151 * @since MU 1.0 |
152 * |
152 * |
153 * @param int $blog_id ID of the blog. |
153 * @param int $blog_id ID of the blog. |
154 * @param int $post_id ID of the post you're looking for. |
154 * @param int $post_id ID of the post you're looking for. |
155 * @return object The post. |
155 * @return WP_Post|null WP_Post on success or null on failure |
156 */ |
156 */ |
157 function get_blog_post( $blog_id, $post_id ) { |
157 function get_blog_post( $blog_id, $post_id ) { |
158 global $wpdb; |
158 switch_to_blog( $blog_id ); |
159 |
159 $post = get_post( $post_id ); |
160 $key = $blog_id . '-' . $post_id; |
160 restore_current_blog(); |
161 $post = wp_cache_get( $key, 'global-posts' ); |
|
162 if ( $post == false ) { |
|
163 $post = $wpdb->get_row( $wpdb->prepare( 'SELECT * FROM ' . $wpdb->get_blog_prefix( $blog_id ) . 'posts WHERE ID = %d', $post_id ) ); |
|
164 wp_cache_add( $key, $post, 'global-posts' ); |
|
165 } |
|
166 |
161 |
167 return $post; |
162 return $post; |
168 } |
163 } |
169 |
164 |
170 /** |
165 /** |
181 * @return bool |
176 * @return bool |
182 */ |
177 */ |
183 function add_user_to_blog( $blog_id, $user_id, $role ) { |
178 function add_user_to_blog( $blog_id, $user_id, $role ) { |
184 switch_to_blog($blog_id); |
179 switch_to_blog($blog_id); |
185 |
180 |
186 $user = new WP_User($user_id); |
181 $user = get_userdata( $user_id ); |
187 |
182 |
188 if ( ! $user->exists() ) { |
183 if ( ! $user ) { |
189 restore_current_blog(); |
184 restore_current_blog(); |
190 return new WP_Error('user_does_not_exist', __('That user does not exist.')); |
185 return new WP_Error( 'user_does_not_exist', __( 'The requested user does not exist.' ) ); |
191 } |
186 } |
192 |
187 |
193 if ( !get_user_meta($user_id, 'primary_blog', true) ) { |
188 if ( !get_user_meta($user_id, 'primary_blog', true) ) { |
194 update_user_meta($user_id, 'primary_blog', $blog_id); |
189 update_user_meta($user_id, 'primary_blog', $blog_id); |
195 $details = get_blog_details($blog_id); |
190 $details = get_blog_details($blog_id); |
244 update_user_meta($user_id, 'primary_blog', $new_id); |
239 update_user_meta($user_id, 'primary_blog', $new_id); |
245 update_user_meta($user_id, 'source_domain', $new_domain); |
240 update_user_meta($user_id, 'source_domain', $new_domain); |
246 } |
241 } |
247 |
242 |
248 // wp_revoke_user($user_id); |
243 // wp_revoke_user($user_id); |
249 $user = new WP_User($user_id); |
244 $user = get_userdata( $user_id ); |
250 if ( ! $user->exists() ) { |
245 if ( ! $user ) { |
251 restore_current_blog(); |
246 restore_current_blog(); |
252 return new WP_Error('user_does_not_exist', __('That user does not exist.')); |
247 return new WP_Error('user_does_not_exist', __('That user does not exist.')); |
253 } |
248 } |
254 |
249 |
255 $user->remove_all_caps(); |
250 $user->remove_all_caps(); |
311 /** |
306 /** |
312 * Get the permalink for a post on another blog. |
307 * Get the permalink for a post on another blog. |
313 * |
308 * |
314 * @since MU 1.0 |
309 * @since MU 1.0 |
315 * |
310 * |
316 * @param int $_blog_id ID of the source blog. |
311 * @param int $blog_id ID of the source blog. |
317 * @param int $post_id ID of the desired post. |
312 * @param int $post_id ID of the desired post. |
318 * @return string The post's permalink |
313 * @return string The post's permalink |
319 */ |
314 */ |
320 function get_blog_permalink( $_blog_id, $post_id ) { |
315 function get_blog_permalink( $blog_id, $post_id ) { |
321 $key = "{$_blog_id}-{$post_id}-blog_permalink"; |
316 switch_to_blog( $blog_id ); |
322 $link = wp_cache_get( $key, 'site-options' ); |
317 $link = get_permalink( $post_id ); |
323 if ( $link == false ) { |
318 restore_current_blog(); |
324 switch_to_blog( $_blog_id ); |
319 |
325 $link = get_permalink( $post_id ); |
|
326 restore_current_blog(); |
|
327 wp_cache_add( $key, $link, 'site-options', 360 ); |
|
328 } |
|
329 return $link; |
320 return $link; |
330 } |
321 } |
331 |
322 |
332 /** |
323 /** |
333 * Get a blog's numeric ID from its URL. |
324 * Get a blog's numeric ID from its URL. |
339 * |
330 * |
340 * @since MU 2.6.5 |
331 * @since MU 2.6.5 |
341 * |
332 * |
342 * @param string $domain |
333 * @param string $domain |
343 * @param string $path Optional. Not required for subdomain installations. |
334 * @param string $path Optional. Not required for subdomain installations. |
344 * @return int |
335 * @return int 0 if no blog found, otherwise the ID of the matching blog |
345 */ |
336 */ |
346 function get_blog_id_from_url( $domain, $path = '/' ) { |
337 function get_blog_id_from_url( $domain, $path = '/' ) { |
347 global $wpdb; |
338 global $wpdb; |
348 |
339 |
349 $domain = strtolower( $wpdb->escape( $domain ) ); |
340 $domain = strtolower( $domain ); |
350 $path = strtolower( $wpdb->escape( $path ) ); |
341 $path = strtolower( $path ); |
351 $id = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' ); |
342 $id = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' ); |
352 |
343 |
353 if ( $id == -1 ) { // blog does not exist |
344 if ( $id == -1 ) // blog does not exist |
354 return 0; |
345 return 0; |
355 } elseif ( $id ) { |
346 elseif ( $id ) |
356 return (int)$id; |
347 return (int) $id; |
357 } |
348 |
358 |
349 $id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s and path = %s /* get_blog_id_from_url */", $domain, $path ) ); |
359 $id = $wpdb->get_var( "SELECT blog_id FROM $wpdb->blogs WHERE domain = '$domain' and path = '$path' /* get_blog_id_from_url */" ); |
350 |
360 |
351 if ( ! $id ) { |
361 if ( !$id ) { |
|
362 wp_cache_set( md5( $domain . $path ), -1, 'blog-id-cache' ); |
352 wp_cache_set( md5( $domain . $path ), -1, 'blog-id-cache' ); |
363 return false; |
353 return 0; |
364 } |
354 } |
|
355 |
365 wp_cache_set( md5( $domain . $path ), $id, 'blog-id-cache' ); |
356 wp_cache_set( md5( $domain . $path ), $id, 'blog-id-cache' ); |
366 |
357 |
367 return $id; |
358 return $id; |
368 } |
359 } |
369 |
360 |
382 * @param string $user_email The email provided by the user at registration. |
373 * @param string $user_email The email provided by the user at registration. |
383 * @return bool Returns true when the email address is banned. |
374 * @return bool Returns true when the email address is banned. |
384 */ |
375 */ |
385 function is_email_address_unsafe( $user_email ) { |
376 function is_email_address_unsafe( $user_email ) { |
386 $banned_names = get_site_option( 'banned_email_domains' ); |
377 $banned_names = get_site_option( 'banned_email_domains' ); |
387 if ($banned_names && !is_array( $banned_names )) |
378 if ( $banned_names && ! is_array( $banned_names ) ) |
388 $banned_names = explode( "\n", $banned_names); |
379 $banned_names = explode( "\n", $banned_names ); |
389 |
380 |
390 if ( is_array( $banned_names ) && empty( $banned_names ) == false ) { |
381 $is_email_address_unsafe = false; |
391 $email_domain = strtolower( substr( $user_email, 1 + strpos( $user_email, '@' ) ) ); |
382 |
392 foreach ( (array) $banned_names as $banned_domain ) { |
383 if ( $banned_names && is_array( $banned_names ) ) { |
393 if ( $banned_domain == '' ) |
384 list( $email_local_part, $email_domain ) = explode( '@', $user_email ); |
|
385 |
|
386 foreach ( $banned_names as $banned_domain ) { |
|
387 if ( ! $banned_domain ) |
394 continue; |
388 continue; |
395 if ( |
389 |
396 strstr( $email_domain, $banned_domain ) || |
390 if ( $email_domain == $banned_domain ) { |
397 ( |
391 $is_email_address_unsafe = true; |
398 strstr( $banned_domain, '/' ) && |
392 break; |
399 preg_match( $banned_domain, $email_domain ) |
393 } |
400 ) |
394 |
401 ) |
395 $dotted_domain = ".$banned_domain"; |
402 return true; |
396 if ( $dotted_domain === substr( $user_email, -strlen( $dotted_domain ) ) ) { |
|
397 $is_email_address_unsafe = true; |
|
398 break; |
|
399 } |
403 } |
400 } |
404 } |
401 } |
405 return false; |
402 |
|
403 return apply_filters( 'is_email_address_unsafe', $is_email_address_unsafe, $user_email ); |
406 } |
404 } |
407 |
405 |
408 /** |
406 /** |
409 * Processes new user registrations. |
407 * Processes new user registrations. |
410 * |
408 * |
469 preg_match( '/[0-9]*/', $user_name, $match ); |
467 preg_match( '/[0-9]*/', $user_name, $match ); |
470 if ( $match[0] == $user_name ) |
468 if ( $match[0] == $user_name ) |
471 $errors->add('user_name', __('Sorry, usernames must have letters too!')); |
469 $errors->add('user_name', __('Sorry, usernames must have letters too!')); |
472 |
470 |
473 if ( !is_email( $user_email ) ) |
471 if ( !is_email( $user_email ) ) |
474 $errors->add('user_email', __( 'Please enter a correct email address.' ) ); |
472 $errors->add('user_email', __( 'Please enter a valid email address.' ) ); |
475 |
473 |
476 $limited_email_domains = get_site_option( 'limited_email_domains' ); |
474 $limited_email_domains = get_site_option( 'limited_email_domains' ); |
477 if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) { |
475 if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) { |
478 $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) ); |
476 $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) ); |
479 if ( in_array( $emaildomain, $limited_email_domains ) == false ) |
477 if ( in_array( $emaildomain, $limited_email_domains ) == false ) |
480 $errors->add('user_email', __('Sorry, that email address is not allowed!')); |
478 $errors->add('user_email', __('Sorry, that email address is not allowed!')); |
481 } |
479 } |
482 |
480 |
483 // Check if the username has been used already. |
481 // Check if the username has been used already. |
484 if ( username_exists($user_name) ) |
482 if ( username_exists($user_name) ) |
485 $errors->add('user_name', __('Sorry, that username already exists!')); |
483 $errors->add( 'user_name', __( 'Sorry, that username already exists!' ) ); |
486 |
484 |
487 // Check if the email address has been used already. |
485 // Check if the email address has been used already. |
488 if ( email_exists($user_email) ) |
486 if ( email_exists($user_email) ) |
489 $errors->add('user_email', __('Sorry, that email address is already used!')); |
487 $errors->add( 'user_email', __( 'Sorry, that email address is already used!' ) ); |
490 |
488 |
491 // Has someone already signed up for this username? |
489 // Has someone already signed up for this username? |
492 $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE user_login = %s", $user_name) ); |
490 $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE user_login = %s", $user_name) ); |
493 if ( $signup != null ) { |
491 if ( $signup != null ) { |
494 $registered_at = mysql2date('U', $signup->registered); |
492 $registered_at = mysql2date('U', $signup->registered); |
495 $now = current_time( 'timestamp', true ); |
493 $now = current_time( 'timestamp', true ); |
496 $diff = $now - $registered_at; |
494 $diff = $now - $registered_at; |
497 // If registered more than two days ago, cancel registration and let this signup go through. |
495 // If registered more than two days ago, cancel registration and let this signup go through. |
498 if ( $diff > 172800 ) |
496 if ( $diff > 2 * DAY_IN_SECONDS ) |
499 $wpdb->delete( $wpdb->signups, array( 'user_login' => $user_name ) ); |
497 $wpdb->delete( $wpdb->signups, array( 'user_login' => $user_name ) ); |
500 else |
498 else |
501 $errors->add('user_name', __('That username is currently reserved but may be available in a couple of days.')); |
499 $errors->add('user_name', __('That username is currently reserved but may be available in a couple of days.')); |
502 |
500 |
503 if ( $signup->active == 0 && $signup->user_email == $user_email ) |
501 if ( $signup->active == 0 && $signup->user_email == $user_email ) |
506 |
504 |
507 $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE user_email = %s", $user_email) ); |
505 $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE user_email = %s", $user_email) ); |
508 if ( $signup != null ) { |
506 if ( $signup != null ) { |
509 $diff = current_time( 'timestamp', true ) - mysql2date('U', $signup->registered); |
507 $diff = current_time( 'timestamp', true ) - mysql2date('U', $signup->registered); |
510 // If registered more than two days ago, cancel registration and let this signup go through. |
508 // If registered more than two days ago, cancel registration and let this signup go through. |
511 if ( $diff > 172800 ) |
509 if ( $diff > 2 * DAY_IN_SECONDS ) |
512 $wpdb->delete( $wpdb->signups, array( 'user_email' => $user_email ) ); |
510 $wpdb->delete( $wpdb->signups, array( 'user_email' => $user_email ) ); |
513 else |
511 else |
514 $errors->add('user_email', __('That email address has already been used. Please check your inbox for an activation email. It will become available in a couple of days if you do nothing.')); |
512 $errors->add('user_email', __('That email address has already been used. Please check your inbox for an activation email. It will become available in a couple of days if you do nothing.')); |
515 } |
513 } |
516 |
514 |
540 * @param string $blogname The blog name provided by the user. Must be unique. |
538 * @param string $blogname The blog name provided by the user. Must be unique. |
541 * @param string $blog_title The blog title provided by the user. |
539 * @param string $blog_title The blog title provided by the user. |
542 * @return array Contains the new site data and error messages. |
540 * @return array Contains the new site data and error messages. |
543 */ |
541 */ |
544 function wpmu_validate_blog_signup($blogname, $blog_title, $user = '') { |
542 function wpmu_validate_blog_signup($blogname, $blog_title, $user = '') { |
545 global $wpdb, $domain, $base, $current_site; |
543 global $wpdb, $domain, $current_site; |
|
544 |
|
545 $base = $current_site->path; |
546 |
546 |
547 $blog_title = strip_tags( $blog_title ); |
547 $blog_title = strip_tags( $blog_title ); |
548 $blog_title = substr( $blog_title, 0, 50 ); |
548 $blog_title = substr( $blog_title, 0, 50 ); |
549 |
549 |
550 $errors = new WP_Error(); |
550 $errors = new WP_Error(); |
560 |
560 |
561 if ( empty( $blogname ) ) |
561 if ( empty( $blogname ) ) |
562 $errors->add('blogname', __( 'Please enter a site name.' ) ); |
562 $errors->add('blogname', __( 'Please enter a site name.' ) ); |
563 |
563 |
564 if ( preg_match( '/[^a-z0-9]+/', $blogname ) ) |
564 if ( preg_match( '/[^a-z0-9]+/', $blogname ) ) |
565 $errors->add('blogname', __( 'Only lowercase letters and numbers allowed.' ) ); |
565 $errors->add('blogname', __( 'Only lowercase letters (a-z) and numbers are allowed.' ) ); |
566 |
566 |
567 if ( in_array( $blogname, $illegal_names ) == true ) |
567 if ( in_array( $blogname, $illegal_names ) == true ) |
568 $errors->add('blogname', __( 'That name is not allowed.' ) ); |
568 $errors->add('blogname', __( 'That name is not allowed.' ) ); |
569 |
569 |
570 if ( strlen( $blogname ) < 4 && !is_super_admin() ) |
570 if ( strlen( $blogname ) < 4 && !is_super_admin() ) |
596 $path = $base; |
596 $path = $base; |
597 } else { |
597 } else { |
598 $mydomain = "$domain"; |
598 $mydomain = "$domain"; |
599 $path = $base.$blogname.'/'; |
599 $path = $base.$blogname.'/'; |
600 } |
600 } |
601 if ( domain_exists($mydomain, $path) ) |
601 if ( domain_exists($mydomain, $path, $current_site->id) ) |
602 $errors->add('blogname', __('Sorry, that site already exists!')); |
602 $errors->add( 'blogname', __( 'Sorry, that site already exists!' ) ); |
603 |
603 |
604 if ( username_exists( $blogname ) ) { |
604 if ( username_exists( $blogname ) ) { |
605 if ( is_object( $user ) == false || ( is_object($user) && ( $user->user_login != $blogname ) ) ) |
605 if ( is_object( $user ) == false || ( is_object($user) && ( $user->user_login != $blogname ) ) ) |
606 $errors->add( 'blogname', __( 'Sorry, that site is reserved!' ) ); |
606 $errors->add( 'blogname', __( 'Sorry, that site is reserved!' ) ); |
607 } |
607 } |
609 // Has someone already signed up for this domain? |
609 // Has someone already signed up for this domain? |
610 $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE domain = %s AND path = %s", $mydomain, $path) ); // TODO: Check email too? |
610 $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE domain = %s AND path = %s", $mydomain, $path) ); // TODO: Check email too? |
611 if ( ! empty($signup) ) { |
611 if ( ! empty($signup) ) { |
612 $diff = current_time( 'timestamp', true ) - mysql2date('U', $signup->registered); |
612 $diff = current_time( 'timestamp', true ) - mysql2date('U', $signup->registered); |
613 // If registered more than two days ago, cancel registration and let this signup go through. |
613 // If registered more than two days ago, cancel registration and let this signup go through. |
614 if ( $diff > 172800 ) |
614 if ( $diff > 2 * DAY_IN_SECONDS ) |
615 $wpdb->delete( $wpdb->signups, array( 'domain' => $mydomain , 'path' => $path ) ); |
615 $wpdb->delete( $wpdb->signups, array( 'domain' => $mydomain , 'path' => $path ) ); |
616 else |
616 else |
617 $errors->add('blogname', __('That site is currently reserved but may be available in a couple days.')); |
617 $errors->add('blogname', __('That site is currently reserved but may be available in a couple days.')); |
618 } |
618 } |
619 |
619 |
620 $result = array('domain' => $mydomain, 'path' => $path, 'blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors); |
620 $result = array('domain' => $mydomain, 'path' => $path, 'blogname' => $blogname, 'blog_title' => $blog_title, 'user' => $user, 'errors' => $errors); |
621 return apply_filters('wpmu_validate_blog_signup', $result); |
621 return apply_filters('wpmu_validate_blog_signup', $result); |
622 } |
622 } |
623 |
623 |
624 /** |
624 /** |
625 * Record site signup information for future activation. |
625 * Record site signup information for future activation. |
788 $admin_email = 'support@' . $_SERVER['SERVER_NAME']; |
788 $admin_email = 'support@' . $_SERVER['SERVER_NAME']; |
789 $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) ); |
789 $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) ); |
790 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; |
790 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; |
791 $message = sprintf( |
791 $message = sprintf( |
792 apply_filters( 'wpmu_signup_user_notification_email', |
792 apply_filters( 'wpmu_signup_user_notification_email', |
793 __( "To activate your user, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login.\n\n" ), |
793 __( "To activate your user, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login." ), |
794 $user, $user_email, $key, $meta |
794 $user, $user_email, $key, $meta |
795 ), |
795 ), |
796 site_url( "wp-activate.php?key=$key" ) |
796 site_url( "wp-activate.php?key=$key" ) |
797 ); |
797 ); |
798 // TODO: Don't hard code activation link. |
798 // TODO: Don't hard code activation link. |
963 if ( empty($path) ) |
963 if ( empty($path) ) |
964 $path = '/'; |
964 $path = '/'; |
965 |
965 |
966 // Check if the domain has been used already. We should return an error message. |
966 // Check if the domain has been used already. We should return an error message. |
967 if ( domain_exists($domain, $path, $site_id) ) |
967 if ( domain_exists($domain, $path, $site_id) ) |
968 return new WP_Error('blog_taken', __('Site already exists.')); |
968 return new WP_Error( 'blog_taken', __( 'Sorry, that site already exists!' ) ); |
969 |
969 |
970 if ( !defined('WP_INSTALLING') ) |
970 if ( !defined('WP_INSTALLING') ) |
971 define( 'WP_INSTALLING', true ); |
971 define( 'WP_INSTALLING', true ); |
972 |
972 |
973 if ( ! $blog_id = insert_blog($domain, $path, $site_id) ) |
973 if ( ! $blog_id = insert_blog($domain, $path, $site_id) ) |
1022 switch_to_blog( $blog_id ); |
1022 switch_to_blog( $blog_id ); |
1023 $blogname = get_option( 'blogname' ); |
1023 $blogname = get_option( 'blogname' ); |
1024 $siteurl = site_url(); |
1024 $siteurl = site_url(); |
1025 restore_current_blog(); |
1025 restore_current_blog(); |
1026 |
1026 |
1027 $msg = sprintf( __( 'New Site: %1s |
1027 $msg = sprintf( __( 'New Site: %1$s |
1028 URL: %2s |
1028 URL: %2$s |
1029 Remote IP: %3s |
1029 Remote IP: %3$s |
1030 |
1030 |
1031 Disable these notifications: %4s' ), $blogname, $siteurl, $_SERVER['REMOTE_ADDR'], $options_site_url); |
1031 Disable these notifications: %4$s' ), $blogname, $siteurl, $_SERVER['REMOTE_ADDR'], $options_site_url); |
1032 $msg = apply_filters( 'newblog_notify_siteadmin', $msg ); |
1032 $msg = apply_filters( 'newblog_notify_siteadmin', $msg ); |
1033 |
1033 |
1034 wp_mail( $email, sprintf( __( 'New Site Registration: %s' ), $siteurl ), $msg ); |
1034 wp_mail( $email, sprintf( __( 'New Site Registration: %s' ), $siteurl ), $msg ); |
1035 return true; |
1035 return true; |
1036 } |
1036 } |
1054 $email = get_site_option( 'admin_email' ); |
1054 $email = get_site_option( 'admin_email' ); |
1055 |
1055 |
1056 if ( is_email($email) == false ) |
1056 if ( is_email($email) == false ) |
1057 return false; |
1057 return false; |
1058 |
1058 |
1059 $user = new WP_User($user_id); |
1059 $user = get_userdata( $user_id ); |
1060 |
1060 |
1061 $options_site_url = esc_url(network_admin_url('settings.php')); |
1061 $options_site_url = esc_url(network_admin_url('settings.php')); |
1062 $msg = sprintf(__('New User: %1s |
1062 $msg = sprintf(__('New User: %1$s |
1063 Remote IP: %2s |
1063 Remote IP: %2$s |
1064 |
1064 |
1065 Disable these notifications: %3s'), $user->user_login, $_SERVER['REMOTE_ADDR'], $options_site_url); |
1065 Disable these notifications: %3$s'), $user->user_login, $_SERVER['REMOTE_ADDR'], $options_site_url); |
1066 |
1066 |
1067 $msg = apply_filters( 'newuser_notify_siteadmin', $msg, $user ); |
1067 $msg = apply_filters( 'newuser_notify_siteadmin', $msg, $user ); |
1068 wp_mail( $email, sprintf(__('New User Registration: %s'), $user->user_login), $msg ); |
1068 wp_mail( $email, sprintf(__('New User Registration: %s'), $user->user_login), $msg ); |
1069 return true; |
1069 return true; |
1070 } |
1070 } |
1082 * @param int $site_id Optional. Relevant only on multi-network installs. |
1082 * @param int $site_id Optional. Relevant only on multi-network installs. |
1083 * @return int |
1083 * @return int |
1084 */ |
1084 */ |
1085 function domain_exists($domain, $path, $site_id = 1) { |
1085 function domain_exists($domain, $path, $site_id = 1) { |
1086 global $wpdb; |
1086 global $wpdb; |
1087 return $wpdb->get_var( $wpdb->prepare("SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s AND site_id = %d", $domain, $path, $site_id) ); |
1087 $result = $wpdb->get_var( $wpdb->prepare("SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s AND site_id = %d", $domain, $path, $site_id) ); |
|
1088 return apply_filters( 'domain_exists', $result, $domain, $path, $site_id ); |
1088 } |
1089 } |
1089 |
1090 |
1090 /** |
1091 /** |
1091 * Store basic site info in the blogs table. |
1092 * Store basic site info in the blogs table. |
1092 * |
1093 * |
1127 * |
1128 * |
1128 * @param int $blog_id The value returned by insert_blog(). |
1129 * @param int $blog_id The value returned by insert_blog(). |
1129 * @param string $blog_title The title of the new site. |
1130 * @param string $blog_title The title of the new site. |
1130 */ |
1131 */ |
1131 function install_blog($blog_id, $blog_title = '') { |
1132 function install_blog($blog_id, $blog_title = '') { |
1132 global $wpdb, $table_prefix, $wp_roles; |
1133 global $wpdb, $wp_roles, $current_site; |
1133 $wpdb->suppress_errors(); |
|
1134 |
1134 |
1135 // Cast for security |
1135 // Cast for security |
1136 $blog_id = (int) $blog_id; |
1136 $blog_id = (int) $blog_id; |
1137 |
1137 |
1138 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
1138 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
1139 |
1139 |
1140 if ( $wpdb->get_results("SELECT ID FROM $wpdb->posts") ) |
1140 $wpdb->suppress_errors(); |
1141 die(__('<h1>Already Installed</h1><p>You appear to have already installed WordPress. To reinstall please clear your old database tables first.</p>') . '</body></html>'); |
1141 if ( $wpdb->get_results( "DESCRIBE {$wpdb->posts}" ) ) |
1142 |
1142 die( '<h1>' . __( 'Already Installed' ) . '</h1><p>' . __( 'You appear to have already installed WordPress. To reinstall please clear your old database tables first.' ) . '</p></body></html>' ); |
1143 $wpdb->suppress_errors(false); |
1143 $wpdb->suppress_errors( false ); |
1144 |
1144 |
1145 $url = get_blogaddress_by_id($blog_id); |
1145 $url = get_blogaddress_by_id( $blog_id ); |
1146 |
1146 |
1147 // Set everything up |
1147 // Set everything up |
1148 make_db_current_silent( 'blog' ); |
1148 make_db_current_silent( 'blog' ); |
1149 populate_options(); |
1149 populate_options(); |
1150 populate_roles(); |
1150 populate_roles(); |
1151 $wp_roles->_init(); |
1151 $wp_roles->_init(); |
1152 |
1152 |
1153 // fix url. |
1153 $url = untrailingslashit( $url ); |
1154 update_option('siteurl', $url); |
1154 |
1155 update_option('home', $url); |
1155 update_option( 'siteurl', $url ); |
1156 update_option('fileupload_url', $url . "files" ); |
1156 update_option( 'home', $url ); |
1157 update_option('upload_path', UPLOADBLOGSDIR . "/$blog_id/files"); |
1157 |
1158 update_option('blogname', stripslashes( $blog_title ) ); |
1158 if ( get_site_option( 'ms_files_rewriting' ) ) |
1159 update_option('admin_email', ''); |
1159 update_option( 'upload_path', UPLOADBLOGSDIR . "/$blog_id/files" ); |
1160 $wpdb->update( $wpdb->options, array('option_value' => ''), array('option_name' => 'admin_email') ); |
1160 else |
|
1161 update_option( 'upload_path', get_blog_option( $current_site->blog_id, 'upload_path' ) ); |
|
1162 |
|
1163 update_option( 'blogname', stripslashes( $blog_title ) ); |
|
1164 update_option( 'admin_email', '' ); |
1161 |
1165 |
1162 // remove all perms |
1166 // remove all perms |
1163 $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => $table_prefix.'user_level' ) ); |
1167 $table_prefix = $wpdb->get_blog_prefix(); |
1164 |
1168 delete_metadata( 'user', 0, $table_prefix . 'user_level', null, true ); // delete all |
1165 $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => $table_prefix.'capabilities' ) ); |
1169 delete_metadata( 'user', 0, $table_prefix . 'capabilities', null, true ); // delete all |
1166 |
|
1167 $wpdb->suppress_errors( false ); |
|
1168 } |
1170 } |
1169 |
1171 |
1170 /** |
1172 /** |
1171 * Set blog defaults. |
1173 * Set blog defaults. |
1172 * |
1174 * |
1230 We hope you enjoy your new site. Thanks! |
1232 We hope you enjoy your new site. Thanks! |
1231 |
1233 |
1232 --The Team @ SITE_NAME' ) ); |
1234 --The Team @ SITE_NAME' ) ); |
1233 |
1235 |
1234 $url = get_blogaddress_by_id($blog_id); |
1236 $url = get_blogaddress_by_id($blog_id); |
1235 $user = new WP_User($user_id); |
1237 $user = get_userdata( $user_id ); |
1236 |
1238 |
1237 $welcome_email = str_replace( 'SITE_NAME', $current_site->site_name, $welcome_email ); |
1239 $welcome_email = str_replace( 'SITE_NAME', $current_site->site_name, $welcome_email ); |
1238 $welcome_email = str_replace( 'BLOG_TITLE', $title, $welcome_email ); |
1240 $welcome_email = str_replace( 'BLOG_TITLE', $title, $welcome_email ); |
1239 $welcome_email = str_replace( 'BLOG_URL', $url, $welcome_email ); |
1241 $welcome_email = str_replace( 'BLOG_URL', $url, $welcome_email ); |
1240 $welcome_email = str_replace( 'USERNAME', $user->user_login, $welcome_email ); |
1242 $welcome_email = str_replace( 'USERNAME', $user->user_login, $welcome_email ); |
1279 if ( !apply_filters('wpmu_welcome_user_notification', $user_id, $password, $meta) ) |
1281 if ( !apply_filters('wpmu_welcome_user_notification', $user_id, $password, $meta) ) |
1280 return false; |
1282 return false; |
1281 |
1283 |
1282 $welcome_email = get_site_option( 'welcome_user_email' ); |
1284 $welcome_email = get_site_option( 'welcome_user_email' ); |
1283 |
1285 |
1284 $user = new WP_User($user_id); |
1286 $user = get_userdata( $user_id ); |
1285 |
1287 |
1286 $welcome_email = apply_filters( 'update_welcome_user_email', $welcome_email, $user_id, $password, $meta); |
1288 $welcome_email = apply_filters( 'update_welcome_user_email', $welcome_email, $user_id, $password, $meta); |
1287 $welcome_email = str_replace( 'SITE_NAME', $current_site->site_name, $welcome_email ); |
1289 $welcome_email = str_replace( 'SITE_NAME', $current_site->site_name, $welcome_email ); |
1288 $welcome_email = str_replace( 'USERNAME', $user->user_login, $welcome_email ); |
1290 $welcome_email = str_replace( 'USERNAME', $user->user_login, $welcome_email ); |
1289 $welcome_email = str_replace( 'PASSWORD', $password, $welcome_email ); |
1291 $welcome_email = str_replace( 'PASSWORD', $password, $welcome_email ); |
1456 } |
1458 } |
1457 return $size; |
1459 return $size; |
1458 } |
1460 } |
1459 |
1461 |
1460 /** |
1462 /** |
1461 * Check whether a blog has used its allotted upload space. |
|
1462 * |
|
1463 * @since MU |
|
1464 * @uses get_dirsize() |
|
1465 * |
|
1466 * @param bool $echo Optional. If $echo is set and the quota is exceeded, a warning message is echoed. Default is true. |
|
1467 * @return int |
|
1468 */ |
|
1469 function upload_is_user_over_quota( $echo = true ) { |
|
1470 if ( get_site_option( 'upload_space_check_disabled' ) ) |
|
1471 return false; |
|
1472 |
|
1473 $spaceAllowed = get_space_allowed(); |
|
1474 if ( empty( $spaceAllowed ) || !is_numeric( $spaceAllowed ) ) |
|
1475 $spaceAllowed = 10; // Default space allowed is 10 MB |
|
1476 |
|
1477 $size = get_dirsize( BLOGUPLOADDIR ) / 1024 / 1024; |
|
1478 |
|
1479 if ( ($spaceAllowed-$size) < 0 ) { |
|
1480 if ( $echo ) |
|
1481 _e( 'Sorry, you have used your space allocation. Please delete some files to upload more files.' ); // No space left |
|
1482 return true; |
|
1483 } else { |
|
1484 return false; |
|
1485 } |
|
1486 } |
|
1487 |
|
1488 /** |
|
1489 * Check an array of MIME types against a whitelist. |
1463 * Check an array of MIME types against a whitelist. |
1490 * |
1464 * |
1491 * WordPress ships with a set of allowed upload filetypes, |
1465 * WordPress ships with a set of allowed upload filetypes, |
1492 * which is defined in wp-includes/functions.php in |
1466 * which is defined in wp-includes/functions.php in |
1493 * get_allowed_mime_types(). This function is used to filter |
1467 * get_allowed_mime_types(). This function is used to filter |
1533 * @param int $blog_id |
1507 * @param int $blog_id |
1534 * @param int $user_id |
1508 * @param int $user_id |
1535 */ |
1509 */ |
1536 function wpmu_log_new_registrations( $blog_id, $user_id ) { |
1510 function wpmu_log_new_registrations( $blog_id, $user_id ) { |
1537 global $wpdb; |
1511 global $wpdb; |
1538 $user = new WP_User( (int) $user_id ); |
1512 $user = get_userdata( (int) $user_id ); |
1539 $wpdb->insert( $wpdb->registration_log, array('email' => $user->user_email, 'IP' => preg_replace( '/[^0-9., ]/', '',$_SERVER['REMOTE_ADDR'] ), 'blog_id' => $blog_id, 'date_registered' => current_time('mysql')) ); |
1513 $wpdb->insert( $wpdb->registration_log, array('email' => $user->user_email, 'IP' => preg_replace( '/[^0-9., ]/', '',$_SERVER['REMOTE_ADDR'] ), 'blog_id' => $blog_id, 'date_registered' => current_time('mysql')) ); |
1540 } |
|
1541 |
|
1542 /** |
|
1543 * Get the remaining upload space for this blog. |
|
1544 * |
|
1545 * @since MU |
|
1546 * @uses upload_is_user_over_quota() |
|
1547 * @uses get_space_allowed() |
|
1548 * @uses get_dirsize() |
|
1549 * |
|
1550 * @param int $size |
|
1551 * @return int |
|
1552 */ |
|
1553 function fix_import_form_size( $size ) { |
|
1554 if ( upload_is_user_over_quota( false ) == true ) |
|
1555 return 0; |
|
1556 |
|
1557 $spaceAllowed = 1024 * 1024 * get_space_allowed(); |
|
1558 $dirsize = get_dirsize( BLOGUPLOADDIR ); |
|
1559 if ( $size > $spaceAllowed - $dirsize ) |
|
1560 return $spaceAllowed - $dirsize; // remaining space |
|
1561 else |
|
1562 return $size; // default |
|
1563 } |
1514 } |
1564 |
1515 |
1565 /** |
1516 /** |
1566 * Maintains a canonical list of terms by syncing terms created for each blog with the global terms table. |
1517 * Maintains a canonical list of terms by syncing terms created for each blog with the global terms table. |
1567 * |
1518 * |
1650 * |
1601 * |
1651 * @param array $upload |
1602 * @param array $upload |
1652 * @return mixed If the upload is under the size limit, $upload is returned. Otherwise returns an error message. |
1603 * @return mixed If the upload is under the size limit, $upload is returned. Otherwise returns an error message. |
1653 */ |
1604 */ |
1654 function upload_is_file_too_big( $upload ) { |
1605 function upload_is_file_too_big( $upload ) { |
1655 if ( is_array( $upload ) == false || defined( 'WP_IMPORTING' ) ) |
1606 if ( is_array( $upload ) == false || defined( 'WP_IMPORTING' ) || get_site_option( 'upload_space_check_disabled' ) ) |
1656 return $upload; |
1607 return $upload; |
1657 |
1608 |
1658 if ( strlen( $upload['bits'] ) > ( 1024 * get_site_option( 'fileupload_maxk', 1500 ) ) ) |
1609 if ( strlen( $upload['bits'] ) > ( 1024 * get_site_option( 'fileupload_maxk', 1500 ) ) ) |
1659 return sprintf( __( 'This file is too big. Files must be less than %d KB in size.' ) . '<br />', get_site_option( 'fileupload_maxk', 1500 )); |
1610 return sprintf( __( 'This file is too big. Files must be less than %d KB in size.' ) . '<br />', get_site_option( 'fileupload_maxk', 1500 )); |
1660 |
1611 |
1732 delete_option( 'new_user_' . $key ); |
1683 delete_option( 'new_user_' . $key ); |
1733 |
1684 |
1734 if ( empty( $details ) || is_wp_error( add_existing_user_to_blog( $details ) ) ) |
1685 if ( empty( $details ) || is_wp_error( add_existing_user_to_blog( $details ) ) ) |
1735 wp_die( sprintf(__('An error occurred adding you to this site. Back to the <a href="%s">homepage</a>.'), home_url() ) ); |
1686 wp_die( sprintf(__('An error occurred adding you to this site. Back to the <a href="%s">homepage</a>.'), home_url() ) ); |
1736 |
1687 |
1737 wp_die( sprintf(__('You have been added to this site. Please visit the <a href="%s">homepage</a> or <a href="%s">log in</a> using your username and password.'), home_url(), admin_url() ), __('Success') ); |
1688 wp_die( sprintf( __( 'You have been added to this site. Please visit the <a href="%s">homepage</a> or <a href="%s">log in</a> using your username and password.' ), home_url(), admin_url() ), __( 'WordPress › Success' ) ); |
1738 } |
1689 } |
1739 |
1690 |
1740 /** |
1691 /** |
1741 * Add a user to a blog based on details from maybe_add_existing_user_to_blog(). |
1692 * Add a user to a blog based on details from maybe_add_existing_user_to_blog(). |
1742 * |
1693 * |
1932 |
1883 |
1933 return $forced_content; |
1884 return $forced_content; |
1934 } |
1885 } |
1935 |
1886 |
1936 /** |
1887 /** |
1937 * Formats an String URL to use HTTPS if HTTP is found. |
1888 * Formats a URL to use https. |
|
1889 * |
1938 * Useful as a filter. |
1890 * Useful as a filter. |
1939 * |
1891 * |
1940 * @since 2.8.5 |
1892 * @since 2.8.5 |
1941 **/ |
1893 * |
|
1894 * @param string URL |
|
1895 * @return string URL with https as the scheme |
|
1896 */ |
1942 function filter_SSL( $url ) { |
1897 function filter_SSL( $url ) { |
1943 if ( !is_string( $url ) ) |
1898 if ( ! is_string( $url ) ) |
1944 return get_bloginfo( 'url' ); //return home blog url with proper scheme |
1899 return get_bloginfo( 'url' ); // Return home blog url with proper scheme |
1945 |
1900 |
1946 $arrURL = parse_url( $url ); |
1901 if ( force_ssl_content() && is_ssl() ) |
1947 |
1902 $url = set_url_scheme( $url, 'https' ); |
1948 if ( force_ssl_content() && is_ssl() ) { |
|
1949 if ( 'http' === $arrURL['scheme'] ) |
|
1950 $url = str_replace( $arrURL['scheme'], 'https', $url ); |
|
1951 } |
|
1952 |
1903 |
1953 return $url; |
1904 return $url; |
1954 } |
1905 } |
1955 |
1906 |
1956 /** |
1907 /** |
1975 global $wpdb; |
1926 global $wpdb; |
1976 |
1927 |
1977 $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(blog_id) as c FROM $wpdb->blogs WHERE site_id = %d AND spam = '0' AND deleted = '0' and archived = '0'", $wpdb->siteid) ); |
1928 $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(blog_id) as c FROM $wpdb->blogs WHERE site_id = %d AND spam = '0' AND deleted = '0' and archived = '0'", $wpdb->siteid) ); |
1978 update_site_option( 'blog_count', $count ); |
1929 update_site_option( 'blog_count', $count ); |
1979 |
1930 |
1980 $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'") ); |
1931 $count = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" ); |
1981 update_site_option( 'user_count', $count ); |
1932 update_site_option( 'user_count', $count ); |
1982 } |
1933 } |
|
1934 |
|
1935 /** |
|
1936 * Returns the space used by the current blog. |
|
1937 * |
|
1938 * @since 3.5.0 |
|
1939 * |
|
1940 * @return int Used space in megabytes |
|
1941 */ |
|
1942 function get_space_used() { |
|
1943 // Allow for an alternative way of tracking storage space used |
|
1944 $space_used = apply_filters( 'pre_get_space_used', false ); |
|
1945 if ( false === $space_used ) { |
|
1946 $upload_dir = wp_upload_dir(); |
|
1947 $space_used = get_dirsize( $upload_dir['basedir'] ) / 1024 / 1024; |
|
1948 } |
|
1949 |
|
1950 return $space_used; |
|
1951 } |
|
1952 |
|
1953 /** |
|
1954 * Returns the upload quota for the current blog. |
|
1955 * |
|
1956 * @since MU |
|
1957 * |
|
1958 * @return int Quota in megabytes |
|
1959 */ |
|
1960 function get_space_allowed() { |
|
1961 $space_allowed = get_option( 'blog_upload_space' ); |
|
1962 |
|
1963 if ( ! is_numeric( $space_allowed ) ) |
|
1964 $space_allowed = get_site_option( 'blog_upload_space' ); |
|
1965 |
|
1966 if ( empty( $space_allowed ) || ! is_numeric( $space_allowed ) ) |
|
1967 $space_allowed = 50; |
|
1968 |
|
1969 return $space_allowed; |
|
1970 } |
|
1971 |
|
1972 /** |
|
1973 * Determines if there is any upload space left in the current blog's quota. |
|
1974 * |
|
1975 * @since 3.0.0 |
|
1976 * |
|
1977 * @return int of upload space available in bytes |
|
1978 */ |
|
1979 function get_upload_space_available() { |
|
1980 $space_allowed = get_space_allowed() * 1024 * 1024; |
|
1981 if ( get_site_option( 'upload_space_check_disabled' ) ) |
|
1982 return $space_allowed; |
|
1983 |
|
1984 $space_used = get_space_used() * 1024 * 1024; |
|
1985 |
|
1986 if ( ( $space_allowed - $space_used ) <= 0 ) |
|
1987 return 0; |
|
1988 |
|
1989 return $space_allowed - $space_used; |
|
1990 } |
|
1991 |
|
1992 /** |
|
1993 * Determines if there is any upload space left in the current blog's quota. |
|
1994 * |
|
1995 * @since 3.0.0 |
|
1996 * @return bool True if space is available, false otherwise. |
|
1997 */ |
|
1998 function is_upload_space_available() { |
|
1999 if ( get_site_option( 'upload_space_check_disabled' ) ) |
|
2000 return true; |
|
2001 |
|
2002 return (bool) get_upload_space_available(); |
|
2003 } |
|
2004 |
|
2005 /** |
|
2006 * @since 3.0.0 |
|
2007 * |
|
2008 * @return int of upload size limit in bytes |
|
2009 */ |
|
2010 function upload_size_limit_filter( $size ) { |
|
2011 $fileupload_maxk = 1024 * get_site_option( 'fileupload_maxk', 1500 ); |
|
2012 if ( get_site_option( 'upload_space_check_disabled' ) ) |
|
2013 return min( $size, $fileupload_maxk ); |
|
2014 |
|
2015 return min( $size, $fileupload_maxk, get_upload_space_available() ); |
|
2016 } |