Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/06/2010 04:24:57 PM (14 years ago)
Author:
apeatling
Message:

Merging 1.2 branch with trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-wpabstraction.php

    r2925 r3232  
    9090    }
    9191}
     92
     93if ( !function_exists( 'wpmu_validate_user_signup' ) ) {
     94    function wpmu_validate_user_signup( $user_name, $user_email ) {
     95        global $wpdb;
     96
     97        $errors = new WP_Error();
     98
     99        $user_email = sanitize_email( $user_email );
     100
     101        if ( empty( $user_name ) )
     102            $errors->add('user_name', __("Please enter a username"));
     103
     104        $maybe = array();
     105        preg_match( "/[a-z0-9]+/", $user_name, $maybe );
     106
     107        $illegal_names = get_site_option( "illegal_names" );
     108        if( is_array( $illegal_names ) == false ) {
     109            $illegal_names = array(  "www", "web", "root", "admin", "main", "invite", "administrator" );
     110            add_site_option( "illegal_names", $illegal_names );
     111        }
     112
     113        if ( !validate_username( $user_name ) || in_array( $user_name, $illegal_names ) == true || $user_name != $maybe[0] ) {
     114            $errors->add('user_name', __("Only lowercase letters and numbers allowed"));
     115        }
     116
     117        if( strlen( $user_name ) < 4 ) {
     118            $errors->add('user_name',  __("Username must be at least 4 characters"));
     119        }
     120
     121        if ( strpos( " " . $user_name, "_" ) != false )
     122            $errors->add('user_name', __("Sorry, usernames may not contain the character '_'!"));
     123
     124        // all numeric?
     125        $match = array();
     126        preg_match( '/[0-9]*/', $user_name, $match );
     127        if ( $match[0] == $user_name )
     128            $errors->add('user_name', __("Sorry, usernames must have letters too!"));
     129
     130        if ( !is_email( $user_email ) )
     131            $errors->add('user_email', __("Please check your email address."));
     132
     133        $limited_email_domains = get_site_option( 'limited_email_domains' );
     134        if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) {
     135            $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) );
     136            if( in_array( $emaildomain, $limited_email_domains ) == false ) {
     137                $errors->add('user_email', __("Sorry, that email address is not allowed!"));
     138            }
     139        }
     140
     141        // Check if the username has been used already.
     142        if ( username_exists($user_name) )
     143            $errors->add('user_name', __("Sorry, that username already exists!"));
     144
     145        // Check if the email address has been used already.
     146        if ( email_exists($user_email) )
     147            $errors->add('user_email', __("Sorry, that email address is already used!"));
     148
     149        $result = array('user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors);
     150
     151        return apply_filters('wpmu_validate_user_signup', $result);
     152    }
     153}
     154?>
Note: See TracChangeset for help on using the changeset viewer.