Skip to:
Content

BuddyPress.org

Changeset 2832


Ignore:
Timestamp:
03/11/2010 04:52:34 PM (14 years ago)
Author:
apeatling
Message:

Fixes #2149, fixed inconsistencies between single WP and WPMU with registration and activation. Single WP users must now activate their accounts and confirm they are using a valid email.

Location:
branches/1.2
Files:
1 added
1 deleted
6 edited

Legend:

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

    r2815 r2832  
    3333require ( BP_PLUGIN_DIR . '/bp-core/bp-core-catchuri.php' );
    3434require ( BP_PLUGIN_DIR . '/bp-core/bp-core-classes.php' );
     35require ( BP_PLUGIN_DIR . '/bp-core/bp-core-filters.php' );
    3536require ( BP_PLUGIN_DIR . '/bp-core/bp-core-cssjs.php' );
    3637require ( BP_PLUGIN_DIR . '/bp-core/bp-core-avatars.php' );
     
    4041require ( BP_PLUGIN_DIR . '/bp-core/bp-core-notifications.php' );
    4142require ( BP_PLUGIN_DIR . '/bp-core/bp-core-signup.php' );
    42 
    43 /* Multisite includes built in account activation support. */
    44 if ( bp_core_is_multisite() )
    45     require ( BP_PLUGIN_DIR . '/bp-core/bp-core-activation.php' );
    4643
    4744/* If BP_DISABLE_ADMIN_BAR is defined, do not load the global admin bar. */
     
    16641661    update_site_option( 'illegal_names', $new );
    16651662}
    1666 
    1667 /**
    1668  * bp_core_email_from_name_filter()
    1669  *
    1670  * Sets the "From" name in emails sent to the name of the site and not "WordPress"
    1671  *
    1672  * @package BuddyPress Core
    1673  * @uses get_blog_option() fetches the value for a meta_key in the wp_X_options table
    1674  * @return The blog name for the root blog
    1675  */
    1676 function bp_core_email_from_name_filter() {
    1677     return apply_filters( 'bp_core_email_from_name_filter', get_blog_option( BP_ROOT_BLOG, 'blogname' ) );
    1678 }
    1679 add_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' );
    1680 
    1681 
    1682 /**
    1683  * bp_core_email_from_name_filter()
    1684  *
    1685  * Sets the "From" address in emails sent
    1686  *
    1687  * @package BuddyPress Core
    1688  * @global $current_site Object containing current site metadata
    1689  * @return noreply@sitedomain email address
    1690  */
    1691 function bp_core_email_from_address_filter() {
    1692     $domain = (array) explode( '/', site_url() );
    1693 
    1694     return apply_filters( 'bp_core_email_from_address_filter', __( 'noreply', 'buddypress' ) . '@' . $domain[2] );
    1695 }
    1696 add_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' );
    16971663
    16981664/**
     
    19721938
    19731939/**
    1974  * bp_core_filter_parent_theme()
    1975  *
    1976  * Remove social network parent theme from the theme list.
    1977  *
    1978  * @package BuddyPress Core
    1979  */
    1980 function bp_core_filter_parent_theme() {
    1981     global $wp_themes, $pagenow;
    1982 
    1983     if ( is_admin() && 'themes.php' == $pagenow )
    1984         $wp_themes = get_themes();
    1985 
    1986     unset( $wp_themes['BuddyPress Classic Parent'] );
    1987 }
    1988 add_filter( 'admin_menu', 'bp_core_filter_parent_theme' );
    1989 
    1990 /**
    1991  * bp_core_allow_default_theme()
    1992  *
    1993  * On multiblog installations you must first allow themes to be activated and show
    1994  * up on the theme selection screen. This function will let the BuddyPress bundled
    1995  * themes show up on the root blog selection screen and bypass this step. It also
    1996  * means that the themes won't show for selection on other blogs.
    1997  *
    1998  * @package BuddyPress Core
    1999  */
    2000 function bp_core_allow_default_theme( $themes ) {
    2001     global $bp, $current_blog;
    2002 
    2003     if ( !is_site_admin() )
    2004         return $themes;
    2005 
    2006     if ( $current_blog->ID == $bp->root_blog ) {
    2007         $themes['bp-default'] = 1;
    2008         $themes['bp-classic'] = 1;
    2009     }
    2010 
    2011     return $themes;
    2012 }
    2013 add_filter( 'allowed_themes', 'bp_core_allow_default_theme' );
    2014 
    2015 /**
    20161940 * bp_core_activation_notice()
    20171941 *
     
    20541978add_action( 'admin_notices', 'bp_core_activation_notice' );
    20551979
    2056 /**
    2057  * bp_core_filter_comments()
    2058  *
    2059  * Filter the blog post comments array and insert BuddyPress URLs for users.
    2060  *
    2061  * @package BuddyPress Core
    2062  */
    2063 function bp_core_filter_comments( $comments, $post_id ) {
    2064     global $wpdb;
    2065 
    2066     foreach( (array)$comments as $comment ) {
    2067         if ( $comment->user_id )
    2068             $user_ids[] = $comment->user_id;
    2069     }
    2070 
    2071     if ( empty( $user_ids ) )
    2072         return $comments;
    2073 
    2074     $user_ids = implode( ',', $user_ids );
    2075 
    2076     if ( !$userdata = $wpdb->get_results( $wpdb->prepare( "SELECT ID as user_id, user_login, user_nicename FROM {$wpdb->users} WHERE ID IN ({$user_ids})" ) ) )
    2077         return $comments;
    2078 
    2079     foreach( (array)$userdata as $user )
    2080         $users[$user->user_id] = bp_core_get_user_domain( $user->user_id, $user->user_nicename, $user->user_login );
    2081 
    2082     foreach( (array)$comments as $i => $comment ) {
    2083         if ( !empty( $comment->user_id ) ) {
    2084             if ( !empty( $users[$comment->user_id] ) )
    2085                 $comments[$i]->comment_author_url = $users[$comment->user_id];
    2086         }
    2087     }
    2088 
    2089     return $comments;
    2090 }
    2091 add_filter( 'comments_array', 'bp_core_filter_comments', 10, 2 );
    2092 
    2093 /**
    2094  * bp_core_login_redirect()
    2095  *
    2096  * When a user logs in, always redirect them back to the previous page. NOT the admin area.
    2097  *
    2098  * @package BuddyPress Core
    2099  */
    2100 function bp_core_login_redirect( $redirect_to ) {
    2101     global $bp, $current_blog;
    2102 
    2103     if ( bp_core_is_multisite() && $current_blog->blog_id != BP_ROOT_BLOG )
    2104         return $redirect_to;
    2105 
    2106     if ( !empty( $_REQUEST['redirect_to'] ) || strpos( $_REQUEST['redirect_to'], 'wp-admin' ) )
    2107         return $redirect_to;
    2108 
    2109     if ( false === strpos( wp_get_referer(), 'wp-login.php' ) && false === strpos( wp_get_referer(), 'activate' ) && empty( $_REQUEST['nr'] ) )
    2110         return wp_get_referer();
    2111 
    2112     return $bp->root_domain;
    2113 }
    2114 add_filter( 'login_redirect', 'bp_core_login_redirect' );
    2115 
    2116 
    21171980/********************************************************************************
    21181981 * Custom Actions
  • branches/1.2/bp-core/bp-core-signup.php

    r2829 r2832  
    11<?php
     2
     3/********************************************************************************
     4 * Screen Functions
     5 *
     6 * Screen functions are the controllers of BuddyPress. They will execute when their
     7 * specific URL is caught. They will first save or manipulate data using business
     8 * functions, then pass on the user to a template file.
     9 */
    210
    311function bp_core_screen_signup() {
     
    1119        bp_core_redirect( $bp->root_domain );
    1220
    13     /***
    14      * For backwards compatibility with the old pre 1.1 two theme system, skip this screen function
    15      * if the user is using the old two theme method.
    16      */
    17     if ( file_exists( WP_CONTENT_DIR . '/bp-themes' ) )
    18         return false;
    19 
    2021    /* If signups are disabled, just re-direct */
    2122    if ( !bp_get_signup_allowed() )
     
    3334
    3435        /* Check the base account details for problems */
    35         $account_details = wpmu_validate_user_signup( $_POST['signup_username'], $_POST['signup_email'] );
     36        $account_details = bp_core_validate_user_signup( $_POST['signup_username'], $_POST['signup_email'] );
    3637
    3738        /* If there are errors with account details, set them for display */
     
    7475
    7576            if ( 'blog' == $active_signup || 'all' == $active_signup ) {
    76                 $blog_details = wpmu_validate_blog_signup( $_POST['signup_blog_url'], $_POST['signup_blog_title'] );
     77                $blog_details = bp_core_validate_blog_signup( $_POST['signup_blog_url'], $_POST['signup_blog_title'] );
    7778
    7879                /* If there are errors with blog details, set them for display */
     
    126127                $usermeta = apply_filters( 'bp_signup_usermeta', $usermeta );
    127128
    128                 /* Finally, sign up the user and/or blog*/
     129                /* Finally, sign up the user and/or blog */
    129130                if ( isset( $_POST['signup_with_blog'] ) && bp_core_is_multisite() )
    130                     wpmu_signup_blog( $blog_details['domain'], $blog_details['path'], $blog_details['blog_title'], $_POST['signup_username'], $_POST['signup_email'], $usermeta );
     131                    bp_core_signup_blog( $blog_details['domain'], $blog_details['path'], $blog_details['blog_title'], $_POST['signup_username'], $_POST['signup_email'], $usermeta );
    131132                else {
    132133                    bp_core_signup_user( $_POST['signup_username'], $_POST['signup_password'], $_POST['signup_email'], $usermeta );
     
    159160                $bp->signup->avatar_dir = wp_hash( $bp->signup->key );
    160161            }
    161         } else
    162             $bp->signup->avatar_dir = wp_hash( $bp->signup->username );
     162        } else {
     163            $user_id = bp_core_get_userid( $_POST['signup_username'] );
     164            $bp->signup->avatar_dir = wp_hash( $user_id );
     165        }
    163166
    164167        /* Pass the file to the avatar upload handler */
     
    185188        else
    186189            bp_core_add_message( __( 'Your new avatar was uploaded successfully', 'buddypress' ) );
    187 
    188         /* If this is a single WP install, move the avatar to the user's folder since there is no activation process to move it. */
    189         if ( !bp_core_is_multisite() ) {
    190             $user_id = bp_core_get_userid( $_POST['signup_username'] );
    191 
    192             if ( !empty( $user_id ) && file_exists( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $_POST['signup_avatar_dir'] ) ) {
    193                 @rename( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $_POST['signup_avatar_dir'], BP_AVATAR_UPLOAD_PATH . '/avatars/' . $user_id );
     190    }
     191    bp_core_load_template( 'registration/register' );
     192}
     193add_action( 'wp', 'bp_core_screen_signup', 3 );
     194
     195function bp_core_screen_activation() {
     196    global $bp, $wpdb;
     197
     198    if ( BP_ACTIVATION_SLUG != $bp->current_component )
     199        return false;
     200
     201    /* Check if an activation key has been passed */
     202    if ( isset( $_GET['key'] ) ) {
     203
     204        require_once( ABSPATH . WPINC . '/registration.php' );
     205
     206        /* Activate the signup */
     207        $user = apply_filters( 'bp_core_activate_account', bp_core_activate_signup( $_GET['key'] ) );
     208
     209        /* If there was errors, add a message and redirect */
     210        if ( $user->errors ) {
     211            bp_core_add_message( __( 'There was an error activating your account, please try again.', 'buddypress' ), 'error' );
     212            bp_core_redirect( $bp->root_domain . '/' . BP_ACTIVATION_SLUG );
     213        }
     214
     215        /* Check for an uploaded avatar and move that to the correct user folder */
     216        if ( bp_core_is_multisite() )
     217            $hashed_key = wp_hash( $_GET['key'] );
     218        else
     219            $hashed_key = wp_hash( $user );
     220
     221        /* Check if the avatar folder exists. If it does, move rename it, move it and delete the signup avatar dir */
     222        if ( file_exists( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $hashed_key ) )
     223            @rename( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $hashed_key, BP_AVATAR_UPLOAD_PATH . '/avatars/' . $user );
     224
     225        bp_core_add_message( __( 'Your account is now active!', 'buddypress' ) );
     226
     227        $bp->activation_complete = true;
     228    }
     229
     230    if ( '' != locate_template( array( 'registration/activate' ), false ) )
     231        bp_core_load_template( apply_filters( 'bp_core_template_activate', 'activate' ) );
     232    else
     233        bp_core_load_template( apply_filters( 'bp_core_template_activate', 'registration/activate' ) );
     234}
     235add_action( 'wp', 'bp_core_screen_activation', 3 );
     236
     237
     238/********************************************************************************
     239 * Business Functions
     240 *
     241 * Business functions are where all the magic happens in BuddyPress. They will
     242 * handle the actual saving or manipulation of information. Usually they will
     243 * hand off to a database class for data access, then return
     244 * true or false on success or failure.
     245 */
     246
     247function bp_core_validate_user_signup( $user_name, $user_email ) {
     248    global $wpdb;
     249
     250    $errors = new WP_Error();
     251    $user_email = sanitize_email( $user_email );
     252
     253    if ( empty( $user_name ) )
     254        $errors->add( 'user_name', __( 'Please enter a username', 'buddypress' ) );
     255
     256    $maybe = array();
     257    preg_match( "/[a-z0-9]+/", $user_name, $maybe );
     258
     259    $db_illegal_names = get_site_option( 'illegal_names' );
     260    $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 ) );
     261
     262    $illegal_names = array_merge( (array)$db_illegal_names, (array)$filtered_illegal_names );
     263    update_site_option( 'illegal_names', $illegal_names );
     264
     265    if ( !validate_username( $user_name ) || in_array( $user_name, (array)$illegal_names ) || $user_name != $maybe[0] )
     266        $errors->add( 'user_name', __( 'Only lowercase letters and numbers allowed', 'buddypress' ) );
     267
     268    if( strlen( $user_name ) < 4 )
     269        $errors->add( 'user_name',  __( 'Username must be at least 4 characters', 'buddypress' ) );
     270
     271    if ( strpos( ' ' . $user_name, '_' ) != false )
     272        $errors->add( 'user_name', __( 'Sorry, usernames may not contain the character "_"!', 'buddypress' ) );
     273
     274    /* Is the user_name all numeric? */
     275    $match = array();
     276    preg_match( '/[0-9]*/', $user_name, $match );
     277
     278    if ( $match[0] == $user_name )
     279        $errors->add( 'user_name', __( 'Sorry, usernames must have letters too!', 'buddypress' ) );
     280
     281    if ( !is_email( $user_email ) )
     282        $errors->add( 'user_email', __( 'Please check your email address.', 'buddypress' ) );
     283
     284    $limited_email_domains = get_site_option( 'limited_email_domains', 'buddypress' );
     285
     286    if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) {
     287        $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) );
     288
     289        if ( in_array( $emaildomain, (array)$limited_email_domains ) == false )
     290            $errors->add( 'user_email', __( 'Sorry, that email address is not allowed!', 'buddypress' ) );
     291    }
     292
     293    /* Check if the username has been used already. */
     294    if ( username_exists( $user_name ) )
     295        $errors->add( 'user_name', __( 'Sorry, that username already exists!', 'buddypress' ) );
     296
     297    /* Check if the email address has been used already. */
     298    if ( email_exists( $user_email ) )
     299        $errors->add( 'user_email', __( 'Sorry, that email address is already used!', 'buddypress' ) );
     300
     301    $result = array( 'user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors );
     302
     303    /* Apply WPMU legacy filter */
     304    $result = apply_filters( 'wpmu_validate_user_signup', $result );
     305
     306    return apply_filters( 'bp_core_validate_user_signup', $result );
     307}
     308
     309function bp_core_validate_blog_signup( $blog_url, $blog_title ) {
     310    if ( !bp_core_is_multisite() || !function_exists( 'wpmu_validate_blog_signup' ) )
     311        return false;
     312
     313    return apply_filters( 'bp_core_validate_blog_signup', wpmu_validate_blog_signup( $blog_url, $blog_title ) );
     314}
     315
     316function bp_core_signup_user( $user_login, $user_password, $user_email, $usermeta ) {
     317    global $bp, $wpdb;
     318
     319    /* Multisite installs have their own install procedure */
     320    if ( bp_core_is_multisite() ) {
     321        wpmu_signup_user( $user_login, $user_email, $usermeta );
     322
     323    } else {
     324        $errors = new WP_Error();
     325
     326        $user_id = wp_insert_user( array(
     327            'user_login' => $user_login,
     328            'user_pass' => $user_password,
     329            'display_name' => sanitize_title( $user_login ),
     330            'user_email' => $user_email
     331        ) );
     332
     333        if ( !$user_id ) {
     334            $errors->add( 'registerfail', sprintf( __('<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !', 'buddypress' ), get_option( 'admin_email' ) ) );
     335            return $errors;
     336        }
     337
     338        /* Update the user status to '2' which we will use as 'not activated' (0 = active, 1 = spam, 2 = not active) */
     339        $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_status = 2 WHERE ID = %d", $user_id ) );
     340
     341        /* Set any profile data */
     342        if ( function_exists( 'xprofile_set_field_data' ) ) {
     343            if ( !empty( $usermeta['profile_field_ids'] ) ) {
     344                $profile_field_ids = explode( ',', $usermeta['profile_field_ids'] );
     345
     346                foreach( (array)$profile_field_ids as $field_id ) {
     347                    $current_field = $usermeta["field_{$field_id}"];
     348
     349                    if ( !empty( $current_field ) )
     350                        xprofile_set_field_data( $field_id, $user_id, $current_field );
     351                }
    194352            }
    195353        }
    196354    }
    197     bp_core_load_template( 'registration/register' );
    198 }
    199 add_action( 'wp', 'bp_core_screen_signup', 3 );
    200 
    201 function bp_core_signup_user( $user_login, $user_password, $user_email, $usermeta ) {
    202     global $bp;
    203 
    204     if ( bp_core_is_multisite() )
    205         return wpmu_signup_user( $user_login, $user_email, $usermeta );
    206 
    207     $errors = new WP_Error();
    208 
    209     $user_id = wp_insert_user( array(
    210         'user_login' => $user_login,
    211         'user_pass' => $user_password,
    212         'display_name' => sanitize_title( $user_login ),
    213         'user_email' => $user_email
    214     ) );
    215 
    216     if ( !$user_id ) {
    217         $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')));
    218         return $errors;
    219     }
    220 
    221     /* Update the user_url */
    222     wp_update_user( array( 'ID' => $user_id, 'user_url' => bp_core_get_user_domain( $user_id, sanitize_title( $user_login ), $user_login ) ) );
    223 
    224     /* Set any profile data */
    225     if ( function_exists( 'xprofile_set_field_data' ) ) {
    226         if ( !empty( $usermeta['profile_field_ids'] ) ) {
    227             $profile_field_ids = explode( ',', $usermeta['profile_field_ids'] );
    228 
    229             foreach( (array)$profile_field_ids as $field_id ) {
    230                 $current_field = $usermeta["field_{$field_id}"];
    231 
    232                 if ( !empty( $current_field ) )
    233                     xprofile_set_field_data( $field_id, $user_id, $current_field );
     355    $bp->signup->username = $user_login;
     356
     357    /***
     358     * Now generate an activation key and send an email to the user so they can activate their account
     359     * and validate their email address. Multisite installs send their own email, so this is only for single blog installs.
     360     */
     361    if ( !bp_core_is_multisite() ) {
     362        $activation_key = wp_hash( $user_id );
     363        update_usermeta( $user_id, 'activation_key', $activation_key );
     364        bp_core_signup_send_validation_email( $user_id, $activation_key );
     365    }
     366
     367    do_action( 'bp_core_signup_user', $user_id, $user_login, $user_password, $user_email, $usermeta );
     368
     369    return $user_id;
     370}
     371
     372function bp_core_signup_blog( $blog_domain, $blog_path, $blog_title, $user_name, $user_email, $usermeta ) {
     373    if ( !bp_core_is_multisite() || !function_exists( 'wpmu_signup_blog' ) )
     374        return false;
     375
     376    return apply_filters( 'bp_core_signup_blog', wpmu_signup_blog( $blog_domain, $blog_path, $blog_title, $user_name, $user_email, $usermeta ) );
     377}
     378
     379function bp_core_activate_signup( $key ) {
     380    global $wpdb;
     381
     382    $user = false;
     383
     384    /* Multisite installs have their own activation routine */
     385    if ( bp_core_is_multisite() ) {
     386        $user = wpmu_activate_signup( $key );
     387
     388        /* If there was errors, add a message and redirect */
     389        if ( $user->errors ) {
     390            bp_core_add_message( __( 'There was an error activating your account, please try again.', 'buddypress' ), 'error' );
     391            bp_core_redirect( $bp->root_domain . '/' . BP_ACTIVATION_SLUG );
     392        }
     393
     394        $user_id = $user['user_id'];
     395
     396        /* Set any profile data */
     397        if ( function_exists( 'xprofile_set_field_data' ) ) {
     398            if ( !empty( $user['meta']['profile_field_ids'] ) ) {
     399                $profile_field_ids = explode( ',', $user['meta']['profile_field_ids'] );
     400
     401                foreach( (array)$profile_field_ids as $field_id ) {
     402                    $current_field = $user['meta']["field_{$field_id}"];
     403
     404                    if ( !empty( $current_field ) )
     405                        xprofile_set_field_data( $field_id, $user_id, $current_field );
     406                }
    234407            }
    235408        }
    236     }
     409
     410    } else {
     411        /* Get the user_id based on the $key */
     412        $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_value = %s", $key ) );
     413
     414        if ( empty( $user_id ) )
     415            return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) );
     416
     417        /* Change the user's status so they become active */
     418        if ( !$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_status = 0 WHERE ID = %d", $user_id ) ) )
     419            return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) );
     420
     421        /* Notify the site admin of a new user registration */
     422        wp_new_user_notification( $user_id );
     423
     424        /* Remove the activation key meta */
     425        delete_usermeta( $user_id, 'activation_key' );
     426    }
     427
     428    /* Update the user_url and display_name */
     429    wp_update_user( array( 'ID' => $user_id, 'user_url' => bp_core_get_user_domain( $user_id, sanitize_title( $user_login ), $user_login ), 'display_name' => bp_core_get_user_displayname( $user_id ) ) );
    237430
    238431    /* Add a last active entry */
    239432    update_usermeta( $user_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
    240433
    241     wp_new_user_notification( $user_id, $user_pass );
     434    /* Set the password on multisite installs */
     435    if ( bp_core_is_multisite() && !empty( $user['meta']['password'] ) )
     436        $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_pass = %s WHERE ID = %d", $user['meta']['password'], $user_id ) );
     437
     438    /* Delete the total member cache */
    242439    wp_cache_delete( 'bp_total_member_count', 'bp' );
    243440
    244     $bp->signup->username = $user_login;
    245 
    246     do_action( 'bp_core_signup_user', $user_id, $user_login, $user_password, $user_email, $usermeta );
     441    do_action( 'bp_core_activated_user', $user_id, $key, $user );
    247442
    248443    return $user_id;
    249444}
     445
     446function bp_core_new_user_activity( $user ) {
     447    if ( empty( $user ) || !function_exists( 'bp_activity_add' ) )
     448        return false;
     449
     450    if ( is_array( $user ) )
     451        $user_id = $user['user_id'];
     452    else
     453        $user_id = $user;
     454
     455    if ( empty( $user_id ) )
     456        return false;
     457
     458    $userlink = bp_core_get_userlink( $user_id );
     459
     460    bp_activity_add( array(
     461        'user_id' => $user_id,
     462        'action' => apply_filters( 'bp_core_activity_registered_member_action', sprintf( __( '%s became a registered member', 'buddypress' ), $userlink ), $user_id ),
     463        'component' => 'profile',
     464        'type' => 'new_member'
     465    ) );
     466}
     467add_action( 'bp_core_activated_user', 'bp_core_new_user_activity' );
    250468
    251469function bp_core_map_user_registration( $user_id ) {
     
    290508}
    291509
     510function bp_core_signup_send_validation_email( $user_id, $key ) {
     511    $activate_url = bp_get_activation_page() ."?key=$key";
     512    $activate_url = clean_url( $activate_url );
     513    $admin_email = get_site_option( "admin_email" );
     514
     515    if ( empty( $admin_email ) )
     516        $admin_email = 'noreply@' . $_SERVER['SERVER_NAME'];
     517
     518    $from_name = ( '' == get_option( 'blogname' ) ) ? 'BuddyPress' : wp_specialchars( get_option( 'blogname' ) );
     519    $message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option( 'blog_charset' ) . "\"\n";
     520    $message = sprintf( __( "Thanks for registering! To complete the activation of your account please click the following link:\n\n%s\n\n", 'buddypress' ), $activate_url );
     521    $subject = '[' . $from_name . '] ' . __( 'Activate Your Account', 'buddypress' );
     522
     523    /* Send the message */
     524    $to = apply_filters( 'bp_core_activation_signup_user_notification_to', $user_email );
     525    $subject = apply_filters( 'bp_core_activation_signup_user_notification_subject', $subject );
     526    $message = apply_filters( 'bp_core_activation_signup_user_notification_message', $message );
     527
     528    wp_mail( $to, $subject, $message, $message_headers );
     529}
     530
     531/* Stop user accounts logging in that have not been activated (user_status = 2) */
     532function bp_core_signup_disable_inactive( $auth_obj, $username ) {
     533    global $bp, $wpdb;
     534
     535    if ( !$user_id = bp_core_get_userid( $username ) )
     536        return $auth_obj;
     537
     538    $user_status = (int) $wpdb->get_var( $wpdb->prepare( "SELECT user_status FROM $wpdb->users WHERE ID = %d", $user_id ) );
     539
     540    if ( 2 == $user_status )
     541        bp_core_redirect( $bp->root_domain );
     542    else
     543        return $auth_obj;
     544}
     545add_filter( 'authenticate', 'bp_core_signup_disable_inactive', 11, 2 );
     546
    292547/* Kill the wp-signup.php if custom registration signup templates are present */
    293548function bp_core_wpsignup_redirect() {
  • branches/1.2/bp-core/bp-core-templatetags.php

    r2820 r2832  
    11841184        extract( $r, EXTR_SKIP );
    11851185
    1186         if ( !bp_core_is_multisite() && !empty( $_POST['signup_username'] ) ) {
    1187             $user_id = bp_core_get_userid( $_POST['signup_username'] );
    1188             return apply_filters( 'bp_get_signup_avatar', bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'full', 'width' => $size, 'height' => $size, 'alt' => $alt, 'class' => $class ) ) );
     1186        $signup_avatar_dir = ( !empty( $_POST['signup_avatar_dir'] ) ) ? $_POST['signup_avatar_dir'] : $bp->signup->avatar_dir;
     1187
     1188        if ( empty( $signup_avatar_dir ) ) {
     1189            if ( empty( $bp->grav_default->user ) ) {
     1190                $default_grav = 'wavatar';
     1191            } else if ( 'mystery' == $bp->grav_default->user ) {
     1192                $default_grav = BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg';
     1193            } else {
     1194                $default_grav = $bp->grav_default->user;
     1195            }
     1196
     1197            $gravatar_url = apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' );
     1198            return apply_filters( 'bp_get_signup_avatar', '<img src="' . $gravatar_url . md5( $_POST['signup_email'] ) . '?d=' . $default_grav . '&amp;s=' . $size ) . '" width="' . $size . '" height="' . $size . '" alt="' . $alt . '" class="' . $class . '" />';
    11891199        } else {
    1190             $signup_avatar_dir = ( !empty( $_POST['signup_avatar_dir'] ) ) ? $_POST['signup_avatar_dir'] : $bp->signup->avatar_dir;
    1191 
    1192             if ( empty( $signup_avatar_dir ) ) {
    1193                 if ( empty( $bp->grav_default->user ) ) {
    1194                     $default_grav = 'wavatar';
    1195                 } else if ( 'mystery' == $bp->grav_default->user ) {
    1196                     $default_grav = BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg';
    1197                 } else {
    1198                     $default_grav = $bp->grav_default->user;
    1199                 }
    1200 
    1201                 $gravatar_url = apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' );
    1202                 return apply_filters( 'bp_get_signup_avatar', '<img src="' . $gravatar_url . md5( $_POST['signup_email'] ) . '?d=' . $default_grav . '&amp;s=' . $size ) . '" width="' . $size . '" height="' . $size . '" alt="' . $alt . '" class="' . $class . '" />';
    1203             } else {
    1204                 return apply_filters( 'bp_get_signup_avatar', bp_core_fetch_avatar( array( 'item_id' => $signup_avatar_dir, 'object' => 'signup', 'avatar_dir' => 'avatars/signups', 'type' => 'full', 'width' => $size, 'height' => $size, 'alt' => $alt, 'class' => $class ) ) );
    1205             }
     1200            return apply_filters( 'bp_get_signup_avatar', bp_core_fetch_avatar( array( 'item_id' => $signup_avatar_dir, 'object' => 'signup', 'avatar_dir' => 'avatars/signups', 'type' => 'full', 'width' => $size, 'height' => $size, 'alt' => $alt, 'class' => $class ) ) );
    12061201        }
    12071202    }
     
    12461241
    12471242function bp_registration_needs_activation() {
    1248     return apply_filters( 'bp_registration_needs_activation', bp_core_is_multisite() );
     1243    return apply_filters( 'bp_registration_needs_activation', true );
    12491244}
    12501245
  • branches/1.2/bp-core/bp-core-wpabstraction.php

    r2752 r2832  
    9090    }
    9191}
    92 
    93 if ( !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 }
  • branches/1.2/bp-loader.php

    r2776 r2832  
    55Description: Social networking in a box. Build a social network for your company, school, sports team or niche community all based on the power and flexibility of WordPress.
    66Author: The BuddyPress Community
    7 Version: 1.2.1
     7Version: 1.2.2
    88Author URI: http://buddypress.org/developers/
    99Site Wide Only: true
    1010*/
    1111
    12 define( 'BP_VERSION', '1.2.1' );
     12define( 'BP_VERSION', '1.2.2' );
    1313
    1414/***
  • branches/1.2/bp-themes/bp-default/style.css

    r2776 r2832  
    33Theme URI: http://buddypress.org/extend/themes/
    44Description: The default theme for BuddyPress.
    5 Version: 1.2.1
     5Version: 1.2.2
    66Author: BuddyPress.org
    77Author URI: http://buddypress.org
Note: See TracChangeset for help on using the changeset viewer.