Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/27/2009 10:41:10 AM (16 years ago)
Author:
apeatling
Message:

Single WP support. Yes, you read that correctly.

File:
1 edited

Legend:

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

    r2077 r2209  
    1919
    2020    /* If signups are disabled, just re-direct */
    21     if ( 'none' == bp_get_signup_allowed() || 'blog' == bp_get_signup_allowed() )
     21    if ( !bp_get_signup_allowed() || 'none' == bp_get_signup_allowed() || 'blog' == bp_get_signup_allowed() )
    2222        bp_core_redirect( $bp->root_domain );
    2323
     
    3333
    3434        /* Check the base account details for problems */
    35         $account_details = wpmu_validate_user_signup( $_POST['signup_username'] , $_POST['signup_email'] );
     35        $account_details = wpmu_validate_user_signup( $_POST['signup_username'], $_POST['signup_email'] );
    3636
    3737        /* If there are errors with account details, set them for display */
     
    4949        if ( ( !empty( $_POST['signup_password'] ) && !empty( $_POST['signup_password_confirm'] ) ) && $_POST['signup_password'] != $_POST['signup_password_confirm'] )
    5050            $bp->signup->errors['signup_password'] = __( 'The passwords you entered do not match.', 'buddypress' );
     51
     52        $bp->signup->username = $_POST['signup_username'];
     53        $bp->signup->email = $_POST['signup_email'];
    5154
    5255        /* Now we've checked account details, we can check profile information */
     
    122125
    123126                /* Finally, sign up the user and/or blog*/
    124                 if ( isset( $_POST['signup_with_blog'] ) )
     127                if ( isset( $_POST['signup_with_blog'] ) && bp_core_is_multiblog_install() )
    125128                    wpmu_signup_blog( $blog_details['domain'], $blog_details['path'], $blog_details['blog_title'], $_POST['signup_username'], $_POST['signup_email'], $usermeta );
    126                 else
    127                     wpmu_signup_user( $_POST['signup_username'], $_POST['signup_email'], $usermeta );
     129                else {
     130                    bp_core_signup_user( $_POST['signup_username'], $_POST['signup_password'], $_POST['signup_email'], $usermeta );
     131                }
    128132
    129133                $bp->signup->step = 'completed-confirmation';
     
    145149        $bp->signup->step = 'completed-confirmation';
    146150
    147         /* Get the activation key */
    148         if ( !$bp->signup->key = $wpdb->get_var( $wpdb->prepare( "SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s", $_POST[ 'signup_username' ], $_POST[ 'signup_email' ] ) ) ) {
    149             bp_core_add_message( __( 'There was a problem uploading your avatar, please try uploading it again', 'buddypress' ) );
    150         } else {
    151             /* Hash the key to create the upload folder (added security so people don't sniff the activation key) */
    152             $bp->signup->avatar_dir = wp_hash( $bp->signup->key );
    153 
    154             /* Pass the file to the avatar upload handler */
    155             if ( bp_core_avatar_handle_upload( $_FILES, 'bp_core_signup_avatar_upload_dir' ) ) {
    156                 $bp->avatar_admin->step = 'crop-image';
    157 
    158                 /* Make sure we include the jQuery jCrop file for image cropping */
    159                 add_action( 'wp', 'bp_core_add_jquery_cropper' );
    160             }
     151        if ( bp_core_is_multiblog_install() ) {
     152            /* Get the activation key */
     153            if ( !$bp->signup->key = $wpdb->get_var( $wpdb->prepare( "SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s", $_POST[ 'signup_username' ], $_POST[ 'signup_email' ] ) ) ) {
     154                bp_core_add_message( __( 'There was a problem uploading your avatar, please try uploading it again', 'buddypress' ) );
     155            } else {
     156                /* Hash the key to create the upload folder (added security so people don't sniff the activation key) */
     157                $bp->signup->avatar_dir = wp_hash( $bp->signup->key );
     158            }
     159        } else
     160            $bp->signup->avatar_dir = wp_hash( $bp->signup->username );
     161
     162        /* Pass the file to the avatar upload handler */
     163        if ( bp_core_avatar_handle_upload( $_FILES, 'bp_core_signup_avatar_upload_dir' ) ) {
     164            $bp->avatar_admin->step = 'crop-image';
     165
     166            /* Make sure we include the jQuery jCrop file for image cropping */
     167            add_action( 'wp', 'bp_core_add_jquery_cropper' );
    161168        }
    162169    }
     
    182189add_action( 'wp', 'bp_core_screen_signup', 3 );
    183190
     191function bp_core_signup_user( $user_login, $user_password, $user_email, $usermeta ) {
     192    global $bp;
     193
     194    if ( bp_core_is_multiblog_install() )
     195        return wpmu_signup_user( $user_login, $user_email, $usermeta );
     196
     197    $errors = new WP_Error();
     198
     199    $user_id = wp_create_user( $user_login, $user_password, $user_email );
     200    if ( !$user_id ) {
     201        $errors->add('registerfail', sprintf(__('<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !'), get_option('admin_email')));
     202        return $errors;
     203    }
     204
     205    /* Set any profile data */
     206    if ( function_exists( 'xprofile_set_field_data' ) ) {
     207        if ( !empty( $usermeta['profile_field_ids'] ) ) {
     208            $profile_field_ids = explode( ',', $usermeta['profile_field_ids'] );
     209
     210            foreach( $profile_field_ids as $field_id ) {
     211                $current_field = $usermeta["field_{$field_id}"];
     212
     213                if ( !empty( $current_field ) )
     214                    xprofile_set_field_data( $field_id, $user_id, $current_field );
     215            }
     216        }
     217    }
     218
     219    wp_new_user_notification( $user_id, $user_pass );
     220
     221    $bp->signup->username = $user_login;
     222
     223    return $user_id;
     224}
     225
    184226function bp_core_signup_avatar_upload_dir() {
    185227    global $bp;
     
    188230        return false;
    189231
    190     $path = get_blog_option( BP_ROOT_BLOG, 'upload_path' );
    191     $newdir = WP_CONTENT_DIR . str_replace( 'wp-content', '', $path );
    192     $newdir .= '/avatars/signups/' . $bp->signup->avatar_dir;
    193 
    194     $newbdir = $newdir;
    195 
    196     if ( !file_exists( $newdir ) )
    197         @wp_mkdir_p( $newdir );
    198 
    199     $newurl = WP_CONTENT_URL . '/blogs.dir/' . BP_ROOT_BLOG . '/files/avatars/signups/' . $bp->signup->avatar_dir;
     232    $path  = BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $bp->signup->avatar_dir;
     233    $newbdir = $path;
     234
     235    if ( !file_exists( $path ) )
     236        @wp_mkdir_p( $path );
     237
     238    $newurl = str_replace( WP_CONTENT_DIR, WP_CONTENT_URL, $path );
    200239    $newburl = $newurl;
    201240    $newsubdir = '/avatars/signups/' . $bp->signup->avatar_dir;
    202241
    203     return apply_filters( 'bp_core_signup_avatar_upload_dir', array( 'path' => $newdir, 'url' => $newurl, 'subdir' => $newsubdir, 'basedir' => $newbdir, 'baseurl' => $newburl, 'error' => false ) );
     242    return apply_filters( 'bp_core_signup_avatar_upload_dir', array( 'path' => $path, 'url' => $newurl, 'subdir' => $newsubdir, 'basedir' => $newbdir, 'baseurl' => $newburl, 'error' => false ) );
    204243}
    205244
Note: See TracChangeset for help on using the changeset viewer.