Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/27/2024 07:01:02 PM (20 months ago)
Author:
espellcaste
Message:

Enforce requirement of usernames having valid letters.

Profile links dont

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/bp-members-functions.php

    r13983 r13984  
    16221622    // Note: This check only works on Multisite.
    16231623    $limited_email_domains = get_site_option( 'limited_email_domains' );
    1624     if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) {
     1624    if ( is_array( $limited_email_domains ) && ! empty( $limited_email_domains ) ) {
    16251625        $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) );
    1626         if ( ! in_array( $emaildomain, $limited_email_domains ) ) {
     1626
     1627        if ( ! in_array( $emaildomain, $limited_email_domains, true ) ) {
    16271628            $errors['domain_not_allowed'] = 1;
    16281629        }
     
    16341635    }
    16351636
    1636     $retval = ! empty( $errors ) ? $errors : true;
    1637 
    1638     return $retval;
     1637    return ! empty( $errors ) ? $errors : true;
    16391638}
    16401639
     
    17131712        // User name can't be on the list of illegal names.
    17141713        $illegal_names = get_site_option( 'illegal_names' );
    1715         if ( in_array( $user_name, (array) $illegal_names ) ) {
    1716             $errors->add( 'user_name', __( 'That username is not allowed', 'buddypress' ) );
     1714        if ( in_array( $user_name, (array) $illegal_names, true ) ) {
     1715            $errors->add( 'user_name', __( 'That username is not allowed.', 'buddypress' ) );
    17171716        }
    17181717
     
    17241723        // Minimum of 4 characters.
    17251724        if ( strlen( $user_name ) < 4 ) {
    1726             $errors->add( 'user_name',  __( 'Username must be at least 4 characters', 'buddypress' ) );
     1725            $errors->add( 'user_name', __( 'Username must be at least 4 characters.', 'buddypress' ) );
     1726        }
     1727
     1728        // Maximum of 60 characters.
     1729        if ( strlen( $user_name ) > 60 ) {
     1730            $errors->add( 'user_name', __( 'Username may not be longer than 60 characters.', 'buddypress' ) );
    17271731        }
    17281732
    17291733        // No underscores. @todo Why not?
    1730         if ( false !== strpos( ' ' . $user_name, '_' ) ) {
     1734        if ( str_contains( ' ' . $user_name, '_' ) ) {
    17311735            $errors->add( 'user_name', __( 'Sorry, usernames may not contain the character "_"!', 'buddypress' ) );
    17321736        }
     
    17351739        $match = array();
    17361740        preg_match( '/[0-9]*/', $user_name, $match );
    1737         if ( $match[0] == $user_name ) {
     1741
     1742        // Check for valid letters.
     1743        $valid_letters = preg_match( '/[a-zA-Z]+/', $user_name );
     1744
     1745        if ( $match[0] === $user_name || ! $valid_letters ) {
    17381746            $errors->add( 'user_name', __( 'Sorry, usernames must have letters too!', 'buddypress' ) );
    17391747        }
    17401748
    17411749        // Check into signups.
    1742         $signups = BP_Signup::get( array(
    1743             'user_login' => $user_name,
    1744         ) );
     1750        $signups = BP_Signup::get(
     1751            array(
     1752                'user_login' => $user_name,
     1753            )
     1754        );
    17451755
    17461756        $signup = isset( $signups['signups'] ) && ! empty( $signups['signups'][0] ) ? $signups['signups'][0] : false;
Note: See TracChangeset for help on using the changeset viewer.