3 * Multisite WordPress API
6 * @subpackage Multisite
11 * Gets the network's site and user counts.
15 * @return array Site and user count for the network.
17 function get_sitestats() {
19 'blogs' => get_blog_count(),
20 'users' => get_user_count(),
27 * Get the admin for a domain/path combination.
31 * @param string $sitedomain Optional. Site domain.
32 * @param string $path Optional. Site path.
33 * @return array The network admins
35 function get_admin_users_for_domain( $sitedomain = '', $path = '' ) {
39 $site_id = $wpdb->siteid;
41 $site_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path ) );
44 return $wpdb->get_results( $wpdb->prepare( "SELECT u.ID, u.user_login, u.user_pass FROM $wpdb->users AS u, $wpdb->sitemeta AS sm WHERE sm.meta_key = 'admin_user_id' AND u.ID = sm.meta_value AND sm.site_id = %d", $site_id ), ARRAY_A );
50 * Get one of a user's active blogs
52 * Returns the user's primary blog, if they have one and
53 * it is active. If it's inactive, function returns another
54 * active blog of the user. If none are found, the user
55 * is added as a Subscriber to the Dashboard Blog and that blog
60 * @param int $user_id The unique ID of the user
61 * @return object The blog object
63 function get_active_blog_for_user( $user_id ) {
65 $blogs = get_blogs_of_user( $user_id );
66 if ( empty( $blogs ) )
69 if ( !is_multisite() )
70 return $blogs[$wpdb->blogid];
72 $primary_blog = get_user_meta( $user_id, 'primary_blog', true );
73 $first_blog = current($blogs);
74 if ( false !== $primary_blog ) {
75 if ( ! isset( $blogs[ $primary_blog ] ) ) {
76 update_user_meta( $user_id, 'primary_blog', $first_blog->userblog_id );
77 $primary = get_blog_details( $first_blog->userblog_id );
79 $primary = get_blog_details( $primary_blog );
82 //TODO Review this call to add_user_to_blog too - to get here the user must have a role on this blog?
83 add_user_to_blog( $first_blog->userblog_id, $user_id, 'subscriber' );
84 update_user_meta( $user_id, 'primary_blog', $first_blog->userblog_id );
85 $primary = $first_blog;
88 if ( ( ! is_object( $primary ) ) || ( $primary->archived == 1 || $primary->spam == 1 || $primary->deleted == 1 ) ) {
89 $blogs = get_blogs_of_user( $user_id, true ); // if a user's primary blog is shut down, check their other blogs.
91 if ( is_array( $blogs ) && count( $blogs ) > 0 ) {
92 foreach ( (array) $blogs as $blog_id => $blog ) {
93 if ( $blog->site_id != $wpdb->siteid )
95 $details = get_blog_details( $blog_id );
96 if ( is_object( $details ) && $details->archived == 0 && $details->spam == 0 && $details->deleted == 0 ) {
98 if ( get_user_meta( $user_id , 'primary_blog', true ) != $blog_id )
99 update_user_meta( $user_id, 'primary_blog', $blog_id );
100 if ( !get_user_meta($user_id , 'source_domain', true) )
101 update_user_meta( $user_id, 'source_domain', $blog->domain );
115 * The number of active users in your installation.
117 * The count is cached and updated twice daily. This is not a live count.
123 function get_user_count() {
124 return get_site_option( 'user_count' );
128 * The number of active sites on your installation.
130 * The count is cached and updated twice daily. This is not a live count.
134 * @param int $network_id Deprecated, not supported.
137 function get_blog_count( $network_id = 0 ) {
138 if ( func_num_args() )
139 _deprecated_argument( __FUNCTION__, '3.1' );
141 return get_site_option( 'blog_count' );
145 * Get a blog post from any site on the network.
149 * @param int $blog_id ID of the blog.
150 * @param int $post_id ID of the post you're looking for.
151 * @return WP_Post|null WP_Post on success or null on failure
153 function get_blog_post( $blog_id, $post_id ) {
154 switch_to_blog( $blog_id );
155 $post = get_post( $post_id );
156 restore_current_blog();
162 * Add a user to a blog.
164 * Use the 'add_user_to_blog' action to fire an event when
165 * users are added to a blog.
169 * @param int $blog_id ID of the blog you're adding the user to.
170 * @param int $user_id ID of the user you're adding.
171 * @param string $role The role you want the user to have
174 function add_user_to_blog( $blog_id, $user_id, $role ) {
175 switch_to_blog($blog_id);
177 $user = get_userdata( $user_id );
180 restore_current_blog();
181 return new WP_Error( 'user_does_not_exist', __( 'The requested user does not exist.' ) );
184 if ( !get_user_meta($user_id, 'primary_blog', true) ) {
185 update_user_meta($user_id, 'primary_blog', $blog_id);
186 $details = get_blog_details($blog_id);
187 update_user_meta($user_id, 'source_domain', $details->domain);
190 $user->set_role($role);
193 * Fires immediately after a user is added to a site.
197 * @param int $user_id User ID.
198 * @param string $role User role.
199 * @param int $blog_id Blog ID.
201 do_action( 'add_user_to_blog', $user_id, $role, $blog_id );
202 wp_cache_delete( $user_id, 'users' );
203 restore_current_blog();
208 * Remove a user from a blog.
210 * Use the 'remove_user_from_blog' action to fire an event when
211 * users are removed from a blog.
213 * Accepts an optional $reassign parameter, if you want to
214 * reassign the user's blog posts to another user upon removal.
218 * @param int $user_id ID of the user you're removing.
219 * @param int $blog_id ID of the blog you're removing the user from.
220 * @param string $reassign Optional. A user to whom to reassign posts.
223 function remove_user_from_blog($user_id, $blog_id = '', $reassign = '') {
225 switch_to_blog($blog_id);
226 $user_id = (int) $user_id;
228 * Fires before a user is removed from a site.
232 * @param int $user_id User ID.
233 * @param int $blog_id Blog ID.
235 do_action( 'remove_user_from_blog', $user_id, $blog_id );
237 // If being removed from the primary blog, set a new primary if the user is assigned
238 // to multiple blogs.
239 $primary_blog = get_user_meta($user_id, 'primary_blog', true);
240 if ( $primary_blog == $blog_id ) {
243 $blogs = get_blogs_of_user($user_id);
244 foreach ( (array) $blogs as $blog ) {
245 if ( $blog->userblog_id == $blog_id )
247 $new_id = $blog->userblog_id;
248 $new_domain = $blog->domain;
252 update_user_meta($user_id, 'primary_blog', $new_id);
253 update_user_meta($user_id, 'source_domain', $new_domain);
256 // wp_revoke_user($user_id);
257 $user = get_userdata( $user_id );
259 restore_current_blog();
260 return new WP_Error('user_does_not_exist', __('That user does not exist.'));
263 $user->remove_all_caps();
265 $blogs = get_blogs_of_user($user_id);
266 if ( count($blogs) == 0 ) {
267 update_user_meta($user_id, 'primary_blog', '');
268 update_user_meta($user_id, 'source_domain', '');
271 if ( $reassign != '' ) {
272 $reassign = (int) $reassign;
273 $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $user_id ) );
274 $link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $user_id ) );
276 if ( ! empty( $post_ids ) ) {
277 $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_author = %d WHERE post_author = %d", $reassign, $user_id ) );
278 array_walk( $post_ids, 'clean_post_cache' );
281 if ( ! empty( $link_ids ) ) {
282 $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->links SET link_owner = %d WHERE link_owner = %d", $reassign, $user_id ) );
283 array_walk( $link_ids, 'clean_bookmark_cache' );
287 restore_current_blog();
293 * Create an empty blog.
297 * @param string $domain The new blog's domain.
298 * @param string $path The new blog's path.
299 * @param string $weblog_title The new blog's title.
300 * @param int $site_id Optional. Defaults to 1.
301 * @return int The ID of the newly created blog
303 function create_empty_blog( $domain, $path, $weblog_title, $site_id = 1 ) {
307 // Check if the domain has been used already. We should return an error message.
308 if ( domain_exists($domain, $path, $site_id) )
309 return __( '<strong>ERROR</strong>: Site URL already taken.' );
311 // Need to back up wpdb table names, and create a new wp_blogs entry for new blog.
312 // Need to get blog_id from wp_blogs, and create new table names.
313 // Must restore table names at the end of function.
315 if ( ! $blog_id = insert_blog($domain, $path, $site_id) )
316 return __( '<strong>ERROR</strong>: problem creating site entry.' );
318 switch_to_blog($blog_id);
319 install_blog($blog_id);
320 restore_current_blog();
326 * Get the permalink for a post on another blog.
330 * @param int $blog_id ID of the source blog.
331 * @param int $post_id ID of the desired post.
332 * @return string The post's permalink
334 function get_blog_permalink( $blog_id, $post_id ) {
335 switch_to_blog( $blog_id );
336 $link = get_permalink( $post_id );
337 restore_current_blog();
343 * Get a blog's numeric ID from its URL.
345 * On a subdirectory installation like example.com/blog1/,
346 * $domain will be the root 'example.com' and $path the
347 * subdirectory '/blog1/'. With subdomains like blog1.example.com,
348 * $domain is 'blog1.example.com' and $path is '/'.
352 * @param string $domain
353 * @param string $path Optional. Not required for subdomain installations.
354 * @return int 0 if no blog found, otherwise the ID of the matching blog
356 function get_blog_id_from_url( $domain, $path = '/' ) {
359 $domain = strtolower( $domain );
360 $path = strtolower( $path );
361 $id = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' );
363 if ( $id == -1 ) // blog does not exist
368 $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 ) );
371 wp_cache_set( md5( $domain . $path ), -1, 'blog-id-cache' );
375 wp_cache_set( md5( $domain . $path ), $id, 'blog-id-cache' );
383 * Checks an email address against a list of banned domains.
385 * This function checks against the Banned Email Domains list
386 * at wp-admin/network/settings.php. The check is only run on
387 * self-registrations; user creation at wp-admin/network/users.php
388 * bypasses this check.
392 * @param string $user_email The email provided by the user at registration.
393 * @return bool Returns true when the email address is banned.
395 function is_email_address_unsafe( $user_email ) {
396 $banned_names = get_site_option( 'banned_email_domains' );
397 if ( $banned_names && ! is_array( $banned_names ) )
398 $banned_names = explode( "\n", $banned_names );
400 $is_email_address_unsafe = false;
402 if ( $banned_names && is_array( $banned_names ) ) {
403 $banned_names = array_map( 'strtolower', $banned_names );
404 $normalized_email = strtolower( $user_email );
406 list( $email_local_part, $email_domain ) = explode( '@', $normalized_email );
408 foreach ( $banned_names as $banned_domain ) {
409 if ( ! $banned_domain )
412 if ( $email_domain == $banned_domain ) {
413 $is_email_address_unsafe = true;
417 $dotted_domain = ".$banned_domain";
418 if ( $dotted_domain === substr( $normalized_email, -strlen( $dotted_domain ) ) ) {
419 $is_email_address_unsafe = true;
426 * Filter whether an email address is unsafe.
430 * @param bool $is_email_address_unsafe Whether the email address is "unsafe". Default false.
431 * @param string $user_email User email address.
433 return apply_filters( 'is_email_address_unsafe', $is_email_address_unsafe, $user_email );
437 * Sanitize and validate data required for a user sign-up.
439 * Verifies the validity and uniqueness of user names and user email addresses,
440 * and checks email addresses against admin-provided domain whitelists and blacklists.
442 * The {@see 'wpmu_validate_user_signup'} hook provides an easy way to modify the sign-up
443 * process. The value $result, which is passed to the hook, contains both the user-provided
444 * info and the error messages created by the function. {@see 'wpmu_validate_user_signup'}
445 * allows you to process the data in any way you'd like, and unset the relevant errors if
450 * @param string $user_name The login name provided by the user.
451 * @param string $user_email The email provided by the user.
452 * @return array Contains username, email, and error messages.
454 function wpmu_validate_user_signup($user_name, $user_email) {
457 $errors = new WP_Error();
459 $orig_username = $user_name;
460 $user_name = preg_replace( '/\s+/', '', sanitize_user( $user_name, true ) );
462 if ( $user_name != $orig_username || preg_match( '/[^a-z0-9]/', $user_name ) ) {
463 $errors->add( 'user_name', __( 'Only lowercase letters (a-z) and numbers are allowed.' ) );
464 $user_name = $orig_username;
467 $user_email = sanitize_email( $user_email );
469 if ( empty( $user_name ) )
470 $errors->add('user_name', __( 'Please enter a username.' ) );
472 $illegal_names = get_site_option( 'illegal_names' );
473 if ( is_array( $illegal_names ) == false ) {
474 $illegal_names = array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' );
475 add_site_option( 'illegal_names', $illegal_names );
477 if ( in_array( $user_name, $illegal_names ) == true )
478 $errors->add('user_name', __( 'That username is not allowed.' ) );
480 if ( is_email_address_unsafe( $user_email ) )
481 $errors->add('user_email', __('You cannot use that email address to signup. We are having problems with them blocking some of our email. Please use another email provider.'));
483 if ( strlen( $user_name ) < 4 )
484 $errors->add('user_name', __( 'Username must be at least 4 characters.' ) );
486 if ( strpos( ' ' . $user_name, '_' ) != false )
487 $errors->add( 'user_name', __( 'Sorry, usernames may not contain the character “_”!' ) );
490 if ( preg_match( '/^[0-9]*$/', $user_name ) )
491 $errors->add('user_name', __('Sorry, usernames must have letters too!'));
493 if ( !is_email( $user_email ) )
494 $errors->add('user_email', __( 'Please enter a valid email address.' ) );
496 $limited_email_domains = get_site_option( 'limited_email_domains' );
497 if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) {
498 $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) );
499 if ( in_array( $emaildomain, $limited_email_domains ) == false )
500 $errors->add('user_email', __('Sorry, that email address is not allowed!'));
503 // Check if the username has been used already.
504 if ( username_exists($user_name) )
505 $errors->add( 'user_name', __( 'Sorry, that username already exists!' ) );
507 // Check if the email address has been used already.
508 if ( email_exists($user_email) )
509 $errors->add( 'user_email', __( 'Sorry, that email address is already used!' ) );
511 // Has someone already signed up for this username?
512 $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE user_login = %s", $user_name) );
513 if ( $signup != null ) {
514 $registered_at = mysql2date('U', $signup->registered);
515 $now = current_time( 'timestamp', true );
516 $diff = $now - $registered_at;
517 // If registered more than two days ago, cancel registration and let this signup go through.
518 if ( $diff > 2 * DAY_IN_SECONDS )
519 $wpdb->delete( $wpdb->signups, array( 'user_login' => $user_name ) );
521 $errors->add('user_name', __('That username is currently reserved but may be available in a couple of days.'));
524 $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE user_email = %s", $user_email) );
525 if ( $signup != null ) {
526 $diff = current_time( 'timestamp', true ) - mysql2date('U', $signup->registered);
527 // If registered more than two days ago, cancel registration and let this signup go through.
528 if ( $diff > 2 * DAY_IN_SECONDS )
529 $wpdb->delete( $wpdb->signups, array( 'user_email' => $user_email ) );
531 $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.'));
534 $result = array('user_name' => $user_name, 'orig_username' => $orig_username, 'user_email' => $user_email, 'errors' => $errors);
537 * Filter the validated user registration details.
539 * This does not allow you to override the username or email of the user during
540 * registration. The values are solely used for validation and error handling.
544 * @param array $result {
545 * The array of user name, email and the error messages.
547 * @type string $user_name Sanitized and unique username.
548 * @type string $orig_username Original username.
549 * @type string $user_email User email address.
550 * @type WP_Error $errors WP_Error object containing any errors found.
553 return apply_filters( 'wpmu_validate_user_signup', $result );
557 * Processes new site registrations.
559 * Checks the data provided by the user during blog signup. Verifies
560 * the validity and uniqueness of blog paths and domains.
562 * This function prevents the current user from registering a new site
563 * with a blogname equivalent to another user's login name. Passing the
564 * $user parameter to the function, where $user is the other user, is
565 * effectively an override of this limitation.
567 * Filter 'wpmu_validate_blog_signup' if you want to modify
568 * the way that WordPress validates new site signups.
572 * @param string $blogname The blog name provided by the user. Must be unique.
573 * @param string $blog_title The blog title provided by the user.
574 * @return array Contains the new site data and error messages.
576 function wpmu_validate_blog_signup( $blogname, $blog_title, $user = '' ) {
577 global $wpdb, $domain;
579 $current_site = get_current_site();
580 $base = $current_site->path;
582 $blog_title = strip_tags( $blog_title );
583 $blog_title = substr( $blog_title, 0, 50 );
585 $errors = new WP_Error();
586 $illegal_names = get_site_option( 'illegal_names' );
587 if ( $illegal_names == false ) {
588 $illegal_names = array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' );
589 add_site_option( 'illegal_names', $illegal_names );
593 * On sub dir installs, some names are so illegal, only a filter can
594 * spring them from jail.
596 if ( ! is_subdomain_install() ) {
597 $illegal_names = array_merge(
600 * Filter reserved site names on a sub-directory Multisite install.
604 * @param array $subdirectory_reserved_names Array of reserved names.
606 apply_filters( 'subdirectory_reserved_names', array( 'page', 'comments', 'blog', 'files', 'feed' ) )
610 if ( empty( $blogname ) )
611 $errors->add('blogname', __( 'Please enter a site name.' ) );
613 if ( preg_match( '/[^a-z0-9]+/', $blogname ) )
614 $errors->add('blogname', __( 'Only lowercase letters (a-z) and numbers are allowed.' ) );
616 if ( in_array( $blogname, $illegal_names ) == true )
617 $errors->add('blogname', __( 'That name is not allowed.' ) );
619 if ( strlen( $blogname ) < 4 && !is_super_admin() )
620 $errors->add('blogname', __( 'Site name must be at least 4 characters.' ) );
622 if ( strpos( $blogname, '_' ) !== false )
623 $errors->add( 'blogname', __( 'Sorry, site names may not contain the character “_”!' ) );
625 // do not allow users to create a blog that conflicts with a page on the main blog.
626 if ( !is_subdomain_install() && $wpdb->get_var( $wpdb->prepare( "SELECT post_name FROM " . $wpdb->get_blog_prefix( $current_site->blog_id ) . "posts WHERE post_type = 'page' AND post_name = %s", $blogname ) ) )
627 $errors->add( 'blogname', __( 'Sorry, you may not use that site name.' ) );
630 if ( preg_match( '/^[0-9]*$/', $blogname ) )
631 $errors->add('blogname', __('Sorry, site names must have letters too!'));
634 * Filter the new site name during registration.
636 * The name is the site's subdomain or the site's subdirectory
637 * path depending on the network settings.
641 * @param string $blogname Site name.
643 $blogname = apply_filters( 'newblogname', $blogname );
645 $blog_title = wp_unslash( $blog_title );
647 if ( empty( $blog_title ) )
648 $errors->add('blog_title', __( 'Please enter a site title.' ) );
650 // Check if the domain/path has been used already.
651 if ( is_subdomain_install() ) {
652 $mydomain = $blogname . '.' . preg_replace( '|^www\.|', '', $domain );
655 $mydomain = "$domain";
656 $path = $base.$blogname.'/';
658 if ( domain_exists($mydomain, $path, $current_site->id) )
659 $errors->add( 'blogname', __( 'Sorry, that site already exists!' ) );
661 if ( username_exists( $blogname ) ) {
662 if ( is_object( $user ) == false || ( is_object($user) && ( $user->user_login != $blogname ) ) )
663 $errors->add( 'blogname', __( 'Sorry, that site is reserved!' ) );
666 // Has someone already signed up for this domain?
667 $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE domain = %s AND path = %s", $mydomain, $path) ); // TODO: Check email too?
668 if ( ! empty($signup) ) {
669 $diff = current_time( 'timestamp', true ) - mysql2date('U', $signup->registered);
670 // If registered more than two days ago, cancel registration and let this signup go through.
671 if ( $diff > 2 * DAY_IN_SECONDS )
672 $wpdb->delete( $wpdb->signups, array( 'domain' => $mydomain , 'path' => $path ) );
674 $errors->add('blogname', __('That site is currently reserved but may be available in a couple days.'));
677 $result = array('domain' => $mydomain, 'path' => $path, 'blogname' => $blogname, 'blog_title' => $blog_title, 'user' => $user, 'errors' => $errors);
680 * Filter site details and error messages following registration.
684 * @param array $result {
685 * Array of domain, path, blog name, blog title, user and error messages.
687 * @type string $domain Domain for the site.
688 * @type string $path Path for the site. Used in subdirectory installs.
689 * @type string $blogname The unique site name (slug).
690 * @type string $blog_title Blog title.
691 * @type string $user User email address.
692 * @type WP_Error $errors WP_Error containing any errors found.
695 return apply_filters( 'wpmu_validate_blog_signup', $result );
699 * Record site signup information for future activation.
703 * @param string $domain The requested domain.
704 * @param string $path The requested path.
705 * @param string $title The requested site title.
706 * @param string $user The user's requested login name.
707 * @param string $user_email The user's email address.
708 * @param array $meta By default, contains the requested privacy setting and lang_id.
710 function wpmu_signup_blog( $domain, $path, $title, $user, $user_email, $meta = array() ) {
713 $key = substr( md5( time() . rand() . $domain ), 0, 16 );
714 $meta = serialize($meta);
716 $wpdb->insert( $wpdb->signups, array(
720 'user_login' => $user,
721 'user_email' => $user_email,
722 'registered' => current_time('mysql', true),
723 'activation_key' => $key,
727 wpmu_signup_blog_notification($domain, $path, $title, $user, $user_email, $key, $meta);
731 * Record user signup information for future activation.
733 * This function is used when user registration is open but
734 * new site registration is not.
738 * @param string $user The user's requested login name.
739 * @param string $user_email The user's email address.
740 * @param array $meta By default, this is an empty array.
742 function wpmu_signup_user( $user, $user_email, $meta = array() ) {
746 $user = preg_replace( '/\s+/', '', sanitize_user( $user, true ) );
747 $user_email = sanitize_email( $user_email );
748 $key = substr( md5( time() . rand() . $user_email ), 0, 16 );
749 $meta = serialize($meta);
751 $wpdb->insert( $wpdb->signups, array(
755 'user_login' => $user,
756 'user_email' => $user_email,
757 'registered' => current_time('mysql', true),
758 'activation_key' => $key,
762 wpmu_signup_user_notification($user, $user_email, $key, $meta);
766 * Notify user of signup success.
768 * This is the notification function used when site registration
771 * Filter 'wpmu_signup_blog_notification' to bypass this function or
772 * replace it with your own notification behavior.
774 * Filter 'wpmu_signup_blog_notification_email' and
775 * 'wpmu_signup_blog_notification_subject' to change the content
776 * and subject line of the email sent to newly registered users.
780 * @param string $domain The new blog domain.
781 * @param string $path The new blog path.
782 * @param string $title The site title.
783 * @param string $user The user's login name.
784 * @param string $user_email The user's email address.
785 * @param string $key The activation key created in wpmu_signup_blog()
786 * @param array $meta By default, contains the requested privacy setting and lang_id.
789 function wpmu_signup_blog_notification( $domain, $path, $title, $user, $user_email, $key, $meta = array() ) {
791 * Filter whether to bypass the new site email notification.
795 * @param string|bool $domain Site domain.
796 * @param string $path Site path.
797 * @param string $title Site title.
798 * @param string $user User login name.
799 * @param string $user_email User email address.
800 * @param string $key Activation key created in wpmu_signup_blog().
801 * @param array $meta By default, contains the requested privacy setting and lang_id.
803 if ( ! apply_filters( 'wpmu_signup_blog_notification', $domain, $path, $title, $user, $user_email, $key, $meta ) ) {
807 // Send email with activation link.
808 if ( !is_subdomain_install() || get_current_site()->id != 1 )
809 $activate_url = network_site_url("wp-activate.php?key=$key");
811 $activate_url = "http://{$domain}{$path}wp-activate.php?key=$key"; // @todo use *_url() API
813 $activate_url = esc_url($activate_url);
814 $admin_email = get_site_option( 'admin_email' );
815 if ( $admin_email == '' )
816 $admin_email = 'support@' . $_SERVER['SERVER_NAME'];
817 $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) );
818 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
821 * Filter the message content of the new blog notification email.
823 * Content should be formatted for transmission via wp_mail().
827 * @param string $content Content of the notification email.
828 * @param string $domain Site domain.
829 * @param string $path Site path.
830 * @param string $title Site title.
831 * @param string $user User login name.
832 * @param string $user_email User email address.
833 * @param string $key Activation key created in wpmu_signup_blog().
834 * @param array $meta By default, contains the requested privacy setting and lang_id.
836 apply_filters( 'wpmu_signup_blog_notification_email',
837 __( "To activate your blog, please click the following link:\n\n%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%s" ),
838 $domain, $path, $title, $user, $user_email, $key, $meta
841 esc_url( "http://{$domain}{$path}" ),
844 // TODO: Don't hard code activation link.
847 * Filter the subject of the new blog notification email.
851 * @param string $subject Subject of the notification email.
852 * @param string $domain Site domain.
853 * @param string $path Site path.
854 * @param string $title Site title.
855 * @param string $user User login name.
856 * @param string $user_email User email address.
857 * @param string $key Activation key created in wpmu_signup_blog().
858 * @param array $meta By default, contains the requested privacy setting and lang_id.
860 apply_filters( 'wpmu_signup_blog_notification_subject',
861 __( '[%1$s] Activate %2$s' ),
862 $domain, $path, $title, $user, $user_email, $key, $meta
865 esc_url( 'http://' . $domain . $path )
867 wp_mail( $user_email, wp_specialchars_decode( $subject ), $message, $message_headers );
872 * Notify user of signup success.
874 * This is the notification function used when no new site has
877 * Filter 'wpmu_signup_user_notification' to bypass this function or
878 * replace it with your own notification behavior.
880 * Filter 'wpmu_signup_user_notification_email' and
881 * 'wpmu_signup_user_notification_subject' to change the content
882 * and subject line of the email sent to newly registered users.
886 * @param string $user The user's login name.
887 * @param string $user_email The user's email address.
888 * @param string $key The activation key created in wpmu_signup_user()
889 * @param array $meta By default, an empty array.
892 function wpmu_signup_user_notification( $user, $user_email, $key, $meta = array() ) {
894 * Filter whether to bypass the email notification for new user sign-up.
898 * @param string $user User login name.
899 * @param string $user_email User email address.
900 * @param string $key Activation key created in wpmu_signup_user().
901 * @param array $meta Signup meta data.
903 if ( ! apply_filters( 'wpmu_signup_user_notification', $user, $user_email, $key, $meta ) )
906 // Send email with activation link.
907 $admin_email = get_site_option( 'admin_email' );
908 if ( $admin_email == '' )
909 $admin_email = 'support@' . $_SERVER['SERVER_NAME'];
910 $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) );
911 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
914 * Filter the content of the notification email for new user sign-up.
916 * Content should be formatted for transmission via wp_mail().
920 * @param string $content Content of the notification email.
921 * @param string $user User login name.
922 * @param string $user_email User email address.
923 * @param string $key Activation key created in wpmu_signup_user().
924 * @param array $meta Signup meta data.
926 apply_filters( 'wpmu_signup_user_notification_email',
927 __( "To activate your user, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login." ),
928 $user, $user_email, $key, $meta
930 site_url( "wp-activate.php?key=$key" )
932 // TODO: Don't hard code activation link.
935 * Filter the subject of the notification email of new user signup.
939 * @param string $subject Subject of the notification email.
940 * @param string $user User login name.
941 * @param string $user_email User email address.
942 * @param string $key Activation key created in wpmu_signup_user().
943 * @param array $meta Signup meta data.
945 apply_filters( 'wpmu_signup_user_notification_subject',
946 __( '[%1$s] Activate %2$s' ),
947 $user, $user_email, $key, $meta
952 wp_mail( $user_email, wp_specialchars_decode( $subject ), $message, $message_headers );
959 * Hook to 'wpmu_activate_user' or 'wpmu_activate_blog' for events
960 * that should happen only when users or sites are self-created (since
961 * those actions are not called when users and sites are created
966 * @param string $key The activation key provided to the user.
967 * @return array An array containing information about the activated user and/or blog
969 function wpmu_activate_signup($key) {
972 $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE activation_key = %s", $key) );
974 if ( empty( $signup ) )
975 return new WP_Error( 'invalid_key', __( 'Invalid activation key.' ) );
977 if ( $signup->active ) {
978 if ( empty( $signup->domain ) )
979 return new WP_Error( 'already_active', __( 'The user is already active.' ), $signup );
981 return new WP_Error( 'already_active', __( 'The site is already active.' ), $signup );
984 $meta = maybe_unserialize($signup->meta);
985 $password = wp_generate_password( 12, false );
987 $user_id = username_exists($signup->user_login);
990 $user_id = wpmu_create_user($signup->user_login, $password, $signup->user_email);
992 $user_already_exists = true;
995 return new WP_Error('create_user', __('Could not create user'), $signup);
997 $now = current_time('mysql', true);
999 if ( empty($signup->domain) ) {
1000 $wpdb->update( $wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key) );
1002 if ( isset( $user_already_exists ) )
1003 return new WP_Error( 'user_already_exists', __( 'That username is already activated.' ), $signup);
1005 wpmu_welcome_user_notification( $user_id, $password, $meta );
1007 * Fires immediately after a new user is activated.
1011 * @param int $user_id User ID.
1012 * @param int $password User password.
1013 * @param array $meta Signup meta data.
1015 do_action( 'wpmu_activate_user', $user_id, $password, $meta );
1016 return array( 'user_id' => $user_id, 'password' => $password, 'meta' => $meta );
1019 $blog_id = wpmu_create_blog( $signup->domain, $signup->path, $signup->title, $user_id, $meta, $wpdb->siteid );
1021 // TODO: What to do if we create a user but cannot create a blog?
1022 if ( is_wp_error($blog_id) ) {
1023 // If blog is taken, that means a previous attempt to activate this blog failed in between creating the blog and
1024 // setting the activation flag. Let's just set the active flag and instruct the user to reset their password.
1025 if ( 'blog_taken' == $blog_id->get_error_code() ) {
1026 $blog_id->add_data( $signup );
1027 $wpdb->update( $wpdb->signups, array( 'active' => 1, 'activated' => $now ), array( 'activation_key' => $key ) );
1032 $wpdb->update( $wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key) );
1033 wpmu_welcome_notification($blog_id, $user_id, $password, $signup->title, $meta);
1035 * Fires immediately after a site is activated.
1039 * @param int $blog_id Blog ID.
1040 * @param int $user_id User ID.
1041 * @param int $password User password.
1042 * @param string $signup_title Site title.
1043 * @param array $meta Signup meta data.
1045 do_action( 'wpmu_activate_blog', $blog_id, $user_id, $password, $signup->title, $meta );
1047 return array('blog_id' => $blog_id, 'user_id' => $user_id, 'password' => $password, 'title' => $signup->title, 'meta' => $meta);
1053 * This function runs when a user self-registers as well as when
1054 * a Super Admin creates a new user. Hook to 'wpmu_new_user' for events
1055 * that should affect all new users, but only on Multisite (otherwise
1056 * use 'user_register').
1060 * @param string $user_name The new user's login name.
1061 * @param string $password The new user's password.
1062 * @param string $email The new user's email address.
1063 * @return int|bool Returns false on failure, or int $user_id on success
1065 function wpmu_create_user( $user_name, $password, $email ) {
1066 $user_name = preg_replace( '/\s+/', '', sanitize_user( $user_name, true ) );
1068 $user_id = wp_create_user( $user_name, $password, $email );
1069 if ( is_wp_error( $user_id ) )
1072 // Newly created users have no roles or caps until they are added to a blog.
1073 delete_user_option( $user_id, 'capabilities' );
1074 delete_user_option( $user_id, 'user_level' );
1077 * Fires immediately after a new user is created.
1081 * @param int $user_id User ID.
1083 do_action( 'wpmu_new_user', $user_id );
1091 * This function runs when a user self-registers a new site as well
1092 * as when a Super Admin creates a new site. Hook to 'wpmu_new_blog'
1093 * for events that should affect all new sites.
1095 * On subdirectory installs, $domain is the same as the main site's
1096 * domain, and the path is the subdirectory name (eg 'example.com'
1097 * and '/blog1/'). On subdomain installs, $domain is the new subdomain +
1098 * root domain (eg 'blog1.example.com'), and $path is '/'.
1102 * @param string $domain The new site's domain.
1103 * @param string $path The new site's path.
1104 * @param string $title The new site's title.
1105 * @param int $user_id The user ID of the new site's admin.
1106 * @param array $meta Optional. Used to set initial site options.
1107 * @param int $site_id Optional. Only relevant on multi-network installs.
1108 * @return mixed Returns WP_Error object on failure, int $blog_id on success
1110 function wpmu_create_blog( $domain, $path, $title, $user_id, $meta = array(), $site_id = 1 ) {
1111 $defaults = array( 'public' => 0 );
1112 $meta = wp_parse_args( $meta, $defaults );
1114 $domain = preg_replace( '/\s+/', '', sanitize_user( $domain, true ) );
1116 if ( is_subdomain_install() )
1117 $domain = str_replace( '@', '', $domain );
1119 $title = strip_tags( $title );
1120 $user_id = (int) $user_id;
1125 // Check if the domain has been used already. We should return an error message.
1126 if ( domain_exists($domain, $path, $site_id) )
1127 return new WP_Error( 'blog_taken', __( 'Sorry, that site already exists!' ) );
1129 if ( !defined('WP_INSTALLING') )
1130 define( 'WP_INSTALLING', true );
1132 if ( ! $blog_id = insert_blog($domain, $path, $site_id) )
1133 return new WP_Error('insert_blog', __('Could not create site.'));
1135 switch_to_blog($blog_id);
1136 install_blog($blog_id, $title);
1137 wp_install_defaults($user_id);
1139 add_user_to_blog($blog_id, $user_id, 'administrator');
1141 foreach ( $meta as $key => $value ) {
1142 if ( in_array( $key, array( 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' ) ) )
1143 update_blog_status( $blog_id, $key, $value );
1145 update_option( $key, $value );
1148 add_option( 'WPLANG', get_site_option( 'WPLANG' ) );
1149 update_option( 'blog_public', (int) $meta['public'] );
1151 if ( ! is_super_admin( $user_id ) && ! get_user_meta( $user_id, 'primary_blog', true ) )
1152 update_user_meta( $user_id, 'primary_blog', $blog_id );
1154 restore_current_blog();
1156 * Fires immediately after a new site is created.
1160 * @param int $blog_id Blog ID.
1161 * @param int $user_id User ID.
1162 * @param string $domain Site domain.
1163 * @param string $path Site path.
1164 * @param int $site_id Site ID. Only relevant on multi-network installs.
1165 * @param array $meta Meta data. Used to set initial site options.
1167 do_action( 'wpmu_new_blog', $blog_id, $user_id, $domain, $path, $site_id, $meta );
1173 * Notifies the network admin that a new site has been activated.
1175 * Filter 'newblog_notify_siteadmin' to change the content of
1176 * the notification email.
1180 * @param int $blog_id The new site's ID.
1183 function newblog_notify_siteadmin( $blog_id, $deprecated = '' ) {
1184 if ( get_site_option( 'registrationnotification' ) != 'yes' )
1187 $email = get_site_option( 'admin_email' );
1188 if ( is_email($email) == false )
1191 $options_site_url = esc_url(network_admin_url('settings.php'));
1193 switch_to_blog( $blog_id );
1194 $blogname = get_option( 'blogname' );
1195 $siteurl = site_url();
1196 restore_current_blog();
1198 $msg = sprintf( __( 'New Site: %1$s
1202 Disable these notifications: %4$s' ), $blogname, $siteurl, wp_unslash( $_SERVER['REMOTE_ADDR'] ), $options_site_url);
1204 * Filter the message body of the new site activation email sent
1205 * to the network administrator.
1209 * @param string $msg Email body.
1211 $msg = apply_filters( 'newblog_notify_siteadmin', $msg );
1213 wp_mail( $email, sprintf( __( 'New Site Registration: %s' ), $siteurl ), $msg );
1218 * Notifies the network admin that a new user has been activated.
1220 * Filter 'newuser_notify_siteadmin' to change the content of
1221 * the notification email.
1225 * @param int $user_id The new user's ID.
1228 function newuser_notify_siteadmin( $user_id ) {
1229 if ( get_site_option( 'registrationnotification' ) != 'yes' )
1232 $email = get_site_option( 'admin_email' );
1234 if ( is_email($email) == false )
1237 $user = get_userdata( $user_id );
1239 $options_site_url = esc_url(network_admin_url('settings.php'));
1240 $msg = sprintf(__('New User: %1$s
1243 Disable these notifications: %3$s'), $user->user_login, wp_unslash( $_SERVER['REMOTE_ADDR'] ), $options_site_url);
1246 * Filter the message body of the new user activation email sent
1247 * to the network administrator.
1251 * @param string $msg Email body.
1252 * @param WP_User $user WP_User instance of the new user.
1254 $msg = apply_filters( 'newuser_notify_siteadmin', $msg, $user );
1255 wp_mail( $email, sprintf(__('New User Registration: %s'), $user->user_login), $msg );
1260 * Check whether a blogname is already taken.
1262 * Used during the new site registration process to ensure
1263 * that each blogname is unique.
1267 * @param string $domain The domain to be checked.
1268 * @param string $path The path to be checked.
1269 * @param int $site_id Optional. Relevant only on multi-network installs.
1272 function domain_exists($domain, $path, $site_id = 1) {
1274 $path = trailingslashit( $path );
1275 $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) );
1278 * Filter whether a blogname is taken.
1282 * @param int|null $result The blog_id if the blogname exists, null otherwise.
1283 * @param string $domain Domain to be checked.
1284 * @param string $path Path to be checked.
1285 * @param int $site_id Site ID. Relevant only on multi-network installs.
1287 return apply_filters( 'domain_exists', $result, $domain, $path, $site_id );
1291 * Store basic site info in the blogs table.
1293 * This function creates a row in the wp_blogs table and returns
1294 * the new blog's ID. It is the first step in creating a new blog.
1298 * @param string $domain The domain of the new site.
1299 * @param string $path The path of the new site.
1300 * @param int $site_id Unless you're running a multi-network install, be sure to set this value to 1.
1301 * @return int The ID of the new row
1303 function insert_blog($domain, $path, $site_id) {
1306 $path = trailingslashit($path);
1307 $site_id = (int) $site_id;
1309 $result = $wpdb->insert( $wpdb->blogs, array('site_id' => $site_id, 'domain' => $domain, 'path' => $path, 'registered' => current_time('mysql')) );
1313 $blog_id = $wpdb->insert_id;
1314 refresh_blog_details( $blog_id );
1316 wp_maybe_update_network_site_counts();
1322 * Install an empty blog.
1324 * Creates the new blog tables and options. If calling this function
1325 * directly, be sure to use switch_to_blog() first, so that $wpdb
1326 * points to the new blog.
1330 * @param int $blog_id The value returned by insert_blog().
1331 * @param string $blog_title The title of the new site.
1333 function install_blog( $blog_id, $blog_title = '' ) {
1334 global $wpdb, $wp_roles;
1336 // Cast for security
1337 $blog_id = (int) $blog_id;
1339 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
1341 $suppress = $wpdb->suppress_errors();
1342 if ( $wpdb->get_results( "DESCRIBE {$wpdb->posts}" ) )
1343 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>' );
1344 $wpdb->suppress_errors( $suppress );
1346 $url = get_blogaddress_by_id( $blog_id );
1348 // Set everything up
1349 make_db_current_silent( 'blog' );
1353 // populate_roles() clears previous role definitions so we start over.
1354 $wp_roles = new WP_Roles();
1356 $url = untrailingslashit( $url );
1358 update_option( 'siteurl', $url );
1359 update_option( 'home', $url );
1361 if ( get_site_option( 'ms_files_rewriting' ) )
1362 update_option( 'upload_path', UPLOADBLOGSDIR . "/$blog_id/files" );
1364 update_option( 'upload_path', get_blog_option( get_current_site()->blog_id, 'upload_path' ) );
1366 update_option( 'blogname', wp_unslash( $blog_title ) );
1367 update_option( 'admin_email', '' );
1370 $table_prefix = $wpdb->get_blog_prefix();
1371 delete_metadata( 'user', 0, $table_prefix . 'user_level', null, true ); // delete all
1372 delete_metadata( 'user', 0, $table_prefix . 'capabilities', null, true ); // delete all
1376 * Set blog defaults.
1378 * This function creates a row in the wp_blogs table.
1382 * @deprecated Use wp_install_defaults()
1384 * @param int $blog_id Ignored in this function.
1385 * @param int $user_id
1387 function install_blog_defaults($blog_id, $user_id) {
1390 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
1392 $suppress = $wpdb->suppress_errors();
1394 wp_install_defaults($user_id);
1396 $wpdb->suppress_errors( $suppress );
1400 * Notify a user that their blog activation has been successful.
1402 * Filter 'wpmu_welcome_notification' to disable or bypass.
1404 * Filter 'update_welcome_email' and 'update_welcome_subject' to
1405 * modify the content and subject line of the notification email.
1409 * @param int $blog_id
1410 * @param int $user_id
1411 * @param string $password
1412 * @param string $title The new blog's title
1413 * @param array $meta Optional. Not used in the default function, but is passed along to hooks for customization.
1416 function wpmu_welcome_notification( $blog_id, $user_id, $password, $title, $meta = array() ) {
1417 $current_site = get_current_site();
1420 * Filter whether to bypass the welcome email after site activation.
1422 * Returning false disables the welcome email.
1426 * @param int|bool $blog_id Blog ID.
1427 * @param int $user_id User ID.
1428 * @param string $password User password.
1429 * @param string $title Site title.
1430 * @param array $meta Signup meta data.
1432 if ( ! apply_filters( 'wpmu_welcome_notification', $blog_id, $user_id, $password, $title, $meta ) )
1435 $welcome_email = get_site_option( 'welcome_email' );
1436 if ( $welcome_email == false )
1437 $welcome_email = __( 'Howdy USERNAME,
1439 Your new SITE_NAME site has been successfully set up at:
1442 You can log in to the administrator account with the following information:
1446 Log in here: BLOG_URLwp-login.php
1448 We hope you enjoy your new site. Thanks!
1450 --The Team @ SITE_NAME' );
1452 $url = get_blogaddress_by_id($blog_id);
1453 $user = get_userdata( $user_id );
1455 $welcome_email = str_replace( 'SITE_NAME', $current_site->site_name, $welcome_email );
1456 $welcome_email = str_replace( 'BLOG_TITLE', $title, $welcome_email );
1457 $welcome_email = str_replace( 'BLOG_URL', $url, $welcome_email );
1458 $welcome_email = str_replace( 'USERNAME', $user->user_login, $welcome_email );
1459 $welcome_email = str_replace( 'PASSWORD', $password, $welcome_email );
1462 * Filter the content of the welcome email after site activation.
1464 * Content should be formatted for transmission via wp_mail().
1468 * @param string $welcome_email Message body of the email.
1469 * @param int $blog_id Blog ID.
1470 * @param int $user_id User ID.
1471 * @param string $password User password.
1472 * @param string $title Site title.
1473 * @param array $meta Signup meta data.
1475 $welcome_email = apply_filters( 'update_welcome_email', $welcome_email, $blog_id, $user_id, $password, $title, $meta );
1476 $admin_email = get_site_option( 'admin_email' );
1478 if ( $admin_email == '' )
1479 $admin_email = 'support@' . $_SERVER['SERVER_NAME'];
1481 $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) );
1482 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
1483 $message = $welcome_email;
1485 if ( empty( $current_site->site_name ) )
1486 $current_site->site_name = 'WordPress';
1489 * Filter the subject of the welcome email after site activation.
1493 * @param string $subject Subject of the email.
1495 $subject = apply_filters( 'update_welcome_subject', sprintf( __( 'New %1$s Site: %2$s' ), $current_site->site_name, wp_unslash( $title ) ) );
1496 wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers );
1501 * Notify a user that their account activation has been successful.
1503 * Filter 'wpmu_welcome_user_notification' to disable or bypass.
1505 * Filter 'update_welcome_user_email' and 'update_welcome_user_subject' to
1506 * modify the content and subject line of the notification email.
1510 * @param int $user_id
1511 * @param string $password
1512 * @param array $meta Optional. Not used in the default function, but is passed along to hooks for customization.
1515 function wpmu_welcome_user_notification( $user_id, $password, $meta = array() ) {
1516 $current_site = get_current_site();
1519 * Filter whether to bypass the welcome email after user activation.
1521 * Returning false disables the welcome email.
1525 * @param int $user_id User ID.
1526 * @param string $password User password.
1527 * @param array $meta Signup meta data.
1529 if ( ! apply_filters( 'wpmu_welcome_user_notification', $user_id, $password, $meta ) )
1532 $welcome_email = get_site_option( 'welcome_user_email' );
1534 $user = get_userdata( $user_id );
1537 * Filter the content of the welcome email after user activation.
1539 * Content should be formatted for transmission via wp_mail().
1543 * @param type $welcome_email The message body of the account activation success email.
1544 * @param int $user_id User ID.
1545 * @param string $password User password.
1546 * @param array $meta Signup meta data.
1548 $welcome_email = apply_filters( 'update_welcome_user_email', $welcome_email, $user_id, $password, $meta );
1549 $welcome_email = str_replace( 'SITE_NAME', $current_site->site_name, $welcome_email );
1550 $welcome_email = str_replace( 'USERNAME', $user->user_login, $welcome_email );
1551 $welcome_email = str_replace( 'PASSWORD', $password, $welcome_email );
1552 $welcome_email = str_replace( 'LOGINLINK', wp_login_url(), $welcome_email );
1554 $admin_email = get_site_option( 'admin_email' );
1556 if ( $admin_email == '' )
1557 $admin_email = 'support@' . $_SERVER['SERVER_NAME'];
1559 $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) );
1560 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
1561 $message = $welcome_email;
1563 if ( empty( $current_site->site_name ) )
1564 $current_site->site_name = 'WordPress';
1567 * Filter the subject of the welcome email after user activation.
1571 * @param string $subject Subject of the email.
1573 $subject = apply_filters( 'update_welcome_user_subject', sprintf( __( 'New %1$s User: %2$s' ), $current_site->site_name, $user->user_login) );
1574 wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers );
1579 * Get the current site info.
1581 * Returns an object containing the 'id', 'domain', 'path', and 'site_name'
1582 * properties of the site being viewed.
1584 * @see wpmu_current_site()
1590 function get_current_site() {
1591 global $current_site;
1592 return $current_site;
1596 * Get a user's most recent post.
1598 * Walks through each of a user's blogs to find the post with
1599 * the most recent post_date_gmt.
1603 * @param int $user_id
1604 * @return array Contains the blog_id, post_id, post_date_gmt, and post_gmt_ts
1606 function get_most_recent_post_of_user( $user_id ) {
1609 $user_blogs = get_blogs_of_user( (int) $user_id );
1610 $most_recent_post = array();
1612 // Walk through each blog and get the most recent post
1613 // published by $user_id
1614 foreach ( (array) $user_blogs as $blog ) {
1615 $prefix = $wpdb->get_blog_prefix( $blog->userblog_id );
1616 $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);
1618 // Make sure we found a post
1619 if ( isset($recent_post['ID']) ) {
1620 $post_gmt_ts = strtotime($recent_post['post_date_gmt']);
1622 // If this is the first post checked or if this post is
1623 // newer than the current recent post, make it the new
1624 // most recent post.
1625 if ( !isset($most_recent_post['post_gmt_ts']) || ( $post_gmt_ts > $most_recent_post['post_gmt_ts'] ) ) {
1626 $most_recent_post = array(
1627 'blog_id' => $blog->userblog_id,
1628 'post_id' => $recent_post['ID'],
1629 'post_date_gmt' => $recent_post['post_date_gmt'],
1630 'post_gmt_ts' => $post_gmt_ts
1636 return $most_recent_post;
1642 * Get the size of a directory.
1644 * A helper function that is used primarily to check whether
1645 * a blog has exceeded its allowed upload space.
1649 * @param string $directory
1652 function get_dirsize( $directory ) {
1653 $dirsize = get_transient( 'dirsize_cache' );
1654 if ( is_array( $dirsize ) && isset( $dirsize[ $directory ][ 'size' ] ) )
1655 return $dirsize[ $directory ][ 'size' ];
1657 if ( false == is_array( $dirsize ) )
1660 $dirsize[ $directory ][ 'size' ] = recurse_dirsize( $directory );
1662 set_transient( 'dirsize_cache', $dirsize, HOUR_IN_SECONDS );
1663 return $dirsize[ $directory ][ 'size' ];
1667 * Get the size of a directory recursively.
1669 * Used by get_dirsize() to get a directory's size when it contains
1670 * other directories.
1674 * @param string $directory
1677 function recurse_dirsize( $directory ) {
1680 $directory = untrailingslashit( $directory );
1682 if ( !file_exists($directory) || !is_dir( $directory ) || !is_readable( $directory ) )
1685 if ($handle = opendir($directory)) {
1686 while(($file = readdir($handle)) !== false) {
1687 $path = $directory.'/'.$file;
1688 if ($file != '.' && $file != '..') {
1689 if (is_file($path)) {
1690 $size += filesize($path);
1691 } elseif (is_dir($path)) {
1692 $handlesize = recurse_dirsize($path);
1693 if ($handlesize > 0)
1694 $size += $handlesize;
1704 * Check an array of MIME types against a whitelist.
1706 * WordPress ships with a set of allowed upload filetypes,
1707 * which is defined in wp-includes/functions.php in
1708 * get_allowed_mime_types(). This function is used to filter
1709 * that list against the filetype whitelist provided by Multisite
1710 * Super Admins at wp-admin/network/settings.php.
1714 * @param array $mimes
1717 function check_upload_mimes( $mimes ) {
1718 $site_exts = explode( ' ', get_site_option( 'upload_filetypes', 'jpg jpeg png gif' ) );
1719 $site_mimes = array();
1720 foreach ( $site_exts as $ext ) {
1721 foreach ( $mimes as $ext_pattern => $mime ) {
1722 if ( $ext != '' && strpos( $ext_pattern, $ext ) !== false )
1723 $site_mimes[$ext_pattern] = $mime;
1730 * Update a blog's post count.
1732 * WordPress MS stores a blog's post count as an option so as
1733 * to avoid extraneous COUNTs when a blog's details are fetched
1734 * with get_blog_details(). This function is called when posts
1735 * are published or unpublished to make sure the count stays current.
1739 function update_posts_count( $deprecated = '' ) {
1741 update_option( 'post_count', (int) $wpdb->get_var( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_status = 'publish' and post_type = 'post'" ) );
1745 * Logs user registrations.
1749 * @param int $blog_id
1750 * @param int $user_id
1752 function wpmu_log_new_registrations( $blog_id, $user_id ) {
1754 $user = get_userdata( (int) $user_id );
1756 $wpdb->insert( $wpdb->registration_log, array('email' => $user->user_email, 'IP' => preg_replace( '/[^0-9., ]/', '', wp_unslash( $_SERVER['REMOTE_ADDR'] ) ), 'blog_id' => $blog_id, 'date_registered' => current_time('mysql')) );
1760 * Maintains a canonical list of terms by syncing terms created for each blog with the global terms table.
1764 * @see term_id_filter
1766 * @param int $term_id An ID for a term on the current blog.
1767 * @return int An ID from the global terms table mapped from $term_id.
1769 function global_terms( $term_id, $deprecated = '' ) {
1771 static $global_terms_recurse = null;
1773 if ( !global_terms_enabled() )
1776 // prevent a race condition
1777 $recurse_start = false;
1778 if ( $global_terms_recurse === null ) {
1779 $recurse_start = true;
1780 $global_terms_recurse = 1;
1781 } elseif ( 10 < $global_terms_recurse++ ) {
1785 $term_id = intval( $term_id );
1786 $c = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->terms WHERE term_id = %d", $term_id ) );
1788 $global_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM $wpdb->sitecategories WHERE category_nicename = %s", $c->slug ) );
1789 if ( $global_id == null ) {
1790 $used_global_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM $wpdb->sitecategories WHERE cat_ID = %d", $c->term_id ) );
1791 if ( null == $used_global_id ) {
1792 $wpdb->insert( $wpdb->sitecategories, array( 'cat_ID' => $term_id, 'cat_name' => $c->name, 'category_nicename' => $c->slug ) );
1793 $global_id = $wpdb->insert_id;
1794 if ( empty( $global_id ) )
1797 $max_global_id = $wpdb->get_var( "SELECT MAX(cat_ID) FROM $wpdb->sitecategories" );
1798 $max_local_id = $wpdb->get_var( "SELECT MAX(term_id) FROM $wpdb->terms" );
1799 $new_global_id = max( $max_global_id, $max_local_id ) + mt_rand( 100, 400 );
1800 $wpdb->insert( $wpdb->sitecategories, array( 'cat_ID' => $new_global_id, 'cat_name' => $c->name, 'category_nicename' => $c->slug ) );
1801 $global_id = $wpdb->insert_id;
1803 } elseif ( $global_id != $term_id ) {
1804 $local_id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms WHERE term_id = %d", $global_id ) );
1805 if ( null != $local_id ) {
1806 global_terms( $local_id );
1807 if ( 10 < $global_terms_recurse ) {
1808 $global_id = $term_id;
1813 if ( $global_id != $term_id ) {
1814 if ( get_option( 'default_category' ) == $term_id )
1815 update_option( 'default_category', $global_id );
1817 $wpdb->update( $wpdb->terms, array('term_id' => $global_id), array('term_id' => $term_id) );
1818 $wpdb->update( $wpdb->term_taxonomy, array('term_id' => $global_id), array('term_id' => $term_id) );
1819 $wpdb->update( $wpdb->term_taxonomy, array('parent' => $global_id), array('parent' => $term_id) );
1821 clean_term_cache($term_id);
1823 if( $recurse_start )
1824 $global_terms_recurse = null;
1830 * Ensure that the current site's domain is listed in the allowed redirect host list.
1832 * @see wp_validate_redirect()
1835 * @return array The current site's domain
1837 function redirect_this_site( $deprecated = '' ) {
1838 return array( get_current_site()->domain );
1842 * Check whether an upload is too big.
1846 * @param array $upload
1847 * @return mixed If the upload is under the size limit, $upload is returned. Otherwise returns an error message.
1849 function upload_is_file_too_big( $upload ) {
1850 if ( is_array( $upload ) == false || defined( 'WP_IMPORTING' ) || get_site_option( 'upload_space_check_disabled' ) )
1853 if ( strlen( $upload['bits'] ) > ( 1024 * get_site_option( 'fileupload_maxk', 1500 ) ) )
1854 return sprintf( __( 'This file is too big. Files must be less than %d KB in size.' ) . '<br />', get_site_option( 'fileupload_maxk', 1500 ));
1860 * Add a nonce field to the signup page.
1864 function signup_nonce_fields() {
1866 echo "<input type='hidden' name='signup_form_id' value='{$id}' />";
1867 wp_nonce_field('signup_form_' . $id, '_signup_form', false);
1871 * Process the signup nonce created in signup_nonce_fields().
1875 * @param array $result
1878 function signup_nonce_check( $result ) {
1879 if ( !strpos( $_SERVER[ 'PHP_SELF' ], 'wp-signup.php' ) )
1882 if ( wp_create_nonce('signup_form_' . $_POST[ 'signup_form_id' ]) != $_POST['_signup_form'] )
1883 wp_die( __( 'Please try again.' ) );
1889 * Correct 404 redirects when NOBLOGREDIRECT is defined.
1893 function maybe_redirect_404() {
1895 * Filter the redirect URL for 404s on the main site.
1897 * The filter is only evaluated if the NOBLOGREDIRECT constant is defined.
1901 * @param string $no_blog_redirect The redirect URL defined in NOBLOGREDIRECT.
1903 if ( is_main_site() && is_404() && defined( 'NOBLOGREDIRECT' ) && ( $destination = apply_filters( 'blog_redirect_404', NOBLOGREDIRECT ) ) ) {
1904 if ( $destination == '%siteurl%' )
1905 $destination = network_home_url();
1906 wp_redirect( $destination );
1912 * Add a new user to a blog by visiting /newbloguser/username/.
1914 * This will only work when the user's details are saved as an option
1915 * keyed as 'new_user_x', where 'x' is the username of the user to be
1916 * added, as when a user is invited through the regular WP Add User interface.
1920 function maybe_add_existing_user_to_blog() {
1921 if ( false === strpos( $_SERVER[ 'REQUEST_URI' ], '/newbloguser/' ) )
1924 $parts = explode( '/', $_SERVER[ 'REQUEST_URI' ] );
1925 $key = array_pop( $parts );
1928 $key = array_pop( $parts );
1930 $details = get_option( 'new_user_' . $key );
1931 if ( !empty( $details ) )
1932 delete_option( 'new_user_' . $key );
1934 if ( empty( $details ) || is_wp_error( add_existing_user_to_blog( $details ) ) )
1935 wp_die( sprintf(__('An error occurred adding you to this site. Back to the <a href="%s">homepage</a>.'), home_url() ) );
1937 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' ), array( 'response' => 200 ) );
1941 * Add a user to a blog based on details from maybe_add_existing_user_to_blog().
1945 * @param array $details
1947 function add_existing_user_to_blog( $details = false ) {
1950 if ( is_array( $details ) ) {
1951 $result = add_user_to_blog( $blog_id, $details[ 'user_id' ], $details[ 'role' ] );
1953 * Fires immediately after an existing user is added to a site.
1957 * @param int $user_id User ID.
1958 * @param mixed $result True on success or a WP_Error object if the user doesn't exist.
1960 do_action( 'added_existing_user', $details['user_id'], $result );
1966 * Add a newly created user to the appropriate blog
1968 * To add a user in general, use add_user_to_blog(). This function
1969 * is specifically hooked into the wpmu_activate_user action.
1972 * @see add_user_to_blog()
1974 * @param int $user_id
1975 * @param mixed $password Ignored.
1976 * @param array $meta
1978 function add_new_user_to_blog( $user_id, $password, $meta ) {
1979 if ( !empty( $meta[ 'add_to_blog' ] ) ) {
1980 $blog_id = $meta[ 'add_to_blog' ];
1981 $role = $meta[ 'new_role' ];
1982 remove_user_from_blog($user_id, get_current_site()->blog_id); // remove user from main blog.
1983 add_user_to_blog( $blog_id, $user_id, $role );
1984 update_user_meta( $user_id, 'primary_blog', $blog_id );
1989 * Correct From host on outgoing mail to match the site domain
1993 function fix_phpmailer_messageid( $phpmailer ) {
1994 $phpmailer->Hostname = get_current_site()->domain;
1998 * Check to see whether a user is marked as a spammer, based on user login.
2002 * @param string|WP_User $user Optional. Defaults to current user. WP_User object,
2003 * or user login name as a string.
2006 function is_user_spammy( $user = null ) {
2007 if ( ! ( $user instanceof WP_User ) ) {
2009 $user = get_user_by( 'login', $user );
2011 $user = wp_get_current_user();
2015 return $user && isset( $user->spam ) && 1 == $user->spam;
2019 * Update this blog's 'public' setting in the global blogs table.
2021 * Public blogs have a setting of 1, private blogs are 0.
2025 * @param int $old_value
2026 * @param int $value The new public value
2028 function update_blog_public( $old_value, $value ) {
2029 update_blog_status( get_current_blog_id(), 'public', (int) $value );
2033 * Check whether a usermeta key has to do with the current blog.
2037 * @param string $key
2038 * @param int $user_id Optional. Defaults to current user.
2039 * @param int $blog_id Optional. Defaults to current blog.
2042 function is_user_option_local( $key, $user_id = 0, $blog_id = 0 ) {
2045 $current_user = wp_get_current_user();
2046 if ( $blog_id == 0 ) {
2047 $blog_id = $wpdb->blogid;
2049 $local_key = $wpdb->get_blog_prefix( $blog_id ) . $key;
2051 if ( isset( $current_user->$local_key ) )
2058 * Check whether users can self-register, based on Network settings.
2064 function users_can_register_signup_filter() {
2065 $registration = get_site_option('registration');
2066 if ( $registration == 'all' || $registration == 'user' )
2073 * Ensure that the welcome message is not empty. Currently unused.
2077 * @param string $text
2080 function welcome_user_msg_filter( $text ) {
2082 remove_filter( 'site_option_welcome_user_email', 'welcome_user_msg_filter' );
2083 $text = __( 'Howdy USERNAME,
2085 Your new account is set up.
2087 You can log in with the following information:
2094 --The Team @ SITE_NAME' );
2095 update_site_option( 'welcome_user_email', $text );
2101 * Whether to force SSL on content.
2105 * @param string|bool $force
2106 * @return bool True if forced, false if not forced.
2108 function force_ssl_content( $force = '' ) {
2109 static $forced_content;
2111 if ( '' != $force ) {
2112 $old_forced = $forced_content;
2113 $forced_content = $force;
2117 return $forced_content;
2121 * Formats a URL to use https.
2123 * Useful as a filter.
2128 * @return string URL with https as the scheme
2130 function filter_SSL( $url ) {
2131 if ( ! is_string( $url ) )
2132 return get_bloginfo( 'url' ); // Return home blog url with proper scheme
2134 if ( force_ssl_content() && is_ssl() )
2135 $url = set_url_scheme( $url, 'https' );
2141 * Schedule update of the network-wide counts for the current network.
2145 function wp_schedule_update_network_counts() {
2146 if ( !is_main_site() )
2149 if ( !wp_next_scheduled('update_network_counts') && !defined('WP_INSTALLING') )
2150 wp_schedule_event(time(), 'twicedaily', 'update_network_counts');
2154 * Update the network-wide counts for the current network.
2158 function wp_update_network_counts() {
2159 wp_update_network_user_counts();
2160 wp_update_network_site_counts();
2164 * Update the count of sites for the current network.
2166 * If enabled through the 'enable_live_network_counts' filter, update the sites count
2167 * on a network when a site is created or its status is updated.
2171 function wp_maybe_update_network_site_counts() {
2172 $is_small_network = ! wp_is_large_network( 'sites' );
2175 * Filter whether to update network site or user counts when a new site is created.
2179 * @see wp_is_large_network()
2181 * @param bool $small_network Whether the network is considered small.
2182 * @param string $context Context. Either 'users' or 'sites'.
2184 if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'sites' ) )
2187 wp_update_network_site_counts();
2191 * Update the network-wide users count.
2193 * If enabled through the 'enable_live_network_counts' filter, update the users count
2194 * on a network when a user is created or its status is updated.
2198 function wp_maybe_update_network_user_counts() {
2199 $is_small_network = ! wp_is_large_network( 'users' );
2201 /** This filter is documented in wp-includes/ms-functions.php */
2202 if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'users' ) )
2205 wp_update_network_user_counts();
2209 * Update the network-wide site count.
2213 function wp_update_network_site_counts() {
2216 $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) );
2217 update_site_option( 'blog_count', $count );
2221 * Update the network-wide user count.
2225 function wp_update_network_user_counts() {
2228 $count = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" );
2229 update_site_option( 'user_count', $count );
2233 * Returns the space used by the current blog.
2237 * @return int Used space in megabytes
2239 function get_space_used() {
2241 * Filter the amount of storage space used by the current site.
2245 * @param int|bool $space_used The amount of used space, in megabytes. Default false.
2247 $space_used = apply_filters( 'pre_get_space_used', false );
2248 if ( false === $space_used ) {
2249 $upload_dir = wp_upload_dir();
2250 $space_used = get_dirsize( $upload_dir['basedir'] ) / 1024 / 1024;
2257 * Returns the upload quota for the current blog.
2261 * @return int Quota in megabytes
2263 function get_space_allowed() {
2264 $space_allowed = get_option( 'blog_upload_space' );
2266 if ( ! is_numeric( $space_allowed ) )
2267 $space_allowed = get_site_option( 'blog_upload_space' );
2269 if ( empty( $space_allowed ) || ! is_numeric( $space_allowed ) )
2270 $space_allowed = 100;
2273 * Filter the upload quota for the current site.
2277 * @param int $space_allowed Upload quota in megabytes for the current blog.
2279 return apply_filters( 'get_space_allowed', $space_allowed );
2283 * Determines if there is any upload space left in the current blog's quota.
2287 * @return int of upload space available in bytes
2289 function get_upload_space_available() {
2290 $space_allowed = get_space_allowed() * 1024 * 1024;
2291 if ( get_site_option( 'upload_space_check_disabled' ) )
2292 return $space_allowed;
2294 $space_used = get_space_used() * 1024 * 1024;
2296 if ( ( $space_allowed - $space_used ) <= 0 )
2299 return $space_allowed - $space_used;
2303 * Determines if there is any upload space left in the current blog's quota.
2306 * @return bool True if space is available, false otherwise.
2308 function is_upload_space_available() {
2309 if ( get_site_option( 'upload_space_check_disabled' ) )
2312 return (bool) get_upload_space_available();
2318 * @return int of upload size limit in bytes
2320 function upload_size_limit_filter( $size ) {
2321 $fileupload_maxk = 1024 * get_site_option( 'fileupload_maxk', 1500 );
2322 if ( get_site_option( 'upload_space_check_disabled' ) )
2323 return min( $size, $fileupload_maxk );
2325 return min( $size, $fileupload_maxk, get_upload_space_available() );
2329 * Whether or not we have a large network.
2331 * The default criteria for a large network is either more than 10,000 users or more than 10,000 sites.
2332 * Plugins can alter this criteria using the 'wp_is_large_network' filter.
2335 * @param string $using 'sites or 'users'. Default is 'sites'.
2336 * @return bool True if the network meets the criteria for large. False otherwise.
2338 function wp_is_large_network( $using = 'sites' ) {
2339 if ( 'users' == $using ) {
2340 $count = get_user_count();
2342 * Filter whether the network is considered large.
2346 * @param bool $is_large_network Whether the network has more than 10000 users or sites.
2347 * @param string $component The component to count. Accepts 'users', or 'sites'.
2348 * @param int $count The count of items for the component.
2350 return apply_filters( 'wp_is_large_network', $count > 10000, 'users', $count );
2353 $count = get_blog_count();
2354 /** This filter is documented in wp-includes/ms-functions.php */
2355 return apply_filters( 'wp_is_large_network', $count > 10000, 'sites', $count );
2360 * Return an array of sites for a network or networks.
2364 * @param array $args {
2365 * Array of default arguments. Optional.
2367 * @type int|array $network_id A network ID or array of network IDs. Set to null to retrieve sites
2368 * from all networks. Defaults to current network ID.
2369 * @type int $public Retrieve public or non-public sites. Default null, for any.
2370 * @type int $archived Retrieve archived or non-archived sites. Default null, for any.
2371 * @type int $mature Retrieve mature or non-mature sites. Default null, for any.
2372 * @type int $spam Retrieve spam or non-spam sites. Default null, for any.
2373 * @type int $deleted Retrieve deleted or non-deleted sites. Default null, for any.
2374 * @type int $limit Number of sites to limit the query to. Default 100.
2375 * @type int $offset Exclude the first x sites. Used in combination with the $limit parameter. Default 0.
2377 * @return array An empty array if the install is considered "large" via wp_is_large_network(). Otherwise,
2378 * an associative array of site data arrays, each containing the site (network) ID, blog ID,
2379 * site domain and path, dates registered and modified, and the language ID. Also, boolean
2380 * values for whether the site is public, archived, mature, spam, and/or deleted.
2382 function wp_get_sites( $args = array() ) {
2385 if ( wp_is_large_network() )
2389 'network_id' => $wpdb->siteid,
2399 $args = wp_parse_args( $args, $defaults );
2401 $query = "SELECT * FROM $wpdb->blogs WHERE 1=1 ";
2403 if ( isset( $args['network_id'] ) && ( is_array( $args['network_id'] ) || is_numeric( $args['network_id'] ) ) ) {
2404 $network_ids = implode( ',', wp_parse_id_list( $args['network_id'] ) );
2405 $query .= "AND site_id IN ($network_ids) ";
2408 if ( isset( $args['public'] ) )
2409 $query .= $wpdb->prepare( "AND public = %d ", $args['public'] );
2411 if ( isset( $args['archived'] ) )
2412 $query .= $wpdb->prepare( "AND archived = %d ", $args['archived'] );
2414 if ( isset( $args['mature'] ) )
2415 $query .= $wpdb->prepare( "AND mature = %d ", $args['mature'] );
2417 if ( isset( $args['spam'] ) )
2418 $query .= $wpdb->prepare( "AND spam = %d ", $args['spam'] );
2420 if ( isset( $args['deleted'] ) )
2421 $query .= $wpdb->prepare( "AND deleted = %d ", $args['deleted'] );
2423 if ( isset( $args['limit'] ) && $args['limit'] ) {
2424 if ( isset( $args['offset'] ) && $args['offset'] )
2425 $query .= $wpdb->prepare( "LIMIT %d , %d ", $args['offset'], $args['limit'] );
2427 $query .= $wpdb->prepare( "LIMIT %d ", $args['limit'] );
2430 $site_results = $wpdb->get_results( $query, ARRAY_A );
2432 return $site_results;