Skip to:
Content

BuddyPress.org

Changeset 8119


Ignore:
Timestamp:
03/13/2014 12:58:28 AM (11 years ago)
Author:
imath
Message:

Introduce Sign Ups Management

In Users Administration Screen, a new view is now available to manage the pending accounts of a site or of the network of sites. The following actions are supported:

  • Resend the activation email
  • Delete the pending account
  • Activate the pending account

The corresponding bulk actions are also supported. A search box is available in order to let the administrator easily find some specific pending accounts.

The registration process have also been modified so that multisite and regular configs handles it in a similar way. A mechnanism is in place to ensure plugin backward compatibility concerning the regular configs.

See #5374

props boonebgorges, imath

Fixes #4651

Location:
trunk
Files:
3 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/admin/bp-core-functions.php

    r8117 r8119  
    277277            'name' => __( 'Register', 'buddypress' )
    278278        );
     279
     280        bp_core_maybe_install_signups();
    279281    }
    280282
     
    791793<?php
    792794}
     795
     796/**
     797 * Check if the signups table needs to be created.
     798 *
     799 * @since BuddyPress (2.0.0)
     800 *
     801 * @global $wpdb
     802 */
     803function bp_core_maybe_install_signups() {
     804    global $wpdb;
     805
     806    // Multisite installations already have the signups table.
     807    if ( ! empty( $wpdb->signups ) ) {
     808        return;
     809    }
     810
     811    $bp_signups = bp_core_get_table_prefix() . 'signups';
     812
     813    // Check for the table
     814    $suppress = $wpdb->suppress_errors();
     815    $table_exists = $wpdb->get_results( "DESCRIBE {$bp_signups};" );
     816    $wpdb->suppress_errors( $suppress );
     817
     818    // Bail if the table exists
     819    if ( ! empty( $table_exists ) ) {
     820        return;
     821    }
     822
     823    // Signups is not there and we need it so let's create it
     824    require_once( buddypress()->plugin_dir . '/bp-core/admin/bp-core-schema.php' );
     825
     826    bp_core_install_signups();
     827}
  • trunk/bp-core/admin/bp-core-schema.php

    r7860 r8119  
    5151    if ( !empty( $active_components['blogs'] ) )
    5252        bp_core_install_blog_tracking();
     53
     54    // Install the signups table
     55    if ( bp_get_signup_allowed() )
     56        bp_core_install_signups();
     57
    5358}
    5459
     
    344349    dbDelta( $sql );
    345350}
     351
     352/**
     353 * Install the signups table.
     354 *
     355 * @since BuddyPress (2.0.0)
     356 *
     357 * @global $wpdb
     358 * @uses wp_get_db_schema() to get WordPress ms_global schema
     359 */
     360function bp_core_install_signups() {
     361    global $wpdb;
     362
     363    // Multisite installations already have the signups table
     364    if ( ! empty( $wpdb->signups ) ) {
     365        return;
     366    }
     367
     368    $wpdb->signups = bp_core_get_table_prefix() . 'signups';
     369
     370    // Setting the charset to be sure WordPress upgrade.php is loaded
     371    $charset_collate = bp_core_set_charset();
     372
     373    // Use WP's core CREATE TABLE query
     374    $create_queries = wp_get_db_schema( 'ms_global' );
     375
     376    if ( ! is_array( $create_queries ) ) {
     377        $create_queries = explode( ';', $create_queries );
     378        $create_queries = array_filter( $create_queries );
     379    }
     380
     381    // Filter out all the queries except wp_signups
     382    foreach ( $create_queries as $key => $query ) {
     383        if ( preg_match( "|CREATE TABLE ([^ ]*)|", $query, $matches ) ) {
     384            if ( $wpdb->signups != trim( $matches[1], '`' ) ) {
     385                unset( $create_queries[ $key ] );
     386            }
     387        }
     388    }
     389
     390    if ( ! empty( $create_queries ) ) {
     391        dbDelta( $create_queries );
     392    }
     393}
  • trunk/bp-core/bp-core-update.php

    r7989 r8119  
    366366    $wpdb->query( $sql );
    367367
     368    /** Migrate signups data *********************************************/
     369
     370    if ( bp_get_signup_allowed() && ! is_multisite() ) {
     371
     372        if ( empty( $wpdb->signups ) ) {
     373            bp_core_install_signups();
     374        }
     375
     376        $signups = get_users( array(
     377            'fields'       => 'all_with_meta',
     378            'meta_key'     => 'activation_key',
     379            'meta_compare' => 'EXISTS',
     380        ) );
     381
     382        if ( empty( $signups ) ) {
     383            return;
     384        }
     385
     386        foreach ( $signups as $signup ) {
     387            $meta = array();
     388
     389            if ( bp_is_active( 'xprofile' ) ) {
     390                $meta['field_1'] = $signup->display_name;
     391            }
     392
     393            $meta['password'] = $signup->user_pass;
     394
     395            $user_login = preg_replace( '/\s+/', '', sanitize_user( $signup->user_login, true ) );
     396            $user_email = sanitize_email( $signup->user_email );
     397
     398            $args = array(
     399                'user_login'     => $user_login,
     400                'user_email'     => $user_email,
     401                'registered'     => $signup->user_registered,
     402                'activation_key' => $signup->activation_key,
     403                'meta'           => $meta
     404            );
     405
     406            BP_Signup::add( $args );
     407
     408            // Deleting these options will remove signups from users count
     409            delete_user_option( $signup->ID, 'capabilities' );
     410            delete_user_option( $signup->ID, 'user_level' );
     411        }
     412    }
     413
    368414    /** Add BP options to the options table ******************************/
    369415    bp_add_options();
  • trunk/bp-members/bp-members-admin.php

    r8030 r8119  
    117117        // BuddyPress edit user's profile url
    118118        $this->edit_profile_url = add_query_arg( 'page', 'bp-profile-edit', bp_get_admin_url( 'users.php' ) );
     119
     120        // Data specific to signups
     121        $this->users_page   = '';
     122        $this->signups_page = '';
     123        $this->users_url    = bp_get_admin_url( 'users.php' );
     124        $this->users_screen = bp_core_do_network_admin() ? 'users-network' : 'users';
    119125    }
    120126
     
    127133    private function setup_actions() {
    128134
    129         /** Actions ***************************************************/
     135        /** Community Profile ***************************************************/
    130136
    131137        // Add some page specific output to the <head>
     
    141147        add_action( 'edit_user_profile',        array( $this, 'profile_nav'     ),  99, 1 );
    142148
    143 
    144         /** Filters ***************************************************/
    145 
    146149        // Add a row action to users listing
    147150        add_filter( bp_core_do_network_admin() ? 'ms_user_row_actions' : 'user_row_actions', array( $this, 'row_actions' ), 10, 2 );
    148151
    149     }
    150 
    151     /**
    152      * Create the All Users > Edit Profile submenu.
     152        /** Signups **************************************************************/
     153
     154        if ( bp_get_signup_allowed() ) {
     155            if ( ! is_multisite() && is_admin() ) {
     156                add_action( 'pre_user_query', array( $this, 'remove_signups_from_user_query'),  10, 1 );
     157            }
     158
     159            // Reorganise the views navigation in users.php and signups page
     160            add_filter( "views_{$this->users_screen}", array( $this, 'signup_filter_view' ),    10, 1 );
     161            add_filter( 'set-screen-option',           array( $this, 'signup_screen_options' ), 10, 3 );
     162        }
     163    }
     164
     165    /**
     166     * Create the All Users > Edit Profile and Signups submenus.
    153167     *
    154168     * @access public
     
    160174
    161175        // Manage user's profile
    162         $hook = $this->user_page = add_users_page(
     176        $hooks['user'] = $this->user_page = add_users_page(
    163177            __( 'Edit Profile',  'buddypress' ),
    164178            __( 'Edit Profile',  'buddypress' ),
     
    168182        );
    169183
     184        $hooks['signups'] = $this->users_page = add_users_page(
     185            __( 'Manage Signups',  'buddypress' ),
     186            __( 'Manage Signups',  'buddypress' ),
     187            'bp_moderate',
     188            'bp-signups',
     189            array( &$this, 'signups_admin' )
     190        );
     191
    170192        $edit_page = 'user-edit';
     193        $this->users_page = 'users';
    171194
    172195        if ( bp_core_do_network_admin() ) {
    173             $edit_page       .= '-network';
    174             $this->user_page .= '-network';
     196            $edit_page          .= '-network';
     197            $this->users_page   .= '-network';
     198            $this->user_page    .= '-network';
     199            $this->signups_page .= '-network';
    175200        }
    176201
    177202        $this->screen_id = array( $edit_page, $this->user_page );
    178203
    179         add_action( "admin_head-$hook", array( $this, 'modify_admin_menu_highlight' ) );
    180         add_action( "load-$hook",       array( $this, 'user_admin_load' ) );
    181 
    182     }
     204        foreach ( $hooks as $key => $hook ) {
     205            add_action( "admin_head-$hook", array( $this, 'modify_admin_menu_highlight' ) );
     206            add_action( "load-$hook",       array( $this, $key . '_admin_load' ) );
     207        }
     208
     209    }
     210
     211    /**
     212     * Highlight the Users menu if on Edit Profile or Signups pages.
     213     *
     214     * @access public
     215     * @since BuddyPress (2.0.0)
     216     */
     217    public function modify_admin_menu_highlight() {
     218        global $plugin_page, $submenu_file;
     219
     220        // Only Show the All users menu
     221        if ( in_array( $plugin_page, array( 'bp-profile-edit', 'bp-signups' ) ) ) {
     222            $submenu_file = 'users.php';
     223        }
     224    }
     225
     226    /**
     227     * Remove the Edit Profile & Signups submenu page.
     228     *
     229     * We add these pages in order to integrate with WP's Users panel, but
     230     * we want them to show up as Views of the WP panel, not as separate
     231     * subnav items under the Users menu.
     232     *
     233     * @access public
     234     * @since BuddyPress (2.0.0)
     235     */
     236    public function admin_head() {
     237        // Remove submenu to force using Profile Navigation
     238        remove_submenu_page( 'users.php', 'bp-profile-edit' );
     239
     240        // Remove submenu to force using users views
     241        remove_submenu_page( 'users.php', 'bp-signups' );
     242    }
     243
     244    /** Community Profile ************************************************/
    183245
    184246    /**
     
    246308
    247309        <?php
    248     }
    249 
    250     /**
    251      * Highlight the Users menu if on Edit Profile pages.
    252      *
    253      * @access public
    254      * @since BuddyPress (2.0.0)
    255      */
    256     public function modify_admin_menu_highlight() {
    257         global $plugin_page, $submenu_file;
    258 
    259         // Only Show the All users menu
    260         if ( 'bp-profile-edit' ==  $plugin_page ) {
    261             $submenu_file = 'users.php';
    262         }
    263     }
    264 
    265     /**
    266      * Remove the Edit Profile submenu page.
    267      *
    268      * @access public
    269      * @since BuddyPress (2.0.0)
    270      */
    271     public function admin_head() {
    272         // Remove submenu to force using Profile Navigation
    273         remove_submenu_page( 'users.php', 'bp-profile-edit' );
    274310    }
    275311
     
    691727        return array_merge( $new_edit_actions, $actions );
    692728    }
     729
     730    /** Signups Management ***********************************************/
     731
     732    /**
     733     * Display the admin preferences about signups pagination.
     734     *
     735     * @access public
     736     * @since BuddyPress (2.0.0)
     737     *
     738     * @param  int $value
     739     * @param  string $option
     740     * @param  int $new_value
     741     * @return int the pagination preferences
     742     */
     743    public function signup_screen_options( $value = 0, $option = '', $new_value = 0 ) {
     744        if ( 'users_page_bp_signups_network_per_page' != $option && 'users_page_bp_signups_per_page' != $option ) {
     745            return $value;
     746        }
     747
     748        // Per page
     749        $new_value = (int) $new_value;
     750        if ( $new_value < 1 || $new_value > 999 ) {
     751            return $value;
     752        }
     753
     754        return $new_value;
     755    }
     756
     757    /**
     758     * Make sure no signups will show in users list.
     759     *
     760     * This is needed to handle signups that may have not been activated
     761     * before the 2.0.0 upgrade.
     762     *
     763     * @since BuddyPress (2.0.0)
     764     *
     765     * @param  WP_User_Query $query The users query.
     766     * @return WP_User_Query The users query without the signups.
     767     */
     768    public function remove_signups_from_user_query( $query = null ) {
     769        global $wpdb;
     770
     771        // Bail if this is an ajax request
     772        if ( defined( 'DOING_AJAX' ) )
     773            return;
     774
     775        if ( bp_is_update() ) {
     776            return;
     777        }
     778
     779        if ( $this->users_page != get_current_screen()->id ) {
     780            return;
     781        }
     782
     783        if ( ! empty( $query->query_vars['role'] ) ) {
     784            return;
     785        }
     786
     787        $query->query_where .= " AND {$wpdb->users}.user_status != 2";
     788    }
     789
     790    /**
     791     * Filter the WP Users List Table views to include 'bp-signups'.
     792     *
     793     * @since BuddyPress (2.0.0)
     794     *
     795     * @param  array $views WP List Table views.
     796     * @return array The views with the signup view added.
     797     */
     798    public function signup_filter_view( $views = array() ) {
     799        $class = '';
     800
     801        $signups = BP_Signup::count_signups();
     802
     803        // Remove the 'current' class from All if we're on the signups
     804        // view
     805        if ( $this->signups_page == get_current_screen()->id ) {
     806            $views['all'] = str_replace( 'class="current"', '', $views['all'] );
     807            $class = ' class="current"';
     808        }
     809
     810        $views['registered'] = '<a href="' . add_query_arg( 'page', 'bp-signups', bp_get_admin_url( 'users.php' ) ) . '"' . $class . '>' . sprintf( _nx( 'Pending account <span class="count">(%s)</span>', 'Pending accounts <span class="count">(%s)</span>', $signups, 'signup users', 'buddypress' ), number_format_i18n( $signups ) ) . '</a>';
     811
     812        return $views;
     813    }
     814
     815    /**
     816     * Load the Signup WP Users List table.
     817     *
     818     * @since BuddyPress (2.0.0)
     819     *
     820     * @param  string $class    The name of the class to use.
     821     * @param  string $required The parent class.
     822     * @return WP_List_Table    The List table.
     823     */
     824    public static function get_list_table_class( $class = '', $required = '' ) {
     825        if ( empty( $class ) ) {
     826            return;
     827        }
     828
     829        if ( ! empty( $required ) ) {
     830            require_once( ABSPATH . 'wp-admin/includes/class-wp-' . $required . '-list-table.php' );
     831            require_once( buddypress()->members->admin->admin_dir . 'bp-members-classes.php'    );
     832        }
     833
     834        return new $class();
     835    }
     836
     837    /**
     838     * Set up the signups admin page.
     839     *
     840     * Loaded before the page is rendered, this function does all initial
     841     * setup, including: processing form requests, registering contextual
     842     * help, and setting up screen options.
     843     *
     844     * @since BuddyPress (2.0.0)
     845     *
     846     * @global $bp_members_signup_list_table
     847     */
     848    public function signups_admin_load() {
     849        global $bp_members_signup_list_table;
     850
     851        // Build redirection URL
     852        $redirect_to = remove_query_arg( array( 'action', 'error', 'updated', 'activated', 'notactivated', 'deleted', 'notdeleted', 'resent', 'notresent', 'do_delete', 'do_resend', 'do_activate', '_wpnonce', 'signup_ids' ), $_SERVER['REQUEST_URI'] );
     853        $doaction = bp_admin_list_table_current_bulk_action();
     854
     855        // Call an action for plugins to hook in early
     856        do_action( 'bp_signups_admin_load', $doaction, $_REQUEST );
     857
     858        // Allowed actions
     859        $allowed_actions = apply_filters( 'bp_signups_admin_allowed_actions', array( 'do_delete', 'do_activate', 'do_resend' ) );
     860
     861        // Prepare the display of the Community Profile screen
     862        if ( ! in_array( $doaction, $allowed_actions ) || -1 == $doaction ) {
     863
     864            if ( bp_core_do_network_admin() ) {
     865                $bp_members_signup_list_table = self::get_list_table_class( 'BP_Members_MS_List_Table', 'ms-users' );
     866            } else {
     867                $bp_members_signup_list_table = self::get_list_table_class( 'BP_Members_List_Table', 'users' );
     868            }
     869
     870            // per_page screen option
     871            add_screen_option( 'per_page', array( 'label' => _x( 'Pending Accounts', 'Pending Accounts per page (screen options)', 'buddypress' ) ) );
     872
     873            get_current_screen()->add_help_tab( array(
     874                'id'      => 'bp-signups-overview',
     875                'title'   => __( 'Overview', 'buddypress' ),
     876                'content' =>
     877                '<p>' . __( 'This is the admininistration screen for pending accounts on your site.', 'buddypress' ) . '</p>' .
     878                '<p>' . __( 'From the screen options, you can customize the displayed columns and the pagination of this screen.', 'buddypress' ) . '</p>' .
     879                '<p>' . __( 'You can reorder the list of your pending accounts by clicking on the Username, E-mail or Registered column headers.', 'buddypress' ) . '</p>' .
     880                '<p>' . __( 'Using the search form, you can find pending accounts more easily. The Username and E-mail fields will be included in the search.', 'buddypress' ) . '</p>'
     881            ) );
     882
     883            get_current_screen()->add_help_tab( array(
     884                'id'      => 'bp-signups-actions',
     885                'title'   => __( 'Actions', 'buddypress' ),
     886                'content' =>
     887                '<p>' . __( 'Hovering over a row in the pending accounts list will display action links that allow you to manage pending accounts. You can perform the following actions:', 'buddypress' ) . '</p>' .
     888                '<ul><li>' . __( '"Email" takes you to the confirmation screen before being able to send the activation link to the desired pending account. You can only send the activation email once per day.', 'buddypress' ) . '</li>' .
     889                '<li>' . __( '"Delete" allows you to delete a pending account from your site. You will be asked to confirm this deletion.', 'buddypress' ) . '</li></ul>' .
     890                '<p>' . __( 'By clicking on a Username you will be able to activate a pending account from the confirmation screen.', 'buddypress' ) . '</p>' .
     891                '<p>' . __( 'Bulk actions allow you to perform these 3 actions for the selected rows.', 'buddypress' ) . '</p>'
     892            ) );
     893
     894            // Help panel - sidebar links
     895            get_current_screen()->set_help_sidebar(
     896                '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
     897                '<p>' . __( '<a href="http://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
     898            );
     899        } else {
     900            if ( ! empty( $_REQUEST['signup_ids' ] ) ) {
     901                $signups = wp_parse_id_list( $_REQUEST['signup_ids' ] );
     902            }
     903
     904            // Handle resent activation links
     905            if ( 'do_resend' == $doaction ) {
     906                // nonce check
     907                check_admin_referer( 'signups_resend' );
     908
     909                $resent = BP_Signup::resend( $signups );
     910
     911                if ( empty( $resent ) ) {
     912                    $redirect_to = add_query_arg( 'error', $doaction, $redirect_to );
     913                } else {
     914                    $query_arg = array( 'updated' => 'resent' );
     915
     916                    if ( ! empty( $resent['resent'] ) ) {
     917                        $query_arg['resent'] = count( $resent['resent'] );
     918                    }
     919
     920                    if ( ! empty( $resent['errors'] ) ) {
     921                        $query_arg['notsent'] = count( $resent['errors'] );
     922                        set_transient( '_bp_admin_signups_errors', $resent['errors'], 30 );
     923                    }
     924
     925                    $redirect_to = add_query_arg( $query_arg, $redirect_to );
     926                }
     927
     928                bp_core_redirect( $redirect_to );
     929
     930            // Handle activated accounts
     931            } else if ( 'do_activate' == $doaction ) {
     932                // nonce check
     933                check_admin_referer( 'signups_activate' );
     934
     935                $activated = BP_Signup::activate( $signups );
     936
     937                if ( empty( $activated ) ) {
     938                    $redirect_to = add_query_arg( 'error', $doaction, $redirect_to );
     939                } else {
     940                    $query_arg = array( 'updated' => 'activated' );
     941
     942                    if ( ! empty( $activated['activated'] ) ) {
     943                        $query_arg['activated'] = count( $activated['activated'] );
     944                    }
     945
     946                    if ( ! empty( $activated['errors'] ) ) {
     947                        $query_arg['notactivated'] = count( $activated['errors'] );
     948                        set_transient( '_bp_admin_signups_errors', $activated['errors'], 30 );
     949                    }
     950
     951                    $redirect_to = add_query_arg( $query_arg, $redirect_to );
     952                }
     953
     954                bp_core_redirect( $redirect_to );
     955
     956            // Handle sign-ups delete
     957            } else if ( 'do_delete' == $doaction ) {
     958                // nonce check
     959                check_admin_referer( 'signups_delete' );
     960
     961                $deleted = BP_Signup::delete( $signups );
     962
     963                if ( empty( $deleted ) ) {
     964                    $redirect_to = add_query_arg( 'error', $doaction, $redirect_to );
     965                } else {
     966                    $query_arg = array( 'updated' => 'deleted' );
     967
     968                    if ( ! empty( $deleted['deleted'] ) ) {
     969                        $query_arg['deleted'] = count( $deleted['deleted'] );
     970                    }
     971
     972                    if ( ! empty( $deleted['errors'] ) ) {
     973                        $query_arg['notdeleted'] = count( $deleted['errors'] );
     974                        set_transient( '_bp_admin_signups_errors', $deleted['errors'], 30 );
     975                    }
     976
     977                    $redirect_to = add_query_arg( $query_arg, $redirect_to );
     978                }
     979
     980                bp_core_redirect( $redirect_to );
     981
     982            // Plugins can update other stuff from here
     983            } else {
     984                $this->redirect = $redirect_to;
     985
     986                do_action( 'bp_members_admin_update_signups', $doaction, $_REQUEST, $this->redirect );
     987
     988                bp_core_redirect( $this->redirect );
     989            }
     990        }
     991    }
     992
     993    /**
     994     * Display any activation errors.
     995     *
     996     * @since BuddyPress (2.0.0)
     997     */
     998    public function signups_display_errors() {
     999        // Bail if no activation errors
     1000        if ( ! $errors = get_transient( '_bp_admin_signups_errors' ) ) {
     1001            return;
     1002        }
     1003
     1004        foreach ( $errors as $error ) {
     1005            ?>
     1006            <li><?php echo esc_html( $error[0] );?>: <?php echo esc_html( $error[1] );?></li>
     1007            <?php
     1008        }
     1009
     1010        // Delete the redirect transient
     1011        delete_transient( '_bp_admin_signups_errors' );
     1012    }
     1013
     1014    /**
     1015     * Signups admin page router.
     1016     *
     1017     * Depending on the context, display
     1018     * - the list of signups
     1019     * - or the delete confirmation screen
     1020     * - or the activate confirmation screen
     1021     * - or the "resend" email confirmation screen
     1022     *
     1023     * Also prepare the admin notices.
     1024     *
     1025     * @since BuddyPress (2.0.0)
     1026     */
     1027    public function signups_admin() {
     1028        $doaction = bp_admin_list_table_current_bulk_action();
     1029
     1030        // Prepare notices for admin
     1031        $notice = array();
     1032
     1033        if ( ! empty( $_REQUEST['updated'] ) ) {
     1034            switch ( $_REQUEST['updated'] ) {
     1035                case 'resent':
     1036                    $notice = array(
     1037                        'class'   => 'updated',
     1038                        'message' => ''
     1039                    );
     1040
     1041                    if ( ! empty( $_REQUEST['resent'] ) ) {
     1042                        $notice['message'] .= sprintf(
     1043                            _nx( '%s activation email successfully sent! ', '%s activation emails successfully sent! ',
     1044                             absint( $_REQUEST['resent'] ),
     1045                             'signup resent',
     1046                             'buddypress'
     1047                            ),
     1048                            number_format_i18n( absint( $_REQUEST['resent'] ) )
     1049                        );
     1050                    }
     1051
     1052                    if ( ! empty( $_REQUEST['notsent'] ) ) {
     1053                        $notice['message'] .= sprintf(
     1054                            _nx( '%s activation email was not sent.', '%s activation emails were not sent.',
     1055                             absint( $_REQUEST['notsent'] ),
     1056                             'signup notsent',
     1057                             'buddypress'
     1058                            ),
     1059                            number_format_i18n( absint( $_REQUEST['notsent'] ) )
     1060                        );
     1061
     1062                        if ( empty( $_REQUEST['resent'] ) ) {
     1063                            $notice['class'] = 'error';
     1064                        }
     1065                    }
     1066
     1067                    break;
     1068
     1069                case 'activated':
     1070                    $notice = array(
     1071                        'class'   => 'updated',
     1072                        'message' => ''
     1073                    );
     1074
     1075                    if ( ! empty( $_REQUEST['activated'] ) ) {
     1076                        $notice['message'] .= sprintf(
     1077                            _nx( '%s account successfully activated! ', '%s accounts successfully activated! ',
     1078                             absint( $_REQUEST['activated'] ),
     1079                             'signup resent',
     1080                             'buddypress'
     1081                            ),
     1082                            number_format_i18n( absint( $_REQUEST['activated'] ) )
     1083                        );
     1084                    }
     1085
     1086                    if ( ! empty( $_REQUEST['notactivated'] ) ) {
     1087                        $notice['message'] .= sprintf(
     1088                            _nx( '%s account was not activated.', '%s accounts were not activated.',
     1089                             absint( $_REQUEST['notactivated'] ),
     1090                             'signup notsent',
     1091                             'buddypress'
     1092                            ),
     1093                            number_format_i18n( absint( $_REQUEST['notactivated'] ) )
     1094                        );
     1095
     1096                        if ( empty( $_REQUEST['activated'] ) ) {
     1097                            $notice['class'] = 'error';
     1098                        }
     1099                    }
     1100
     1101                    break;
     1102
     1103                case 'deleted':
     1104                    $notice = array(
     1105                        'class'   => 'updated',
     1106                        'message' => ''
     1107                    );
     1108
     1109                    if ( ! empty( $_REQUEST['deleted'] ) ) {
     1110                        $notice['message'] .= sprintf(
     1111                            _nx( '%s sign-up successfully deleted!', '%s sign-ups successfully deleted!',
     1112                             absint( $_REQUEST['deleted'] ),
     1113                             'signup deleted',
     1114                             'buddypress'
     1115                            ),
     1116                            number_format_i18n( absint( $_REQUEST['deleted'] ) )
     1117                        );
     1118                    }
     1119
     1120                    if ( ! empty( $_REQUEST['notdeleted'] ) ) {
     1121                        $notice['message'] .= sprintf(
     1122                            _nx( '%s sign-up was not deleted.', '%s sign-ups were not deleted.',
     1123                             absint( $_REQUEST['notdeleted'] ),
     1124                             'signup notdeleted',
     1125                             'buddypress'
     1126                            ),
     1127                            number_format_i18n( absint( $_REQUEST['notdeleted'] ) )
     1128                        );
     1129
     1130                        if ( empty( $_REQUEST['deleted'] ) ) {
     1131                            $notice['class'] = 'error';
     1132                        }
     1133                    }
     1134
     1135                    break;
     1136            }
     1137        }
     1138
     1139        // Process error messages
     1140        if ( ! empty( $_REQUEST['error'] ) ) {
     1141            switch ( $_REQUEST['error'] ) {
     1142                case 'do_resend':
     1143                    $notice = array(
     1144                        'class'   => 'error',
     1145                        'message' => esc_html__( 'There was a problem sending the activation emails, please try again.', 'buddypress' ),
     1146                    );
     1147                    break;
     1148
     1149                case 'do_activate':
     1150                    $notice = array(
     1151                        'class'   => 'error',
     1152                        'message' => esc_html__( 'There was a problem activating accounts, please try again.', 'buddypress' ),
     1153                    );
     1154                    break;
     1155
     1156                case 'do_delete':
     1157                    $notice = array(
     1158                        'class'   => 'error',
     1159                        'message' => esc_html__( 'There was a problem deleting sign-ups, please try again.', 'buddypress' ),
     1160                    );
     1161                    break;
     1162            }
     1163        }
     1164
     1165        // Display notices
     1166        if ( ! empty( $notice ) ) :
     1167            if ( 'updated' === $notice['class'] ) : ?>
     1168                <div id="message" class="<?php echo esc_attr( $notice['class'] ); ?>">
     1169            <?php else: ?>
     1170                <div class="<?php echo esc_attr( $notice['class'] ); ?>">
     1171            <?php endif; ?>
     1172                <p><?php echo $notice['message']; ?></p>
     1173                <?php if ( ! empty( $_REQUEST['notactivated'] ) || ! empty( $_REQUEST['notdeleted'] ) || ! empty( $_REQUEST['notsent'] ) ) :?>
     1174                    <ul><?php $this->signups_display_errors();?></ul>
     1175                <?php endif ;?>
     1176            </div>
     1177        <?php endif;
     1178
     1179        // Show the proper screen
     1180        switch ( $doaction ) {
     1181            case 'activate' :
     1182            case 'delete' :
     1183            case 'resend' :
     1184                $this->signups_admin_manage( $doaction );
     1185                break;
     1186
     1187            default:
     1188                $this->signups_admin_index();
     1189                break;
     1190
     1191        }
     1192    }
     1193
     1194    /**
     1195     * This is the list of the Pending accounts (signups).
     1196     *
     1197     * @since BuddyPress (2.0.0)
     1198     *
     1199     * @global $plugin_page
     1200     * @global $bp_members_signup_list_table
     1201     */
     1202    public function signups_admin_index() {
     1203        global $plugin_page, $bp_members_signup_list_table;
     1204
     1205        $usersearch = ! empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';
     1206
     1207        // Prepare the group items for display
     1208        $bp_members_signup_list_table->prepare_items();
     1209
     1210        $form_url = add_query_arg(
     1211            array(
     1212                'page' => 'bp-signups',
     1213            ),
     1214            bp_get_admin_url( 'users.php' )
     1215        );
     1216
     1217        $search_form_url = remove_query_arg(
     1218            array(
     1219                'action',
     1220                'deleted',
     1221                'notdeleted',
     1222                'error',
     1223                'updated',
     1224                'delete',
     1225                'activate',
     1226                'activated',
     1227                'notactivated',
     1228                'resend',
     1229                'resent',
     1230                'notresent',
     1231                'do_delete',
     1232                'do_activate',
     1233                'do_resend',
     1234                'action2',
     1235                '_wpnonce',
     1236                'signup_ids'
     1237            ), $_SERVER['REQUEST_URI']
     1238        );
     1239
     1240        ?>
     1241
     1242        <div class="wrap">
     1243            <?php screen_icon( 'users' ); ?>
     1244            <h2>
     1245                <?php
     1246                _e( 'Users', 'buddypress' );
     1247                if ( current_user_can( 'create_users' ) ) { ?>
     1248                    <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'user' ); ?></a>
     1249                <?php } elseif ( is_multisite() && current_user_can( 'promote_users' ) ) { ?>
     1250                    <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add Existing', 'user' ); ?></a>
     1251                <?php }
     1252
     1253                if ( $usersearch ) {
     1254                    printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( $usersearch ) );
     1255                }
     1256
     1257                ?>
     1258            </h2>
     1259
     1260            <?php // Display each signups on its own row ?>
     1261            <?php $bp_members_signup_list_table->views(); ?>
     1262
     1263            <form id="bp-signups-search-form" action="<?php echo esc_url( $search_form_url ) ;?>">
     1264                <input type="hidden" name="page" value="<?php echo esc_attr( $plugin_page ); ?>" />
     1265                <?php $bp_members_signup_list_table->search_box( __( 'Search Pending accounts', 'buddypress' ), 'bp-signups' ); ?>
     1266            </form>
     1267
     1268            <form id="bp-signups-form" action="<?php echo esc_url( $form_url );?>" method="post">
     1269                <?php $bp_members_signup_list_table->display(); ?>
     1270            </form>
     1271        </div>
     1272    <?php
     1273    }
     1274
     1275    /**
     1276     * This is the confirmation screen for actions.
     1277     *
     1278     * @since BuddyPress (2.0.0)
     1279     *
     1280     * @param string $action Delete, activate, or resend activation link.
     1281     */
     1282    public function signups_admin_manage( $action = '' ) {
     1283        if ( ! is_super_admin() || empty( $action ) ) {
     1284            die( '-1' );
     1285        }
     1286
     1287        // Get the user IDs from the URL
     1288        $ids = false;
     1289        if ( ! empty( $_POST['allsignups'] ) ) {
     1290            $ids = wp_parse_id_list( $_POST['allsignups'] );
     1291        } else if ( ! empty( $_GET['signup_id'] ) ) {
     1292            $ids = absint( $_GET['signup_id'] );
     1293        }
     1294
     1295        if ( empty( $ids ) ) {
     1296            return false;
     1297        }
     1298
     1299        // Query for signups, and filter out those IDs that don't
     1300        // correspond to an actual signup
     1301        $signups_query = BP_Signup::get( array(
     1302            'include' => $ids,
     1303        ) );
     1304
     1305        $signups    = $signups_query['signups'];
     1306        $signup_ids = wp_list_pluck( $signups, 'signup_id' );
     1307
     1308        // Set up strings
     1309        switch ( $action ) {
     1310            case 'delete' :
     1311                $header_text = __( 'Delete Pending Accounts', 'buddypress' );
     1312                $helper_text = _n( 'You are about to delete the following account:', 'You are about to delete the following accounts:', count( $signup_ids ), 'buddypress' );
     1313                break;
     1314
     1315            case 'activate' :
     1316                $header_text = __( 'Activate Pending Accounts', 'buddypress' );
     1317                $helper_text = _n( 'You are about to activate the following account:', 'You are about to activate the following accounts:', count( $signup_ids ), 'buddypress' );
     1318                break;
     1319
     1320            case 'resend' :
     1321                $header_text = __( 'Resend Activation Emails', 'buddypress' );
     1322                $helper_text = _n( 'You are about to resend an activation email to the following account:', 'You are about to resend activation emails to the following accounts:', count( $signup_ids ), 'buddypress' );
     1323                break;
     1324        }
     1325
     1326        // These arguments are added to all URLs
     1327        $url_args = array( 'page' => 'bp-signups' );
     1328
     1329        // These arguments are only added when performing an action
     1330        $action_args = array(
     1331            'action'     => 'do_' . $action,
     1332            'signup_ids' => implode( ',', $signup_ids )
     1333        );
     1334
     1335        $cancel_url = add_query_arg( $url_args, bp_get_admin_url( 'users.php' ) );
     1336        $action_url = wp_nonce_url(
     1337            add_query_arg(
     1338                array_merge( $url_args, $action_args ),
     1339                bp_get_admin_url( 'users.php' )
     1340            ),
     1341            'signups_' . $action
     1342        );
     1343
     1344        ?>
     1345
     1346        <div class="wrap">
     1347            <?php screen_icon( 'users' ); ?>
     1348            <h2><?php echo esc_html( $header_text ); ?></h2>
     1349            <p><?php echo esc_html( $helper_text ); ?></p>
     1350
     1351            <ol class="bp-signups-list">
     1352            <?php foreach ( $signups as $signup ) :
     1353                $last_notified = mysql2date( 'Y/m/d g:i:s a', $signup->date_sent )
     1354            ?>
     1355
     1356                <li>
     1357                    <?php echo esc_html( $signup->user_name ) ?> - <?php echo sanitize_email( $signup->user_email );?>
     1358
     1359                    <?php if ( 'resend' == $action ) : ?>
     1360                        <p class="description">
     1361                            <?php printf( esc_html__( 'Last notified: %s', 'buddypress'), $last_notified ) ;?>
     1362
     1363                            <?php if ( ! empty( $signup->recently_sent ) ) : ?>
     1364                                <span class="attention wp-ui-text-notification"> <?php esc_html_e( '(less than 24 hours ago)', 'buddypress' ); ?></span>
     1365                            <?php endif; ?>
     1366                        </p>
     1367
     1368                    <?php endif; ?>
     1369                </li>
     1370
     1371            <?php endforeach; ?>
     1372            </ol>
     1373
     1374            <?php if ( 'resend' != $action ) : ?>
     1375                <p><strong><?php esc_html_e( 'This action cannot be undone.', 'buddypress' ) ?></strong></p>
     1376            <?php endif ; ?>
     1377
     1378            <a class="button-primary" href="<?php echo esc_url( $action_url ); ?>"><?php esc_html_e( 'Confirm', 'buddypress' ); ?></a>
     1379            <a class="button" href="<?php echo esc_url( $cancel_url ); ?>"><?php esc_html_e( 'Cancel', 'buddypress' ) ?></a>
     1380        </div>
     1381
     1382        <?php
     1383    }
    6931384}
    6941385endif; // class_exists check
    6951386
    6961387// Load the BP Members admin
    697 add_action( 'bp_init', array( 'BP_Members_Admin','register_members_admin' ) );
     1388add_action( 'bp_init', array( 'BP_Members_Admin', 'register_members_admin' ) );
  • trunk/bp-members/bp-members-functions.php

    r8027 r8119  
    13621362        }
    13631363
     1364        // Check into signups
     1365        $signups = BP_Signup::get( array(
     1366            'user_login' => $user_name,
     1367        ) );
     1368
     1369        $signup = isset( $signups['signups'] ) && ! empty( $signups['signups'][0] ) ? $signups['signups'][0] : false;
     1370
    13641371        // Check if the username has been used already.
    1365         if ( username_exists( $user_name ) ) {
     1372        if ( username_exists( $user_name ) || ! empty( $signup ) ) {
    13661373            $errors->add( 'user_name', __( 'Sorry, that username already exists!', 'buddypress' ) );
    13671374        }
     
    13941401
    13951402function bp_core_signup_user( $user_login, $user_password, $user_email, $usermeta ) {
    1396     global $bp, $wpdb;
     1403    global $bp;
     1404
     1405    // We need to cast $user_id to pass to the filters
     1406    $user_id = false;
    13971407
    13981408    // Multisite installs have their own install procedure
     
    14001410        wpmu_signup_user( $user_login, $user_email, $usermeta );
    14011411
    1402         // On multisite, the user id is not created until the user activates the account
    1403         // but we need to cast $user_id to pass to the filters
    1404         $user_id = false;
    1405 
    14061412    } else {
    1407         $errors = new WP_Error();
    1408 
    1409         $user_id = wp_insert_user( array(
    1410             'user_login' => $user_login,
    1411             'user_pass' => $user_password,
    1412             'display_name' => sanitize_title( $user_login ),
    1413             'user_email' => $user_email
    1414         ) );
    1415 
    1416         if ( is_wp_error( $user_id ) || empty( $user_id ) ) {
    1417             $errors->add( 'registerfail', sprintf( __('<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !', 'buddypress' ), bp_get_option( 'admin_email' ) ) );
    1418             return $errors;
    1419         }
    1420 
    1421         // Update the user status to '2' which we will use as 'not activated' (0 = active, 1 = spam, 2 = not active)
    1422         $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_status = 2 WHERE ID = %d", $user_id ) );
    1423 
    1424         // Set any profile data
    1425         if ( bp_is_active( 'xprofile' ) ) {
    1426             if ( !empty( $usermeta['profile_field_ids'] ) ) {
    1427                 $profile_field_ids = explode( ',', $usermeta['profile_field_ids'] );
    1428 
    1429                 foreach( (array) $profile_field_ids as $field_id ) {
    1430                     if ( empty( $usermeta["field_{$field_id}"] ) )
    1431                         continue;
    1432 
    1433                     $current_field = $usermeta["field_{$field_id}"];
    1434                     xprofile_set_field_data( $field_id, $user_id, $current_field );
    1435 
    1436                     // Save the visibility level
    1437                     $visibility_level = !empty( $usermeta['field_' . $field_id . '_visibility'] ) ? $usermeta['field_' . $field_id . '_visibility'] : 'public';
    1438                     xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level );
    1439                 }
     1413        // Format data
     1414        $user_login     = preg_replace( '/\s+/', '', sanitize_user( $user_login, true ) );
     1415        $user_email     = sanitize_email( $user_email );
     1416        $activation_key = substr( md5( time() . rand() . $user_email ), 0, 16 );
     1417
     1418        /**
     1419         * WordPress's default behavior is to create user accounts
     1420         * immediately at registration time. BuddyPress uses a system
     1421         * borrowed from WordPress Multisite, where signups are stored
     1422         * separately and accounts are only created at the time of
     1423         * activation. For backward compatibility with plugins that may
     1424         * be anticipating WP's default behavior, BP silently creates
     1425         * accounts for registrations (though it does not use them). If
     1426         * you know that you are not running any plugins dependent on
     1427         * these pending accounts, you may want to save a little DB
     1428         * clutter by defining setting the BP_SIGNUPS_SKIP_USER_CREATION
     1429         * to true in your wp-config.php file.
     1430         */
     1431        if ( ! defined( 'BP_SIGNUPS_SKIP_USER_CREATION' ) || ! BP_SIGNUPS_SKIP_USER_CREATION ) {
     1432            $user_id = BP_Signup::add_backcompat( $user_login, $user_password, $user_email, $usermeta );
     1433
     1434            if ( is_wp_error( $user_id ) ) {
     1435                return $user_id;
    14401436            }
    1441         }
    1442     }
    1443     $bp->signup->username = $user_login;
    1444 
    1445     /***
    1446      * Now generate an activation key and send an email to the user so they can activate their
    1447      * account and validate their email address. Multisite installs send their own email, so
    1448      * this is only for single blog installs.
    1449      *
    1450      * To disable sending activation emails you can user the filter
    1451      * 'bp_core_signup_send_activation_key' and return false. Note that this will only disable
    1452      * the email - a key will still be generated, and the account must still be activated
    1453      * before use.
    1454      */
    1455     if ( !is_multisite() ) {
    1456         $activation_key = wp_hash( $user_id );
    1457         update_user_meta( $user_id, 'activation_key', $activation_key );
     1437
     1438            $activation_key = wp_hash( $user_id );
     1439            update_user_meta( $user_id, 'activation_key', $activation_key );
     1440        }
     1441
     1442        $args = array(
     1443            'user_login'     => $user_login,
     1444            'user_email'     => $user_email,
     1445            'activation_key' => $activation_key,
     1446            'meta'           => $usermeta,
     1447        );
     1448
     1449        BP_Signup::add( $args );
    14581450
    14591451        if ( apply_filters( 'bp_core_signup_send_activation_key', true ) ) {
     
    14611453        }
    14621454    }
     1455
     1456    $bp->signup->username = $user_login;
    14631457
    14641458    do_action( 'bp_core_signup_user', $user_id, $user_login, $user_password, $user_email, $usermeta );
     
    14841478
    14851479        // If there were errors, add a message and redirect
    1486         if ( !empty( $user->errors ) ) {
     1480        if ( ! empty( $user->errors ) ) {
    14871481            return $user;
    14881482        }
     
    14901484        $user_id = $user['user_id'];
    14911485
    1492         // Set any profile data
    1493         if ( bp_is_active( 'xprofile' ) ) {
    1494             if ( !empty( $user['meta']['profile_field_ids'] ) ) {
    1495                 $profile_field_ids = explode( ',', $user['meta']['profile_field_ids'] );
    1496 
    1497                 foreach( (array) $profile_field_ids as $field_id ) {
    1498                     $current_field = isset( $user['meta']["field_{$field_id}"] ) ? $user['meta']["field_{$field_id}"] : false;
    1499 
    1500                     if ( !empty( $current_field ) )
    1501                         xprofile_set_field_data( $field_id, $user_id, $current_field );
    1502 
    1503                     // Save the visibility level
    1504                     $visibility_level = !empty( $user['meta']['field_' . $field_id . '_visibility'] ) ? $user['meta']['field_' . $field_id . '_visibility'] : 'public';
    1505                     xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level );
    1506                 }
     1486    } else {
     1487        $signups = BP_Signup::get( array(
     1488            'activation_key' => $key,
     1489        ) );
     1490
     1491        if ( empty( $signups['signups'] ) ) {
     1492            return new WP_Error( 'invalid_key', __( 'Invalid activation key.', 'buddypress' ) );
     1493        }
     1494
     1495        $signup = $signups['signups'][0];
     1496
     1497        if ( $signup->active ) {
     1498            if ( empty( $signup->domain ) ) {
     1499                return new WP_Error( 'already_active', __( 'The user is already active.', 'buddypress' ), $signup );
     1500            } else {
     1501                return new WP_Error( 'already_active', __( 'The site is already active.', 'buddypress' ), $signup );
    15071502            }
    15081503        }
    1509     } else {
    1510 
    1511         // Get the user_id based on the $key
    1512         $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = 'activation_key' AND meta_value = %s", $key ) );
    1513 
    1514         if ( empty( $user_id ) )
    1515             return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) );
    1516 
    1517         // Change the user's status so they become active
    1518         if ( !$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_status = 0 WHERE ID = %d", $user_id ) ) )
    1519             return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) );
     1504
     1505        // password is hashed again in wp_insert_user
     1506        $password = wp_generate_password( 12, false );
     1507
     1508        $user_id = username_exists( $signup->user_login );
     1509
     1510        // Create the user
     1511        if ( ! $user_id ) {
     1512            $user_id = wp_create_user( $signup->user_login, $password, $signup->user_email );
     1513
     1514        // If a user ID is found, this may be a legacy signup, or one
     1515        // created locally for backward compatibility. Process it.
     1516        } else if ( $key == wp_hash( $user_id ) ) {
     1517            // Change the user's status so they become active
     1518            if ( ! $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_status = 0 WHERE ID = %d", $user_id ) ) ) {
     1519                return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) );
     1520            }
     1521
     1522            bp_delete_user_meta( $user_id, 'activation_key' );
     1523
     1524            $member = get_userdata( $user_id );
     1525            $member->set_role( get_option('default_role') );
     1526
     1527            $user_already_created = true;
     1528
     1529        } else {
     1530            $user_already_exists = true;
     1531        }
     1532
     1533        if ( ! $user_id ) {
     1534            return new WP_Error( 'create_user', __( 'Could not create user', 'buddypress' ), $signup );
     1535        }
     1536
     1537        // Fetch the signup so we have the data later on
     1538        $signups = BP_Signup::get( array(
     1539            'activation_key' => $key,
     1540        ) );
     1541
     1542        $signup = isset( $signups['signups'] ) && ! empty( $signups['signups'][0] ) ? $signups['signups'][0] : false;
     1543
     1544        // Activate the signup
     1545        BP_Signup::validate( $key );
     1546
     1547        if ( isset( $user_already_exists ) ) {
     1548            return new WP_Error( 'user_already_exists', __( 'That username is already activated.' ), $signup );
     1549        }
     1550
     1551        // Set up data to pass to the legacy filter
     1552        $user = array(
     1553            'user_id'  => $user_id,
     1554            'password' => $signup->meta['password'],
     1555            'meta'     => $signup->meta,
     1556        );
    15201557
    15211558        // Notify the site admin of a new user registration
    15221559        wp_new_user_notification( $user_id );
    15231560
    1524         // Remove the activation key meta
    1525         delete_user_meta( $user_id, 'activation_key' );
     1561        if ( isset( $user_already_created ) ) {
     1562            do_action( 'bp_core_activated_user', $user_id, $key, $user );
     1563            return $user_id;
     1564        }
     1565    }
     1566
     1567    // Set any profile data
     1568    if ( bp_is_active( 'xprofile' ) ) {
     1569        if ( ! empty( $user['meta']['profile_field_ids'] ) ) {
     1570            $profile_field_ids = explode( ',', $user['meta']['profile_field_ids'] );
     1571
     1572            foreach( (array) $profile_field_ids as $field_id ) {
     1573                $current_field = isset( $user['meta']["field_{$field_id}"] ) ? $user['meta']["field_{$field_id}"] : false;
     1574
     1575                if ( !empty( $current_field ) )
     1576                    xprofile_set_field_data( $field_id, $user_id, $current_field );
     1577
     1578                // Save the visibility level
     1579                $visibility_level = ! empty( $user['meta']['field_' . $field_id . '_visibility'] ) ? $user['meta']['field_' . $field_id . '_visibility'] : 'public';
     1580                xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level );
     1581            }
     1582        }
    15261583    }
    15271584
    15281585    // Update the display_name
    1529     wp_update_user( array( 'ID' => $user_id, 'display_name' => bp_core_get_user_displayname( $user_id ) ) );
     1586    wp_update_user( array(
     1587        'ID'           => $user_id,
     1588        'display_name' => bp_core_get_user_displayname( $user_id ),
     1589    ) );
    15301590
    15311591    // Set the password on multisite installs
    1532     if ( is_multisite() && !empty( $user['meta']['password'] ) )
     1592    if ( ! empty( $user['meta']['password'] ) ) {
    15331593        $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_pass = %s WHERE ID = %d", $user['meta']['password'], $user_id ) );
     1594    }
    15341595
    15351596    do_action( 'bp_core_activated_user', $user_id, $key, $user );
  • trunk/bp-members/bp-members-loader.php

    r8090 r8119  
    3838        $includes = array(
    3939            'actions',
     40            'classes',
    4041            'filters',
    4142            'screens',
     
    6970            define( 'BP_MEMBERS_SLUG', $this->id );
    7071
    71         parent::setup_globals( array(
     72        $members_globals = array(
    7273            'slug'          => BP_MEMBERS_SLUG,
    7374            'root_slug'     => isset( $bp->pages->members->slug ) ? $bp->pages->members->slug : BP_MEMBERS_SLUG,
     
    7879            ),
    7980            'search_string' => __( 'Search Members...', 'buddypress' ),
    80         ) );
     81        );
     82
     83        if ( bp_get_signup_allowed() ) {
     84            $members_globals['global_tables']['table_name_signups'] = bp_core_get_table_prefix() . 'signups';
     85        }
     86
     87        parent::setup_globals( $members_globals );
    8188
    8289        /** Logged in user ****************************************************/
  • trunk/bp-members/bp-members-screens.php

    r8090 r8119  
    252252        }
    253253
    254         // Check for an uploaded avatar and move that to the correct user folder
    255         if ( is_multisite() )
    256             $hashed_key = wp_hash( $_GET['key'] );
    257         else
    258             $hashed_key = wp_hash( $user );
     254        $hashed_key = wp_hash( $_GET['key'] );
    259255
    260256        // Check if the avatar folder exists. If it does, move rename it, move
  • trunk/tests/includes/factory.php

    r7873 r8119  
    1111        $this->xprofile_field = new BP_UnitTest_Factory_For_XProfileField( $this );
    1212        $this->notification = new BP_UnitTest_Factory_For_Notification( $this );
     13        $this->signup = new BP_UnitTest_Factory_For_Signup( $this );
    1314    }
    1415}
     
    164165    }
    165166}
     167
     168class BP_UnitTest_Factory_For_Signup extends WP_UnitTest_Factory_For_Thing {
     169    public function __construct( $factory = null ) {
     170        parent::__construct( $factory );
     171    }
     172
     173    public function create_object( $args ) {
     174        return BP_Signup::add( $args );
     175    }
     176
     177    public function update_object( $id, $fields ) {}
     178
     179    public function get_object_by_id( $id ) {
     180        return new BP_Signup( $id );
     181    }
     182}
  • trunk/tests/includes/install.php

    r7849 r8119  
    3131tests_add_filter( 'bp_new_install_default_components', 'wp_test_bp_install' );
    3232
     33tests_add_filter( 'bp_get_signup_allowed', '__return_true' );
     34
    3335$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
    3436$_SERVER['HTTP_HOST'] = WP_TESTS_DOMAIN;
Note: See TracChangeset for help on using the changeset viewer.