wpmu_validate_blog_signup

Processes new site registrations.

Description

(array) wpmu_validate_blog_signup( (string) $blogname, (string) $blog_title, (string) $user = '' ); 

Checks the data provided by the user during blog signup. Verifies the validity and uniqueness of blog paths and domains.

This function prevents the current user from registering a new site with a blogname equivalent to another user's login name. Passing the $user parameter to the function, where $user is the other user, is effectively an override of this limitation.

Filter if you want to modify the way that WordPress validates new site signups.

Returns (array)

Contains the new site data and error messages.

Parameters (3)

0. $blogname (string)
The blog name provided by the user. Must be unique.
1. $blog_title (string)
The blog title provided by the user.
2. $user — Optional. (string) => ''
The user object to check against the new site name.

Usage

  1. if ( !function_exists( 'wpmu_validate_blog_signup' ) ) { 
  2. require_once ABSPATH . WPINC . '/ms-functions.php'; 
  3.  
  4. // The blog name provided by the user. Must be unique. 
  5. $blogname = ''; 
  6.  
  7. // The blog title provided by the user. 
  8. $blog_title = ''; 
  9.  
  10. // Optional. The user object to check against the new site name. 
  11. $user = ''; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = wpmu_validate_blog_signup($blogname, $blog_title, $user); 
  15.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/ms-functions.php  
  1. function wpmu_validate_blog_signup( $blogname, $blog_title, $user = '' ) { 
  2. global $wpdb, $domain; 
  3.  
  4. $current_network = get_network(); 
  5. $base = $current_network->path; 
  6.  
  7. $blog_title = strip_tags( $blog_title ); 
  8.  
  9. $errors = new WP_Error(); 
  10. $illegal_names = get_site_option( 'illegal_names' ); 
  11. if ( $illegal_names == false ) { 
  12. $illegal_names = array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' ); 
  13. add_site_option( 'illegal_names', $illegal_names ); 
  14.  
  15. /** 
  16. * On sub dir installs, some names are so illegal, only a filter can 
  17. * spring them from jail. 
  18. */ 
  19. if ( ! is_subdomain_install() ) { 
  20. $illegal_names = array_merge( $illegal_names, get_subdirectory_reserved_names() ); 
  21.  
  22. if ( empty( $blogname ) ) 
  23. $errors->add('blogname', __( 'Please enter a site name.' ) ); 
  24.  
  25. if ( preg_match( '/[^a-z0-9]+/', $blogname ) ) { 
  26. $errors->add( 'blogname', __( 'Site names can only contain lowercase letters (a-z) and numbers.' ) ); 
  27.  
  28. if ( in_array( $blogname, $illegal_names ) ) 
  29. $errors->add('blogname', __( 'That name is not allowed.' ) ); 
  30.  
  31. if ( strlen( $blogname ) < 4 && !is_super_admin() ) 
  32. $errors->add('blogname', __( 'Site name must be at least 4 characters.' ) ); 
  33.  
  34. // do not allow users to create a blog that conflicts with a page on the main blog. 
  35. 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 ) ) ) 
  36. $errors->add( 'blogname', __( 'Sorry, you may not use that site name.' ) ); 
  37.  
  38. // all numeric? 
  39. if ( preg_match( '/^[0-9]*$/', $blogname ) ) 
  40. $errors->add('blogname', __('Sorry, site names must have letters too!')); 
  41.  
  42. /** 
  43. * Filters the new site name during registration. 
  44. * The name is the site's subdomain or the site's subdirectory 
  45. * path depending on the network settings. 
  46. * @since MU 
  47. * @param string $blogname Site name. 
  48. */ 
  49. $blogname = apply_filters( 'newblogname', $blogname ); 
  50.  
  51. $blog_title = wp_unslash( $blog_title ); 
  52.  
  53. if ( empty( $blog_title ) ) 
  54. $errors->add('blog_title', __( 'Please enter a site title.' ) ); 
  55.  
  56. // Check if the domain/path has been used already. 
  57. if ( is_subdomain_install() ) { 
  58. $mydomain = $blogname . '.' . preg_replace( '|^www\.|', '', $domain ); 
  59. $path = $base; 
  60. } else { 
  61. $mydomain = "$domain"; 
  62. $path = $base.$blogname.'/'; 
  63. if ( domain_exists($mydomain, $path, $current_network->id) ) 
  64. $errors->add( 'blogname', __( 'Sorry, that site already exists!' ) ); 
  65.  
  66. if ( username_exists( $blogname ) ) { 
  67. if ( ! is_object( $user ) || ( is_object($user) && ( $user->user_login != $blogname ) ) ) 
  68. $errors->add( 'blogname', __( 'Sorry, that site is reserved!' ) ); 
  69.  
  70. // Has someone already signed up for this domain? 
  71. $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE domain = %s AND path = %s", $mydomain, $path) ); // TODO: Check email too? 
  72. if ( ! empty($signup) ) { 
  73. $diff = current_time( 'timestamp', true ) - mysql2date('U', $signup->registered); 
  74. // If registered more than two days ago, cancel registration and let this signup go through. 
  75. if ( $diff > 2 * DAY_IN_SECONDS
  76. $wpdb->delete( $wpdb->signups, array( 'domain' => $mydomain , 'path' => $path ) ); 
  77. else 
  78. $errors->add('blogname', __('That site is currently reserved but may be available in a couple days.')); 
  79.  
  80. $result = array('domain' => $mydomain, 'path' => $path, 'blogname' => $blogname, 'blog_title' => $blog_title, 'user' => $user, 'errors' => $errors); 
  81.  
  82. /** 
  83. * Filters site details anderrormessages following registration. 
  84. * @since MU 
  85. * @param array $result { 
  86. * Array of domain, path, blog name, blog title, user anderrormessages. 
  87. * @type string $domain Domain for the site. 
  88. * @type string $path Path for the site. Used in subdirectory installs. 
  89. * @type string $blogname The unique site name (slug). 
  90. * @type string $blog_title Blog title. 
  91. * @type string|WP_User $user By default, an empty string. A user object if provided. 
  92. * @type WP_Error $errors WP_Error containing any errors found. 
  93. * } 
  94. */