Definition:
function wpmu_validate_blog_signup($blogname, $blog_title, $user = '') {}
Processes new site registrations.
Checks the data provided by the user during blog signup. Verifies the validity and uniqueness of blog paths and domains.
Parameters
- string $blogname: The blog name provided by the user. Must be unique.
- string $blog_title: The blog title provided by the user.
- $user
Return values
returns:Contains the new site data and error messages.
Defined filters
- subdirectory_reserved_names
apply_filters( 'subdirectory_reserved_names', array( 'page', 'comments', 'blog', 'files', 'feed' ) - newblogname
apply_filters( 'newblogname', $blogname ) - wpmu_validate_blog_signup
apply_filters('wpmu_validate_blog_signup', $result)
Source code
function wpmu_validate_blog_signup($blogname, $blog_title, $user = '') {
global $wpdb, $domain, $base, $current_site;
$blog_title = strip_tags( $blog_title );
$blog_title = substr( $blog_title, 0, 50 );
$errors = new WP_Error();
$illegal_names = get_site_option( 'illegal_names' );
if ( $illegal_names == false ) {
$illegal_names = array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' );
add_site_option( 'illegal_names', $illegal_names );
}
// On sub dir installs, Some names are so illegal, only a filter can spring them from jail
if (! is_subdomain_install() )
$illegal_names = array_merge($illegal_names, apply_filters( 'subdirectory_reserved_names', array( 'page', 'comments', 'blog', 'files', 'feed' ) ) );
if ( empty( $blogname ) )
$errors->add('blogname', __('Please enter a site name'));
if ( preg_match( '/[^a-z0-9]+/', $blogname ) )
$errors->add('blogname', __('Only lowercase letters and numbers allowed'));
if ( in_array( $blogname, $illegal_names ) == true )
$errors->add('blogname', __('That name is not allowed'));
if ( strlen( $blogname ) < 4 && !is_super_admin() )
$errors->add('blogname', __('Site name must be at least 4 characters'));
if ( strpos( ' ' . $blogname, '_' ) != false )
$errors->add( 'blogname', __( 'Sorry, site names may not contain the character “_”!' ) );
// do not allow users to create a blog that conflicts with a page on the main blog.
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 ) ) )
$errors->add( 'blogname', __( 'Sorry, you may not use that site name.' ) );
// all numeric?
$match = array();
preg_match( '/[0-9]*/', $blogname, $match );
if ( $match[0] == $blogname )
$errors->add('blogname', __('Sorry, site names must have letters too!'));
$blogname = apply_filters( 'newblogname', $blogname );
$blog_title = stripslashes( $blog_title );
if ( empty( $blog_title ) )
$errors->add('blog_title', __('Please enter a site title'));
// Check if the domain/path has been used already.
if ( is_subdomain_install() ) {
$mydomain = $blogname . '.' . preg_replace( '|^www\.|', '', $domain );
$path = $base;
} else {
$mydomain = "$domain";
$path = $base.$blogname.'/';
}
if ( domain_exists($mydomain, $path) )
$errors->add('blogname', __('Sorry, that site already exists!'));
if ( username_exists( $blogname ) ) {
if ( is_object( $user ) == false || ( is_object($user) && ( $user->user_login != $blogname ) ) )
$errors->add( 'blogname', __( 'Sorry, that site is reserved!' ) );
}
// Has someone already signed up for this domain?
$signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE domain = %s AND path = %s", $mydomain, $path) ); // TODO: Check email too?
if ( ! empty($signup) ) {
$diff = current_time( 'timestamp', true ) - mysql2date('U', $signup->registered);
// If registered more than two days ago, cancel registration and let this signup go through.
if ( $diff > 172800 )
$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->signups WHERE domain = %s AND path = %s", $mydomain, $path) );
else
$errors->add('blogname', __('That site is currently reserved but may be available in a couple days.'));
}
$result = array('domain' => $mydomain, 'path' => $path, 'blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors);
return apply_filters('wpmu_validate_blog_signup', $result);
}
3403

February 12, 2011 


No comments yet... Be the first to leave a reply!