Skip to:
Content

BuddyPress.org

Ticket #5374: 5374.03.diff

File 5374.03.diff, 76.2 KB (added by imath, 11 years ago)
  • bp-core/admin/bp-core-functions.php

    diff --git bp-core/admin/bp-core-functions.php bp-core/admin/bp-core-functions.php
    index e47e7da..d8e979b 100644
    function bp_core_activation_notice() { 
    271271                        'id'   => 'register',
    272272                        'name' => __( 'Register', 'buddypress' )
    273273                );
     274
     275                bp_core_maybe_install_signups();
    274276        }
    275277
    276278        // On the first admin screen after a new installation, this isn't set, so grab it to supress a misleading error message.
    function bp_admin_wp_nav_menu_restrict_items() { 
    785787        </script>
    786788<?php
    787789}
     790
     791/**
     792 * Checks if the signups table needs to be created
     793 *
     794 * @since BuddyPress (2.0.0)
     795 *
     796 * @global $wpdb
     797 */
     798function bp_core_maybe_install_signups() {
     799        global $wpdb;
     800
     801        // Multisite allready have signups table
     802        if ( ! empty( $wpdb->signups ) )
     803                return;
     804
     805        $bp_signups = bp_core_get_table_prefix() . 'signups';
     806
     807        $suppress = $wpdb->suppress_errors();
     808        $table_exists = $wpdb->get_results("DESCRIBE {$bp_signups};");
     809        $wpdb->suppress_errors( $suppress );
     810
     811        if ( ! empty( $table_exists ) )
     812                return;
     813
     814        // Signups is not there and we need it so let's create it
     815        require_once( buddypress()->plugin_dir . '/bp-core/admin/bp-core-schema.php' );
     816       
     817        bp_core_install_signups();
     818}
  • bp-core/admin/bp-core-schema.php

    diff --git bp-core/admin/bp-core-schema.php bp-core/admin/bp-core-schema.php
    index 6001979..f9d642c 100644
    function bp_core_install( $active_components = false ) { 
    5050        // Blog tracking
    5151        if ( !empty( $active_components['blogs'] ) )
    5252                bp_core_install_blog_tracking();
     53
     54        if ( bp_get_signup_allowed() )
     55                bp_core_install_signups();
     56
    5357}
    5458
    5559function bp_core_install_notifications() {
    function bp_core_install_blog_tracking() { 
    343347
    344348        dbDelta( $sql );
    345349}
     350
     351/**
     352 * Installs the signups table
     353 *
     354 * @since BuddyPress (2.0.0)
     355 *
     356 * @global $wpdb
     357 * @uses wp_get_db_schema() to get WordPress ms_global schema
     358 */
     359function bp_core_install_signups() {
     360        global $wpdb;
     361
     362        // Multisite allready have signups table
     363        if ( ! empty( $wpdb->signups ) )
     364                return;
     365
     366        $sql             = array();
     367        $charset_collate = bp_core_set_charset();
     368        $bp_prefix       = bp_core_get_table_prefix();
     369
     370        $wpdb->signups = $bp_prefix . 'signups';
     371
     372        $create_queries = wp_get_db_schema( 'ms_global' );
     373
     374        if ( ! is_array( $create_queries ) ) {
     375                $create_queries = explode( ';', $create_queries );
     376                $create_queries = array_filter( $create_queries );
     377        }
     378
     379        foreach ( $create_queries as $key => $query ) {
     380                if ( preg_match( "|CREATE TABLE ([^ ]*)|", $query, $matches ) ) {
     381                        if ( $wpdb->signups != trim( $matches[1], '`' ) )
     382                                unset( $create_queries[ $key ] );
     383                }
     384        }
     385
     386        if ( ! empty( $create_queries ) )
     387                dbDelta( $create_queries );
     388}
  • bp-core/bp-core-classes.php

    diff --git bp-core/bp-core-classes.php bp-core/bp-core-classes.php
    index c3d2d66..031ae7c 100644
    class BP_Walker_Nav_Menu_Checklist extends Walker_Nav_Menu { 
    22212221                $output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="'. esc_attr( $item->xfn ) .'" />';
    22222222        }
    22232223}
     2224
     2225/**
     2226 * Signups Management class.
     2227 *
     2228 * @package BuddyPress
     2229 * @subpackage coreClasses
     2230 *
     2231 * @since BuddyPress (2.0.0)
     2232 */
     2233class BP_Core_SignUp {
     2234
     2235        /**
     2236         * ID of the signup which the object relates to.
     2237         *
     2238         * @var integer
     2239         */
     2240        public $id;
     2241
     2242        /**
     2243         * The URL to the full size of the avatar for the user.
     2244         *
     2245         * @var string
     2246         */
     2247        public $avatar;
     2248
     2249        /**
     2250         * The username for the user.
     2251         *
     2252         * @var string
     2253         */
     2254        public $user_login;
     2255
     2256        /**
     2257         * The email for the user.
     2258         *
     2259         * @var string
     2260         */
     2261        public $user_email;
     2262
     2263        /**
     2264         * The full name of the user
     2265         *
     2266         * @var string
     2267         */
     2268        public $user_name;
     2269
     2270        /**
     2271         * The registered date for the user.
     2272         *
     2273         * @var string
     2274         */
     2275        public $registered;
     2276
     2277        /**
     2278         * The activation key for the user.
     2279         *
     2280         * @var string
     2281         */
     2282        public $activation_key;
     2283
     2284
     2285        /** Public Methods *******************************************************/
     2286
     2287        /**
     2288         * Class constructor.
     2289         *
     2290         * @access public
     2291         * @since BuddyPress (2.0.0)
     2292         *
     2293         * @param integer $signup_id The ID for the signup being queried.
     2294         */
     2295        public function __construct( $signup_id = 0 ) {
     2296                if ( !empty( $signup_id ) ) {
     2297                        $this->id = $signup_id;
     2298                        $this->populate();
     2299                }
     2300        }
     2301
     2302        /**
     2303         * Populate the instantiated class with data based on the signup_id provided.
     2304         *
     2305         * @access public
     2306         * @since BuddyPress (2.0.0)
     2307         *
     2308         * @global $wpdb
     2309         */
     2310        public function populate() {
     2311                global $wpdb;
     2312                $signups_table = buddypress()->members->table_name_signups;
     2313                $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$signups_table} WHERE signup_id = %d AND active = 0", $this->id ) );
     2314
     2315                $this->avatar     = get_avatar( $signup->user_email, 32 );
     2316                $this->user_login = $signup->user_login;
     2317                $this->user_email = $signup->user_email;
     2318                $meta = maybe_unserialize( $signup->meta );
     2319                $this->user_name = '';
     2320
     2321                if ( ! empty( $meta['field_1'] ) )
     2322                        $this->user_name   = esc_html( wp_unslash( $meta['field_1'] ) );
     2323
     2324                $this->registered = $signup->registered;
     2325
     2326        }
     2327
     2328        /** Static Methods *******************************************************/
     2329
     2330        /**
     2331         * Populate the instantiated class with data based on the signup_id provided.
     2332         *
     2333         * @access public
     2334         * @since BuddyPress (2.0.0)
     2335         *
     2336         * @global $wpdb
     2337         * @param array $args the argument to retrieve desired signups
     2338         * @static
     2339         */
     2340        public static function get( $args = array() ) {
     2341                global $wpdb;
     2342
     2343                $r = bp_parse_args( $args,
     2344                        array(
     2345                                'offset'     => 0,
     2346                                'number'     => 1,
     2347                                'usersearch' => false,
     2348                                'orderby'    => 'signup_id',
     2349                                'order'      => 'DESC',
     2350                                'include'    => false
     2351                        ),
     2352                        'bp_core_signups_get_args'
     2353                );
     2354
     2355                extract( $r, EXTR_SKIP );
     2356
     2357                if ( $orderby != 'signup_id' )
     2358                        $orderby = 'user_' . $orderby;
     2359
     2360                $orderby = sanitize_title( $orderby );
     2361
     2362                $sql = array();
     2363                $signups_table = buddypress()->members->table_name_signups;
     2364                $sql['select']  = "SELECT * FROM {$signups_table}";
     2365                $sql['where']   = "WHERE active = 0";
     2366
     2367                if ( empty( $include ) ) {
     2368                        if ( ! empty( $usersearch ) ) {
     2369                                $search_terms_clean = mysql_real_escape_string( mysql_real_escape_string( $usersearch ) );
     2370                                $search_terms_clean = like_escape( $search_terms_clean );
     2371                                $sql['search'] = "AND ( user_login LIKE '%" . $search_terms_clean . "%' OR user_email LIKE '%" . $search_terms_clean . "%' OR meta LIKE '%" . $search_terms_clean . "%' )";
     2372                        }
     2373
     2374                        $sql['orderby'] = "ORDER BY {$orderby}";
     2375                        $sql['order']   = strtoupper( $order );
     2376                        $sql['limit']   = $wpdb->prepare( "LIMIT %d, %d", $offset, $number );
     2377                } else {
     2378                        $in = implode( ',', wp_parse_id_list( $include ) );
     2379                        $sql['in'] = "AND signup_id IN ({$in})";
     2380                }
     2381
     2382                $paged_signups = $wpdb->get_results( apply_filters( 'bp_members_signups_paged_query', join( ' ', $sql ), $sql, $args, $r ) );
     2383
     2384                if ( empty( $paged_signups ) )
     2385                        return array( 'signups' => false, 'total' => false );
     2386
     2387                foreach ( (array) $paged_signups as $key => $signup ) {
     2388
     2389                        $signup->id = intval( $signup->signup_id );
     2390
     2391                        $meta = !empty( $signup->meta ) ? maybe_unserialize( $signup->meta ) : false;
     2392
     2393                        $signup->user_name = '';
     2394
     2395                        if ( ! empty( $meta['field_1'] ) )
     2396                                $signup->user_name  = esc_html( wp_unslash( $meta['field_1'] ) );
     2397
     2398                        if ( ! empty( $meta['sent_date'] ) ) {
     2399                                $signup->date_sent = $meta['sent_date'];
     2400                        // Defaults to date of registration
     2401                        } else {
     2402                                $signup->date_sent = $signup->registered;
     2403                        }
     2404
     2405                        if ( ! empty( $meta['count_sent'] ) ) {
     2406                                $signup->count_sent = absint( $meta['count_sent'] );
     2407                        // Defaults to date of registration
     2408                        } else {
     2409                                $signup->count_sent = 1;
     2410                        }
     2411
     2412                        $paged_signups[ $key ] = $signup;
     2413                }
     2414
     2415                unset( $sql['limit'] );
     2416                $sql['select'] = preg_replace( "/SELECT.*?FROM/", "SELECT COUNT(*) FROM", $sql['select'] );
     2417                $total_signups = $wpdb->get_var( apply_filters( 'bp_members_signups_count_query', join( ' ', $sql ), $sql, $args, $r ) );
     2418
     2419                return array( 'signups' => $paged_signups, 'total' => $total_signups );
     2420        }
     2421
     2422        /**
     2423         * Get a specific signup thanks to registration key.
     2424         *
     2425         * @access public
     2426         * @since BuddyPress (2.0.0)
     2427         *
     2428         * @global $wpdb
     2429         * @param string $key
     2430         * @return object the queried data for the signup
     2431         * @static
     2432         */
     2433        public static function get_by_key( $key = '' ) {
     2434                global $wpdb;
     2435
     2436                if ( empty( $key ) )
     2437                        return false;
     2438
     2439                $signups_table = buddypress()->members->table_name_signups;
     2440                $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$signups_table} WHERE activation_key = %s", $key ) );
     2441
     2442                return apply_filters( 'bp_core_signups_get_by_key', $signup );
     2443        }
     2444
     2445        /**
     2446         * Get a specific signup id thanks to user login.
     2447         *
     2448         * @access public
     2449         * @since BuddyPress (2.0.0)
     2450         *
     2451         * @global $wpdb
     2452         * @param string $user_login
     2453         * @return object the queried data for the signup
     2454         * @static
     2455         */
     2456        public static function get_by_userlogin( $user_login = '' ) {
     2457                global $wpdb;
     2458
     2459                if ( empty( $user_login ) )
     2460                        return false;
     2461
     2462                $signups_table = buddypress()->members->table_name_signups;
     2463                $signup = $wpdb->get_row( $wpdb->prepare( "SELECT signup_id FROM {$signups_table} WHERE user_login = %s", $user_login ) );
     2464
     2465                return apply_filters( 'bp_core_signups_get_by_userlogin', $signup );
     2466        }
     2467
     2468        /**
     2469         * Get a specific signup thanks to its id.
     2470         *
     2471         * @access public
     2472         * @since BuddyPress (2.0.0)
     2473         *
     2474         * @global $wpdb
     2475         * @param int $signup_id
     2476         * @return object the queried data for the signup
     2477         * @static
     2478         */
     2479        public static function get_specific( $signup_id = 0 ) {
     2480                global $wpdb;
     2481
     2482                $signups_table = buddypress()->members->table_name_signups;
     2483                $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$signups_table} WHERE active = 0 AND signup_id = %d", absint( $signup_id ) ) );
     2484
     2485                return apply_filters( 'bp_core_signups_get_specific', $signup );
     2486        }
     2487
     2488        /**
     2489         * Add a signup
     2490         *
     2491         * @access public
     2492         * @since BuddyPress (2.0.0)
     2493         *
     2494         * @global $wpdb
     2495         * @param array $args
     2496         * @return boolean
     2497         * @static
     2498         */
     2499        public static function add( $args = array() ) {
     2500                global $wpdb;
     2501
     2502                $r = bp_parse_args( $args,
     2503                        array(
     2504                                'domain'         => '',
     2505                                'path'           => '',
     2506                                'title'          => '',
     2507                                'user_login'     => '',
     2508                                'user_email'     => '',
     2509                                'registered'     => current_time( 'mysql', true ),
     2510                                'activation_key' => '',
     2511                                'meta'           => ''
     2512                        ),
     2513                        'bp_core_signups_add_args'
     2514                );
     2515
     2516                $inserted = $wpdb->insert(
     2517                        buddypress()->members->table_name_signups,
     2518                        $r,
     2519                        array( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )
     2520                );
     2521
     2522                return apply_filters( 'bp_core_signups_add', $inserted );
     2523        }
     2524
     2525        /**
     2526         * Keep on creating a user on signup
     2527         *
     2528         * Plugins might rely on user_status / activation_key
     2529         *
     2530         * @access public
     2531         * @since BuddyPress (2.0.0)
     2532         *
     2533         * @global $wpdb
     2534         * @param string $user_login
     2535         * @param string $user_password
     2536         * @param string $user_email
     2537         * @param array $usermeta
     2538         * @return int user id
     2539         * @static
     2540         */
     2541        public static function add_backcompat( $user_login = '', $user_password = '', $user_email = '', $usermeta = array() ) {
     2542                global $wpdb;
     2543
     2544                $errors = new WP_Error();
     2545
     2546                $user_id = wp_insert_user( array(
     2547                        'user_login' => $user_login,
     2548                        'user_pass' => $user_password,
     2549                        'display_name' => sanitize_title( $user_login ),
     2550                        'user_email' => $user_email
     2551                ) );
     2552
     2553                if ( is_wp_error( $user_id ) || empty( $user_id ) ) {
     2554                        $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' ) ) );
     2555                        return $errors;
     2556                }
     2557
     2558                // Update the user status to '2' which we will use as 'not activated' (0 = active, 1 = spam, 2 = not active)
     2559                $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_status = 2 WHERE ID = %d", $user_id ) );
     2560
     2561                // Deleting these options will remove signups from users count
     2562                delete_user_option( $user_id, 'capabilities' );
     2563                delete_user_option( $user_id, 'user_level' );
     2564
     2565                // Set any profile data
     2566                if ( bp_is_active( 'xprofile' ) ) {
     2567                        if ( !empty( $usermeta['profile_field_ids'] ) ) {
     2568                                $profile_field_ids = explode( ',', $usermeta['profile_field_ids'] );
     2569
     2570                                foreach( (array) $profile_field_ids as $field_id ) {
     2571                                        if ( empty( $usermeta["field_{$field_id}"] ) )
     2572                                                continue;
     2573
     2574                                        $current_field = $usermeta["field_{$field_id}"];
     2575                                        xprofile_set_field_data( $field_id, $user_id, $current_field );
     2576
     2577                                        // Save the visibility level
     2578                                        $visibility_level = !empty( $usermeta['field_' . $field_id . '_visibility'] ) ? $usermeta['field_' . $field_id . '_visibility'] : 'public';
     2579                                        xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level );
     2580                                }
     2581                        }
     2582                }
     2583
     2584                return apply_filters( 'bp_core_signups_add_backcompat', $user_id );
     2585        }
     2586
     2587        /**
     2588         * Checks a user status for non multisite config
     2589         *
     2590         * @access public
     2591         * @since BuddyPress (2.0.0)
     2592         *
     2593         * @global $wpdb
     2594         * @param int $user_id
     2595         * @return int the status
     2596         * @static
     2597         */
     2598        public static function check_user_status( $user_id = 0 ) {
     2599                global $wpdb;
     2600
     2601                if ( empty( $user_id ) )
     2602                        return false;
     2603
     2604                $user_status = $wpdb->get_var( $wpdb->prepare( "SELECT user_status FROM {$wpdb->users} WHERE ID = %d", $user_id ) );
     2605
     2606                return apply_filters( 'bp_core_signups_check_user_status', intval( $user_status ) );
     2607        }
     2608
     2609        /**
     2610         * "Activate" a signup
     2611         *
     2612         * @access public
     2613         * @since BuddyPress (2.0.0)
     2614         *
     2615         * @global $wpdb
     2616         * @param string $key
     2617         * @return boolean
     2618         * @static
     2619         */
     2620        public static function validate( $key = '' ) {
     2621                global $wpdb;
     2622
     2623                if ( empty( $key ) )
     2624                        return;
     2625
     2626                $activated = $wpdb->update(
     2627                        // Signups table
     2628                        buddypress()->members->table_name_signups,
     2629                        array(
     2630                                'active' => 1,
     2631                                'activated' => current_time( 'mysql', true )
     2632                        ),
     2633                        array(
     2634                                'activation_key' => $key
     2635                        ),
     2636                        // Data sanitization format
     2637                        array(
     2638                                '%d',
     2639                                '%s'
     2640                        ),
     2641                        // WHERE sanitization format
     2642                        array(
     2643                                '%s'
     2644                        )
     2645                );
     2646
     2647                return apply_filters( 'bp_core_signups_validate', $activated );
     2648        }
     2649
     2650        /**
     2651         * How many signups ?
     2652         *
     2653         * @access public
     2654         * @since BuddyPress (2.0.0)
     2655         *
     2656         * @global $wpdb
     2657         * @return int the number of signups
     2658         * @static
     2659         */
     2660        public static function count_signups() {
     2661                global $wpdb;
     2662
     2663                $signups_table = buddypress()->members->table_name_signups;
     2664                $count_signups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) AS total FROM {$signups_table} WHERE active = %d", 0 ) );
     2665
     2666                return apply_filters( 'bp_core_signups_count', (int) $count_signups );
     2667        }
     2668
     2669        /**
     2670         * Update the meta for a signup
     2671         *
     2672         * This is the way we use to "trace" the last date an activation
     2673         * email was sent and how many times activation was sent
     2674         *
     2675         * @access public
     2676         * @since BuddyPress (2.0.0)
     2677         *
     2678         * @global $wpdb
     2679         * @param  array $args
     2680         * @return int the signup id
     2681         * @static
     2682         */
     2683        public static function update( $args = array() ) {
     2684                global $wpdb;
     2685
     2686                $r = bp_parse_args( $args,
     2687                        array(
     2688                                'signup_id'  => 0,
     2689                                'meta'       => array(),
     2690                        ),
     2691                        'bp_core_signups_update_args'
     2692                );
     2693
     2694                extract( $r, EXTR_SKIP );
     2695               
     2696                if ( empty( $signup_id ) || empty( $meta ) )
     2697                        return false;
     2698
     2699                $wpdb->update(
     2700                        // Signups table
     2701                        buddypress()->members->table_name_signups,
     2702                        // Data to update
     2703                        array(
     2704                                'meta' => serialize( $meta )
     2705                        ),
     2706                        // WHERE
     2707                        array(
     2708                                'signup_id' => $signup_id
     2709                        ),
     2710                        // Data sanitization format
     2711                        array(
     2712                                '%s'
     2713                        ),
     2714                        // WHERE sanitization format
     2715                        array(
     2716                                '%d'
     2717                        )
     2718                );
     2719
     2720                return apply_filters( 'bp_core_signups_update', $signup_id );
     2721        }
     2722
     2723        /**
     2724         * Resend an activation link
     2725         *
     2726         * @access public
     2727         * @since BuddyPress (2.0.0)
     2728         *
     2729         * @param array $signup_ids single id or list of ids to resend
     2730         * @return array the results
     2731         * @static
     2732         */
     2733        public static function resend( $signup_ids = array() ) {
     2734                if ( empty( $signup_ids ) || ! is_array( $signup_ids ) )
     2735                        return false;
     2736
     2737                $to_resend = self::get( array( 'include' => $signup_ids ) );
     2738
     2739                if ( ! $signups = $to_resend['signups'] )
     2740                        return false;
     2741
     2742                $now = current_time( 'timestamp', true );
     2743                $result = array();
     2744
     2745                do_action( 'bp_core_signup_before_resend', $signup_ids );
     2746
     2747                foreach ( $signups as $signup ) {
     2748                        $sent_at =  mysql2date('U', $signup->date_sent );
     2749                        $diff = $now - $sent_at;
     2750
     2751                        // If a previous resent happened less than a day ago, skip.
     2752                        if ( $diff < 1 * DAY_IN_SECONDS ) {
     2753                                $result['errors'][ $signup->signup_id ] = array( $signup->user_login, esc_html__( 'already received an activation email today', 'buddypress' ) );;
     2754                                continue;
     2755                        }
     2756
     2757                        $meta = maybe_unserialize( $signup->meta );
     2758
     2759                        $meta['sent_date'] = current_time( 'mysql', true );
     2760                        $meta['count_sent'] = $signup->count_sent + 1;
     2761
     2762                        // Send activation email
     2763                        if ( is_multisite() ) {
     2764                                wpmu_signup_user_notification( $signup->user_login, $signup->user_email, $signup->activation_key, serialize( $meta ) );
     2765                        } else {
     2766
     2767                                // Check user status before sending email
     2768                                $user_id = email_exists( $signup->user_email );
     2769
     2770                                if ( ! empty( $user_id ) && 2 != self::check_user_status( $user_id ) ) {
     2771                                        // Status is not 2, so user's account has been activated
     2772                                        $result['errors'][ $signup->signup_id ] = array( $signup->user_login, esc_html__( 'the sign-up has already been activated.', 'buddypress' ) );;
     2773                                        // repare signups table
     2774                                        self::validate( $signup->activation_key );
     2775                                        continue;
     2776
     2777                                // Send the validation email
     2778                                } else {
     2779                                        bp_core_signup_send_validation_email( false, $signup->user_email, $signup->activation_key );
     2780                                }
     2781                        }
     2782                       
     2783                        // Update metas
     2784                        $result['resent'][] = self::update( array( 'signup_id' => $signup->signup_id, 'meta' => $meta ) );
     2785                }
     2786
     2787                do_action( 'bp_core_signup_after_resend', $signup_ids );
     2788
     2789                return apply_filters( 'bp_core_signup_resend', $result );
     2790        }
     2791
     2792        /**
     2793         * Activate a pending account
     2794         *
     2795         * @access public
     2796         * @since BuddyPress (2.0.0)
     2797         *
     2798         * @param array $signup_ids single id or list of ids to resend
     2799         * @return array the results
     2800         * @static
     2801         */
     2802        public static function activate( $signup_ids = array() ) {
     2803                if ( empty( $signup_ids ) || ! is_array( $signup_ids ) )
     2804                        return false;
     2805
     2806                $to_activate = self::get( array( 'include' => $signup_ids ) );
     2807
     2808                if ( ! $signups = $to_activate['signups'] )
     2809                        return false;
     2810
     2811                $result = array();
     2812
     2813                do_action( 'bp_core_signup_before_activate', $signup_ids );
     2814
     2815                foreach ( $signups as $signup ) {
     2816
     2817                        $user = bp_core_activate_signup( $signup->activation_key );
     2818
     2819                        if ( ! empty( $user->errors ) ) {
     2820
     2821                                if ( $user_id = username_exists( $signup->user_login ) && 2 != self::check_user_status( $user_id ) ) {
     2822                                        // Status is not 2, so user's account has been activated
     2823                                        $result['errors'][ $signup->signup_id ] = array( $signup->user_login, esc_html__( 'the sign-up has already been activated.', 'buddypress' ) );
     2824                                        // repare signups table
     2825                                        self::validate( $signup->activation_key );
     2826
     2827                                // we have a user id, account is not active, let's delete it
     2828                                } else {
     2829                                        $result['errors'][ $signup->signup_id ] = array( $signup->user_login, $user->get_error_message() );
     2830                                }
     2831                               
     2832                        } else {
     2833                                $result['activated'][] = $user;
     2834                        }
     2835
     2836                }
     2837
     2838                do_action( 'bp_core_signup_after_activate', $result );
     2839
     2840                return apply_filters( 'bp_core_signup_activate', $result );
     2841        }
     2842
     2843        /**
     2844         * Delete a pending account
     2845         *
     2846         * @access public
     2847         * @since BuddyPress (2.0.0)
     2848         *
     2849         * @param array $signup_ids single id or list of ids to resend
     2850         * @return array the results
     2851         * @static
     2852         */
     2853        public static function delete( $signup_ids = array() ) {
     2854                global $wpdb;
     2855
     2856                if ( empty( $signup_ids ) || ! is_array( $signup_ids ) )
     2857                        return false;
     2858
     2859                $to_delete = self::get( array( 'include' => $signup_ids ) );
     2860
     2861                if ( ! $signups = $to_delete['signups'] )
     2862                        return false;
     2863
     2864                $result = array();
     2865
     2866                do_action( 'bp_core_signup_before_delete', $signup_ids );
     2867
     2868                foreach ( $signups as $signup ) {
     2869
     2870                        $user_id = username_exists( $signup->user_login );
     2871                       
     2872                        if ( ! empty( $user_id ) && $signup->activation_key == wp_hash( $user_id ) ) {
     2873
     2874                                if ( 2 != self::check_user_status( $user_id ) ) {
     2875                                        // Status is not 2, so user's account has been activated
     2876                                        $result['errors'][ $signup->signup_id ] = array( $signup->user_login, esc_html__( 'the sign-up has already been activated.', 'buddypress' ) );
     2877                                        // repare signups table
     2878                                        self::validate( $signup->activation_key );
     2879
     2880                                // we have a user id, account is not active, let's delete it
     2881                                } else {
     2882                                        bp_core_delete_account( $user_id );
     2883                                }
     2884                        }
     2885                               
     2886                        if( empty( $result['errors'][ $signup->signup_id ] ) ) {
     2887
     2888                                $wpdb->delete(
     2889                                                // Signups table
     2890                                                buddypress()->members->table_name_signups,
     2891                                                // Where
     2892                                                array( 'signup_id' => $signup->signup_id ),
     2893                                                // WHERE sanitization format
     2894                                                array( '%d' )
     2895                                        );
     2896
     2897                                $result['deleted'][] = $signup->signup_id;
     2898                        }
     2899
     2900                }
     2901
     2902                do_action( 'bp_core_signup_after_delete', $signup_ids, $result );
     2903
     2904                return apply_filters( 'bp_core_signup_delete', $result );
     2905        }
     2906
     2907}
  • bp-core/bp-core-update.php

    diff --git bp-core/bp-core-update.php bp-core/bp-core-update.php
    index 54d9d1e..af3292a 100644
    function bp_version_updater() { 
    230230                if ( $raw_db_version < 7731 ) {
    231231                        bp_update_to_1_9_2();
    232232                }
     233
     234                // 2.0.0
     235                if ( $raw_db_version < 7820 ) {
     236                        bp_update_to_2_0();
     237                }
    233238        }
    234239
    235240        /** All done! *************************************************************/
    function bp_update_to_1_9_2() { 
    328333}
    329334
    330335/**
     336 * Installs the new signup process for non multisite configs
     337 *
     338 * If registrations are available, migrates the users not activated
     339 * to the signups without deleting them. Users will lose their roles
     340 * so that they are not taking in account in the WordPress count_users()
     341 * function.
     342 *
     343 * @since BuddyPress (2.0.0)
     344 *
     345 * @global $wpdb
     346 */
     347function bp_update_to_2_0() {
     348        global $wpdb;
     349
     350        if ( bp_get_signup_allowed() && ! is_multisite() ) {
     351
     352                if ( empty( $wpdb->signups ) )
     353                        bp_core_install_signups();
     354
     355                $signups = get_users( array( 'fields' => 'all_with_meta', 'meta_key' => 'activation_key', 'meta_compare' => 'EXISTS' ) );
     356
     357                if ( empty( $signups ) )
     358                        return;
     359
     360                foreach ( $signups as $signup ) {
     361                        $meta = array();
     362
     363                        if ( bp_is_active( 'xprofile' ) )
     364                                $meta['field_1'] = $signup->display_name;
     365
     366                        $meta['password'] = $signup->user_pass;
     367                       
     368                        $user_login = preg_replace( '/\s+/', '', sanitize_user( $signup->user_login, true ) );
     369                        $user_email = sanitize_email( $signup->user_email );
     370                        $meta = serialize( $meta );
     371
     372                        $args = array(
     373                                'user_login'     => $user_login,
     374                                'user_email'     => $user_email,
     375                                'registered'     => $signup->user_registered,
     376                                'activation_key' => $signup->activation_key,
     377                                'meta'           => $meta
     378                        );
     379
     380                        BP_Core_SignUp::add( $args );
     381
     382                        // Deleting these options will remove signups from users count
     383                        delete_user_option( $signup->ID, 'capabilities' );
     384                        delete_user_option( $signup->ID, 'user_level' );
     385                }
     386        }
     387}
     388
     389/**
    331390 * Redirect user to BP's What's New page on first page load after activation.
    332391 *
    333392 * @since BuddyPress (1.7.0)
  • bp-loader.php

    diff --git bp-loader.php bp-loader.php
    index e069db5..aedacad 100644
    class BuddyPress { 
    304304                /** Versions **************************************************/
    305305
    306306                $this->version    = '2.0-alpha-7752';
    307                 $this->db_version = 7731;
     307                $this->db_version = 7820;
    308308
    309309                /** Loading ***************************************************/
    310310
  • bp-members/admin/bp-members-classes.php

    diff --git bp-members/admin/bp-members-classes.php bp-members/admin/bp-members-classes.php
    index e69de29..a2050f1 100644
     
     1<?php
     2
     3/**
     4 * BuddyPress Members List Classes
     5 *
     6 * @package BuddyPress
     7 * @subpackage MembersAdminClasses
     8 */
     9
     10// Exit if accessed directly
     11if ( !defined( 'ABSPATH' ) ) exit;
     12/**
     13 * Using specific List Tables has the benefit to make this inherit
     14 * from parent views, so that we do not need to count users, etc..
     15 */
     16if ( class_exists( 'WP_Users_List_Table') ) :
     17/**
     18 * List table class for signups admin page.
     19 *
     20 * @since BuddyPress (2.0.0)
     21 */
     22class BP_Members_List_Table extends WP_Users_List_Table {
     23
     24        /**
     25         * Signup counts.
     26         *
     27         * @since BuddyPress (2.0.0)
     28         *
     29         * @access public
     30         * @var int
     31         */
     32        public $signup_counts = 0;
     33
     34        /**
     35         * Constructor
     36         *
     37         * @since BuddyPress (2.0.0)
     38         */
     39        public function __construct() {
     40                // Define singular and plural labels, as well as whether we support AJAX.
     41                parent::__construct( array(
     42                        'ajax'     => false,
     43                        'plural'   => 'signups',
     44                        'singular' => 'signup',
     45                ) );
     46        }
     47
     48        /**
     49         * Set up items for display in the list table.
     50         *
     51         * Handles filtering of data, sorting, pagination, and any other data
     52         * manipulation required prior to rendering.
     53         *
     54         * @since BuddyPress (2.0.0)
     55         */
     56        public function prepare_items() {
     57                global $usersearch;
     58
     59                $usersearch = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
     60
     61                $signups_per_page = $this->get_items_per_page( str_replace( '-', '_', "{$this->screen->id}_per_page" ) );
     62
     63                $paged = $this->get_pagenum();
     64
     65                $args = array(
     66                        'offset'     => ( $paged - 1 ) * $signups_per_page,
     67                        'number'     => $signups_per_page,
     68                        'usersearch' => $usersearch,
     69                        'orderby'    => 'signup_id',
     70                        'order'      => 'DESC'
     71                );
     72
     73                if ( isset( $_REQUEST['orderby'] ) )
     74                        $args['orderby'] = $_REQUEST['orderby'];
     75
     76                if ( isset( $_REQUEST['order'] ) )
     77                        $args['order'] = $_REQUEST['order'];
     78
     79                $signups = BP_Core_SignUp::get( $args );
     80
     81                $this->items = $signups['signups'];
     82                $this->signup_counts = $signups['total'];
     83
     84                $this->set_pagination_args( array(
     85                        'total_items' => $this->signup_counts,
     86                        'per_page'    => $signups_per_page,
     87                ) );
     88        }
     89
     90        /**
     91         * Get the views : the links above the WP List Table.
     92         *
     93         * @since BuddyPress (2.0.0)
     94         *
     95         * @uses WP_Users_List_Table::get_views() to get the users views
     96         */
     97        public function get_views() {
     98                $views = parent::get_views();
     99
     100                $views['all'] = str_replace( 'class="current"', '', $views['all'] );
     101                        $class = ' class="current"';
     102
     103                $views['registered'] = '<a href="' . add_query_arg( 'page', 'bp-signups', bp_get_admin_url( 'users.php' ) ) . '"  class="current">' . sprintf( _nx( 'Pending account <span class="count">(%s)</span>', 'Pending accounts <span class="count">(%s)</span>', $this->signup_counts, 'signup users', 'buddypress' ), number_format_i18n( $this->signup_counts ) ) . '</a>';
     104
     105                return $views;
     106        }
     107
     108        /**
     109         * Get rid of the extra nav.
     110         *
     111         * WP_Users_List_Table will add an extra nav to change user's role
     112         * as we're dealing with signups, we don't need this
     113         *
     114         * @since BuddyPress (2.0.0)
     115         */
     116        public function extra_tablenav( $which ) {
     117                return;
     118        }
     119
     120        /**
     121         * Specific signups columns
     122         *
     123         * @since BuddyPress (2.0.0)
     124         */
     125        public function get_columns() {
     126                return apply_filters( 'bp_members_signup_columns', array(
     127                        'cb'         => '<input type="checkbox" />',
     128                        'username'   => __( 'Username', 'buddypress' ),
     129                        'name'       => __( 'Name', 'buddypress' ),
     130                        'email'      => __( 'E-mail', 'buddypress' ),
     131                        'registered' => __( 'Registered', 'buddypress' ),
     132                        'date_sent'  => __( 'Last mail', 'buddypress' ),
     133                        'count_sent' => __( 'Mail count', 'buddypress' )
     134                ) );
     135        }
     136
     137        /**
     138         * Specific bulk actions for signups
     139         *
     140         * @since BuddyPress (2.0.0)
     141         */
     142        public function get_bulk_actions() {
     143                $actions = array();
     144                $actions['resend']     = _x( 'Email', 'user', 'buddypress' );
     145                $actions['activate']   = _x( 'Activate', 'user', 'buddypress' );
     146                if ( current_user_can( 'delete_users' ) )
     147                        $actions['delete'] = __( 'Delete' );
     148
     149                return $actions;
     150        }
     151
     152        /**
     153         * Nice job, clean sheet!
     154         *
     155         * @since BuddyPress (2.0.0)
     156         */
     157        public function no_items() {
     158                _e( 'No pending accounts found.', 'buddypress' );
     159        }
     160
     161        /**
     162         * The columns signups can be reordered with
     163         *
     164         * @since BuddyPress (2.0.0)
     165         */
     166        public function get_sortable_columns() {
     167                return array(
     168                        'username'   => 'login',
     169                        'email'      => 'email',
     170                        'registered' => 'signup_id',
     171                );
     172        }
     173
     174        /**
     175         * Display signups rows
     176         *
     177         * @since BuddyPress (2.0.0)
     178         */
     179        public function display_rows() {
     180                $style = '';
     181                foreach ( $this->items as $userid => $signup_object ) {
     182
     183                        $style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"';
     184                        echo "\n\t" . $this->single_row( $signup_object, $style );
     185                }
     186        }
     187
     188        /**
     189         * Display a signup row
     190         *
     191         * @since BuddyPress (2.0.0)
     192         */
     193        public function single_row( $signup_object = null, $style = '', $role = '', $numposts = 0 ) {
     194
     195                echo '<tr' . $style . ' id="signup-' . esc_attr( $signup_object->id ) . '">';
     196                echo $this->single_row_columns( $signup_object );
     197                echo '</tr>';
     198        }
     199
     200        /**
     201         * The item to select for the bulk actions
     202         *
     203         * @since BuddyPress (2.0.0)
     204         */
     205        public function column_cb( $signup_object = null ) {
     206                ?>
     207                <label class="screen-reader-text" for="signup_<?php echo $signup_object->id; ?>"><?php echo sprintf( __( 'Select %s' ), $signup_object->user_login ); ?></label>
     208                <input type="checkbox" id="signup_<?php echo $signup_object->id ?>" name="allsignups[]" value="<?php echo esc_attr( $signup_object->id ) ?>" />
     209                <?php
     210        }
     211
     212        /**
     213         * The row actions (delete/activate/email)
     214         *
     215         * @since BuddyPress (2.0.0)
     216         */
     217        public function column_username( $signup_object = null ) {
     218                $avatar = get_avatar( $signup_object->user_email, 32 );
     219
     220                // Activation email link
     221                $email_link = add_query_arg( array(
     222                                'page' => 'bp-signups',
     223                                'signup_id' => $signup_object->id,
     224                                'action' => 'resend'
     225                        ),
     226                        bp_get_admin_url( 'users.php' )
     227                );
     228
     229                // Activate link
     230                $activate_link = add_query_arg( array(
     231                                'page' => 'bp-signups',
     232                                'signup_id' => $signup_object->id,
     233                                'action' => 'activate'
     234                        ),
     235                        bp_get_admin_url( 'users.php' )
     236                );
     237
     238                // Delete link
     239                $delete_link = add_query_arg( array(
     240                                'page' => 'bp-signups',
     241                                'signup_id' => $signup_object->id,
     242                                'action' => 'delete'
     243                        ),
     244                        bp_get_admin_url( 'users.php' )
     245                );
     246
     247                echo $avatar . '<strong><a href="' . $activate_link .'" class="edit" title="' . esc_attr__( 'Activate', 'buddypress' ) . '">' . $signup_object->user_login .'</a></strong><br/>';
     248
     249                $actions = array();
     250
     251                $now = current_time( 'timestamp', true );
     252                $sent_at =  mysql2date('U', $signup_object->date_sent );
     253                $diff = $now - $sent_at;
     254
     255                // Only if resent happened more than a day ago.
     256                if ( $diff > 1 * DAY_IN_SECONDS )
     257                        $actions['resend'] = '<a href="' . $email_link . '">' . __( 'Email', 'buddypress' ) . '</a>';
     258
     259                if ( current_user_can( 'delete_users' ) ) {
     260                        $actions['delete'] = '<a href="' . $delete_link . '" class="delete">' . __( 'Delete', 'buddypress' ) . '</a>';
     261                }
     262               
     263                $actions = apply_filters( 'bp_members_ms_signup_row_actions', $actions, $signup_object );
     264                echo $this->row_actions( $actions );
     265        }
     266
     267        /**
     268         * Display user name if any
     269         *
     270         * @since BuddyPress (2.0.0)
     271         */
     272        public function column_name( $signup_object = null ) {
     273                echo $signup_object->user_name;
     274        }
     275
     276        /**
     277         * Display user email
     278         *
     279         * @since BuddyPress (2.0.0)
     280         */
     281        public function column_email( $signup_object = null ) {
     282                echo '<a href="mailto:' . $signup_object->user_email . '">' . $signup_object->user_email .'</a>';
     283        }
     284
     285        /**
     286         * Display registration date
     287         *
     288         * @since BuddyPress (2.0.0)
     289         */
     290        public function column_registered( $signup_object = null ) {
     291                echo mysql2date( 'Y/m/d', $signup_object->registered );
     292        }
     293
     294        /**
     295         * Display the last time an activation email has been sent
     296         *
     297         * @since BuddyPress (2.0.0)
     298         */
     299        public function column_date_sent( $signup_object = null ) {
     300                echo mysql2date( 'Y/m/d', $signup_object->date_sent );
     301        }
     302
     303        /**
     304         * Display number of time an activation email has been sent
     305         *
     306         * @since BuddyPress (2.0.0)
     307         */
     308        public function column_count_sent( $signup_object = null ) {
     309                echo absint( $signup_object->count_sent );
     310        }
     311
     312}
     313
     314endif;
     315
     316
     317if ( class_exists( 'WP_MS_Users_List_Table' ) ) :
     318/**
     319 * List table class for signups network admin page.
     320 *
     321 * @since BuddyPress (2.0.0)
     322 */
     323class BP_Members_MS_List_Table extends WP_MS_Users_List_Table {
     324
     325        /**
     326         * Signup counts.
     327         *
     328         * @since BuddyPress (2.0.0)
     329         *
     330         * @access public
     331         * @var int
     332         */
     333        public $signup_counts = 0;
     334
     335        /**
     336         * Constructor
     337         *
     338         * @since BuddyPress (2.0.0)
     339         */
     340        public function __construct() {
     341                // Define singular and plural labels, as well as whether we support AJAX.
     342                parent::__construct( array(
     343                        'ajax'     => false,
     344                        'plural'   => 'signups',
     345                        'singular' => 'signup',
     346                ) );
     347        }
     348
     349        /**
     350         * Set up items for display in the list table.
     351         *
     352         * Handles filtering of data, sorting, pagination, and any other data
     353         * manipulation required prior to rendering.
     354         *
     355         * @since BuddyPress (2.0.0)
     356         */
     357        public function prepare_items() {
     358                global $usersearch, $wpdb, $mode;
     359               
     360                $usersearch = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
     361
     362                $signups_per_page = $this->get_items_per_page( str_replace( '-', '_', "{$this->screen->id}_per_page" ) );
     363
     364                $paged = $this->get_pagenum();
     365
     366                $args = array(
     367                        'offset'     => ( $paged - 1 ) * $signups_per_page,
     368                        'number'     => $signups_per_page,
     369                        'usersearch' => $usersearch,
     370                        'orderby'    => 'signup_id',
     371                        'order'      => 'DESC'
     372                );
     373
     374                if ( isset( $_REQUEST['orderby'] ) )
     375                        $args['orderby'] = $_REQUEST['orderby'];
     376
     377                if ( isset( $_REQUEST['order'] ) )
     378                        $args['order'] = $_REQUEST['order'];
     379
     380                $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
     381
     382                $signups = BP_Core_SignUp::get( $args );
     383
     384                $this->items = $signups['signups'];
     385                $this->signup_counts = $signups['total'];
     386
     387                $this->set_pagination_args( array(
     388                        'total_items' => $this->signup_counts,
     389                        'per_page'    => $signups_per_page,
     390                ) );
     391        }
     392
     393        /**
     394         * Get the views : the links above the WP List Table.
     395         *
     396         * @since BuddyPress (2.0.0)
     397         *
     398         * @uses WP_MS_Users_List_Table::get_views() to get the users views
     399         */
     400        function get_views() {
     401                $views = parent::get_views();
     402
     403                $views['all'] = str_replace( 'class="current"', '', $views['all'] );
     404                        $class = ' class="current"';
     405
     406                $views['registered'] = '<a href="' . add_query_arg( 'page', 'bp-signups', bp_get_admin_url( 'users.php' ) ) . '"  class="current">' . sprintf( _nx( 'Pending account <span class="count">(%s)</span>', 'Pending accounts <span class="count">(%s)</span>', $this->signup_counts, 'signup users', 'buddypress' ), number_format_i18n( $this->signup_counts ) ) . '</a>';
     407
     408                return $views;
     409        }
     410
     411        /**
     412         * Specific signups columns
     413         *
     414         * @since BuddyPress (2.0.0)
     415         */
     416        public function get_columns() {
     417                return apply_filters( 'bp_members_ms_signup_columns', array(
     418                        'cb'         => '<input type="checkbox" />',
     419                        'username'   => __( 'Username', 'buddypress' ),
     420                        'name'       => __( 'Name', 'buddypress' ),
     421                        'email'      => __( 'E-mail', 'buddypress' ),
     422                        'registered' => __( 'Registered', 'buddypress' ),
     423                        'date_sent'  => __( 'Last mail', 'buddypress' ),
     424                        'count_sent' => __( 'Mail count', 'buddypress' )
     425                ) );
     426        }
     427
     428        /**
     429         * Specific bulk actions for signups
     430         *
     431         * @since BuddyPress (2.0.0)
     432         */
     433        public function get_bulk_actions() {
     434                $actions = array();
     435                $actions['resend']     = _x( 'Email', 'user', 'buddypress' );
     436                $actions['activate']   = _x( 'Activate', 'user', 'buddypress' );
     437                if ( current_user_can( 'delete_users' ) )
     438                        $actions['delete'] = __( 'Delete' );
     439
     440                return $actions;
     441        }
     442
     443        /**
     444         * Nice job, clean sheet!
     445         *
     446         * @since BuddyPress (2.0.0)
     447         */
     448        public function no_items() {
     449                _e( 'No pending accounts found.', 'buddypress' );
     450        }
     451
     452        /**
     453         * The columns signups can be reordered with
     454         *
     455         * @since BuddyPress (2.0.0)
     456         */
     457        public function get_sortable_columns() {
     458                return array(
     459                        'username'   => 'login',
     460                        'email'      => 'email',
     461                        'registered' => 'signup_id',
     462                );
     463        }
     464
     465        /**
     466         * Display signups rows
     467         *
     468         * @since BuddyPress (2.0.0)
     469         */
     470        public function display_rows() {
     471                $style = '';
     472                foreach ( $this->items as $userid => $signup_object ) {
     473
     474                        $style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"';
     475                        echo "\n\t" . $this->single_row( $signup_object, $style );
     476                }
     477        }
     478
     479        /**
     480         * Display a signup row
     481         *
     482         * @since BuddyPress (2.0.0)
     483         */
     484        public function single_row( $signup_object = null, $style = '' ) {
     485
     486                echo '<tr' . $style . ' id="signup-' . esc_attr( $signup_object->id ) . '">';
     487                echo $this->single_row_columns( $signup_object );
     488                echo '</tr>';
     489        }
     490
     491        /**
     492         * The item to select for the bulk actions
     493         *
     494         * @since BuddyPress (2.0.0)
     495         */
     496        public function column_cb( $signup_object = null ) {
     497                ?>
     498                <label class="screen-reader-text" for="signup_<?php echo $signup_object->id; ?>"><?php echo sprintf( __( 'Select %s' ), $signup_object->user_login ); ?></label>
     499                <input type="checkbox" id="signup_<?php echo $signup_object->id ?>" name="allsignups[]" value="<?php echo esc_attr( $signup_object->id ) ?>" />
     500                <?php
     501        }
     502
     503        /**
     504         * The row actions (delete/activate/email)
     505         *
     506         * @since BuddyPress (2.0.0)
     507         */
     508        public function column_username( $signup_object = null ) {
     509                $avatar = get_avatar( $signup_object->user_email, 32 );
     510
     511                // Activation email link
     512                $email_link = add_query_arg( array(
     513                                'page' => 'bp-signups',
     514                                'signup_id' => $signup_object->id,
     515                                'action' => 'resend'
     516                        ),
     517                        bp_get_admin_url( 'users.php' )
     518                );
     519
     520                // Activate link
     521                $activate_link = add_query_arg( array(
     522                                'page' => 'bp-signups',
     523                                'signup_id' => $signup_object->id,
     524                                'action' => 'activate'
     525                        ),
     526                        bp_get_admin_url( 'users.php' )
     527                );
     528
     529                // Delete link
     530                $delete_link = add_query_arg( array(
     531                                'page' => 'bp-signups',
     532                                'signup_id' => $signup_object->id,
     533                                'action' => 'delete'
     534                        ),
     535                        bp_get_admin_url( 'users.php' )
     536                );
     537
     538                echo $avatar . '<strong><a href="' . $activate_link .'" class="edit" title="' . esc_attr__( 'Activate', 'buddypress' ) . '">' . $signup_object->user_login .'</a></strong><br/>';
     539
     540                $now = current_time( 'timestamp', true );
     541                $sent_at =  mysql2date('U', $signup_object->date_sent );
     542                $diff = $now - $sent_at;
     543
     544                // Only if resent happened more than a day ago.
     545                if ( $diff > 1 * DAY_IN_SECONDS )
     546                        $actions['resend'] = '<a href="' . $email_link . '">' . __( 'Email', 'buddypress' ) . '</a>';
     547
     548                if ( current_user_can( 'delete_users' ) ) {
     549                        $actions['delete'] = '<a href="' . $delete_link . '" class="delete">' . __( 'Delete', 'buddypress' ) . '</a>';
     550                }
     551               
     552                $actions = apply_filters( 'bp_members_ms_signup_row_actions', $actions, $signup_object );
     553                echo $this->row_actions( $actions );
     554        }
     555
     556        /**
     557         * Display user name if any
     558         *
     559         * @since BuddyPress (2.0.0)
     560         */
     561        public function column_name( $signup_object = null ) {
     562                echo $signup_object->user_name;
     563        }
     564
     565        /**
     566         * Display user email
     567         *
     568         * @since BuddyPress (2.0.0)
     569         */
     570        public function column_email( $signup_object = null ) {
     571                echo '<a href="mailto:' . $signup_object->user_email . '">' . $signup_object->user_email .'</a>';
     572        }
     573
     574        /**
     575         * Display registration date
     576         *
     577         * @since BuddyPress (2.0.0)
     578         */
     579        public function column_registered( $signup_object = null ) {
     580                global $mode;
     581
     582                if ( 'list' == $mode )
     583                        $date = 'Y/m/d';
     584                else
     585                        $date = 'Y/m/d \<\b\r \/\> g:i:s a';
     586
     587                echo mysql2date( $date, $signup_object->registered ) . "</td>";
     588        }
     589
     590        /**
     591         * Display the last time an activation email has been sent
     592         *
     593         * @since BuddyPress (2.0.0)
     594         */
     595        public function column_date_sent( $signup_object = null ) {
     596                global $mode;
     597
     598                if ( 'list' == $mode )
     599                        $date = 'Y/m/d';
     600                else
     601                        $date = 'Y/m/d \<\b\r \/\> g:i:s a';
     602
     603                echo mysql2date( $date, $signup_object->date_sent );
     604        }
     605
     606        /**
     607         * Display number of time an activation email has been sent
     608         *
     609         * @since BuddyPress (2.0.0)
     610         */
     611        public function column_count_sent( $signup_object = null ) {
     612                echo absint( $signup_object->count_sent );
     613        }
     614
     615}
     616
     617endif;
  • bp-members/bp-members-admin.php

    diff --git bp-members/bp-members-admin.php bp-members/bp-members-admin.php
    index c9c99e1..f7df668 100644
    class BP_Members_Admin { 
    6262         * @since BuddyPress (2.0.0)
    6363         *
    6464         * @uses buddypress() to get BuddyPress main instance
     65         * @static
    6566         */
    6667        public static function register_members_admin() {
    6768                if( ! is_admin() )
    class BP_Members_Admin { 
    116117
    117118                // BuddyPress edit user's profile url
    118119                $this->edit_profile_url = add_query_arg( 'page', 'bp-profile-edit', bp_get_admin_url( 'users.php' ) );
     120
     121                /**** Specific to Signups ****/
     122               
     123                $this->users_page = '';
     124                $this->signups_page = '';
     125                $this->users_url = bp_get_admin_url( 'users.php' );
     126                $this->users_screen = bp_core_do_network_admin() ? 'users-network' : 'users';
    119127        }
    120128
    121129        /**
    class BP_Members_Admin { 
    126134         */
    127135        private function setup_actions() {
    128136
    129                 /** Actions ***************************************************/
     137                /** Community Profile ***************************************************/
    130138
    131139                // Add some page specific output to the <head>
    132140                add_action( 'bp_admin_head',            array( $this, 'admin_head'      ), 999    );
    class BP_Members_Admin { 
    140148                // Create the Profile Navigation (WordPress/Community)
    141149                add_action( 'edit_user_profile',        array( $this, 'profile_nav'     ),  99, 1 );
    142150
    143 
    144                 /** Filters ***************************************************/
    145 
    146151                // Add a row action to users listing
    147152                add_filter( bp_core_do_network_admin() ? 'ms_user_row_actions' : 'user_row_actions', array( $this, 'row_actions' ), 10, 2 );
    148153
     154
     155                /** Signups **************************************************************/
     156               
     157                if( bp_get_signup_allowed() ) {
     158
     159                        if ( ! is_multisite() )
     160                                add_action( 'pre_user_query', array( $this, 'remove_signups_from_user_query'),  10, 1 );
     161
     162                        // Reorganise the views navigation in users.php and signups page
     163                        add_filter( "views_{$this->users_screen}", array( $this, 'signup_filter_view' ),    10, 1 );
     164                        add_filter( 'set-screen-option',           array( $this, 'signup_screen_options' ), 10, 3 );
     165                }
     166
    149167        }
    150168
    151169        /**
    152          * Create the All Users > Edit Profile submenu.
     170         * Create the All Users > Edit Profile and Signups submenus.
    153171         *
    154172         * @access public
    155173         * @since BuddyPress (2.0.0)
    class BP_Members_Admin { 
    159177        public function admin_menus() {
    160178
    161179                // Manage user's profile
    162                 $hook = $this->user_page = add_users_page(
     180                $hooks['user'] = $this->user_page = add_users_page(
    163181                        __( 'Edit Profile',  'buddypress' ),
    164182                        __( 'Edit Profile',  'buddypress' ),
    165183                        'bp_moderate',
    class BP_Members_Admin { 
    167185                        array( &$this, 'user_admin' )
    168186                );
    169187
     188                $hooks['signups'] = $this->users_page = add_users_page(
     189                        __( 'Manage Signups',  'buddypress' ),
     190                        __( 'Manage Signups',  'buddypress' ),
     191                        'bp_moderate',
     192                        'bp-signups',
     193                        array( &$this, 'signups_admin' )
     194                );
     195
    170196                $edit_page = 'user-edit';
     197                $this->users_page = 'users';
    171198
    172199                if ( bp_core_do_network_admin() ) {
    173                         $edit_page       .= '-network';
    174                         $this->user_page .= '-network';
     200                        $edit_page          .= '-network';
     201                        $this->users_page   .= '-network';
     202                        $this->user_page    .= '-network';
     203                        $this->signups_page .= '-network';
    175204                }
    176205
    177206                $this->screen_id = array( $edit_page, $this->user_page );
    178207
    179                 add_action( "admin_head-$hook", array( $this, 'modify_admin_menu_highlight' ) );
    180                 add_action( "load-$hook",       array( $this, 'user_admin_load' ) );
     208                foreach ( $hooks as $key => $hook ) {
     209                        add_action( "admin_head-$hook", array( $this, 'modify_admin_menu_highlight' ) );
     210                        add_action( "load-$hook",       array( $this, $key .'_admin_load' ) );
     211                }
     212
     213        }
     214
     215        /**
     216         * Highlight the Users menu if on Edit Profile or Signups pages.
     217         *
     218         * @access public
     219         * @since BuddyPress (2.0.0)
     220         */
     221        public function modify_admin_menu_highlight() {
     222                global $plugin_page, $submenu_file;
     223
     224                // Only Show the All users menu
     225                if ( in_array( $plugin_page, array( 'bp-profile-edit', 'bp-signups' ) ) ) {
     226                        $submenu_file = 'users.php';
     227                }
     228        }
     229
     230        /**
     231         * Remove the Edit Profile & Signups submenu page.
     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' );
    181239
     240                // Remove submenu to force using users views
     241                remove_submenu_page( 'users.php', 'bp-signups' );
    182242        }
    183243
     244        /******* Community Profile ******************************************************************************************/
     245
    184246        /**
    185247         * Add some specific styling to the Edit User and Edit User's Profile page.
    186248         *
    class BP_Members_Admin { 
    248310        }
    249311
    250312        /**
    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' );
    274         }
    275 
    276         /**
    277313         * Set up the user's profile admin page.
    278314         *
    279315         * Loaded before the page is rendered, this function does all initial
    class BP_Members_Admin { 
    691727
    692728                return array_merge( $new_edit_actions, $actions );
    693729        }
     730
     731        /******* Signups Management ******************************************************************************************/
     732
     733        /**
     734         * Display the admin preferences about signups pagination
     735         *
     736         * @access public
     737         * @since BuddyPress (2.0.0)
     738         *
     739         * @param  int $value
     740         * @param  string $option
     741         * @param  int $new_value
     742         * @return int the pagination preferences
     743         */
     744        public function signup_screen_options( $value = 0, $option = '', $new_value = 0 ) {
     745                if ( 'users_page_bp_signups_network_per_page' != $option && 'users_page_bp_signups_per_page' != $option )
     746                        return $value;
     747
     748                // Per page
     749                $new_value = (int) $new_value;
     750                if ( $new_value < 1 || $new_value > 999 )
     751                        return $value;
     752
     753                return $new_value;
     754        }
     755
     756        /**
     757         * Make sure no signups will show in users list
     758         *
     759         * This is needed to eventually handle signups that
     760         * may have not been activated before the 2.0.0 upgrade
     761         *
     762         * @access public
     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                if ( bp_is_update() )
     772                        return;
     773
     774                if ( $this->users_page != get_current_screen()->id )
     775                        return;
     776
     777                if ( ! empty( $query->query_vars['role'] ) )
     778                        return;
     779
     780                $query->query_where .= " AND {$wpdb->users}.user_status != 2";
     781        }
     782
     783        /**
     784         * Filter the WP Users List Table views to include the signup one
     785         *
     786         * @access public
     787         * @since BuddyPress (2.0.0)
     788         *
     789         * @param  array  $views the WP List Table views
     790         * @return array  the views with the signup one
     791         */
     792        public function signup_filter_view( $views = array() ) {
     793                $class = '';
     794
     795                $signups = BP_Core_Signup::count_signups();
     796
     797                if ( $this->signups_page == get_current_screen()->id ) {
     798                        $views['all'] = str_replace( 'class="current"', '', $views['all'] );
     799                        $class = ' class="current"';
     800                }
     801
     802                $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>';
     803
     804                return $views;
     805        }
     806
     807        /**
     808         * Load the Signup WP Users List table
     809         *
     810         * @access public
     811         * @since BuddyPress (2.0.0)
     812         *
     813         * @param  string $class    the name of the class to use
     814         * @param  string $required the parent class
     815         * @return WP_List_Table    the List table
     816         * @static
     817         */
     818        public static function get_list_table_class( $class = '', $required = '' ) {
     819                if ( empty( $class ) )
     820                        return;
     821
     822                if ( ! empty( $required ) ) {
     823                        require_once( ABSPATH . 'wp-admin/includes/class-wp-' . $required . '-list-table.php' );
     824                        require_once( buddypress()->members->admin->admin_dir . 'bp-members-classes.php'    );
     825                }
     826
     827                return new $class();
     828        }
     829
     830        /**
     831         * Set up the signups admin page.
     832         *
     833         * Loaded before the page is rendered, this function does all initial
     834         * setup, including: processing form requests, registering contextual
     835         * help, and setting up screen options.
     836         *
     837         * @access public
     838         * @since BuddyPress (2.0.0)
     839         *
     840         * @global $bp_members_signup_list_table
     841         */
     842        public function signups_admin_load() {
     843                global $bp_members_signup_list_table;
     844
     845                // Build redirection URL
     846                $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'] );
     847                $doaction = bp_admin_list_table_current_bulk_action();
     848
     849                // Call an action for plugins to hook in early
     850                do_action_ref_array( 'bp_signups_admin_load', array( $doaction, $_REQUEST ) );
     851
     852                // Allowed actions
     853                $allowed_actions = apply_filters( 'bp_signups_admin_allowed_actions', array( 'do_delete', 'do_activate', 'do_resend' ) );
     854
     855                // Prepare the display of the Community Profile screen
     856                if ( ! in_array( $doaction, $allowed_actions ) || -1 == $doaction ) {
     857                       
     858                        if ( bp_core_do_network_admin() ) {
     859                                $bp_members_signup_list_table = self::get_list_table_class( 'BP_Members_MS_List_Table', 'ms-users' );
     860                        } else {
     861                                $bp_members_signup_list_table = self::get_list_table_class( 'BP_Members_List_Table', 'users' );
     862                        }
     863
     864                        // per_page screen option
     865                        add_screen_option( 'per_page', array( 'label' => _x( 'Pending Accounts', 'Pending Accounts per page (screen options)', 'buddypress' ) ) );
     866
     867                        get_current_screen()->add_help_tab( array(
     868                                'id'      => 'bp-signups-overview',
     869                                'title'   => __( 'Overview', 'buddypress' ),
     870                                'content' =>
     871                                '<p>' . __( 'This is the admininistration screen of the pending accounts of your site.', 'buddypress' ) . '</p>' .
     872                                '<p>' . __( 'From the screen options, you can customize the displayed columns and the pagination of this screen.', 'buddypress' ) . '</p>' .
     873                                '<p>' . __( 'You can reorder the list of your pending accounts by clicking on the Username, E-mail or Registered column headers.', 'buddypress' ) . '</p>' .
     874                                '<p>' . __( 'Using the search form, you can find pending accounts more easily: Username and E-mail fields will be looked at.', 'buddypress' ) . '</p>'
     875                        ) );
     876
     877                        get_current_screen()->add_help_tab( array(
     878                                'id'      => 'bp-signups-actions',
     879                                'title'   => __( 'Actions', 'buddypress' ),
     880                                'content' =>
     881                                '<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>' .
     882                                '<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 link once per day.', 'buddypress' ) . '</li>' .
     883                                '<li>' . __( 'Delete allows you to delete a pending account from your site, once you confirmed your choice from the confirmation screen.', 'buddypress' ) . '</li></ul>' .
     884                                '<p>' . __( 'By clicking on a Username you will be able to activate a pending account from the confirmation screen.', 'buddypress' ) . '</p>' .
     885                                '<p>' . __( 'Bulk actions allow you to perform these 3 actions for the selected rows.', 'buddypress' ) . '</p>'
     886                        ) );
     887
     888                        // Help panel - sidebar links
     889                        get_current_screen()->set_help_sidebar(
     890                                '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
     891                                '<p>' . __( '<a href="http://codex.buddypress.org/buddypress-site-administration/managing-signups/">Managing Sign-ups</a>', 'buddypress' ) . '</p>' .
     892                                '<p>' . __( '<a href="http://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
     893                        );
     894                } else {
     895                        if ( ! empty( $_REQUEST['signup_ids' ] ) )
     896                                $signups = wp_parse_id_list( $_REQUEST['signup_ids' ] );
     897
     898                        // Handle resent activation links
     899                        if ( 'do_resend' == $doaction ) {
     900                                // nonce check
     901                                check_admin_referer( 'signups_resend' );
     902
     903                                $resent = BP_Core_SignUp::resend( $signups );
     904
     905                                if ( empty( $resent ) ) {
     906                                        $redirect_to = add_query_arg( 'error', $doaction, $redirect_to );
     907                                // resent activation emails
     908                                } else {
     909                                        $query_arg = array( 'updated' => 'resent' );
     910
     911                                        if ( ! empty( $resent['resent'] ) )
     912                                                $query_arg['resent'] = count( $resent['resent'] );
     913
     914                                        if ( ! empty( $resent['errors'] ) ) {
     915                                                $query_arg['notsent'] = count( $resent['errors'] );
     916                                                set_transient( '_bp_admin_signups_errors', $resent['errors'], 30 );
     917                                        }                                               
     918
     919                                        $redirect_to = add_query_arg( $query_arg, $redirect_to );
     920                                }
     921
     922                                bp_core_redirect( $redirect_to );
     923
     924                        // Handle activated accounts
     925                        } else if ( 'do_activate' == $doaction ) {
     926                                // nonce check
     927                                check_admin_referer( 'signups_activate' );
     928
     929                                $activated = BP_Core_SignUp::activate( $signups );
     930
     931                                if ( empty( $activated ) ) {
     932                                        $redirect_to = add_query_arg( 'error', $doaction, $redirect_to );
     933                                // activate signups
     934                                } else {
     935                                        $query_arg = array( 'updated' => 'activated' );
     936
     937                                        if ( ! empty( $activated['activated'] ) )
     938                                                $query_arg['activated'] = count( $activated['activated'] );
     939
     940                                        if ( ! empty( $activated['errors'] ) ) {
     941                                                $query_arg['notactivated'] = count( $activated['errors'] );
     942                                                set_transient( '_bp_admin_signups_errors', $activated['errors'], 30 );
     943                                        }
     944
     945                                        $redirect_to = add_query_arg( $query_arg, $redirect_to );
     946                                }
     947
     948                                bp_core_redirect( $redirect_to );
     949
     950                        // Handle sign-ups delete
     951                        } else if ( 'do_delete' == $doaction ) {
     952                                // nonce check
     953                                check_admin_referer( 'signups_delete' );
     954
     955                                $deleted = BP_Core_SignUp::delete( $signups );
     956
     957                                if ( empty( $deleted ) ) {
     958                                        $redirect_to = add_query_arg( 'error', $doaction, $redirect_to );
     959                                // delete signups
     960                                } else {
     961                                        $query_arg = array( 'updated' => 'deleted' );
     962
     963                                        if ( ! empty( $deleted['deleted'] ) )
     964                                                $query_arg['deleted'] = count( $deleted['deleted'] );
     965
     966                                        if ( ! empty( $deleted['errors'] ) ) {
     967                                                $query_arg['notdeleted'] = count( $deleted['errors'] );
     968                                                set_transient( '_bp_admin_signups_errors', $deleted['errors'], 30 );
     969                                        }
     970
     971                                        $redirect_to = add_query_arg( $query_arg, $redirect_to );
     972                                }
     973
     974                                bp_core_redirect( $redirect_to );
     975
     976                        // Plugins can update other stuff from here
     977                        } else {
     978                                $this->redirect = $redirect_to;
     979
     980                                do_action_ref_array( 'bp_members_admin_update_signups', array( $doaction, $_REQUEST, $this->redirect ) );
     981
     982                                bp_core_redirect( $this->redirect );
     983                        }
     984                }
     985        }
     986
     987        /**
     988         * Display the activation errors
     989         *
     990         * @access public
     991         * @since BuddyPress (2.0.0)
     992         */
     993        public function signups_display_errors() {
     994                // Bail if no activation errors
     995                if ( ! $errors = get_transient( '_bp_admin_signups_errors' ) )
     996                        return;
     997
     998                foreach ( $errors as $error ) {
     999                        ?>
     1000                        <li><?php echo esc_html( $error[0] );?>: <?php echo esc_html( $error[1] );?></li>
     1001                        <?php
     1002                }
     1003
     1004                // Delete the redirect transient
     1005                delete_transient( '_bp_admin_signups_errors' );
     1006        }
     1007
     1008        /**
     1009         * Choose the best signups admin page
     1010         *
     1011         * Depending on the context, display
     1012         * - the list of signups
     1013         * - or the delete confirmation screen
     1014         * - or the activate confirmation screen
     1015         * - or the "resend" email confirmation screen
     1016         *
     1017         * Also prepare the admin notices
     1018         *
     1019         * @access public
     1020         * @since BuddyPress (2.0.0)
     1021         */
     1022        public function signups_admin() {
     1023                $doaction = bp_admin_list_table_current_bulk_action();
     1024
     1025                // Prepare notices for admin
     1026                $notice = array();
     1027
     1028                if ( ! empty( $_REQUEST['updated'] ) ) {
     1029                        switch ( $_REQUEST['updated'] ) {
     1030                                case 'resent':
     1031                                        $notice = array(
     1032                                                'class'   => 'updated',
     1033                                                'message' => ''
     1034                                        );
     1035
     1036                                        if ( ! empty( $_REQUEST['resent'] ) ) {
     1037                                                $notice['message'] .= sprintf(
     1038                                                        _nx( '%s activation email successfully sent! ', '%s activation emails successfully sent! ',
     1039                                                         absint( $_REQUEST['resent'] ),
     1040                                                         'signup resent',
     1041                                                         'buddypress'
     1042                                                        ),
     1043                                                        number_format_i18n( absint( $_REQUEST['resent'] ) )
     1044                                                );
     1045                                        }
     1046
     1047                                        if ( ! empty( $_REQUEST['notsent'] ) ) {
     1048                                                $notice['message'] .= sprintf(
     1049                                                        _nx( '%s activation email was not sent.', '%s activation emails were not sent.',
     1050                                                         absint( $_REQUEST['notsent'] ),
     1051                                                         'signup notsent',
     1052                                                         'buddypress'
     1053                                                        ),
     1054                                                        number_format_i18n( absint( $_REQUEST['notsent'] ) )
     1055                                                );
     1056
     1057                                                if ( empty( $_REQUEST['resent'] ) )
     1058                                                        $notice['class'] = 'error';
     1059                                        }
     1060                                               
     1061                                        break;
     1062
     1063                                case 'activated':
     1064                                        $notice = array(
     1065                                                'class'   => 'updated',
     1066                                                'message' => ''
     1067                                        );
     1068
     1069                                        if ( ! empty( $_REQUEST['activated'] ) ) {
     1070                                                $notice['message'] .= sprintf(
     1071                                                        _nx( '%s account successfully activated! ', '%s accounts successfully activated! ',
     1072                                                         absint( $_REQUEST['activated'] ),
     1073                                                         'signup resent',
     1074                                                         'buddypress'
     1075                                                        ),
     1076                                                        number_format_i18n( absint( $_REQUEST['activated'] ) )
     1077                                                );
     1078                                        }
     1079
     1080                                        if ( ! empty( $_REQUEST['notactivated'] ) ) {
     1081                                                $notice['message'] .= sprintf(
     1082                                                        _nx( '%s account was not activated.', '%s accounts were not activated.',
     1083                                                         absint( $_REQUEST['notactivated'] ),
     1084                                                         'signup notsent',
     1085                                                         'buddypress'
     1086                                                        ),
     1087                                                        number_format_i18n( absint( $_REQUEST['notactivated'] ) )
     1088                                                );
     1089
     1090                                                if ( empty( $_REQUEST['activated'] ) )
     1091                                                        $notice['class'] = 'error';
     1092                                        }
     1093                                               
     1094                                        break;
     1095
     1096                                case 'deleted':
     1097                                        $notice = array(
     1098                                                'class'   => 'updated',
     1099                                                'message' => ''
     1100                                        );
     1101
     1102                                        if ( ! empty( $_REQUEST['deleted'] ) ) {
     1103                                                $notice['message'] .= sprintf(
     1104                                                        _nx( '%s sign-up successfully deleted!', '%s sign-ups successfully deleted!',
     1105                                                         absint( $_REQUEST['deleted'] ),
     1106                                                         'signup deleted',
     1107                                                         'buddypress'
     1108                                                        ),
     1109                                                        number_format_i18n( absint( $_REQUEST['deleted'] ) )
     1110                                                );
     1111                                        }
     1112
     1113                                        if ( ! empty( $_REQUEST['notdeleted'] ) ) {
     1114                                                $notice['message'] .= sprintf(
     1115                                                        _nx( '%s sign-up was not deleted.', '%s sign-ups were not deleted.',
     1116                                                         absint( $_REQUEST['notdeleted'] ),
     1117                                                         'signup notdeleted',
     1118                                                         'buddypress'
     1119                                                        ),
     1120                                                        number_format_i18n( absint( $_REQUEST['notdeleted'] ) )
     1121                                                );
     1122
     1123                                                if ( empty( $_REQUEST['deleted'] ) )
     1124                                                        $notice['class'] = 'error';
     1125                                        }
     1126                                               
     1127                                        break;
     1128                        }
     1129                }
     1130
     1131                if ( ! empty( $_REQUEST['error'] ) ) {
     1132                        switch ( $_REQUEST['error'] ) {
     1133                                case 'do_resend':
     1134                                        $notice = array(
     1135                                                'class'   => 'error',
     1136                                                'message' => esc_html__( 'There was a problem sending the activation emails, please try again.', 'buddypress' )
     1137                                        );
     1138                                        break;
     1139                                case 'do_activate':
     1140                                        $notice = array(
     1141                                                'class'   => 'error',
     1142                                                'message' => esc_html__( 'There was a problem activating accounts, please try again.', 'buddypress' )
     1143                                        );
     1144                                        break;
     1145                                case 'do_delete':
     1146                                        $notice = array(
     1147                                                'class'   => 'error',
     1148                                                'message' => esc_html__( 'There was a problem deleting sign-ups, please try again.', 'buddypress' )
     1149                                        );
     1150                                        break;
     1151                        }
     1152                }
     1153
     1154                if ( ! empty( $notice ) ) :
     1155                        if ( 'updated' === $notice['class'] ) : ?>
     1156                                <div id="message" class="<?php echo esc_attr( $notice['class'] ); ?>">
     1157                        <?php else: ?>
     1158                                <div class="<?php echo esc_attr( $notice['class'] ); ?>">
     1159                        <?php endif; ?>
     1160                                <p><?php echo $notice['message']; ?></p>
     1161                                <?php if ( ! empty( $_REQUEST['notactivated'] ) || ! empty( $_REQUEST['notdeleted'] ) || ! empty( $_REQUEST['notsent'] ) ) :?>
     1162                                        <ul><?php $this->signups_display_errors();?></ul>
     1163                                <?php endif ;?>
     1164                        </div>
     1165                <?php endif;
     1166
     1167                switch( $doaction ) {
     1168                        case 'activate' :
     1169                        case 'delete' :
     1170                        case 'resend' :
     1171                                $this->signups_admin_manage( $doaction );
     1172                                break;
     1173
     1174                        default:
     1175                                $this->signups_admin_index();
     1176                                break;
     1177
     1178                }
     1179        }
     1180
     1181        /**
     1182         * This is the list of the Pending accounts (signups)
     1183         *
     1184         * @access public
     1185         * @since BuddyPress (2.0.0)
     1186         *
     1187         * @global $plugin_page
     1188         * @global $bp_members_signup_list_table
     1189         */
     1190        public function signups_admin_index() {
     1191                global $plugin_page, $bp_members_signup_list_table;
     1192
     1193                $usersearch = ! empty( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
     1194                // Prepare the group items for display
     1195                $bp_members_signup_list_table->prepare_items();
     1196
     1197                $form_url = add_query_arg( array(
     1198                        'page' => 'bp-signups'
     1199                        ),
     1200                        bp_get_admin_url( 'users.php' )
     1201                );
     1202                $search_form_url = remove_query_arg(
     1203                        array(
     1204                                'action',
     1205                                'deleted',
     1206                                'notdeleted',
     1207                                'error',
     1208                                'updated',
     1209                                'delete',
     1210                                'activate',
     1211                                'activated',
     1212                                'notactivated',
     1213                                'resend',
     1214                                'resent',
     1215                                'notresent',
     1216                                'do_delete',
     1217                                'do_activate',
     1218                                'do_resend',
     1219                                'action2',
     1220                                '_wpnonce',
     1221                                'signup_ids'
     1222                        ), $_SERVER['REQUEST_URI']
     1223                );
     1224                ?>
     1225
     1226                <div class="wrap">
     1227                        <?php screen_icon( 'users' ); ?>
     1228                        <h2>
     1229                                <?php
     1230                                _e( 'Users', 'buddypress' );
     1231                                if ( current_user_can( 'create_users' ) ) { ?>
     1232                                        <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'user' ); ?></a>
     1233                                <?php } elseif ( is_multisite() && current_user_can( 'promote_users' ) ) { ?>
     1234                                        <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add Existing', 'user' ); ?></a>
     1235                                <?php }
     1236
     1237                                if ( $usersearch )
     1238                                        printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( $usersearch ) ); ?>
     1239                        </h2>
     1240
     1241                        <?php // Display each signups on its own row ?>
     1242                        <?php $bp_members_signup_list_table->views(); ?>
     1243
     1244                        <form id="bp-signups-search-form" action="<?php echo $search_form_url ;?>">
     1245                                <input type="hidden" name="page" value="<?php echo esc_attr( $plugin_page ); ?>" />
     1246                                <?php $bp_members_signup_list_table->search_box( __( 'Search Pending accounts', 'buddypress' ), 'bp-signups' ); ?>
     1247                        </form>
     1248
     1249                        <form id="bp-signups-form" action="<?php echo $form_url;?>" method="post">
     1250                                <?php $bp_members_signup_list_table->display(); ?>
     1251                        </form>
     1252
     1253                </div>
     1254        <?php
     1255        }
     1256
     1257        /**
     1258         * This is the confirmation screen for actions
     1259         *
     1260         * @access public
     1261         * @since BuddyPress (2.0.0)
     1262         *
     1263         * @param  string $action delete/activate or resend activation link
     1264         */
     1265        public function signups_admin_manage( $action = '' ) {
     1266                if ( ! is_super_admin() || empty( $action ) )
     1267                        die( '-1' );
     1268
     1269                $ids = false;
     1270
     1271
     1272                if ( ! empty( $_REQUEST['allsignups'] ) ) {
     1273                        $ids = wp_parse_id_list( $_REQUEST['allsignups'] );
     1274                } else if ( ! empty( $_REQUEST['signup_id'] ) ) {
     1275                        $ids = absint( $_REQUEST['signup_id'] );
     1276                }
     1277
     1278                if ( empty( $ids ) )
     1279                        return false;
     1280
     1281                $signups_query = BP_Core_SignUp::get( array( 'include' => $ids ) );
     1282                $signups = $signups_query['signups'];
     1283
     1284                // Create a new list of signup ids, based on those that actually exist
     1285                $signup_ids = array();
     1286                foreach ( $signups as $signup ) {
     1287                        $signup_ids[] = $signup->signup_id;
     1288                }
     1289
     1290                switch ( $action ) {
     1291                        case 'delete' :
     1292                                $caption = __( 'delete', 'buddypress' );
     1293                                break;
     1294                        case 'activate' :
     1295                                $caption = __( 'activate', 'buddypress' );
     1296                                break;
     1297                        case 'resend' :
     1298                                $caption = __( 'resend activation email to', 'buddypress' ) ;
     1299                }
     1300               
     1301
     1302                $url_args = array( 'page' => 'bp-signups' );
     1303                $action_args = array(
     1304                        'action'     => 'do_' . $action,
     1305                        'signup_ids' => implode( ',', $signup_ids )
     1306                );
     1307
     1308                $cancel_url = add_query_arg( $url_args, bp_get_admin_url( 'users.php' ) );
     1309                $action_url = wp_nonce_url(
     1310                        add_query_arg(
     1311                                array_merge( $url_args, $action_args ),
     1312                                bp_get_admin_url( 'users.php' )
     1313                        ),
     1314                        'signups_' . $action );
     1315                ?>
     1316
     1317                <div class="wrap">
     1318                        <?php screen_icon( 'users' ); ?>
     1319                        <h2><?php printf( __( '%s Pending accounts', 'buddypress' ), ucfirst( $caption ) ); ?></h2>
     1320                        <p><?php printf( _n( 'You are about to %s the following account:', 'You are about to %s the following accounts:', count( $signup_ids ), 'buddypress' ), $caption ); ?></p>
     1321
     1322                        <ol class="bp-signups-list">
     1323                        <?php foreach ( $signups as $signup ) : ?>
     1324                                <li><?php echo esc_html( $signup->user_name ) ?> - <?php echo sanitize_email( $signup->user_email );?></li>
     1325                        <?php endforeach; ?>
     1326                        </ol>
     1327
     1328                        <?php if ( 'resend' != $action ) : ?>
     1329                                <p><strong><?php esc_html_e( 'This action cannot be undone.', 'buddypress' ) ?></strong></p>
     1330                        <?php endif ; ?>
     1331
     1332                        <a class="button-primary" href="<?php echo $action_url; ?>"><?php esc_html_e( 'Confirm', 'buddypress' ); ?></a>
     1333                        <a class="button" href="<?php echo esc_attr( $cancel_url ); ?>"><?php esc_html_e( 'Cancel', 'buddypress' ) ?></a>
     1334                </div>
     1335
     1336                <?php
     1337        }
     1338
    6941339}
    6951340endif; // class_exists check
    6961341
  • bp-members/bp-members-functions.php

    diff --git bp-members/bp-members-functions.php bp-members/bp-members-functions.php
    index d7744fa..f6cc125 100644
    function bp_core_validate_user_signup( $user_name, $user_email ) { 
    12321232                        $errors->add( 'user_name', __( 'Sorry, usernames must have letters too!', 'buddypress' ) );
    12331233                }
    12341234
     1235                // Check into signups
     1236                $signup = BP_Core_SignUp::get_by_userlogin( $user_name );
     1237
    12351238                // Check if the username has been used already.
    1236                 if ( username_exists( $user_name ) ) {
     1239                if ( username_exists( $user_name ) || ! empty( $signup ) ) {
    12371240                        $errors->add( 'user_name', __( 'Sorry, that username already exists!', 'buddypress' ) );
    12381241                }
    12391242
    function bp_core_validate_blog_signup( $blog_url, $blog_title ) { 
    12641267}
    12651268
    12661269function bp_core_signup_user( $user_login, $user_password, $user_email, $usermeta ) {
    1267         global $bp, $wpdb;
     1270        global $bp;
     1271
     1272        // We need to cast $user_id to pass to the filters
     1273        $user_id = false;
    12681274
    12691275        // Multisite installs have their own install procedure
    12701276        if ( is_multisite() ) {
    12711277                wpmu_signup_user( $user_login, $user_email, $usermeta );
    12721278
    1273                 // On multisite, the user id is not created until the user activates the account
    1274                 // but we need to cast $user_id to pass to the filters
    1275                 $user_id = false;
    1276 
    12771279        } else {
    1278                 $errors = new WP_Error();
    1279 
    1280                 $user_id = wp_insert_user( array(
    1281                         'user_login' => $user_login,
    1282                         'user_pass' => $user_password,
    1283                         'display_name' => sanitize_title( $user_login ),
    1284                         'user_email' => $user_email
    1285                 ) );
    12861280
    1287                 if ( is_wp_error( $user_id ) || empty( $user_id ) ) {
    1288                         $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' ) ) );
    1289                         return $errors;
     1281                // Format data
     1282                $user_login     = preg_replace( '/\s+/', '', sanitize_user( $user_login, true ) );
     1283                $user_email     = sanitize_email( $user_email );
     1284                $activation_key = substr( md5( time() . rand() . $user_email ), 0, 16 );
     1285                $meta           = serialize( $usermeta );
     1286
     1287                /**
     1288                 * Plugins may use the user_status / activation_key usermeta mechanism
     1289                 * defining BP_SIGNUP_NOT_USER_YET to true skip this step, in case the
     1290                 * administrator is sure this kind of plugins is not used on his config
     1291                 * and don't want to directly create a user on sign-up.
     1292                 */
     1293                if ( ! defined( 'BP_SIGNUP_NOT_USER_YET' ) ) {
     1294                        $user_id = BP_Core_SignUp::add_backcompat( $user_login, $user_password, $user_email, $usermeta );
     1295
     1296                        if ( is_wp_error( $user_id ) )
     1297                                return $user_id;
     1298
     1299                        $activation_key = wp_hash( $user_id );
     1300                        update_user_meta( $user_id, 'activation_key', $activation_key );
    12901301                }
    12911302
    1292                 // Update the user status to '2' which we will use as 'not activated' (0 = active, 1 = spam, 2 = not active)
    1293                 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_status = 2 WHERE ID = %d", $user_id ) );
    1294 
    1295                 // Set any profile data
    1296                 if ( bp_is_active( 'xprofile' ) ) {
    1297                         if ( !empty( $usermeta['profile_field_ids'] ) ) {
    1298                                 $profile_field_ids = explode( ',', $usermeta['profile_field_ids'] );
    1299 
    1300                                 foreach( (array) $profile_field_ids as $field_id ) {
    1301                                         if ( empty( $usermeta["field_{$field_id}"] ) )
    1302                                                 continue;
    1303 
    1304                                         $current_field = $usermeta["field_{$field_id}"];
    1305                                         xprofile_set_field_data( $field_id, $user_id, $current_field );
    1306 
    1307                                         // Save the visibility level
    1308                                         $visibility_level = !empty( $usermeta['field_' . $field_id . '_visibility'] ) ? $usermeta['field_' . $field_id . '_visibility'] : 'public';
    1309                                         xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level );
    1310                                 }
    1311                         }
    1312                 }
    1313         }
    1314         $bp->signup->username = $user_login;
     1303                $args = array(
     1304                        'user_login'     => $user_login,
     1305                        'user_email'     => $user_email,
     1306                        'activation_key' => $activation_key,
     1307                        'meta'           => $meta
     1308                );
    13151309
    1316         /***
    1317          * Now generate an activation key and send an email to the user so they can activate their
    1318          * account and validate their email address. Multisite installs send their own email, so
    1319          * this is only for single blog installs.
    1320          *
    1321          * To disable sending activation emails you can user the filter
    1322          * 'bp_core_signup_send_activation_key' and return false. Note that this will only disable
    1323          * the email - a key will still be generated, and the account must still be activated
    1324          * before use.
    1325          */
    1326         if ( !is_multisite() ) {
    1327                 $activation_key = wp_hash( $user_id );
    1328                 update_user_meta( $user_id, 'activation_key', $activation_key );
     1310                BP_Core_SignUp::add( $args );
    13291311
    13301312                if ( apply_filters( 'bp_core_signup_send_activation_key', true ) ) {
    13311313                        bp_core_signup_send_validation_email( $user_id, $user_email, $activation_key );
    13321314                }
    13331315        }
    13341316
     1317        $bp->signup->username = $user_login;
     1318
    13351319        do_action( 'bp_core_signup_user', $user_id, $user_login, $user_password, $user_email, $usermeta );
    13361320
    13371321        return $user_id;
    function bp_core_activate_signup( $key ) { 
    13541338                $user = wpmu_activate_signup( $key );
    13551339
    13561340                // If there were errors, add a message and redirect
    1357                 if ( !empty( $user->errors ) ) {
     1341                if ( ! empty( $user->errors ) ) {
    13581342                        return $user;
    13591343                }
    13601344
    13611345                $user_id = $user['user_id'];
    13621346
    1363                 // Set any profile data
    1364                 if ( bp_is_active( 'xprofile' ) ) {
    1365                         if ( !empty( $user['meta']['profile_field_ids'] ) ) {
    1366                                 $profile_field_ids = explode( ',', $user['meta']['profile_field_ids'] );
     1347        } else {
    13671348
    1368                                 foreach( (array) $profile_field_ids as $field_id ) {
    1369                                         $current_field = isset( $user['meta']["field_{$field_id}"] ) ? $user['meta']["field_{$field_id}"] : false;
     1349                $signup = BP_Core_SignUp::get_by_key( $key );
    13701350
    1371                                         if ( !empty( $current_field ) )
    1372                                                 xprofile_set_field_data( $field_id, $user_id, $current_field );
     1351                if ( empty( $signup ) )
     1352                        return new WP_Error( 'invalid_key', __( 'Invalid activation key.', 'buddypress' ) );
    13731353
    1374                                         // Save the visibility level
    1375                                         $visibility_level = !empty( $user['meta']['field_' . $field_id . '_visibility'] ) ? $user['meta']['field_' . $field_id . '_visibility'] : 'public';
    1376                                         xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level );
    1377                                 }
    1378                         }
     1354                if ( $signup->active ) {
     1355                        if ( empty( $signup->domain ) )
     1356                                return new WP_Error( 'already_active', __( 'The user is already active.', 'buddypress' ), $signup );
     1357                        else
     1358                                return new WP_Error( 'already_active', __( 'The site is already active.', 'buddypress' ), $signup );
    13791359                }
    1380         } else {
    13811360
    1382                 // Get the user_id based on the $key
    1383                 $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = 'activation_key' AND meta_value = %s", $key ) );
     1361                $meta = maybe_unserialize( $signup->meta );
     1362                // password is hashed again in wp_insert_user
     1363                $password = wp_generate_password( 12, false );
     1364
     1365                $user_id = username_exists( $signup->user_login );
     1366
     1367                if ( ! $user_id ) {
     1368                        $user_id = wp_create_user( $signup->user_login, $password, $signup->user_email );
     1369                // It might be a signup set in previous versions let's check against previous way of setting activation key
     1370                } else if ( $key == wp_hash( $user_id ) ) {
     1371                        // Change the user's status so they become active
     1372                        if ( ! $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_status = 0 WHERE ID = %d", $user_id ) ) )
     1373                                return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) );
     1374                       
     1375                        bp_delete_user_meta( $user_id, 'activation_key' );
     1376
     1377                        $member = get_userdata( $user_id );
     1378                        $member->set_role( get_option('default_role') );
    13841379
    1385                 if ( empty( $user_id ) )
    1386                         return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) );
     1380                        $user_already_created = true;
    13871381
    1388                 // Change the user's status so they become active
    1389                 if ( !$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_status = 0 WHERE ID = %d", $user_id ) ) )
    1390                         return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) );
     1382                } else {
     1383                        $user_already_exists = true;
     1384                }
     1385                       
     1386                if ( ! $user_id )
     1387                        return new WP_Error( 'create_user', __( 'Could not create user', 'buddypress' ), $signup );
     1388               
     1389                BP_Core_SignUp::validate( $key );
     1390
     1391                if ( isset( $user_already_exists ) )
     1392                        return new WP_Error( 'user_already_exists', __( 'That username is already activated.' ), $signup );
     1393
     1394                $user = array( 'user_id' => $user_id, 'password' => $meta['password'], 'meta' => $meta );
    13911395
    13921396                // Notify the site admin of a new user registration
    13931397                wp_new_user_notification( $user_id );
    13941398
    1395                 // Remove the activation key meta
    1396                 delete_user_meta( $user_id, 'activation_key' );
     1399                if ( isset( $user_already_created ) ) {
     1400
     1401                        do_action( 'bp_core_activated_user', $user_id, $key, $user );
     1402
     1403                        return $user_id;
     1404                }
     1405
     1406        }
     1407
     1408        // Set any profile data
     1409        if ( bp_is_active( 'xprofile' ) ) {
     1410                if ( ! empty( $user['meta']['profile_field_ids'] ) ) {
     1411                        $profile_field_ids = explode( ',', $user['meta']['profile_field_ids'] );
     1412
     1413                        foreach( (array) $profile_field_ids as $field_id ) {
     1414                                $current_field = isset( $user['meta']["field_{$field_id}"] ) ? $user['meta']["field_{$field_id}"] : false;
     1415
     1416                                if ( !empty( $current_field ) )
     1417                                        xprofile_set_field_data( $field_id, $user_id, $current_field );
     1418
     1419                                // Save the visibility level
     1420                                $visibility_level = ! empty( $user['meta']['field_' . $field_id . '_visibility'] ) ? $user['meta']['field_' . $field_id . '_visibility'] : 'public';
     1421                                xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level );
     1422                        }
     1423                }
    13971424        }
    13981425
    13991426        // Update the display_name
    14001427        wp_update_user( array( 'ID' => $user_id, 'display_name' => bp_core_get_user_displayname( $user_id ) ) );
    14011428
    14021429        // Set the password on multisite installs
    1403         if ( is_multisite() && !empty( $user['meta']['password'] ) )
     1430        if ( ! empty( $user['meta']['password'] ) )
    14041431                $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_pass = %s WHERE ID = %d", $user['meta']['password'], $user_id ) );
    14051432
    14061433        do_action( 'bp_core_activated_user', $user_id, $key, $user );
  • bp-members/bp-members-loader.php

    diff --git bp-members/bp-members-loader.php bp-members/bp-members-loader.php
    index c654240..d41ff68 100644
    class BP_Members_Component extends BP_Component { 
    6868                if ( !defined( 'BP_MEMBERS_SLUG' ) )
    6969                        define( 'BP_MEMBERS_SLUG', $this->id );
    7070
    71                 parent::setup_globals( array(
     71                $members_globals = array(
    7272                        'slug'          => BP_MEMBERS_SLUG,
    7373                        'root_slug'     => isset( $bp->pages->members->slug ) ? $bp->pages->members->slug : BP_MEMBERS_SLUG,
    7474                        'has_directory' => true,
    7575                        'search_string' => __( 'Search Members...', 'buddypress' ),
    76                 ) );
     76                );
     77
     78                if ( bp_get_signup_allowed() ) {
     79                        $members_globals['global_tables']['table_name_signups'] = bp_core_get_table_prefix() . 'signups';
     80                }
     81
     82                parent::setup_globals( $members_globals );
    7783
    7884                /** Logged in user ****************************************************/
    7985
  • bp-members/bp-members-screens.php

    diff --git bp-members/bp-members-screens.php bp-members/bp-members-screens.php
    index 72a4031..79eab0a 100644
    function bp_core_screen_activation() { 
    251251                        bp_core_redirect( trailingslashit( bp_get_root_domain() . '/' . $bp->pages->activate->slug ) );
    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
    261257                // it and delete the signup avatar dir