bp_groupblog_validate_blog_form

Bp_groupblog_validate_blog_form().

Description

bp_groupblog_validate_blog_form(); 

This function validates that the blog does not exist already, illegal names, etc...


Usage

  1. if ( !function_exists( 'bp_groupblog_validate_blog_form' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bp-groupblog/bp-groupblog.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bp_groupblog_validate_blog_form(); 
  7.  

Defined (1)

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

/bp-groupblog.php  
  1. function bp_groupblog_validate_blog_form() { 
  2.  
  3. $user = ''; 
  4. if ( is_user_logged_in() ) 
  5. $user = wp_get_current_user(); 
  6.  
  7. $result = wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title'], $user); 
  8.  
  9. $errors = $result['errors']; 
  10.  
  11. // we only want to filter if there is an error 
  12. if (!is_object($errors)) { 
  13. return $result; 
  14.  
  15.  
  16. $checks = get_site_option('bp_groupblog_blog_defaults_options'); 
  17.  
  18. // create a new var to hold errors 
  19. $newerrors = new WP_Error(); 
  20.  
  21. // loop through the errors and look for the one we are concerned with 
  22. foreach ($errors->errors as $key => $value) { 
  23. // if theerroris with the blog name, check to see which one 
  24. if ($key == 'blogname') { 
  25.  
  26. foreach ($value as $subkey => $subvalue) { 
  27.  
  28. switch ($subvalue) { 
  29. case 'Only lowercase letters (a-z) and numbers are allowed.': 
  30.  
  31. $allowedchars = ''; 
  32. if ($checks['allowdashes']== 1) $allowedchars .= '-'; 
  33. if ($checks['allowunderscores'] == 1) $allowedchars .= '_'; 
  34.  
  35. $allowed = '/[a-z0-9' . $allowedchars . ']+/'; 
  36. preg_match( $allowed, $result['blogname'], $maybe ); 
  37. if( $result['blogname'] != $maybe[0] ) { 
  38.  
  39. //still fails, so add anerrorto the object 
  40. $newerrors->add('blogname', __("Only lowercase letters and numbers allowed", 'groupblog')); 
  41.  
  42. continue; 
  43. case 'Site name must be at least 4 characters.': 
  44. if( strlen( $result['blogname'] ) < $checks[minlength] && !is_super_admin() ) 
  45. $newerrors->add('blogname', __("Blog name must be at least " . $checks[minlength] . " characters", 'groupblog')); 
  46. continue; 
  47. case "Sorry, site names may not contain the character “_”!": 
  48. if($checks['allowunderscores']!= 1) { 
  49. $newerrors->add('blogname', __("Sorry, blog names may not contain the character '_'!", 'groupblog')); 
  50. continue; 
  51. case 'Sorry, site names must have letters too!': 
  52. if($checks['allownumeric'] != 1) { 
  53. $newerrors->add('blogname', __("Sorry, blog names must have letters too!", 'groupblog')); 
  54. continue; 
  55. default: 
  56. $newerrors->add('blogname', $subvalue); 
  57.  
  58. }// end switch 
  59.  
  60.  
  61. else { 
  62. //Add all other errors into theerrorobject, but they're in sub-arrays, so loop through to get the right stuff. 
  63. foreach ($value as $subkey => $subvalue) { 
  64. $newerrors->add($key, $subvalue); 
  65.  
  66.  
  67.  
  68. //unset theerrorobject from the results & rest it with our new errors 
  69. unset($result['errors']); 
  70. $result['errors'] = $newerrors; 
  71.  
  72. return $result; 
  73.