Skip to:
Content

BuddyPress.org

Changeset 3037


Ignore:
Timestamp:
06/11/2010 12:01:18 AM (16 years ago)
Author:
johnjamesjacoby
Message:

Fixes #2310

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.2/bp-core/bp-core-signup.php

    r3036 r3037  
    256256 */
    257257
     258/**
     259 * bp_core_refresh_illegal_names()
     260 *
     261 * Force refresh of illegal names by
     262 */
     263function bp_core_flush_illegal_names() {
     264    $illegal_names = get_site_option( 'illegal_names' );
     265    update_site_option( 'illegal_names', $illegal_names );
     266}
     267
     268/**
     269 * bp_core_illegal_names()
     270 *
     271 * Filter the illegal_names site option and make sure it includes a few
     272 * specific BuddyPress and Multi-site slugs
     273 *
     274 * @param array|string $value Illegal names from field
     275 * @param array|string $oldvalue The value as it is currently
     276 * @return array Merged and unique array of illegal names
     277 */
     278function bp_core_illegal_names( $value = '', $oldvalue = '' ) {
     279
     280    // Make sure $value is array
     281    if ( empty( $value ) )
     282        $db_illegal_names = array();
     283    if ( is_array( $value ) )
     284        $db_illegal_names = $value;
     285    elseif ( is_string( $value ) )
     286        $db_illegal_names = implode( ' ', $names );
     287
     288    // Add our slugs to the array and allow them to be filtered
     289    $filtered_illegal_names = apply_filters( 'bp_core_illegal_usernames', array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', BP_GROUPS_SLUG, BP_MEMBERS_SLUG, BP_FORUMS_SLUG, BP_BLOGS_SLUG, BP_ACTIVITY_SLUG, BP_XPROFILE_SLUG, BP_FRIENDS_SLUG, BP_SEARCH_SLUG, BP_SETTINGS_SLUG, BP_REGISTER_SLUG, BP_ACTIVATION_SLUG ) );
     290
     291    // Merge the arrays together
     292    $merged_names = array_merge( (array)$filtered_illegal_names, (array)$db_illegal_names );
     293
     294    // Remove duplicates
     295    $illegal_names = array_unique( (array)$merged_names );
     296
     297    return apply_filters( 'bp_core_illegal_names', $illegal_names );
     298}
     299add_filter( 'pre_update_site_option_illegal_names', 'bp_core_illegal_names', 10, 2 );
     300
     301/**
     302 * bp_core_validate_user_signup()
     303 *
     304 * Validate a user name and email address when creating a new user.
     305 *
     306 * @global object $wpdb DB Layer
     307 * @param string $user_name Username to validate
     308 * @param string $user_email Email address to validate
     309 * @return array Results of user validation including errors, if any
     310 */
    258311function bp_core_validate_user_signup( $user_name, $user_email ) {
    259312    global $wpdb;
     
    268321    preg_match( "/[a-z0-9]+/", $user_name, $maybe );
    269322
    270     $db_illegal_names = get_site_option( 'illegal_names' );
    271     $filtered_illegal_names = apply_filters( 'bp_core_illegal_usernames', array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', BP_GROUPS_SLUG, BP_MEMBERS_SLUG, BP_FORUMS_SLUG, BP_BLOGS_SLUG, BP_ACTIVITY_SLUG, BP_XPROFILE_SLUG, BP_FRIENDS_SLUG, BP_SEARCH_SLUG, BP_SETTINGS_SLUG, BP_REGISTER_SLUG, BP_ACTIVATION_SLUG ) );
    272 
    273     /* Safely merge our illegal names into existing site_option */
    274     $common_names           = array_intersect( (array)$db_illegal_names, (array)$filtered_illegal_names );
    275     $diff_names             = array_diff( (array)$db_illegal_names, (array)$filtered_illegal_names );
    276     $illegal_names          = array_merge( (array)$diff_names, (array)$common_names );
    277 
    278     update_site_option( 'illegal_names', $illegal_names );
     323    // Make sure illegal names include BuddyPress slugs and values
     324    bp_core_flush_illegal_names();
    279325
    280326    if ( !validate_username( $user_name ) || in_array( $user_name, (array)$illegal_names ) || $user_name != $maybe[0] )
Note: See TracChangeset for help on using the changeset viewer.