: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$site_mimes[ $ext_pattern ] = $mime;
* Updates a blog's post count.
* WordPress MS stores a blog's post count as an option so as
* to avoid extraneous COUNTs when a blog's details are fetched
* with get_site(). This function is called when posts are published
* or unpublished to make sure the count stays current.
* @global wpdb $wpdb WordPress database abstraction object.
* @param string $deprecated Not used.
function update_posts_count( $deprecated = '' ) {
update_option( 'post_count', (int) $wpdb->get_var( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_status = 'publish' and post_type = 'post'" ) );
* Logs the user email, IP, and registration date of a new site.
* @since 5.1.0 Parameters now support input from the {@see 'wp_initialize_site'} action.
* @global wpdb $wpdb WordPress database abstraction object.
* @param WP_Site|int $blog_id The new site's object or ID.
* @param int|array $user_id User ID, or array of arguments including 'user_id'.
function wpmu_log_new_registrations( $blog_id, $user_id ) {
if ( is_object( $blog_id ) ) {
$blog_id = $blog_id->blog_id;
if ( is_array( $user_id ) ) {
$user_id = ! empty( $user_id['user_id'] ) ? $user_id['user_id'] : 0;
$user = get_userdata( (int) $user_id );
'email' => $user->user_email,
'IP' => preg_replace( '/[^0-9., ]/', '', wp_unslash( $_SERVER['REMOTE_ADDR'] ) ),
'date_registered' => current_time( 'mysql' ),
* Ensures that the current site's domain is listed in the allowed redirect host list.
* @see wp_validate_redirect()
* @param array|string $deprecated Not used.
* An array containing the current site's domain.
* @type string $0 The current site's domain.
function redirect_this_site( $deprecated = '' ) {
return array( get_network()->domain );
* Checks whether an upload is too big.
* @param array $upload An array of information about the newly-uploaded file.
* @return string|array If the upload is under the size limit, $upload is returned. Otherwise returns an error message.
function upload_is_file_too_big( $upload ) {
if ( ! is_array( $upload ) || defined( 'WP_IMPORTING' ) || get_site_option( 'upload_space_check_disabled' ) ) {
if ( strlen( $upload['bits'] ) > ( KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ) ) ) {
/* translators: %s: Maximum allowed file size in kilobytes. */
return sprintf( __( 'This file is too big. Files must be less than %s KB in size.' ) . '<br />', get_site_option( 'fileupload_maxk', 1500 ) );
* Adds a nonce field to the signup page.
function signup_nonce_fields() {
echo "<input type='hidden' name='signup_form_id' value='{$id}' />";
wp_nonce_field( 'signup_form_' . $id, '_signup_form', false );
* Processes the signup nonce created in signup_nonce_fields().
function signup_nonce_check( $result ) {
if ( ! strpos( $_SERVER['PHP_SELF'], 'wp-signup.php' ) ) {
if ( ! wp_verify_nonce( $_POST['_signup_form'], 'signup_form_' . $_POST['signup_form_id'] ) ) {
$result['errors']->add( 'invalid_nonce', __( 'Unable to submit this form, please try again.' ) );
* Corrects 404 redirects when NOBLOGREDIRECT is defined.
function maybe_redirect_404() {
if ( is_main_site() && is_404() && defined( 'NOBLOGREDIRECT' ) ) {
* Filters the redirect URL for 404s on the main site.
* The filter is only evaluated if the NOBLOGREDIRECT constant is defined.
* @param string $no_blog_redirect The redirect URL defined in NOBLOGREDIRECT.
$destination = apply_filters( 'blog_redirect_404', NOBLOGREDIRECT );
if ( '%siteurl%' === $destination ) {
$destination = network_home_url();
wp_redirect( $destination );
* Adds a new user to a blog by visiting /newbloguser/{key}/.
* This will only work when the user's details are saved as an option
* keyed as 'new_user_{key}', where '{key}' is a hash generated for the user to be
* added, as when a user is invited through the regular WP Add User interface.
function maybe_add_existing_user_to_blog() {
if ( ! str_contains( $_SERVER['REQUEST_URI'], '/newbloguser/' ) ) {
$parts = explode( '/', $_SERVER['REQUEST_URI'] );
$key = array_pop( $parts );
$key = array_pop( $parts );
$details = get_option( 'new_user_' . $key );
if ( ! empty( $details ) ) {
delete_option( 'new_user_' . $key );
if ( empty( $details ) || is_wp_error( add_existing_user_to_blog( $details ) ) ) {
/* translators: %s: Home URL. */
__( 'An error occurred adding you to this site. Go to the <a href="%s">homepage</a>.' ),
/* translators: 1: Home URL, 2: Admin URL. */
__( 'You have been added to this site. Please visit the <a href="%1$s">homepage</a> or <a href="%2$s">log in</a> using your username and password.' ),
__( 'WordPress › Success' ),
array( 'response' => 200 )
* Adds a user to a blog based on details from maybe_add_existing_user_to_blog().
* @param array|false $details {
* User details. Must at least contain values for the keys listed below.
* @type int $user_id The ID of the user being added to the current blog.
* @type string $role The role to be assigned to the user.
* @return true|WP_Error|void True on success or a WP_Error object if the user doesn't exist
* or could not be added. Void if $details array was not provided.
function add_existing_user_to_blog( $details = false ) {
if ( is_array( $details ) ) {
$blog_id = get_current_blog_id();
$result = add_user_to_blog( $blog_id, $details['user_id'], $details['role'] );
* Fires immediately after an existing user is added to a site.
* @param int $user_id User ID.
* @param true|WP_Error $result True on success or a WP_Error object if the user doesn't exist
do_action( 'added_existing_user', $details['user_id'], $result );
* Adds a newly created user to the appropriate blog
* To add a user in general, use add_user_to_blog(). This function
* is specifically hooked into the {@see 'wpmu_activate_user'} action.
* @see add_user_to_blog()
* @param int $user_id User ID.
* @param string $password User password. Ignored.
* @param array $meta Signup meta data.
function add_new_user_to_blog( $user_id, $password, $meta ) {
if ( ! empty( $meta['add_to_blog'] ) ) {
$blog_id = $meta['add_to_blog'];
$role = $meta['new_role'];
remove_user_from_blog( $user_id, get_network()->site_id ); // Remove user from main blog.
$result = add_user_to_blog( $blog_id, $user_id, $role );
if ( ! is_wp_error( $result ) ) {
update_user_meta( $user_id, 'primary_blog', $blog_id );
* Corrects From host on outgoing mail to match the site domain.
* @param PHPMailer $phpmailer The PHPMailer instance (passed by reference).
function fix_phpmailer_messageid( $phpmailer ) {
$phpmailer->Hostname = get_network()->domain;
* Determines whether a user is marked as a spammer, based on user login.
* @param string|WP_User $user Optional. Defaults to current user. WP_User object,
* or user login name as a string.
function is_user_spammy( $user = null ) {
if ( ! ( $user instanceof WP_User ) ) {
$user = get_user_by( 'login', $user );
$user = wp_get_current_user();
return $user && isset( $user->spam ) && 1 == $user->spam;
* Updates this blog's 'public' setting in the global blogs table.
* Public blogs have a setting of 1, private blogs are 0.
* @param int $old_value The old public value.
* @param int $value The new public value.
function update_blog_public( $old_value, $value ) {
update_blog_status( get_current_blog_id(), 'public', (int) $value );
* Determines whether users can self-register, based on Network settings.
function users_can_register_signup_filter() {
$registration = get_site_option( 'registration' );
return ( 'all' === $registration || 'user' === $registration );
* Ensures that the welcome message is not empty. Currently unused.
function welcome_user_msg_filter( $text ) {
remove_filter( 'site_option_welcome_user_email', 'welcome_user_msg_filter' );
/* translators: Do not translate USERNAME, PASSWORD, LOGINLINK, SITE_NAME: those are placeholders. */
Your new account is set up.
You can log in with the following information:
update_site_option( 'welcome_user_email', $text );
* Determines whether to force SSL on content.
* @return bool True if forced, false if not forced.
function force_ssl_content( $force = '' ) {
static $forced_content = false;
$old_forced = $forced_content;
$forced_content = $force;
* Formats a URL to use https.
* @param string $url URL.
* @return string URL with https as the scheme.
function filter_SSL( $url ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
if ( ! is_string( $url ) ) {
return get_bloginfo( 'url' ); // Return home site URL with proper scheme.
if ( force_ssl_content() && is_ssl() ) {
$url = set_url_scheme( $url, 'https' );
* Schedules update of the network-wide counts for the current network.
function wp_schedule_update_network_counts() {
if ( ! is_main_site() ) {
if ( ! wp_next_scheduled( 'update_network_counts' ) && ! wp_installing() ) {
wp_schedule_event( time(), 'twicedaily', 'update_network_counts' );
* Updates the network-wide counts for the current network.
* @since 4.8.0 The `$network_id` parameter has been added.
* @param int|null $network_id ID of the network. Default is the current network.
function wp_update_network_counts( $network_id = null ) {
wp_update_network_user_counts( $network_id );
wp_update_network_site_counts( $network_id );
* Updates the count of sites for the current network.
* If enabled through the {@see 'enable_live_network_counts'} filter, update the sites count
* on a network when a site is created or its status is updated.
* @since 4.8.0 The `$network_id` parameter has been added.
* @param int|null $network_id ID of the network. Default is the current network.
function wp_maybe_update_network_site_counts( $network_id = null ) {
$is_small_network = ! wp_is_large_network( 'sites', $network_id );
* Filters whether to update network site or user counts when a new site is created.
* @see wp_is_large_network()
* @param bool $small_network Whether the network is considered small.
* @param string $context Context. Either 'users' or 'sites'.
if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'sites' ) ) {
wp_update_network_site_counts( $network_id );
* Updates the network-wide users count.
* If enabled through the {@see 'enable_live_network_counts'} filter, update the users count
* on a network when a user is created or its status is updated.
* @since 4.8.0 The `$network_id` parameter has been added.
* @param int|null $network_id ID of the network. Default is the current network.
function wp_maybe_update_network_user_counts( $network_id = null ) {
$is_small_network = ! wp_is_large_network( 'users', $network_id );
/** This filter is documented in wp-includes/ms-functions.php */
if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'users' ) ) {
wp_update_network_user_counts( $network_id );
* Updates the network-wide site count.
* @since 4.8.0 The `$network_id` parameter has been added.
* @param int|null $network_id ID of the network. Default is the current network.
function wp_update_network_site_counts( $network_id = null ) {
$network_id = (int) $network_id;
$network_id = get_current_network_id();
'network_id' => $network_id,