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-signup.php

    r2946 r3232  
    181181
    182182            /* Make sure we include the jQuery jCrop file for image cropping */
    183             add_action( 'wp_print_scripts', 'bp_core_add_jquery_cropper' );
     183            add_action( 'wp', 'bp_core_add_jquery_cropper' );
    184184        }
    185185    }
     
    256256 */
    257257
     258/**
     259 * bp_core_flush_illegal_names()
     260 *
     261 * Flush illegal names by getting and setting 'illegal_names' site option
     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 ) {
    259     global $wpdb, $bp;
     312    global $wpdb;
    260313
    261314    $errors = new WP_Error();
     
    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_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 );
    279 
    280     if ( in_array( $user_name, (array)$illegal_names ) )
    281         $errors->add( 'user_name', __( 'Sorry, that username is not allowed', 'buddypress' ) );
    282 
    283     if ( !validate_username( $user_name ) || $user_name != $maybe[0] )
     323    // Make sure illegal names include BuddyPress slugs and values
     324    bp_core_flush_illegal_names();
     325
     326    if ( !validate_username( $user_name ) || in_array( $user_name, (array)$illegal_names ) || $user_name != $maybe[0] )
    284327        $errors->add( 'user_name', __( 'Only lowercase letters and numbers allowed', 'buddypress' ) );
    285328
     
    382425        if ( !bp_core_is_multisite() ) {
    383426            $activation_key = wp_hash( $user_id );
    384             update_usermeta( $user_id, 'activation_key', $activation_key );
     427            update_user_meta( $user_id, 'activation_key', $activation_key );
    385428            bp_core_signup_send_validation_email( $user_id, $user_email, $activation_key );
    386429        }
     
    445488
    446489        /* Remove the activation key meta */
    447         delete_usermeta( $user_id, 'activation_key' );
     490        delete_user_meta( $user_id, 'activation_key' );
    448491    }
    449492
     
    452495
    453496    /* Add a last active entry */
    454     update_usermeta( $user_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
     497    update_user_meta( $user_id, 'last_activity', bp_core_current_time() );
    455498
    456499    /* Set the password on multisite installs */
     
    495538
    496539    /* Add a last active entry */
    497     update_usermeta( $user_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
     540    update_user_meta( $user_id, 'last_activity', bp_core_current_time() );
    498541
    499542    /* Add the user's fullname to Xprofile */
    500543    if ( function_exists( 'xprofile_set_field_data' ) ) {
    501         $firstname = get_usermeta( $user_id, 'first_name' );
    502         $lastname = ' ' . get_usermeta( $user_id, 'last_name' );
     544        $firstname = get_user_meta( $user_id, 'first_name', true );
     545        $lastname = ' ' . get_user_meta( $user_id, 'last_name', true );
    503546        $name = $firstname . $lastname;
    504547
    505548        if ( empty( $name ) || ' ' == $name )
    506             $name = get_usermeta( $user_id, 'nickname' );
     549            $name = get_user_meta( $user_id, 'nickname', true );
    507550
    508551        xprofile_set_field_data( 1, $user_id, $name );
     
    523566        @wp_mkdir_p( $path );
    524567
    525     $newurl = str_replace( BP_AVATAR_UPLOAD_PATH, BP_AVATAR_URL, $path );
     568    $newurl = BP_AVATAR_URL . '/avatars/signups/' . $bp->signup->avatar_dir;
    526569    $newburl = $newurl;
    527570    $newsubdir = '/avatars/signups/' . $bp->signup->avatar_dir;
     
    532575function bp_core_signup_send_validation_email( $user_id, $user_email, $key ) {
    533576    $activate_url = bp_get_activation_page() ."?key=$key";
    534     $activate_url = clean_url( $activate_url );
     577    $activate_url = esc_url( $activate_url );
    535578    $admin_email = get_site_option( "admin_email" );
    536579
Note: See TracChangeset for help on using the changeset viewer.