Edit File by line
/home/barbar84/public_h.../wp-inclu...
File: ms-functions.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Multisite WordPress API
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Multisite
[5] Fix | Delete
* @since 3.0.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Gets the network's site and user counts.
[10] Fix | Delete
*
[11] Fix | Delete
* @since MU (3.0.0)
[12] Fix | Delete
*
[13] Fix | Delete
* @return int[] {
[14] Fix | Delete
* Site and user count for the network.
[15] Fix | Delete
*
[16] Fix | Delete
* @type int $blogs Number of sites on the network.
[17] Fix | Delete
* @type int $users Number of users on the network.
[18] Fix | Delete
* }
[19] Fix | Delete
*/
[20] Fix | Delete
function get_sitestats() {
[21] Fix | Delete
$stats = array(
[22] Fix | Delete
'blogs' => get_blog_count(),
[23] Fix | Delete
'users' => get_user_count(),
[24] Fix | Delete
);
[25] Fix | Delete
[26] Fix | Delete
return $stats;
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
/**
[30] Fix | Delete
* Get one of a user's active blogs
[31] Fix | Delete
*
[32] Fix | Delete
* Returns the user's primary blog, if they have one and
[33] Fix | Delete
* it is active. If it's inactive, function returns another
[34] Fix | Delete
* active blog of the user. If none are found, the user
[35] Fix | Delete
* is added as a Subscriber to the Dashboard Blog and that blog
[36] Fix | Delete
* is returned.
[37] Fix | Delete
*
[38] Fix | Delete
* @since MU (3.0.0)
[39] Fix | Delete
*
[40] Fix | Delete
* @param int $user_id The unique ID of the user
[41] Fix | Delete
* @return WP_Site|void The blog object
[42] Fix | Delete
*/
[43] Fix | Delete
function get_active_blog_for_user( $user_id ) {
[44] Fix | Delete
$blogs = get_blogs_of_user( $user_id );
[45] Fix | Delete
if ( empty( $blogs ) ) {
[46] Fix | Delete
return;
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
if ( ! is_multisite() ) {
[50] Fix | Delete
return $blogs[ get_current_blog_id() ];
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
$primary_blog = get_user_meta( $user_id, 'primary_blog', true );
[54] Fix | Delete
$first_blog = current( $blogs );
[55] Fix | Delete
if ( false !== $primary_blog ) {
[56] Fix | Delete
if ( ! isset( $blogs[ $primary_blog ] ) ) {
[57] Fix | Delete
update_user_meta( $user_id, 'primary_blog', $first_blog->userblog_id );
[58] Fix | Delete
$primary = get_site( $first_blog->userblog_id );
[59] Fix | Delete
} else {
[60] Fix | Delete
$primary = get_site( $primary_blog );
[61] Fix | Delete
}
[62] Fix | Delete
} else {
[63] Fix | Delete
// TODO: Review this call to add_user_to_blog too - to get here the user must have a role on this blog?
[64] Fix | Delete
$result = add_user_to_blog( $first_blog->userblog_id, $user_id, 'subscriber' );
[65] Fix | Delete
[66] Fix | Delete
if ( ! is_wp_error( $result ) ) {
[67] Fix | Delete
update_user_meta( $user_id, 'primary_blog', $first_blog->userblog_id );
[68] Fix | Delete
$primary = $first_blog;
[69] Fix | Delete
}
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
if ( ( ! is_object( $primary ) ) || ( 1 == $primary->archived || 1 == $primary->spam || 1 == $primary->deleted ) ) {
[73] Fix | Delete
$blogs = get_blogs_of_user( $user_id, true ); // If a user's primary blog is shut down, check their other blogs.
[74] Fix | Delete
$ret = false;
[75] Fix | Delete
if ( is_array( $blogs ) && count( $blogs ) > 0 ) {
[76] Fix | Delete
foreach ( (array) $blogs as $blog_id => $blog ) {
[77] Fix | Delete
if ( get_current_network_id() != $blog->site_id ) {
[78] Fix | Delete
continue;
[79] Fix | Delete
}
[80] Fix | Delete
$details = get_site( $blog_id );
[81] Fix | Delete
if ( is_object( $details ) && 0 == $details->archived && 0 == $details->spam && 0 == $details->deleted ) {
[82] Fix | Delete
$ret = $details;
[83] Fix | Delete
if ( get_user_meta( $user_id, 'primary_blog', true ) != $blog_id ) {
[84] Fix | Delete
update_user_meta( $user_id, 'primary_blog', $blog_id );
[85] Fix | Delete
}
[86] Fix | Delete
if ( ! get_user_meta( $user_id, 'source_domain', true ) ) {
[87] Fix | Delete
update_user_meta( $user_id, 'source_domain', $details->domain );
[88] Fix | Delete
}
[89] Fix | Delete
break;
[90] Fix | Delete
}
[91] Fix | Delete
}
[92] Fix | Delete
} else {
[93] Fix | Delete
return;
[94] Fix | Delete
}
[95] Fix | Delete
return $ret;
[96] Fix | Delete
} else {
[97] Fix | Delete
return $primary;
[98] Fix | Delete
}
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
/**
[102] Fix | Delete
* The number of active users in your installation.
[103] Fix | Delete
*
[104] Fix | Delete
* The count is cached and updated twice daily. This is not a live count.
[105] Fix | Delete
*
[106] Fix | Delete
* @since MU (3.0.0)
[107] Fix | Delete
* @since 4.8.0 The `$network_id` parameter has been added.
[108] Fix | Delete
*
[109] Fix | Delete
* @param int|null $network_id ID of the network. Default is the current network.
[110] Fix | Delete
* @return int Number of active users on the network.
[111] Fix | Delete
*/
[112] Fix | Delete
function get_user_count( $network_id = null ) {
[113] Fix | Delete
return get_network_option( $network_id, 'user_count' );
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
/**
[117] Fix | Delete
* The number of active sites on your installation.
[118] Fix | Delete
*
[119] Fix | Delete
* The count is cached and updated twice daily. This is not a live count.
[120] Fix | Delete
*
[121] Fix | Delete
* @since MU (3.0.0)
[122] Fix | Delete
* @since 3.7.0 The `$network_id` parameter has been deprecated.
[123] Fix | Delete
* @since 4.8.0 The `$network_id` parameter is now being used.
[124] Fix | Delete
*
[125] Fix | Delete
* @param int|null $network_id ID of the network. Default is the current network.
[126] Fix | Delete
* @return int Number of active sites on the network.
[127] Fix | Delete
*/
[128] Fix | Delete
function get_blog_count( $network_id = null ) {
[129] Fix | Delete
return get_network_option( $network_id, 'blog_count' );
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
/**
[133] Fix | Delete
* Gets a blog post from any site on the network.
[134] Fix | Delete
*
[135] Fix | Delete
* This function is similar to get_post(), except that it can retrieve a post
[136] Fix | Delete
* from any site on the network, not just the current site.
[137] Fix | Delete
*
[138] Fix | Delete
* @since MU (3.0.0)
[139] Fix | Delete
*
[140] Fix | Delete
* @param int $blog_id ID of the blog.
[141] Fix | Delete
* @param int $post_id ID of the post being looked for.
[142] Fix | Delete
* @return WP_Post|null WP_Post object on success, null on failure
[143] Fix | Delete
*/
[144] Fix | Delete
function get_blog_post( $blog_id, $post_id ) {
[145] Fix | Delete
switch_to_blog( $blog_id );
[146] Fix | Delete
$post = get_post( $post_id );
[147] Fix | Delete
restore_current_blog();
[148] Fix | Delete
[149] Fix | Delete
return $post;
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
/**
[153] Fix | Delete
* Adds a user to a blog, along with specifying the user's role.
[154] Fix | Delete
*
[155] Fix | Delete
* Use the {@see 'add_user_to_blog'} action to fire an event when users are added to a blog.
[156] Fix | Delete
*
[157] Fix | Delete
* @since MU (3.0.0)
[158] Fix | Delete
*
[159] Fix | Delete
* @param int $blog_id ID of the blog the user is being added to.
[160] Fix | Delete
* @param int $user_id ID of the user being added.
[161] Fix | Delete
* @param string $role The role you want the user to have.
[162] Fix | Delete
* @return true|WP_Error True on success or a WP_Error object if the user doesn't exist
[163] Fix | Delete
* or could not be added.
[164] Fix | Delete
*/
[165] Fix | Delete
function add_user_to_blog( $blog_id, $user_id, $role ) {
[166] Fix | Delete
switch_to_blog( $blog_id );
[167] Fix | Delete
[168] Fix | Delete
$user = get_userdata( $user_id );
[169] Fix | Delete
[170] Fix | Delete
if ( ! $user ) {
[171] Fix | Delete
restore_current_blog();
[172] Fix | Delete
return new WP_Error( 'user_does_not_exist', __( 'The requested user does not exist.' ) );
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
/**
[176] Fix | Delete
* Filters whether a user should be added to a site.
[177] Fix | Delete
*
[178] Fix | Delete
* @since 4.9.0
[179] Fix | Delete
*
[180] Fix | Delete
* @param true|WP_Error $retval True if the user should be added to the site, error
[181] Fix | Delete
* object otherwise.
[182] Fix | Delete
* @param int $user_id User ID.
[183] Fix | Delete
* @param string $role User role.
[184] Fix | Delete
* @param int $blog_id Site ID.
[185] Fix | Delete
*/
[186] Fix | Delete
$can_add_user = apply_filters( 'can_add_user_to_blog', true, $user_id, $role, $blog_id );
[187] Fix | Delete
[188] Fix | Delete
if ( true !== $can_add_user ) {
[189] Fix | Delete
restore_current_blog();
[190] Fix | Delete
[191] Fix | Delete
if ( is_wp_error( $can_add_user ) ) {
[192] Fix | Delete
return $can_add_user;
[193] Fix | Delete
}
[194] Fix | Delete
[195] Fix | Delete
return new WP_Error( 'user_cannot_be_added', __( 'User cannot be added to this site.' ) );
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
if ( ! get_user_meta( $user_id, 'primary_blog', true ) ) {
[199] Fix | Delete
update_user_meta( $user_id, 'primary_blog', $blog_id );
[200] Fix | Delete
$site = get_site( $blog_id );
[201] Fix | Delete
update_user_meta( $user_id, 'source_domain', $site->domain );
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
$user->set_role( $role );
[205] Fix | Delete
[206] Fix | Delete
/**
[207] Fix | Delete
* Fires immediately after a user is added to a site.
[208] Fix | Delete
*
[209] Fix | Delete
* @since MU (3.0.0)
[210] Fix | Delete
*
[211] Fix | Delete
* @param int $user_id User ID.
[212] Fix | Delete
* @param string $role User role.
[213] Fix | Delete
* @param int $blog_id Blog ID.
[214] Fix | Delete
*/
[215] Fix | Delete
do_action( 'add_user_to_blog', $user_id, $role, $blog_id );
[216] Fix | Delete
[217] Fix | Delete
clean_user_cache( $user_id );
[218] Fix | Delete
wp_cache_delete( $blog_id . '_user_count', 'blog-details' );
[219] Fix | Delete
[220] Fix | Delete
restore_current_blog();
[221] Fix | Delete
[222] Fix | Delete
return true;
[223] Fix | Delete
}
[224] Fix | Delete
[225] Fix | Delete
/**
[226] Fix | Delete
* Remove a user from a blog.
[227] Fix | Delete
*
[228] Fix | Delete
* Use the {@see 'remove_user_from_blog'} action to fire an event when
[229] Fix | Delete
* users are removed from a blog.
[230] Fix | Delete
*
[231] Fix | Delete
* Accepts an optional `$reassign` parameter, if you want to
[232] Fix | Delete
* reassign the user's blog posts to another user upon removal.
[233] Fix | Delete
*
[234] Fix | Delete
* @since MU (3.0.0)
[235] Fix | Delete
*
[236] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[237] Fix | Delete
*
[238] Fix | Delete
* @param int $user_id ID of the user being removed.
[239] Fix | Delete
* @param int $blog_id Optional. ID of the blog the user is being removed from. Default 0.
[240] Fix | Delete
* @param int $reassign Optional. ID of the user to whom to reassign posts. Default 0.
[241] Fix | Delete
* @return true|WP_Error True on success or a WP_Error object if the user doesn't exist.
[242] Fix | Delete
*/
[243] Fix | Delete
function remove_user_from_blog( $user_id, $blog_id = 0, $reassign = 0 ) {
[244] Fix | Delete
global $wpdb;
[245] Fix | Delete
[246] Fix | Delete
switch_to_blog( $blog_id );
[247] Fix | Delete
$user_id = (int) $user_id;
[248] Fix | Delete
[249] Fix | Delete
/**
[250] Fix | Delete
* Fires before a user is removed from a site.
[251] Fix | Delete
*
[252] Fix | Delete
* @since MU (3.0.0)
[253] Fix | Delete
* @since 5.4.0 Added the `$reassign` parameter.
[254] Fix | Delete
*
[255] Fix | Delete
* @param int $user_id ID of the user being removed.
[256] Fix | Delete
* @param int $blog_id ID of the blog the user is being removed from.
[257] Fix | Delete
* @param int $reassign ID of the user to whom to reassign posts.
[258] Fix | Delete
*/
[259] Fix | Delete
do_action( 'remove_user_from_blog', $user_id, $blog_id, $reassign );
[260] Fix | Delete
[261] Fix | Delete
// If being removed from the primary blog, set a new primary
[262] Fix | Delete
// if the user is assigned to multiple blogs.
[263] Fix | Delete
$primary_blog = get_user_meta( $user_id, 'primary_blog', true );
[264] Fix | Delete
if ( $primary_blog == $blog_id ) {
[265] Fix | Delete
$new_id = '';
[266] Fix | Delete
$new_domain = '';
[267] Fix | Delete
$blogs = get_blogs_of_user( $user_id );
[268] Fix | Delete
foreach ( (array) $blogs as $blog ) {
[269] Fix | Delete
if ( $blog->userblog_id == $blog_id ) {
[270] Fix | Delete
continue;
[271] Fix | Delete
}
[272] Fix | Delete
$new_id = $blog->userblog_id;
[273] Fix | Delete
$new_domain = $blog->domain;
[274] Fix | Delete
break;
[275] Fix | Delete
}
[276] Fix | Delete
[277] Fix | Delete
update_user_meta( $user_id, 'primary_blog', $new_id );
[278] Fix | Delete
update_user_meta( $user_id, 'source_domain', $new_domain );
[279] Fix | Delete
}
[280] Fix | Delete
[281] Fix | Delete
// wp_revoke_user( $user_id );
[282] Fix | Delete
$user = get_userdata( $user_id );
[283] Fix | Delete
if ( ! $user ) {
[284] Fix | Delete
restore_current_blog();
[285] Fix | Delete
return new WP_Error( 'user_does_not_exist', __( 'That user does not exist.' ) );
[286] Fix | Delete
}
[287] Fix | Delete
[288] Fix | Delete
$user->remove_all_caps();
[289] Fix | Delete
[290] Fix | Delete
$blogs = get_blogs_of_user( $user_id );
[291] Fix | Delete
if ( count( $blogs ) == 0 ) {
[292] Fix | Delete
update_user_meta( $user_id, 'primary_blog', '' );
[293] Fix | Delete
update_user_meta( $user_id, 'source_domain', '' );
[294] Fix | Delete
}
[295] Fix | Delete
[296] Fix | Delete
if ( $reassign ) {
[297] Fix | Delete
$reassign = (int) $reassign;
[298] Fix | Delete
$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $user_id ) );
[299] Fix | Delete
$link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $user_id ) );
[300] Fix | Delete
[301] Fix | Delete
if ( ! empty( $post_ids ) ) {
[302] Fix | Delete
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_author = %d WHERE post_author = %d", $reassign, $user_id ) );
[303] Fix | Delete
array_walk( $post_ids, 'clean_post_cache' );
[304] Fix | Delete
}
[305] Fix | Delete
[306] Fix | Delete
if ( ! empty( $link_ids ) ) {
[307] Fix | Delete
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->links SET link_owner = %d WHERE link_owner = %d", $reassign, $user_id ) );
[308] Fix | Delete
array_walk( $link_ids, 'clean_bookmark_cache' );
[309] Fix | Delete
}
[310] Fix | Delete
}
[311] Fix | Delete
[312] Fix | Delete
restore_current_blog();
[313] Fix | Delete
[314] Fix | Delete
return true;
[315] Fix | Delete
}
[316] Fix | Delete
[317] Fix | Delete
/**
[318] Fix | Delete
* Get the permalink for a post on another blog.
[319] Fix | Delete
*
[320] Fix | Delete
* @since MU (3.0.0) 1.0
[321] Fix | Delete
*
[322] Fix | Delete
* @param int $blog_id ID of the source blog.
[323] Fix | Delete
* @param int $post_id ID of the desired post.
[324] Fix | Delete
* @return string The post's permalink
[325] Fix | Delete
*/
[326] Fix | Delete
function get_blog_permalink( $blog_id, $post_id ) {
[327] Fix | Delete
switch_to_blog( $blog_id );
[328] Fix | Delete
$link = get_permalink( $post_id );
[329] Fix | Delete
restore_current_blog();
[330] Fix | Delete
[331] Fix | Delete
return $link;
[332] Fix | Delete
}
[333] Fix | Delete
[334] Fix | Delete
/**
[335] Fix | Delete
* Get a blog's numeric ID from its URL.
[336] Fix | Delete
*
[337] Fix | Delete
* On a subdirectory installation like example.com/blog1/,
[338] Fix | Delete
* $domain will be the root 'example.com' and $path the
[339] Fix | Delete
* subdirectory '/blog1/'. With subdomains like blog1.example.com,
[340] Fix | Delete
* $domain is 'blog1.example.com' and $path is '/'.
[341] Fix | Delete
*
[342] Fix | Delete
* @since MU (3.0.0)
[343] Fix | Delete
*
[344] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[345] Fix | Delete
*
[346] Fix | Delete
* @param string $domain
[347] Fix | Delete
* @param string $path Optional. Not required for subdomain installations.
[348] Fix | Delete
* @return int 0 if no blog found, otherwise the ID of the matching blog
[349] Fix | Delete
*/
[350] Fix | Delete
function get_blog_id_from_url( $domain, $path = '/' ) {
[351] Fix | Delete
$domain = strtolower( $domain );
[352] Fix | Delete
$path = strtolower( $path );
[353] Fix | Delete
$id = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' );
[354] Fix | Delete
[355] Fix | Delete
if ( -1 == $id ) { // Blog does not exist.
[356] Fix | Delete
return 0;
[357] Fix | Delete
} elseif ( $id ) {
[358] Fix | Delete
return (int) $id;
[359] Fix | Delete
}
[360] Fix | Delete
[361] Fix | Delete
$args = array(
[362] Fix | Delete
'domain' => $domain,
[363] Fix | Delete
'path' => $path,
[364] Fix | Delete
'fields' => 'ids',
[365] Fix | Delete
'number' => 1,
[366] Fix | Delete
'update_site_meta_cache' => false,
[367] Fix | Delete
);
[368] Fix | Delete
$result = get_sites( $args );
[369] Fix | Delete
$id = array_shift( $result );
[370] Fix | Delete
[371] Fix | Delete
if ( ! $id ) {
[372] Fix | Delete
wp_cache_set( md5( $domain . $path ), -1, 'blog-id-cache' );
[373] Fix | Delete
return 0;
[374] Fix | Delete
}
[375] Fix | Delete
[376] Fix | Delete
wp_cache_set( md5( $domain . $path ), $id, 'blog-id-cache' );
[377] Fix | Delete
[378] Fix | Delete
return $id;
[379] Fix | Delete
}
[380] Fix | Delete
[381] Fix | Delete
//
[382] Fix | Delete
// Admin functions.
[383] Fix | Delete
//
[384] Fix | Delete
[385] Fix | Delete
/**
[386] Fix | Delete
* Checks an email address against a list of banned domains.
[387] Fix | Delete
*
[388] Fix | Delete
* This function checks against the Banned Email Domains list
[389] Fix | Delete
* at wp-admin/network/settings.php. The check is only run on
[390] Fix | Delete
* self-registrations; user creation at wp-admin/network/users.php
[391] Fix | Delete
* bypasses this check.
[392] Fix | Delete
*
[393] Fix | Delete
* @since MU (3.0.0)
[394] Fix | Delete
*
[395] Fix | Delete
* @param string $user_email The email provided by the user at registration.
[396] Fix | Delete
* @return bool True when the email address is banned, false otherwise.
[397] Fix | Delete
*/
[398] Fix | Delete
function is_email_address_unsafe( $user_email ) {
[399] Fix | Delete
$banned_names = get_site_option( 'banned_email_domains' );
[400] Fix | Delete
if ( $banned_names && ! is_array( $banned_names ) ) {
[401] Fix | Delete
$banned_names = explode( "\n", $banned_names );
[402] Fix | Delete
}
[403] Fix | Delete
[404] Fix | Delete
$is_email_address_unsafe = false;
[405] Fix | Delete
[406] Fix | Delete
if ( $banned_names && is_array( $banned_names ) && false !== strpos( $user_email, '@', 1 ) ) {
[407] Fix | Delete
$banned_names = array_map( 'strtolower', $banned_names );
[408] Fix | Delete
$normalized_email = strtolower( $user_email );
[409] Fix | Delete
[410] Fix | Delete
list( $email_local_part, $email_domain ) = explode( '@', $normalized_email );
[411] Fix | Delete
[412] Fix | Delete
foreach ( $banned_names as $banned_domain ) {
[413] Fix | Delete
if ( ! $banned_domain ) {
[414] Fix | Delete
continue;
[415] Fix | Delete
}
[416] Fix | Delete
[417] Fix | Delete
if ( $email_domain == $banned_domain ) {
[418] Fix | Delete
$is_email_address_unsafe = true;
[419] Fix | Delete
break;
[420] Fix | Delete
}
[421] Fix | Delete
[422] Fix | Delete
$dotted_domain = ".$banned_domain";
[423] Fix | Delete
if ( substr( $normalized_email, -strlen( $dotted_domain ) ) === $dotted_domain ) {
[424] Fix | Delete
$is_email_address_unsafe = true;
[425] Fix | Delete
break;
[426] Fix | Delete
}
[427] Fix | Delete
}
[428] Fix | Delete
}
[429] Fix | Delete
[430] Fix | Delete
/**
[431] Fix | Delete
* Filters whether an email address is unsafe.
[432] Fix | Delete
*
[433] Fix | Delete
* @since 3.5.0
[434] Fix | Delete
*
[435] Fix | Delete
* @param bool $is_email_address_unsafe Whether the email address is "unsafe". Default false.
[436] Fix | Delete
* @param string $user_email User email address.
[437] Fix | Delete
*/
[438] Fix | Delete
return apply_filters( 'is_email_address_unsafe', $is_email_address_unsafe, $user_email );
[439] Fix | Delete
}
[440] Fix | Delete
[441] Fix | Delete
/**
[442] Fix | Delete
* Sanitize and validate data required for a user sign-up.
[443] Fix | Delete
*
[444] Fix | Delete
* Verifies the validity and uniqueness of user names and user email addresses,
[445] Fix | Delete
* and checks email addresses against allowed and disallowed domains provided by
[446] Fix | Delete
* administrators.
[447] Fix | Delete
*
[448] Fix | Delete
* The {@see 'wpmu_validate_user_signup'} hook provides an easy way to modify the sign-up
[449] Fix | Delete
* process. The value $result, which is passed to the hook, contains both the user-provided
[450] Fix | Delete
* info and the error messages created by the function. {@see 'wpmu_validate_user_signup'}
[451] Fix | Delete
* allows you to process the data in any way you'd like, and unset the relevant errors if
[452] Fix | Delete
* necessary.
[453] Fix | Delete
*
[454] Fix | Delete
* @since MU (3.0.0)
[455] Fix | Delete
*
[456] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[457] Fix | Delete
*
[458] Fix | Delete
* @param string $user_name The login name provided by the user.
[459] Fix | Delete
* @param string $user_email The email provided by the user.
[460] Fix | Delete
* @return array {
[461] Fix | Delete
* The array of user name, email, and the error messages.
[462] Fix | Delete
*
[463] Fix | Delete
* @type string $user_name Sanitized and unique username.
[464] Fix | Delete
* @type string $orig_username Original username.
[465] Fix | Delete
* @type string $user_email User email address.
[466] Fix | Delete
* @type WP_Error $errors WP_Error object containing any errors found.
[467] Fix | Delete
* }
[468] Fix | Delete
*/
[469] Fix | Delete
function wpmu_validate_user_signup( $user_name, $user_email ) {
[470] Fix | Delete
global $wpdb;
[471] Fix | Delete
[472] Fix | Delete
$errors = new WP_Error();
[473] Fix | Delete
[474] Fix | Delete
$orig_username = $user_name;
[475] Fix | Delete
$user_name = preg_replace( '/\s+/', '', sanitize_user( $user_name, true ) );
[476] Fix | Delete
[477] Fix | Delete
if ( $user_name != $orig_username || preg_match( '/[^a-z0-9]/', $user_name ) ) {
[478] Fix | Delete
$errors->add( 'user_name', __( 'Usernames can only contain lowercase letters (a-z) and numbers.' ) );
[479] Fix | Delete
$user_name = $orig_username;
[480] Fix | Delete
}
[481] Fix | Delete
[482] Fix | Delete
$user_email = sanitize_email( $user_email );
[483] Fix | Delete
[484] Fix | Delete
if ( empty( $user_name ) ) {
[485] Fix | Delete
$errors->add( 'user_name', __( 'Please enter a username.' ) );
[486] Fix | Delete
}
[487] Fix | Delete
[488] Fix | Delete
$illegal_names = get_site_option( 'illegal_names' );
[489] Fix | Delete
if ( ! is_array( $illegal_names ) ) {
[490] Fix | Delete
$illegal_names = array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' );
[491] Fix | Delete
add_site_option( 'illegal_names', $illegal_names );
[492] Fix | Delete
}
[493] Fix | Delete
if ( in_array( $user_name, $illegal_names, true ) ) {
[494] Fix | Delete
$errors->add( 'user_name', __( 'Sorry, that username is not allowed.' ) );
[495] Fix | Delete
}
[496] Fix | Delete
[497] Fix | Delete
/** This filter is documented in wp-includes/user.php */
[498] Fix | Delete
$illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function