wp/wp-includes/ms-functions.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
    27 
    27 
    28 	return $stats;
    28 	return $stats;
    29 }
    29 }
    30 
    30 
    31 /**
    31 /**
    32  * Get one of a user's active blogs
    32  * Gets one of a user's active blogs.
    33  *
    33  *
    34  * Returns the user's primary blog, if they have one and
    34  * Returns the user's primary blog, if they have one and
    35  * it is active. If it's inactive, function returns another
    35  * it is active. If it's inactive, function returns another
    36  * active blog of the user. If none are found, the user
    36  * active blog of the user. If none are found, the user
    37  * is added as a Subscriber to the Dashboard Blog and that blog
    37  * is added as a Subscriber to the Dashboard Blog and that blog
    99 		return $primary;
    99 		return $primary;
   100 	}
   100 	}
   101 }
   101 }
   102 
   102 
   103 /**
   103 /**
   104  * The number of active users in your installation.
   104  * Gets the number of active sites on the installation.
   105  *
       
   106  * The count is cached and updated twice daily. This is not a live count.
       
   107  *
       
   108  * @since MU (3.0.0)
       
   109  * @since 4.8.0 The `$network_id` parameter has been added.
       
   110  *
       
   111  * @param int|null $network_id ID of the network. Default is the current network.
       
   112  * @return int Number of active users on the network.
       
   113  */
       
   114 function get_user_count( $network_id = null ) {
       
   115 	return get_network_option( $network_id, 'user_count' );
       
   116 }
       
   117 
       
   118 /**
       
   119  * The number of active sites on your installation.
       
   120  *
   105  *
   121  * The count is cached and updated twice daily. This is not a live count.
   106  * The count is cached and updated twice daily. This is not a live count.
   122  *
   107  *
   123  * @since MU (3.0.0)
   108  * @since MU (3.0.0)
   124  * @since 3.7.0 The `$network_id` parameter has been deprecated.
   109  * @since 3.7.0 The `$network_id` parameter has been deprecated.
   223 
   208 
   224 	return true;
   209 	return true;
   225 }
   210 }
   226 
   211 
   227 /**
   212 /**
   228  * Remove a user from a blog.
   213  * Removes a user from a blog.
   229  *
   214  *
   230  * Use the {@see 'remove_user_from_blog'} action to fire an event when
   215  * Use the {@see 'remove_user_from_blog'} action to fire an event when
   231  * users are removed from a blog.
   216  * users are removed from a blog.
   232  *
   217  *
   233  * Accepts an optional `$reassign` parameter, if you want to
   218  * Accepts an optional `$reassign` parameter, if you want to
   278 
   263 
   279 		update_user_meta( $user_id, 'primary_blog', $new_id );
   264 		update_user_meta( $user_id, 'primary_blog', $new_id );
   280 		update_user_meta( $user_id, 'source_domain', $new_domain );
   265 		update_user_meta( $user_id, 'source_domain', $new_domain );
   281 	}
   266 	}
   282 
   267 
   283 	// wp_revoke_user( $user_id );
       
   284 	$user = get_userdata( $user_id );
   268 	$user = get_userdata( $user_id );
   285 	if ( ! $user ) {
   269 	if ( ! $user ) {
   286 		restore_current_blog();
   270 		restore_current_blog();
   287 		return new WP_Error( 'user_does_not_exist', __( 'That user does not exist.' ) );
   271 		return new WP_Error( 'user_does_not_exist', __( 'That user does not exist.' ) );
   288 	}
   272 	}
   315 
   299 
   316 	return true;
   300 	return true;
   317 }
   301 }
   318 
   302 
   319 /**
   303 /**
   320  * Get the permalink for a post on another blog.
   304  * Gets the permalink for a post on another blog.
   321  *
   305  *
   322  * @since MU (3.0.0) 1.0
   306  * @since MU (3.0.0) 1.0
   323  *
   307  *
   324  * @param int $blog_id ID of the source blog.
   308  * @param int $blog_id ID of the source blog.
   325  * @param int $post_id ID of the desired post.
   309  * @param int $post_id ID of the desired post.
   332 
   316 
   333 	return $link;
   317 	return $link;
   334 }
   318 }
   335 
   319 
   336 /**
   320 /**
   337  * Get a blog's numeric ID from its URL.
   321  * Gets a blog's numeric ID from its URL.
   338  *
   322  *
   339  * On a subdirectory installation like example.com/blog1/,
   323  * On a subdirectory installation like example.com/blog1/,
   340  * $domain will be the root 'example.com' and $path the
   324  * $domain will be the root 'example.com' and $path the
   341  * subdirectory '/blog1/'. With subdomains like blog1.example.com,
   325  * subdirectory '/blog1/'. With subdomains like blog1.example.com,
   342  * $domain is 'blog1.example.com' and $path is '/'.
   326  * $domain is 'blog1.example.com' and $path is '/'.
   439 	 */
   423 	 */
   440 	return apply_filters( 'is_email_address_unsafe', $is_email_address_unsafe, $user_email );
   424 	return apply_filters( 'is_email_address_unsafe', $is_email_address_unsafe, $user_email );
   441 }
   425 }
   442 
   426 
   443 /**
   427 /**
   444  * Sanitize and validate data required for a user sign-up.
   428  * Sanitizes and validates data required for a user sign-up.
   445  *
   429  *
   446  * Verifies the validity and uniqueness of user names and user email addresses,
   430  * Verifies the validity and uniqueness of user names and user email addresses,
   447  * and checks email addresses against allowed and disallowed domains provided by
   431  * and checks email addresses against allowed and disallowed domains provided by
   448  * administrators.
   432  * administrators.
   449  *
   433  *
   504 	}
   488 	}
   505 
   489 
   506 	if ( ! is_email( $user_email ) ) {
   490 	if ( ! is_email( $user_email ) ) {
   507 		$errors->add( 'user_email', __( 'Please enter a valid email address.' ) );
   491 		$errors->add( 'user_email', __( 'Please enter a valid email address.' ) );
   508 	} elseif ( is_email_address_unsafe( $user_email ) ) {
   492 	} elseif ( is_email_address_unsafe( $user_email ) ) {
   509 		$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.' ) );
   493 		$errors->add( 'user_email', __( 'You cannot use that email address to signup. There are problems with them blocking some emails from WordPress. Please use another email provider.' ) );
   510 	}
   494 	}
   511 
   495 
   512 	if ( strlen( $user_name ) < 4 ) {
   496 	if ( strlen( $user_name ) < 4 ) {
   513 		$errors->add( 'user_name', __( 'Username must be at least 4 characters.' ) );
   497 		$errors->add( 'user_name', __( 'Username must be at least 4 characters.' ) );
   514 	}
   498 	}
   536 		$errors->add( 'user_name', __( 'Sorry, that username already exists!' ) );
   520 		$errors->add( 'user_name', __( 'Sorry, that username already exists!' ) );
   537 	}
   521 	}
   538 
   522 
   539 	// Check if the email address has been used already.
   523 	// Check if the email address has been used already.
   540 	if ( email_exists( $user_email ) ) {
   524 	if ( email_exists( $user_email ) ) {
   541 		$errors->add( 'user_email', __( 'Sorry, that email address is already used!' ) );
   525 		$errors->add(
       
   526 			'user_email',
       
   527 			sprintf(
       
   528 				/* translators: %s: Link to the login page. */
       
   529 				__( '<strong>Error:</strong> This email address is already registered. <a href="%s">Log in</a> with this address or choose another one.' ),
       
   530 				wp_login_url()
       
   531 			)
       
   532 		);
   542 	}
   533 	}
   543 
   534 
   544 	// Has someone already signed up for this username?
   535 	// Has someone already signed up for this username?
   545 	$signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE user_login = %s", $user_name ) );
   536 	$signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE user_login = %s", $user_name ) );
   546 	if ( $signup instanceof stdClass ) {
   537 	if ( $signup instanceof stdClass ) {
   673 	if ( strlen( $blogname ) < $minimum_site_name_length ) {
   664 	if ( strlen( $blogname ) < $minimum_site_name_length ) {
   674 		/* translators: %s: Minimum site name length. */
   665 		/* translators: %s: Minimum site name length. */
   675 		$errors->add( 'blogname', sprintf( _n( 'Site name must be at least %s character.', 'Site name must be at least %s characters.', $minimum_site_name_length ), number_format_i18n( $minimum_site_name_length ) ) );
   666 		$errors->add( 'blogname', sprintf( _n( 'Site name must be at least %s character.', 'Site name must be at least %s characters.', $minimum_site_name_length ), number_format_i18n( $minimum_site_name_length ) ) );
   676 	}
   667 	}
   677 
   668 
   678 	// Do not allow users to create a blog that conflicts with a page on the main blog.
   669 	// Do not allow users to create a site that conflicts with a page on the main blog.
   679 	if ( ! is_subdomain_install() && $wpdb->get_var( $wpdb->prepare( 'SELECT post_name FROM ' . $wpdb->get_blog_prefix( $current_network->site_id ) . "posts WHERE post_type = 'page' AND post_name = %s", $blogname ) ) ) {
   670 	if ( ! is_subdomain_install() && $wpdb->get_var( $wpdb->prepare( 'SELECT post_name FROM ' . $wpdb->get_blog_prefix( $current_network->site_id ) . "posts WHERE post_type = 'page' AND post_name = %s", $blogname ) ) ) {
   680 		$errors->add( 'blogname', __( 'Sorry, you may not use that site name.' ) );
   671 		$errors->add( 'blogname', __( 'Sorry, you may not use that site name.' ) );
   681 	}
   672 	}
   682 
   673 
   683 	// All numeric?
   674 	// All numeric?
   713 	}
   704 	}
   714 	if ( domain_exists( $mydomain, $path, $current_network->id ) ) {
   705 	if ( domain_exists( $mydomain, $path, $current_network->id ) ) {
   715 		$errors->add( 'blogname', __( 'Sorry, that site already exists!' ) );
   706 		$errors->add( 'blogname', __( 'Sorry, that site already exists!' ) );
   716 	}
   707 	}
   717 
   708 
       
   709 	/*
       
   710 	 * Do not allow users to create a site that matches an existing user's login name,
       
   711 	 * unless it's the user's own username.
       
   712 	 */
   718 	if ( username_exists( $blogname ) ) {
   713 	if ( username_exists( $blogname ) ) {
   719 		if ( ! is_object( $user ) || ( is_object( $user ) && ( $user->user_login != $blogname ) ) ) {
   714 		if ( ! is_object( $user ) || ( is_object( $user ) && ( $user->user_login != $blogname ) ) ) {
   720 			$errors->add( 'blogname', __( 'Sorry, that site is reserved!' ) );
   715 			$errors->add( 'blogname', __( 'Sorry, that site is reserved!' ) );
   721 		}
   716 		}
   722 	}
   717 	}
   767 	 */
   762 	 */
   768 	return apply_filters( 'wpmu_validate_blog_signup', $result );
   763 	return apply_filters( 'wpmu_validate_blog_signup', $result );
   769 }
   764 }
   770 
   765 
   771 /**
   766 /**
   772  * Record site signup information for future activation.
   767  * Records site signup information for future activation.
   773  *
   768  *
   774  * @since MU (3.0.0)
   769  * @since MU (3.0.0)
   775  *
   770  *
   776  * @global wpdb $wpdb WordPress database abstraction object.
   771  * @global wpdb $wpdb WordPress database abstraction object.
   777  *
   772  *
   833 	 */
   828 	 */
   834 	do_action( 'after_signup_site', $domain, $path, $title, $user, $user_email, $key, $meta );
   829 	do_action( 'after_signup_site', $domain, $path, $title, $user, $user_email, $key, $meta );
   835 }
   830 }
   836 
   831 
   837 /**
   832 /**
   838  * Record user signup information for future activation.
   833  * Records user signup information for future activation.
   839  *
   834  *
   840  * This function is used when user registration is open but
   835  * This function is used when user registration is open but
   841  * new site registration is not.
   836  * new site registration is not.
   842  *
   837  *
   843  * @since MU (3.0.0)
   838  * @since MU (3.0.0)
   896 	 */
   891 	 */
   897 	do_action( 'after_signup_user', $user, $user_email, $key, $meta );
   892 	do_action( 'after_signup_user', $user, $user_email, $key, $meta );
   898 }
   893 }
   899 
   894 
   900 /**
   895 /**
   901  * Send a confirmation request email to a user when they sign up for a new site. The new site will not become active
   896  * Sends a confirmation request email to a user when they sign up for a new site. The new site will not become active
   902  * until the confirmation link is clicked.
   897  * until the confirmation link is clicked.
   903  *
   898  *
   904  * This is the notification function used when site registration
   899  * This is the notification function used when site registration
   905  * is enabled.
   900  * is enabled.
   906  *
   901  *
   979 		 * @param array  $meta       Signup meta data. By default, contains the requested privacy setting and lang_id.
   974 		 * @param array  $meta       Signup meta data. By default, contains the requested privacy setting and lang_id.
   980 		 */
   975 		 */
   981 		apply_filters(
   976 		apply_filters(
   982 			'wpmu_signup_blog_notification_email',
   977 			'wpmu_signup_blog_notification_email',
   983 			/* translators: New site notification email. 1: Activation URL, 2: New site URL. */
   978 			/* translators: New site notification email. 1: Activation URL, 2: New site URL. */
   984 			__( "To activate your blog, please click the following link:\n\n%1\$s\n\nAfter you activate, you will receive *another email* with your login.\n\nAfter you activate, you can visit your site here:\n\n%2\$s" ),
   979 			__( "To activate your site, please click the following link:\n\n%1\$s\n\nAfter you activate, you will receive *another email* with your login.\n\nAfter you activate, you can visit your site here:\n\n%2\$s" ),
   985 			$domain,
   980 			$domain,
   986 			$path,
   981 			$path,
   987 			$title,
   982 			$title,
   988 			$user_login,
   983 			$user_login,
   989 			$user_email,
   984 			$user_email,
  1034 
  1029 
  1035 	return true;
  1030 	return true;
  1036 }
  1031 }
  1037 
  1032 
  1038 /**
  1033 /**
  1039  * Send a confirmation request email to a user when they sign up for a new user account (without signing up for a site
  1034  * Sends a confirmation request email to a user when they sign up for a new user account (without signing up for a site
  1040  * at the same time). The user account will not become active until the confirmation link is clicked.
  1035  * at the same time). The user account will not become active until the confirmation link is clicked.
  1041  *
  1036  *
  1042  * This is the notification function used when no new site has
  1037  * This is the notification function used when no new site has
  1043  * been requested.
  1038  * been requested.
  1044  *
  1039  *
  1143 
  1138 
  1144 	return true;
  1139 	return true;
  1145 }
  1140 }
  1146 
  1141 
  1147 /**
  1142 /**
  1148  * Activate a signup.
  1143  * Activates a signup.
  1149  *
  1144  *
  1150  * Hook to {@see 'wpmu_activate_user'} or {@see 'wpmu_activate_blog'} for events
  1145  * Hook to {@see 'wpmu_activate_user'} or {@see 'wpmu_activate_blog'} for events
  1151  * that should happen only when users or sites are self-created (since
  1146  * that should happen only when users or sites are self-created (since
  1152  * those actions are not called when users and sites are created
  1147  * those actions are not called when users and sites are created
  1153  * by a Super Admin).
  1148  * by a Super Admin).
  1262 	 *
  1257 	 *
  1263 	 * @since MU (3.0.0)
  1258 	 * @since MU (3.0.0)
  1264 	 *
  1259 	 *
  1265 	 * @param int    $blog_id       Blog ID.
  1260 	 * @param int    $blog_id       Blog ID.
  1266 	 * @param int    $user_id       User ID.
  1261 	 * @param int    $user_id       User ID.
  1267 	 * @param int    $password      User password.
  1262 	 * @param string $password      User password.
  1268 	 * @param string $signup_title  Site title.
  1263 	 * @param string $signup_title  Site title.
  1269 	 * @param array  $meta          Signup meta data. By default, contains the requested privacy setting and lang_id.
  1264 	 * @param array  $meta          Signup meta data. By default, contains the requested privacy setting and lang_id.
  1270 	 */
  1265 	 */
  1271 	do_action( 'wpmu_activate_blog', $blog_id, $user_id, $password, $signup->title, $meta );
  1266 	do_action( 'wpmu_activate_blog', $blog_id, $user_id, $password, $signup->title, $meta );
  1272 
  1267 
  1278 		'meta'     => $meta,
  1273 		'meta'     => $meta,
  1279 	);
  1274 	);
  1280 }
  1275 }
  1281 
  1276 
  1282 /**
  1277 /**
  1283  * Deletes am associated signup entry when a user is deleted from the database.
  1278  * Deletes an associated signup entry when a user is deleted from the database.
  1284  *
  1279  *
  1285  * @since 5.5.0
  1280  * @since 5.5.0
  1286  *
  1281  *
  1287  * @param int      $id       ID of the user to delete.
  1282  * @param int      $id       ID of the user to delete.
  1288  * @param int|null $reassign ID of the user to reassign posts and links to.
  1283  * @param int|null $reassign ID of the user to reassign posts and links to.
  1293 
  1288 
  1294 	$wpdb->delete( $wpdb->signups, array( 'user_login' => $user->user_login ) );
  1289 	$wpdb->delete( $wpdb->signups, array( 'user_login' => $user->user_login ) );
  1295 }
  1290 }
  1296 
  1291 
  1297 /**
  1292 /**
  1298  * Create a user.
  1293  * Creates a user.
  1299  *
  1294  *
  1300  * This function runs when a user self-registers as well as when
  1295  * This function runs when a user self-registers as well as when
  1301  * a Super Admin creates a new user. Hook to {@see 'wpmu_new_user'} for events
  1296  * a Super Admin creates a new user. Hook to {@see 'wpmu_new_user'} for events
  1302  * that should affect all new users, but only on Multisite (otherwise
  1297  * that should affect all new users, but only on Multisite (otherwise
  1303  * use {@see'user_register'}).
  1298  * use {@see 'user_register'}).
  1304  *
  1299  *
  1305  * @since MU (3.0.0)
  1300  * @since MU (3.0.0)
  1306  *
  1301  *
  1307  * @param string $user_name The new user's login name.
  1302  * @param string $user_name The new user's login name.
  1308  * @param string $password  The new user's password.
  1303  * @param string $password  The new user's password.
  1332 
  1327 
  1333 	return $user_id;
  1328 	return $user_id;
  1334 }
  1329 }
  1335 
  1330 
  1336 /**
  1331 /**
  1337  * Create a site.
  1332  * Creates a site.
  1338  *
  1333  *
  1339  * This function runs when a user self-registers a new site as well
  1334  * This function runs when a user self-registers a new site as well
  1340  * as when a Super Admin creates a new site. Hook to {@see 'wpmu_new_blog'}
  1335  * as when a Super Admin creates a new site. Hook to {@see 'wpmu_new_blog'}
  1341  * for events that should affect all new sites.
  1336  * for events that should affect all new sites.
  1342  *
  1337  *
  1460 	 * to the network administrator.
  1455 	 * to the network administrator.
  1461 	 *
  1456 	 *
  1462 	 * @since MU (3.0.0)
  1457 	 * @since MU (3.0.0)
  1463 	 * @since 5.4.0 The `$blog_id` parameter was added.
  1458 	 * @since 5.4.0 The `$blog_id` parameter was added.
  1464 	 *
  1459 	 *
  1465 	 * @param string $msg     Email body.
  1460 	 * @param string     $msg     Email body.
  1466 	 * @param int    $blog_id The new site's ID.
  1461 	 * @param int|string $blog_id The new site's ID as an integer or numeric string.
  1467 	 */
  1462 	 */
  1468 	$msg = apply_filters( 'newblog_notify_siteadmin', $msg, $blog_id );
  1463 	$msg = apply_filters( 'newblog_notify_siteadmin', $msg, $blog_id );
  1469 
  1464 
  1470 	/* translators: New site notification email subject. %s: New site URL. */
  1465 	/* translators: New site notification email subject. %s: New site URL. */
  1471 	wp_mail( $email, sprintf( __( 'New Site Registration: %s' ), $siteurl ), $msg );
  1466 	wp_mail( $email, sprintf( __( 'New Site Registration: %s' ), $siteurl ), $msg );
  1808 
  1803 
  1809 	return true;
  1804 	return true;
  1810 }
  1805 }
  1811 
  1806 
  1812 /**
  1807 /**
  1813  * Notify a user that their account activation has been successful.
  1808  * Notifies a user that their account activation has been successful.
  1814  *
  1809  *
  1815  * Filter {@see 'wpmu_welcome_user_notification'} to disable or bypass.
  1810  * Filter {@see 'wpmu_welcome_user_notification'} to disable or bypass.
  1816  *
  1811  *
  1817  * Filter {@see 'update_welcome_user_email'} and {@see 'update_welcome_user_subject'} to
  1812  * Filter {@see 'update_welcome_user_email'} and {@see 'update_welcome_user_subject'} to
  1818  * modify the content and subject line of the notification email.
  1813  * modify the content and subject line of the notification email.
  1900 
  1895 
  1901 	return true;
  1896 	return true;
  1902 }
  1897 }
  1903 
  1898 
  1904 /**
  1899 /**
  1905  * Get the current network.
  1900  * Gets the current network.
  1906  *
  1901  *
  1907  * Returns an object containing the 'id', 'domain', 'path', and 'site_name'
  1902  * Returns an object containing the 'id', 'domain', 'path', and 'site_name'
  1908  * properties of the network being viewed.
  1903  * properties of the network being viewed.
  1909  *
  1904  *
  1910  * @see wpmu_current_site()
  1905  * @see wpmu_current_site()
  1919 	global $current_site;
  1914 	global $current_site;
  1920 	return $current_site;
  1915 	return $current_site;
  1921 }
  1916 }
  1922 
  1917 
  1923 /**
  1918 /**
  1924  * Get a user's most recent post.
  1919  * Gets a user's most recent post.
  1925  *
  1920  *
  1926  * Walks through each of a user's blogs to find the post with
  1921  * Walks through each of a user's blogs to find the post with
  1927  * the most recent post_date_gmt.
  1922  * the most recent post_date_gmt.
  1928  *
  1923  *
  1929  * @since MU (3.0.0)
  1924  * @since MU (3.0.0)
  1971 //
  1966 //
  1972 // Misc functions.
  1967 // Misc functions.
  1973 //
  1968 //
  1974 
  1969 
  1975 /**
  1970 /**
  1976  * Check an array of MIME types against a list of allowed types.
  1971  * Checks an array of MIME types against a list of allowed types.
  1977  *
  1972  *
  1978  * WordPress ships with a set of allowed upload filetypes,
  1973  * WordPress ships with a set of allowed upload filetypes,
  1979  * which is defined in wp-includes/functions.php in
  1974  * which is defined in wp-includes/functions.php in
  1980  * get_allowed_mime_types(). This function is used to filter
  1975  * get_allowed_mime_types(). This function is used to filter
  1981  * that list against the filetypes allowed provided by Multisite
  1976  * that list against the filetypes allowed provided by Multisite
  1998 	}
  1993 	}
  1999 	return $site_mimes;
  1994 	return $site_mimes;
  2000 }
  1995 }
  2001 
  1996 
  2002 /**
  1997 /**
  2003  * Update a blog's post count.
  1998  * Updates a blog's post count.
  2004  *
  1999  *
  2005  * WordPress MS stores a blog's post count as an option so as
  2000  * WordPress MS stores a blog's post count as an option so as
  2006  * to avoid extraneous COUNTs when a blog's details are fetched
  2001  * to avoid extraneous COUNTs when a blog's details are fetched
  2007  * with get_site(). This function is called when posts are published
  2002  * with get_site(). This function is called when posts are published
  2008  * or unpublished to make sure the count stays current.
  2003  * or unpublished to make sure the count stays current.
  2144 
  2139 
  2145 	return $global_id;
  2140 	return $global_id;
  2146 }
  2141 }
  2147 
  2142 
  2148 /**
  2143 /**
  2149  * Ensure that the current site's domain is listed in the allowed redirect host list.
  2144  * Ensures that the current site's domain is listed in the allowed redirect host list.
  2150  *
  2145  *
  2151  * @see wp_validate_redirect()
  2146  * @see wp_validate_redirect()
  2152  * @since MU (3.0.0)
  2147  * @since MU (3.0.0)
  2153  *
  2148  *
  2154  * @param array|string $deprecated Not used.
  2149  * @param array|string $deprecated Not used.
  2161 function redirect_this_site( $deprecated = '' ) {
  2156 function redirect_this_site( $deprecated = '' ) {
  2162 	return array( get_network()->domain );
  2157 	return array( get_network()->domain );
  2163 }
  2158 }
  2164 
  2159 
  2165 /**
  2160 /**
  2166  * Check whether an upload is too big.
  2161  * Checks whether an upload is too big.
  2167  *
  2162  *
  2168  * @since MU (3.0.0)
  2163  * @since MU (3.0.0)
  2169  *
  2164  *
  2170  * @blessed
  2165  * @blessed
  2171  *
  2166  *
  2184 
  2179 
  2185 	return $upload;
  2180 	return $upload;
  2186 }
  2181 }
  2187 
  2182 
  2188 /**
  2183 /**
  2189  * Add a nonce field to the signup page.
  2184  * Adds a nonce field to the signup page.
  2190  *
  2185  *
  2191  * @since MU (3.0.0)
  2186  * @since MU (3.0.0)
  2192  */
  2187  */
  2193 function signup_nonce_fields() {
  2188 function signup_nonce_fields() {
  2194 	$id = mt_rand();
  2189 	$id = mt_rand();
  2195 	echo "<input type='hidden' name='signup_form_id' value='{$id}' />";
  2190 	echo "<input type='hidden' name='signup_form_id' value='{$id}' />";
  2196 	wp_nonce_field( 'signup_form_' . $id, '_signup_form', false );
  2191 	wp_nonce_field( 'signup_form_' . $id, '_signup_form', false );
  2197 }
  2192 }
  2198 
  2193 
  2199 /**
  2194 /**
  2200  * Process the signup nonce created in signup_nonce_fields().
  2195  * Processes the signup nonce created in signup_nonce_fields().
  2201  *
  2196  *
  2202  * @since MU (3.0.0)
  2197  * @since MU (3.0.0)
  2203  *
  2198  *
  2204  * @param array $result
  2199  * @param array $result
  2205  * @return array
  2200  * @return array
  2215 
  2210 
  2216 	return $result;
  2211 	return $result;
  2217 }
  2212 }
  2218 
  2213 
  2219 /**
  2214 /**
  2220  * Correct 404 redirects when NOBLOGREDIRECT is defined.
  2215  * Corrects 404 redirects when NOBLOGREDIRECT is defined.
  2221  *
  2216  *
  2222  * @since MU (3.0.0)
  2217  * @since MU (3.0.0)
  2223  */
  2218  */
  2224 function maybe_redirect_404() {
  2219 function maybe_redirect_404() {
  2225 	if ( is_main_site() && is_404() && defined( 'NOBLOGREDIRECT' ) ) {
  2220 	if ( is_main_site() && is_404() && defined( 'NOBLOGREDIRECT' ) ) {
  2244 		}
  2239 		}
  2245 	}
  2240 	}
  2246 }
  2241 }
  2247 
  2242 
  2248 /**
  2243 /**
  2249  * Add a new user to a blog by visiting /newbloguser/{key}/.
  2244  * Adds a new user to a blog by visiting /newbloguser/{key}/.
  2250  *
  2245  *
  2251  * This will only work when the user's details are saved as an option
  2246  * This will only work when the user's details are saved as an option
  2252  * keyed as 'new_user_{key}', where '{key}' is a hash generated for the user to be
  2247  * keyed as 'new_user_{key}', where '{key}' is a hash generated for the user to be
  2253  * added, as when a user is invited through the regular WP Add User interface.
  2248  * added, as when a user is invited through the regular WP Add User interface.
  2254  *
  2249  *
  2292 		array( 'response' => 200 )
  2287 		array( 'response' => 200 )
  2293 	);
  2288 	);
  2294 }
  2289 }
  2295 
  2290 
  2296 /**
  2291 /**
  2297  * Add a user to a blog based on details from maybe_add_existing_user_to_blog().
  2292  * Adds a user to a blog based on details from maybe_add_existing_user_to_blog().
  2298  *
  2293  *
  2299  * @since MU (3.0.0)
  2294  * @since MU (3.0.0)
  2300  *
  2295  *
  2301  * @param array|false $details {
  2296  * @param array|false $details {
  2302  *     User details. Must at least contain values for the keys listed below.
  2297  *     User details. Must at least contain values for the keys listed below.
  2354 		}
  2349 		}
  2355 	}
  2350 	}
  2356 }
  2351 }
  2357 
  2352 
  2358 /**
  2353 /**
  2359  * Correct From host on outgoing mail to match the site domain
  2354  * Corrects From host on outgoing mail to match the site domain
  2360  *
  2355  *
  2361  * @since MU (3.0.0)
  2356  * @since MU (3.0.0)
  2362  *
  2357  *
  2363  * @param PHPMailer $phpmailer The PHPMailer instance (passed by reference).
  2358  * @param PHPMailer $phpmailer The PHPMailer instance (passed by reference).
  2364  */
  2359  */
  2365 function fix_phpmailer_messageid( $phpmailer ) {
  2360 function fix_phpmailer_messageid( $phpmailer ) {
  2366 	$phpmailer->Hostname = get_network()->domain;
  2361 	$phpmailer->Hostname = get_network()->domain;
  2367 }
  2362 }
  2368 
  2363 
  2369 /**
  2364 /**
  2370  * Check to see whether a user is marked as a spammer, based on user login.
  2365  * Determines whether a user is marked as a spammer, based on user login.
  2371  *
  2366  *
  2372  * @since MU (3.0.0)
  2367  * @since MU (3.0.0)
  2373  *
  2368  *
  2374  * @param string|WP_User $user Optional. Defaults to current user. WP_User object,
  2369  * @param string|WP_User $user Optional. Defaults to current user. WP_User object,
  2375  *                             or user login name as a string.
  2370  *                             or user login name as a string.
  2386 
  2381 
  2387 	return $user && isset( $user->spam ) && 1 == $user->spam;
  2382 	return $user && isset( $user->spam ) && 1 == $user->spam;
  2388 }
  2383 }
  2389 
  2384 
  2390 /**
  2385 /**
  2391  * Update this blog's 'public' setting in the global blogs table.
  2386  * Updates this blog's 'public' setting in the global blogs table.
  2392  *
  2387  *
  2393  * Public blogs have a setting of 1, private blogs are 0.
  2388  * Public blogs have a setting of 1, private blogs are 0.
  2394  *
  2389  *
  2395  * @since MU (3.0.0)
  2390  * @since MU (3.0.0)
  2396  *
  2391  *
  2400 function update_blog_public( $old_value, $value ) {
  2395 function update_blog_public( $old_value, $value ) {
  2401 	update_blog_status( get_current_blog_id(), 'public', (int) $value );
  2396 	update_blog_status( get_current_blog_id(), 'public', (int) $value );
  2402 }
  2397 }
  2403 
  2398 
  2404 /**
  2399 /**
  2405  * Check whether users can self-register, based on Network settings.
  2400  * Determines whether users can self-register, based on Network settings.
  2406  *
  2401  *
  2407  * @since MU (3.0.0)
  2402  * @since MU (3.0.0)
  2408  *
  2403  *
  2409  * @return bool
  2404  * @return bool
  2410  */
  2405  */
  2412 	$registration = get_site_option( 'registration' );
  2407 	$registration = get_site_option( 'registration' );
  2413 	return ( 'all' === $registration || 'user' === $registration );
  2408 	return ( 'all' === $registration || 'user' === $registration );
  2414 }
  2409 }
  2415 
  2410 
  2416 /**
  2411 /**
  2417  * Ensure that the welcome message is not empty. Currently unused.
  2412  * Ensures that the welcome message is not empty. Currently unused.
  2418  *
  2413  *
  2419  * @since MU (3.0.0)
  2414  * @since MU (3.0.0)
  2420  *
  2415  *
  2421  * @param string $text
  2416  * @param string $text
  2422  * @return string
  2417  * @return string
  2444 	}
  2439 	}
  2445 	return $text;
  2440 	return $text;
  2446 }
  2441 }
  2447 
  2442 
  2448 /**
  2443 /**
  2449  * Whether to force SSL on content.
  2444  * Determines whether to force SSL on content.
  2450  *
  2445  *
  2451  * @since 2.8.5
  2446  * @since 2.8.5
  2452  *
  2447  *
  2453  * @param bool $force
  2448  * @param bool $force
  2454  * @return bool True if forced, false if not forced.
  2449  * @return bool True if forced, false if not forced.
  2486 
  2481 
  2487 	return $url;
  2482 	return $url;
  2488 }
  2483 }
  2489 
  2484 
  2490 /**
  2485 /**
  2491  * Schedule update of the network-wide counts for the current network.
  2486  * Schedules update of the network-wide counts for the current network.
  2492  *
  2487  *
  2493  * @since 3.1.0
  2488  * @since 3.1.0
  2494  */
  2489  */
  2495 function wp_schedule_update_network_counts() {
  2490 function wp_schedule_update_network_counts() {
  2496 	if ( ! is_main_site() ) {
  2491 	if ( ! is_main_site() ) {
  2501 		wp_schedule_event( time(), 'twicedaily', 'update_network_counts' );
  2496 		wp_schedule_event( time(), 'twicedaily', 'update_network_counts' );
  2502 	}
  2497 	}
  2503 }
  2498 }
  2504 
  2499 
  2505 /**
  2500 /**
  2506  * Update the network-wide counts for the current network.
  2501  * Updates the network-wide counts for the current network.
  2507  *
  2502  *
  2508  * @since 3.1.0
  2503  * @since 3.1.0
  2509  * @since 4.8.0 The `$network_id` parameter has been added.
  2504  * @since 4.8.0 The `$network_id` parameter has been added.
  2510  *
  2505  *
  2511  * @param int|null $network_id ID of the network. Default is the current network.
  2506  * @param int|null $network_id ID of the network. Default is the current network.
  2514 	wp_update_network_user_counts( $network_id );
  2509 	wp_update_network_user_counts( $network_id );
  2515 	wp_update_network_site_counts( $network_id );
  2510 	wp_update_network_site_counts( $network_id );
  2516 }
  2511 }
  2517 
  2512 
  2518 /**
  2513 /**
  2519  * Update the count of sites for the current network.
  2514  * Updates the count of sites for the current network.
  2520  *
  2515  *
  2521  * If enabled through the {@see 'enable_live_network_counts'} filter, update the sites count
  2516  * If enabled through the {@see 'enable_live_network_counts'} filter, update the sites count
  2522  * on a network when a site is created or its status is updated.
  2517  * on a network when a site is created or its status is updated.
  2523  *
  2518  *
  2524  * @since 3.7.0
  2519  * @since 3.7.0
  2545 
  2540 
  2546 	wp_update_network_site_counts( $network_id );
  2541 	wp_update_network_site_counts( $network_id );
  2547 }
  2542 }
  2548 
  2543 
  2549 /**
  2544 /**
  2550  * Update the network-wide users count.
  2545  * Updates the network-wide users count.
  2551  *
  2546  *
  2552  * If enabled through the {@see 'enable_live_network_counts'} filter, update the users count
  2547  * If enabled through the {@see 'enable_live_network_counts'} filter, update the users count
  2553  * on a network when a user is created or its status is updated.
  2548  * on a network when a user is created or its status is updated.
  2554  *
  2549  *
  2555  * @since 3.7.0
  2550  * @since 3.7.0
  2567 
  2562 
  2568 	wp_update_network_user_counts( $network_id );
  2563 	wp_update_network_user_counts( $network_id );
  2569 }
  2564 }
  2570 
  2565 
  2571 /**
  2566 /**
  2572  * Update the network-wide site count.
  2567  * Updates the network-wide site count.
  2573  *
  2568  *
  2574  * @since 3.7.0
  2569  * @since 3.7.0
  2575  * @since 4.8.0 The `$network_id` parameter has been added.
  2570  * @since 4.8.0 The `$network_id` parameter has been added.
  2576  *
  2571  *
  2577  * @param int|null $network_id ID of the network. Default is the current network.
  2572  * @param int|null $network_id ID of the network. Default is the current network.
  2595 
  2590 
  2596 	update_network_option( $network_id, 'blog_count', $count );
  2591 	update_network_option( $network_id, 'blog_count', $count );
  2597 }
  2592 }
  2598 
  2593 
  2599 /**
  2594 /**
  2600  * Update the network-wide user count.
  2595  * Updates the network-wide user count.
  2601  *
  2596  *
  2602  * @since 3.7.0
  2597  * @since 3.7.0
  2603  * @since 4.8.0 The `$network_id` parameter has been added.
  2598  * @since 4.8.0 The `$network_id` parameter has been added.
  2604  *
  2599  * @since 6.0.0 This function is now a wrapper for wp_update_user_counts().
  2605  * @global wpdb $wpdb WordPress database abstraction object.
       
  2606  *
  2600  *
  2607  * @param int|null $network_id ID of the network. Default is the current network.
  2601  * @param int|null $network_id ID of the network. Default is the current network.
  2608  */
  2602  */
  2609 function wp_update_network_user_counts( $network_id = null ) {
  2603 function wp_update_network_user_counts( $network_id = null ) {
  2610 	global $wpdb;
  2604 	wp_update_user_counts( $network_id );
  2611 
       
  2612 	$count = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" );
       
  2613 	update_network_option( $network_id, 'user_count', $count );
       
  2614 }
  2605 }
  2615 
  2606 
  2616 /**
  2607 /**
  2617  * Returns the space used by the current site.
  2608  * Returns the space used by the current site.
  2618  *
  2609  *
  2722 
  2713 
  2723 	return min( $size, $fileupload_maxk, get_upload_space_available() );
  2714 	return min( $size, $fileupload_maxk, get_upload_space_available() );
  2724 }
  2715 }
  2725 
  2716 
  2726 /**
  2717 /**
  2727  * Whether or not we have a large network.
  2718  * Determines whether or not we have a large network.
  2728  *
  2719  *
  2729  * The default criteria for a large network is either more than 10,000 users or more than 10,000 sites.
  2720  * The default criteria for a large network is either more than 10,000 users or more than 10,000 sites.
  2730  * Plugins can alter this criteria using the {@see 'wp_is_large_network'} filter.
  2721  * Plugins can alter this criteria using the {@see 'wp_is_large_network'} filter.
  2731  *
  2722  *
  2732  * @since 3.3.0
  2723  * @since 3.3.0
  2742 		$network_id = get_current_network_id();
  2733 		$network_id = get_current_network_id();
  2743 	}
  2734 	}
  2744 
  2735 
  2745 	if ( 'users' === $using ) {
  2736 	if ( 'users' === $using ) {
  2746 		$count = get_user_count( $network_id );
  2737 		$count = get_user_count( $network_id );
       
  2738 
       
  2739 		$is_large_network = wp_is_large_user_count( $network_id );
       
  2740 
  2747 		/**
  2741 		/**
  2748 		 * Filters whether the network is considered large.
  2742 		 * Filters whether the network is considered large.
  2749 		 *
  2743 		 *
  2750 		 * @since 3.3.0
  2744 		 * @since 3.3.0
  2751 		 * @since 4.8.0 The `$network_id` parameter has been added.
  2745 		 * @since 4.8.0 The `$network_id` parameter has been added.
  2753 		 * @param bool   $is_large_network Whether the network has more than 10000 users or sites.
  2747 		 * @param bool   $is_large_network Whether the network has more than 10000 users or sites.
  2754 		 * @param string $component        The component to count. Accepts 'users', or 'sites'.
  2748 		 * @param string $component        The component to count. Accepts 'users', or 'sites'.
  2755 		 * @param int    $count            The count of items for the component.
  2749 		 * @param int    $count            The count of items for the component.
  2756 		 * @param int    $network_id       The ID of the network being checked.
  2750 		 * @param int    $network_id       The ID of the network being checked.
  2757 		 */
  2751 		 */
  2758 		return apply_filters( 'wp_is_large_network', $count > 10000, 'users', $count, $network_id );
  2752 		return apply_filters( 'wp_is_large_network', $is_large_network, 'users', $count, $network_id );
  2759 	}
  2753 	}
  2760 
  2754 
  2761 	$count = get_blog_count( $network_id );
  2755 	$count = get_blog_count( $network_id );
  2762 
  2756 
  2763 	/** This filter is documented in wp-includes/ms-functions.php */
  2757 	/** This filter is documented in wp-includes/ms-functions.php */
  2796 	 */
  2790 	 */
  2797 	return apply_filters( 'subdirectory_reserved_names', $names );
  2791 	return apply_filters( 'subdirectory_reserved_names', $names );
  2798 }
  2792 }
  2799 
  2793 
  2800 /**
  2794 /**
  2801  * Send a confirmation request email when a change of network admin email address is attempted.
  2795  * Sends a confirmation request email when a change of network admin email address is attempted.
  2802  *
  2796  *
  2803  * The new network admin address will not become active until confirmed.
  2797  * The new network admin address will not become active until confirmed.
  2804  *
  2798  *
  2805  * @since 4.9.0
  2799  * @since 4.9.0
  2806  *
  2800  *
  2884 		restore_previous_locale();
  2878 		restore_previous_locale();
  2885 	}
  2879 	}
  2886 }
  2880 }
  2887 
  2881 
  2888 /**
  2882 /**
  2889  * Send an email to the old network admin email address when the network admin email address changes.
  2883  * Sends an email to the old network admin email address when the network admin email address changes.
  2890  *
  2884  *
  2891  * @since 4.9.0
  2885  * @since 4.9.0
  2892  *
  2886  *
  2893  * @param string $option_name The relevant database option name.
  2887  * @param string $option_name The relevant database option name.
  2894  * @param string $new_email   The new network admin email address.
  2888  * @param string $new_email   The new network admin email address.