Ticket #5374: 5374.04.diff
File 5374.04.diff, 75.4 KB (added by , 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() { 271 271 'id' => 'register', 272 272 'name' => __( 'Register', 'buddypress' ) 273 273 ); 274 275 bp_core_maybe_install_signups(); 274 276 } 275 277 276 278 // 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() { 785 787 </script> 786 788 <?php 787 789 } 790 791 /** 792 * Checks if the signups table needs to be created 793 * 794 * @since BuddyPress (2.0.0) 795 * 796 * @global $wpdb 797 */ 798 function 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 a082d87..dd9f06f 100644
function bp_core_install( $active_components = false ) { 50 50 // Blog tracking 51 51 if ( !empty( $active_components['blogs'] ) ) 52 52 bp_core_install_blog_tracking(); 53 54 if ( bp_get_signup_allowed() ) 55 bp_core_install_signups(); 56 53 57 } 54 58 55 59 function bp_core_install_notifications() { … … function bp_core_install_blog_tracking() { 343 347 344 348 dbDelta( $sql ); 345 349 } 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 */ 359 function 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 43c1afe..9283133 100644
class BP_Walker_Nav_Menu_Checklist extends Walker_Nav_Menu { 2385 2385 $output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="'. esc_attr( $item->xfn ) .'" />'; 2386 2386 } 2387 2387 } 2388 2389 /** 2390 * Signups Management class. 2391 * 2392 * @package BuddyPress 2393 * @subpackage coreClasses 2394 * 2395 * @since BuddyPress (2.0.0) 2396 */ 2397 class BP_Core_SignUp { 2398 2399 /** 2400 * ID of the signup which the object relates to. 2401 * 2402 * @var integer 2403 */ 2404 public $id; 2405 2406 /** 2407 * The URL to the full size of the avatar for the user. 2408 * 2409 * @var string 2410 */ 2411 public $avatar; 2412 2413 /** 2414 * The username for the user. 2415 * 2416 * @var string 2417 */ 2418 public $user_login; 2419 2420 /** 2421 * The email for the user. 2422 * 2423 * @var string 2424 */ 2425 public $user_email; 2426 2427 /** 2428 * The full name of the user 2429 * 2430 * @var string 2431 */ 2432 public $user_name; 2433 2434 /** 2435 * The registered date for the user. 2436 * 2437 * @var string 2438 */ 2439 public $registered; 2440 2441 /** 2442 * The activation key for the user. 2443 * 2444 * @var string 2445 */ 2446 public $activation_key; 2447 2448 2449 /** Public Methods *******************************************************/ 2450 2451 /** 2452 * Class constructor. 2453 * 2454 * @access public 2455 * @since BuddyPress (2.0.0) 2456 * 2457 * @param integer $signup_id The ID for the signup being queried. 2458 */ 2459 public function __construct( $signup_id = 0 ) { 2460 if ( !empty( $signup_id ) ) { 2461 $this->id = $signup_id; 2462 $this->populate(); 2463 } 2464 } 2465 2466 /** 2467 * Populate the instantiated class with data based on the signup_id provided. 2468 * 2469 * @access public 2470 * @since BuddyPress (2.0.0) 2471 * 2472 * @global $wpdb 2473 */ 2474 public function populate() { 2475 global $wpdb; 2476 $signups_table = buddypress()->members->table_name_signups; 2477 $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$signups_table} WHERE signup_id = %d AND active = 0", $this->id ) ); 2478 2479 $this->avatar = get_avatar( $signup->user_email, 32 ); 2480 $this->user_login = $signup->user_login; 2481 $this->user_email = $signup->user_email; 2482 $meta = maybe_unserialize( $signup->meta ); 2483 $this->user_name = ''; 2484 2485 if ( ! empty( $meta['field_1'] ) ) 2486 $this->user_name = esc_html( wp_unslash( $meta['field_1'] ) ); 2487 2488 $this->registered = $signup->registered; 2489 2490 } 2491 2492 /** Static Methods *******************************************************/ 2493 2494 /** 2495 * Populate the instantiated class with data based on the signup_id provided. 2496 * 2497 * @access public 2498 * @since BuddyPress (2.0.0) 2499 * 2500 * @global $wpdb 2501 * @param array $args the argument to retrieve desired signups 2502 * @static 2503 */ 2504 public static function get( $args = array() ) { 2505 global $wpdb; 2506 2507 $r = bp_parse_args( $args, 2508 array( 2509 'offset' => 0, 2510 'number' => 1, 2511 'usersearch' => false, 2512 'orderby' => 'signup_id', 2513 'order' => 'DESC', 2514 'include' => false 2515 ), 2516 'bp_core_signups_get_args' 2517 ); 2518 2519 extract( $r, EXTR_SKIP ); 2520 2521 if ( $orderby != 'signup_id' ) 2522 $orderby = 'user_' . $orderby; 2523 2524 $orderby = sanitize_title( $orderby ); 2525 2526 $sql = array(); 2527 $signups_table = buddypress()->members->table_name_signups; 2528 $sql['select'] = "SELECT * FROM {$signups_table}"; 2529 $sql['where'] = "WHERE active = 0"; 2530 2531 if ( empty( $include ) ) { 2532 if ( ! empty( $usersearch ) ) { 2533 $search_terms_clean = mysql_real_escape_string( mysql_real_escape_string( $usersearch ) ); 2534 $search_terms_clean = like_escape( $search_terms_clean ); 2535 $sql['search'] = "AND ( user_login LIKE '%" . $search_terms_clean . "%' OR user_email LIKE '%" . $search_terms_clean . "%' OR meta LIKE '%" . $search_terms_clean . "%' )"; 2536 } 2537 2538 $sql['orderby'] = "ORDER BY {$orderby}"; 2539 $sql['order'] = strtoupper( $order ); 2540 $sql['limit'] = $wpdb->prepare( "LIMIT %d, %d", $offset, $number ); 2541 } else { 2542 $in = implode( ',', wp_parse_id_list( $include ) ); 2543 $sql['in'] = "AND signup_id IN ({$in})"; 2544 } 2545 2546 $paged_signups = $wpdb->get_results( apply_filters( 'bp_members_signups_paged_query', join( ' ', $sql ), $sql, $args, $r ) ); 2547 2548 if ( empty( $paged_signups ) ) 2549 return array( 'signups' => false, 'total' => false ); 2550 2551 foreach ( (array) $paged_signups as $key => $signup ) { 2552 2553 $signup->id = intval( $signup->signup_id ); 2554 2555 $meta = !empty( $signup->meta ) ? maybe_unserialize( $signup->meta ) : false; 2556 2557 $signup->user_name = ''; 2558 2559 if ( ! empty( $meta['field_1'] ) ) 2560 $signup->user_name = esc_html( wp_unslash( $meta['field_1'] ) ); 2561 2562 if ( ! empty( $meta['sent_date'] ) ) { 2563 $signup->date_sent = $meta['sent_date']; 2564 // Defaults to date of registration 2565 } else { 2566 $signup->date_sent = $signup->registered; 2567 } 2568 2569 if ( ! empty( $meta['count_sent'] ) ) { 2570 $signup->count_sent = absint( $meta['count_sent'] ); 2571 // Defaults to date of registration 2572 } else { 2573 $signup->count_sent = 1; 2574 } 2575 2576 $paged_signups[ $key ] = $signup; 2577 } 2578 2579 unset( $sql['limit'] ); 2580 $sql['select'] = preg_replace( "/SELECT.*?FROM/", "SELECT COUNT(*) FROM", $sql['select'] ); 2581 $total_signups = $wpdb->get_var( apply_filters( 'bp_members_signups_count_query', join( ' ', $sql ), $sql, $args, $r ) ); 2582 2583 return array( 'signups' => $paged_signups, 'total' => $total_signups ); 2584 } 2585 2586 /** 2587 * Get a specific signup thanks to registration key. 2588 * 2589 * @access public 2590 * @since BuddyPress (2.0.0) 2591 * 2592 * @global $wpdb 2593 * @param string $key 2594 * @return object the queried data for the signup 2595 * @static 2596 */ 2597 public static function get_by_key( $key = '' ) { 2598 global $wpdb; 2599 2600 if ( empty( $key ) ) 2601 return false; 2602 2603 $signups_table = buddypress()->members->table_name_signups; 2604 $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$signups_table} WHERE activation_key = %s", $key ) ); 2605 2606 return apply_filters( 'bp_core_signups_get_by_key', $signup ); 2607 } 2608 2609 /** 2610 * Get a specific signup id thanks to user login. 2611 * 2612 * @access public 2613 * @since BuddyPress (2.0.0) 2614 * 2615 * @global $wpdb 2616 * @param string $user_login 2617 * @return object the queried data for the signup 2618 * @static 2619 */ 2620 public static function get_by_userlogin( $user_login = '' ) { 2621 global $wpdb; 2622 2623 if ( empty( $user_login ) ) 2624 return false; 2625 2626 $signups_table = buddypress()->members->table_name_signups; 2627 $signup = $wpdb->get_row( $wpdb->prepare( "SELECT signup_id FROM {$signups_table} WHERE user_login = %s", $user_login ) ); 2628 2629 return apply_filters( 'bp_core_signups_get_by_userlogin', $signup ); 2630 } 2631 2632 /** 2633 * Get a specific signup thanks to its id. 2634 * 2635 * @access public 2636 * @since BuddyPress (2.0.0) 2637 * 2638 * @global $wpdb 2639 * @param int $signup_id 2640 * @return object the queried data for the signup 2641 * @static 2642 */ 2643 public static function get_specific( $signup_id = 0 ) { 2644 global $wpdb; 2645 2646 $signups_table = buddypress()->members->table_name_signups; 2647 $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$signups_table} WHERE active = 0 AND signup_id = %d", absint( $signup_id ) ) ); 2648 2649 return apply_filters( 'bp_core_signups_get_specific', $signup ); 2650 } 2651 2652 /** 2653 * Add a signup 2654 * 2655 * @access public 2656 * @since BuddyPress (2.0.0) 2657 * 2658 * @global $wpdb 2659 * @param array $args 2660 * @return boolean 2661 * @static 2662 */ 2663 public static function add( $args = array() ) { 2664 global $wpdb; 2665 2666 $r = bp_parse_args( $args, 2667 array( 2668 'domain' => '', 2669 'path' => '', 2670 'title' => '', 2671 'user_login' => '', 2672 'user_email' => '', 2673 'registered' => current_time( 'mysql', true ), 2674 'activation_key' => '', 2675 'meta' => '' 2676 ), 2677 'bp_core_signups_add_args' 2678 ); 2679 2680 $inserted = $wpdb->insert( 2681 buddypress()->members->table_name_signups, 2682 $r, 2683 array( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) 2684 ); 2685 2686 return apply_filters( 'bp_core_signups_add', $inserted ); 2687 } 2688 2689 /** 2690 * Keep on creating a user on signup 2691 * 2692 * Plugins might rely on user_status / activation_key 2693 * 2694 * @access public 2695 * @since BuddyPress (2.0.0) 2696 * 2697 * @global $wpdb 2698 * @param string $user_login 2699 * @param string $user_password 2700 * @param string $user_email 2701 * @param array $usermeta 2702 * @return int user id 2703 * @static 2704 */ 2705 public static function add_backcompat( $user_login = '', $user_password = '', $user_email = '', $usermeta = array() ) { 2706 global $wpdb; 2707 2708 $errors = new WP_Error(); 2709 2710 $user_id = wp_insert_user( array( 2711 'user_login' => $user_login, 2712 'user_pass' => $user_password, 2713 'display_name' => sanitize_title( $user_login ), 2714 'user_email' => $user_email 2715 ) ); 2716 2717 if ( is_wp_error( $user_id ) || empty( $user_id ) ) { 2718 $errors->add( 'registerfail', sprintf( __('<strong>ERROR</strong>: Couldn’t register you... please contact the <a href="mailto:%s">webmaster</a> !', 'buddypress' ), bp_get_option( 'admin_email' ) ) ); 2719 return $errors; 2720 } 2721 2722 // Update the user status to '2' which we will use as 'not activated' (0 = active, 1 = spam, 2 = not active) 2723 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_status = 2 WHERE ID = %d", $user_id ) ); 2724 2725 // Deleting these options will remove signups from users count 2726 delete_user_option( $user_id, 'capabilities' ); 2727 delete_user_option( $user_id, 'user_level' ); 2728 2729 // Set any profile data 2730 if ( bp_is_active( 'xprofile' ) ) { 2731 if ( !empty( $usermeta['profile_field_ids'] ) ) { 2732 $profile_field_ids = explode( ',', $usermeta['profile_field_ids'] ); 2733 2734 foreach( (array) $profile_field_ids as $field_id ) { 2735 if ( empty( $usermeta["field_{$field_id}"] ) ) 2736 continue; 2737 2738 $current_field = $usermeta["field_{$field_id}"]; 2739 xprofile_set_field_data( $field_id, $user_id, $current_field ); 2740 2741 // Save the visibility level 2742 $visibility_level = !empty( $usermeta['field_' . $field_id . '_visibility'] ) ? $usermeta['field_' . $field_id . '_visibility'] : 'public'; 2743 xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level ); 2744 } 2745 } 2746 } 2747 2748 return apply_filters( 'bp_core_signups_add_backcompat', $user_id ); 2749 } 2750 2751 /** 2752 * Checks a user status for non multisite config 2753 * 2754 * @access public 2755 * @since BuddyPress (2.0.0) 2756 * 2757 * @global $wpdb 2758 * @param int $user_id 2759 * @return int the status 2760 * @static 2761 */ 2762 public static function check_user_status( $user_id = 0 ) { 2763 global $wpdb; 2764 2765 if ( empty( $user_id ) ) 2766 return false; 2767 2768 $user_status = $wpdb->get_var( $wpdb->prepare( "SELECT user_status FROM {$wpdb->users} WHERE ID = %d", $user_id ) ); 2769 2770 return apply_filters( 'bp_core_signups_check_user_status', intval( $user_status ) ); 2771 } 2772 2773 /** 2774 * "Activate" a signup 2775 * 2776 * @access public 2777 * @since BuddyPress (2.0.0) 2778 * 2779 * @global $wpdb 2780 * @param string $key 2781 * @return boolean 2782 * @static 2783 */ 2784 public static function validate( $key = '' ) { 2785 global $wpdb; 2786 2787 if ( empty( $key ) ) 2788 return; 2789 2790 $activated = $wpdb->update( 2791 // Signups table 2792 buddypress()->members->table_name_signups, 2793 array( 2794 'active' => 1, 2795 'activated' => current_time( 'mysql', true ) 2796 ), 2797 array( 2798 'activation_key' => $key 2799 ), 2800 // Data sanitization format 2801 array( 2802 '%d', 2803 '%s' 2804 ), 2805 // WHERE sanitization format 2806 array( 2807 '%s' 2808 ) 2809 ); 2810 2811 return apply_filters( 'bp_core_signups_validate', $activated ); 2812 } 2813 2814 /** 2815 * How many signups ? 2816 * 2817 * @access public 2818 * @since BuddyPress (2.0.0) 2819 * 2820 * @global $wpdb 2821 * @return int the number of signups 2822 * @static 2823 */ 2824 public static function count_signups() { 2825 global $wpdb; 2826 2827 $signups_table = buddypress()->members->table_name_signups; 2828 $count_signups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) AS total FROM {$signups_table} WHERE active = %d", 0 ) ); 2829 2830 return apply_filters( 'bp_core_signups_count', (int) $count_signups ); 2831 } 2832 2833 /** 2834 * Update the meta for a signup 2835 * 2836 * This is the way we use to "trace" the last date an activation 2837 * email was sent and how many times activation was sent 2838 * 2839 * @access public 2840 * @since BuddyPress (2.0.0) 2841 * 2842 * @global $wpdb 2843 * @param array $args 2844 * @return int the signup id 2845 * @static 2846 */ 2847 public static function update( $args = array() ) { 2848 global $wpdb; 2849 2850 $r = bp_parse_args( $args, 2851 array( 2852 'signup_id' => 0, 2853 'meta' => array(), 2854 ), 2855 'bp_core_signups_update_args' 2856 ); 2857 2858 extract( $r, EXTR_SKIP ); 2859 2860 if ( empty( $signup_id ) || empty( $meta ) ) 2861 return false; 2862 2863 $wpdb->update( 2864 // Signups table 2865 buddypress()->members->table_name_signups, 2866 // Data to update 2867 array( 2868 'meta' => serialize( $meta ) 2869 ), 2870 // WHERE 2871 array( 2872 'signup_id' => $signup_id 2873 ), 2874 // Data sanitization format 2875 array( 2876 '%s' 2877 ), 2878 // WHERE sanitization format 2879 array( 2880 '%d' 2881 ) 2882 ); 2883 2884 return apply_filters( 'bp_core_signups_update', $signup_id ); 2885 } 2886 2887 /** 2888 * Resend an activation link 2889 * 2890 * @access public 2891 * @since BuddyPress (2.0.0) 2892 * 2893 * @param array $signup_ids single id or list of ids to resend 2894 * @return array the results 2895 * @static 2896 */ 2897 public static function resend( $signup_ids = array() ) { 2898 if ( empty( $signup_ids ) || ! is_array( $signup_ids ) ) 2899 return false; 2900 2901 $to_resend = self::get( array( 'include' => $signup_ids ) ); 2902 2903 if ( ! $signups = $to_resend['signups'] ) 2904 return false; 2905 2906 $now = current_time( 'timestamp', true ); 2907 $result = array(); 2908 2909 do_action( 'bp_core_signup_before_resend', $signup_ids ); 2910 2911 foreach ( $signups as $signup ) { 2912 $sent_at = mysql2date('U', $signup->date_sent ); 2913 $diff = $now - $sent_at; 2914 2915 // If a previous resent happened less than a day ago, skip. 2916 if ( $diff < 1 * DAY_IN_SECONDS ) { 2917 $result['errors'][ $signup->signup_id ] = array( $signup->user_login, esc_html__( 'already received an activation email today', 'buddypress' ) );; 2918 continue; 2919 } 2920 2921 $meta = maybe_unserialize( $signup->meta ); 2922 2923 $meta['sent_date'] = current_time( 'mysql', true ); 2924 $meta['count_sent'] = $signup->count_sent + 1; 2925 2926 // Send activation email 2927 if ( is_multisite() ) { 2928 wpmu_signup_user_notification( $signup->user_login, $signup->user_email, $signup->activation_key, serialize( $meta ) ); 2929 } else { 2930 2931 // Check user status before sending email 2932 $user_id = email_exists( $signup->user_email ); 2933 2934 if ( ! empty( $user_id ) && 2 != self::check_user_status( $user_id ) ) { 2935 // Status is not 2, so user's account has been activated 2936 $result['errors'][ $signup->signup_id ] = array( $signup->user_login, esc_html__( 'the sign-up has already been activated.', 'buddypress' ) );; 2937 // repare signups table 2938 self::validate( $signup->activation_key ); 2939 continue; 2940 2941 // Send the validation email 2942 } else { 2943 bp_core_signup_send_validation_email( false, $signup->user_email, $signup->activation_key ); 2944 } 2945 } 2946 2947 // Update metas 2948 $result['resent'][] = self::update( array( 'signup_id' => $signup->signup_id, 'meta' => $meta ) ); 2949 } 2950 2951 do_action( 'bp_core_signup_after_resend', $signup_ids ); 2952 2953 return apply_filters( 'bp_core_signup_resend', $result ); 2954 } 2955 2956 /** 2957 * Activate a pending account 2958 * 2959 * @access public 2960 * @since BuddyPress (2.0.0) 2961 * 2962 * @param array $signup_ids single id or list of ids to resend 2963 * @return array the results 2964 * @static 2965 */ 2966 public static function activate( $signup_ids = array() ) { 2967 if ( empty( $signup_ids ) || ! is_array( $signup_ids ) ) 2968 return false; 2969 2970 $to_activate = self::get( array( 'include' => $signup_ids ) ); 2971 2972 if ( ! $signups = $to_activate['signups'] ) 2973 return false; 2974 2975 $result = array(); 2976 2977 do_action( 'bp_core_signup_before_activate', $signup_ids ); 2978 2979 foreach ( $signups as $signup ) { 2980 2981 $user = bp_core_activate_signup( $signup->activation_key ); 2982 2983 if ( ! empty( $user->errors ) ) { 2984 2985 if ( $user_id = username_exists( $signup->user_login ) && 2 != self::check_user_status( $user_id ) ) { 2986 // Status is not 2, so user's account has been activated 2987 $result['errors'][ $signup->signup_id ] = array( $signup->user_login, esc_html__( 'the sign-up has already been activated.', 'buddypress' ) ); 2988 // repare signups table 2989 self::validate( $signup->activation_key ); 2990 2991 // we have a user id, account is not active, let's delete it 2992 } else { 2993 $result['errors'][ $signup->signup_id ] = array( $signup->user_login, $user->get_error_message() ); 2994 } 2995 2996 } else { 2997 $result['activated'][] = $user; 2998 } 2999 3000 } 3001 3002 do_action( 'bp_core_signup_after_activate', $result ); 3003 3004 return apply_filters( 'bp_core_signup_activate', $result ); 3005 } 3006 3007 /** 3008 * Delete a pending account 3009 * 3010 * @access public 3011 * @since BuddyPress (2.0.0) 3012 * 3013 * @param array $signup_ids single id or list of ids to resend 3014 * @return array the results 3015 * @static 3016 */ 3017 public static function delete( $signup_ids = array() ) { 3018 global $wpdb; 3019 3020 if ( empty( $signup_ids ) || ! is_array( $signup_ids ) ) 3021 return false; 3022 3023 $to_delete = self::get( array( 'include' => $signup_ids ) ); 3024 3025 if ( ! $signups = $to_delete['signups'] ) 3026 return false; 3027 3028 $result = array(); 3029 3030 do_action( 'bp_core_signup_before_delete', $signup_ids ); 3031 3032 foreach ( $signups as $signup ) { 3033 3034 $user_id = username_exists( $signup->user_login ); 3035 3036 if ( ! empty( $user_id ) && $signup->activation_key == wp_hash( $user_id ) ) { 3037 3038 if ( 2 != self::check_user_status( $user_id ) ) { 3039 // Status is not 2, so user's account has been activated 3040 $result['errors'][ $signup->signup_id ] = array( $signup->user_login, esc_html__( 'the sign-up has already been activated.', 'buddypress' ) ); 3041 // repare signups table 3042 self::validate( $signup->activation_key ); 3043 3044 // we have a user id, account is not active, let's delete it 3045 } else { 3046 bp_core_delete_account( $user_id ); 3047 } 3048 } 3049 3050 if( empty( $result['errors'][ $signup->signup_id ] ) ) { 3051 3052 $wpdb->delete( 3053 // Signups table 3054 buddypress()->members->table_name_signups, 3055 // Where 3056 array( 'signup_id' => $signup->signup_id ), 3057 // WHERE sanitization format 3058 array( '%d' ) 3059 ); 3060 3061 $result['deleted'][] = $signup->signup_id; 3062 } 3063 3064 } 3065 3066 do_action( 'bp_core_signup_after_delete', $signup_ids, $result ); 3067 3068 return apply_filters( 'bp_core_signup_delete', $result ); 3069 } 3070 3071 } -
bp-core/bp-core-update.php
diff --git bp-core/bp-core-update.php bp-core/bp-core-update.php index 9ca5922..0d9ff1e 100644
function bp_update_to_2_0() { 365 365 366 366 $wpdb->query( $sql ); 367 367 368 /** Migrate 'Sign-ups' data *************************************/ 369 370 if ( bp_get_signup_allowed() && ! is_multisite() ) { 371 372 if ( empty( $wpdb->signups ) ) 373 bp_core_install_signups(); 374 375 $signups = get_users( array( 'fields' => 'all_with_meta', 'meta_key' => 'activation_key', 'meta_compare' => 'EXISTS' ) ); 376 377 if ( empty( $signups ) ) 378 return; 379 380 foreach ( $signups as $signup ) { 381 $meta = array(); 382 383 if ( bp_is_active( 'xprofile' ) ) 384 $meta['field_1'] = $signup->display_name; 385 386 $meta['password'] = $signup->user_pass; 387 388 $user_login = preg_replace( '/\s+/', '', sanitize_user( $signup->user_login, true ) ); 389 $user_email = sanitize_email( $signup->user_email ); 390 $meta = serialize( $meta ); 391 392 $args = array( 393 'user_login' => $user_login, 394 'user_email' => $user_email, 395 'registered' => $signup->user_registered, 396 'activation_key' => $signup->activation_key, 397 'meta' => $meta 398 ); 399 400 BP_Core_SignUp::add( $args ); 401 402 // Deleting these options will remove signups from users count 403 delete_user_option( $signup->ID, 'capabilities' ); 404 delete_user_option( $signup->ID, 'user_level' ); 405 } 406 } 407 368 408 /** Add BP options to the options table ******************************/ 369 409 bp_add_options(); 370 410 } -
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 11 if ( !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 */ 16 if ( class_exists( 'WP_Users_List_Table') ) : 17 /** 18 * List table class for signups admin page. 19 * 20 * @since BuddyPress (2.0.0) 21 */ 22 class 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 314 endif; 315 316 317 if ( 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 */ 323 class 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 617 endif; -
bp-members/bp-members-admin.php
diff --git bp-members/bp-members-admin.php bp-members/bp-members-admin.php index 3652320..c7a37ed 100644
class BP_Members_Admin { 62 62 * @since BuddyPress (2.0.0) 63 63 * 64 64 * @uses buddypress() to get BuddyPress main instance 65 * @static 65 66 */ 66 67 public static function register_members_admin() { 67 68 if( ! is_admin() ) … … class BP_Members_Admin { 116 117 117 118 // BuddyPress edit user's profile url 118 119 $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'; 119 127 } 120 128 121 129 /** … … class BP_Members_Admin { 126 134 */ 127 135 private function setup_actions() { 128 136 129 /** Actions***************************************************/137 /** Community Profile ***************************************************/ 130 138 131 139 // Add some page specific output to the <head> 132 140 add_action( 'bp_admin_head', array( $this, 'admin_head' ), 999 ); … … class BP_Members_Admin { 140 148 // Create the Profile Navigation (WordPress/Community) 141 149 add_action( 'edit_user_profile', array( $this, 'profile_nav' ), 99, 1 ); 142 150 143 144 /** Filters ***************************************************/145 146 151 // Add a row action to users listing 147 152 add_filter( bp_core_do_network_admin() ? 'ms_user_row_actions' : 'user_row_actions', array( $this, 'row_actions' ), 10, 2 ); 148 153 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 149 167 } 150 168 151 169 /** 152 * Create the All Users > Edit Profile submenu.170 * Create the All Users > Edit Profile and Signups submenus. 153 171 * 154 172 * @access public 155 173 * @since BuddyPress (2.0.0) … … class BP_Members_Admin { 159 177 public function admin_menus() { 160 178 161 179 // Manage user's profile 162 $hook = $this->user_page = add_users_page(180 $hooks['user'] = $this->user_page = add_users_page( 163 181 __( 'Edit Profile', 'buddypress' ), 164 182 __( 'Edit Profile', 'buddypress' ), 165 183 'bp_moderate', … … class BP_Members_Admin { 167 185 array( &$this, 'user_admin' ) 168 186 ); 169 187 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 170 196 $edit_page = 'user-edit'; 197 $this->users_page = 'users'; 171 198 172 199 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'; 175 204 } 176 205 177 206 $this->screen_id = array( $edit_page, $this->user_page ); 178 207 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; 181 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 } 182 228 } 183 229 184 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' ); 239 240 // Remove submenu to force using users views 241 remove_submenu_page( 'users.php', 'bp-signups' ); 242 } 243 244 /******* Community Profile ******************************************************************************************/ 245 246 /** 185 247 * Add some specific styling to the Edit User and Edit User's Profile page. 186 248 * 187 249 * @access public … … class BP_Members_Admin { 248 310 } 249 311 250 312 /** 251 * Highlight the Users menu if on Edit Profile pages.252 *253 * @access public254 * @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 menu260 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 public269 * @since BuddyPress (2.0.0)270 */271 public function admin_head() {272 // Remove submenu to force using Profile Navigation273 remove_submenu_page( 'users.php', 'bp-profile-edit' );274 }275 276 /**277 313 * Set up the user's profile admin page. 278 314 * 279 315 * Loaded before the page is rendered, this function does all initial … … class BP_Members_Admin { 691 727 692 728 return array_merge( $new_edit_actions, $actions ); 693 729 } 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 “%s”') . '</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 694 1339 } 695 1340 endif; // class_exists check 696 1341 -
bp-members/bp-members-functions.php
diff --git bp-members/bp-members-functions.php bp-members/bp-members-functions.php index 9212f9b..ec28c93 100644
function bp_core_validate_user_signup( $user_name, $user_email ) { 1300 1300 $errors->add( 'user_name', __( 'Sorry, usernames must have letters too!', 'buddypress' ) ); 1301 1301 } 1302 1302 1303 // Check into signups 1304 $signup = BP_Core_SignUp::get_by_userlogin( $user_name ); 1305 1303 1306 // Check if the username has been used already. 1304 if ( username_exists( $user_name ) ) {1307 if ( username_exists( $user_name ) || ! empty( $signup ) ) { 1305 1308 $errors->add( 'user_name', __( 'Sorry, that username already exists!', 'buddypress' ) ); 1306 1309 } 1307 1310 … … function bp_core_validate_blog_signup( $blog_url, $blog_title ) { 1332 1335 } 1333 1336 1334 1337 function bp_core_signup_user( $user_login, $user_password, $user_email, $usermeta ) { 1335 global $bp, $wpdb; 1338 global $bp; 1339 1340 // We need to cast $user_id to pass to the filters 1341 $user_id = false; 1336 1342 1337 1343 // Multisite installs have their own install procedure 1338 1344 if ( is_multisite() ) { 1339 1345 wpmu_signup_user( $user_login, $user_email, $usermeta ); 1340 1346 1341 // On multisite, the user id is not created until the user activates the account1342 // but we need to cast $user_id to pass to the filters1343 $user_id = false;1344 1345 1347 } else { 1346 $errors = new WP_Error();1347 1348 $user_id = wp_insert_user( array(1349 'user_login' => $user_login,1350 'user_pass' => $user_password,1351 'display_name' => sanitize_title( $user_login ),1352 'user_email' => $user_email1353 ) );1354 1348 1355 if ( is_wp_error( $user_id ) || empty( $user_id ) ) { 1356 $errors->add( 'registerfail', sprintf( __('<strong>ERROR</strong>: Couldn’t register you... please contact the <a href="mailto:%s">webmaster</a> !', 'buddypress' ), bp_get_option( 'admin_email' ) ) ); 1357 return $errors; 1349 // Format data 1350 $user_login = preg_replace( '/\s+/', '', sanitize_user( $user_login, true ) ); 1351 $user_email = sanitize_email( $user_email ); 1352 $activation_key = substr( md5( time() . rand() . $user_email ), 0, 16 ); 1353 $meta = serialize( $usermeta ); 1354 1355 /** 1356 * Plugins may use the user_status / activation_key usermeta mechanism 1357 * defining BP_SIGNUP_NOT_USER_YET to true skip this step, in case the 1358 * administrator is sure this kind of plugins is not used on his config 1359 * and don't want to directly create a user on sign-up. 1360 */ 1361 if ( ! defined( 'BP_SIGNUP_NOT_USER_YET' ) ) { 1362 $user_id = BP_Core_SignUp::add_backcompat( $user_login, $user_password, $user_email, $usermeta ); 1363 1364 if ( is_wp_error( $user_id ) ) 1365 return $user_id; 1366 1367 $activation_key = wp_hash( $user_id ); 1368 update_user_meta( $user_id, 'activation_key', $activation_key ); 1358 1369 } 1359 1370 1360 // Update the user status to '2' which we will use as 'not activated' (0 = active, 1 = spam, 2 = not active) 1361 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_status = 2 WHERE ID = %d", $user_id ) ); 1362 1363 // Set any profile data 1364 if ( bp_is_active( 'xprofile' ) ) { 1365 if ( !empty( $usermeta['profile_field_ids'] ) ) { 1366 $profile_field_ids = explode( ',', $usermeta['profile_field_ids'] ); 1367 1368 foreach( (array) $profile_field_ids as $field_id ) { 1369 if ( empty( $usermeta["field_{$field_id}"] ) ) 1370 continue; 1371 1372 $current_field = $usermeta["field_{$field_id}"]; 1373 xprofile_set_field_data( $field_id, $user_id, $current_field ); 1374 1375 // Save the visibility level 1376 $visibility_level = !empty( $usermeta['field_' . $field_id . '_visibility'] ) ? $usermeta['field_' . $field_id . '_visibility'] : 'public'; 1377 xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level ); 1378 } 1379 } 1380 } 1381 } 1382 $bp->signup->username = $user_login; 1371 $args = array( 1372 'user_login' => $user_login, 1373 'user_email' => $user_email, 1374 'activation_key' => $activation_key, 1375 'meta' => $meta 1376 ); 1383 1377 1384 /*** 1385 * Now generate an activation key and send an email to the user so they can activate their 1386 * account and validate their email address. Multisite installs send their own email, so 1387 * this is only for single blog installs. 1388 * 1389 * To disable sending activation emails you can user the filter 1390 * 'bp_core_signup_send_activation_key' and return false. Note that this will only disable 1391 * the email - a key will still be generated, and the account must still be activated 1392 * before use. 1393 */ 1394 if ( !is_multisite() ) { 1395 $activation_key = wp_hash( $user_id ); 1396 update_user_meta( $user_id, 'activation_key', $activation_key ); 1378 BP_Core_SignUp::add( $args ); 1397 1379 1398 1380 if ( apply_filters( 'bp_core_signup_send_activation_key', true ) ) { 1399 1381 bp_core_signup_send_validation_email( $user_id, $user_email, $activation_key ); 1400 1382 } 1401 1383 } 1402 1384 1385 $bp->signup->username = $user_login; 1386 1403 1387 do_action( 'bp_core_signup_user', $user_id, $user_login, $user_password, $user_email, $usermeta ); 1404 1388 1405 1389 return $user_id; … … function bp_core_activate_signup( $key ) { 1422 1406 $user = wpmu_activate_signup( $key ); 1423 1407 1424 1408 // If there were errors, add a message and redirect 1425 if ( ! empty( $user->errors ) ) {1409 if ( ! empty( $user->errors ) ) { 1426 1410 return $user; 1427 1411 } 1428 1412 1429 1413 $user_id = $user['user_id']; 1430 1414 1431 // Set any profile data 1432 if ( bp_is_active( 'xprofile' ) ) { 1433 if ( !empty( $user['meta']['profile_field_ids'] ) ) { 1434 $profile_field_ids = explode( ',', $user['meta']['profile_field_ids'] ); 1415 } else { 1435 1416 1436 foreach( (array) $profile_field_ids as $field_id ) { 1437 $current_field = isset( $user['meta']["field_{$field_id}"] ) ? $user['meta']["field_{$field_id}"] : false; 1417 $signup = BP_Core_SignUp::get_by_key( $key ); 1438 1418 1439 if ( !empty( $current_field) )1440 xprofile_set_field_data( $field_id, $user_id, $current_field);1419 if ( empty( $signup ) ) 1420 return new WP_Error( 'invalid_key', __( 'Invalid activation key.', 'buddypress' ) ); 1441 1421 1442 // Save the visibility level1443 $visibility_level = !empty( $user['meta']['field_' . $field_id . '_visibility'] ) ? $user['meta']['field_' . $field_id . '_visibility'] : 'public';1444 xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level);1445 }1446 }1422 if ( $signup->active ) { 1423 if ( empty( $signup->domain ) ) 1424 return new WP_Error( 'already_active', __( 'The user is already active.', 'buddypress' ), $signup ); 1425 else 1426 return new WP_Error( 'already_active', __( 'The site is already active.', 'buddypress' ), $signup ); 1447 1427 } 1448 } else {1449 1428 1450 // Get the user_id based on the $key 1451 $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = 'activation_key' AND meta_value = %s", $key ) ); 1429 $meta = maybe_unserialize( $signup->meta ); 1430 // password is hashed again in wp_insert_user 1431 $password = wp_generate_password( 12, false ); 1432 1433 $user_id = username_exists( $signup->user_login ); 1434 1435 if ( ! $user_id ) { 1436 $user_id = wp_create_user( $signup->user_login, $password, $signup->user_email ); 1437 // It might be a signup set in previous versions let's check against previous way of setting activation key 1438 } else if ( $key == wp_hash( $user_id ) ) { 1439 // Change the user's status so they become active 1440 if ( ! $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_status = 0 WHERE ID = %d", $user_id ) ) ) 1441 return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) ); 1442 1443 bp_delete_user_meta( $user_id, 'activation_key' ); 1444 1445 $member = get_userdata( $user_id ); 1446 $member->set_role( get_option('default_role') ); 1452 1447 1453 if ( empty( $user_id ) ) 1454 return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) ); 1448 $user_already_created = true; 1455 1449 1456 // Change the user's status so they become active 1457 if ( !$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_status = 0 WHERE ID = %d", $user_id ) ) ) 1458 return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) ); 1450 } else { 1451 $user_already_exists = true; 1452 } 1453 1454 if ( ! $user_id ) 1455 return new WP_Error( 'create_user', __( 'Could not create user', 'buddypress' ), $signup ); 1456 1457 BP_Core_SignUp::validate( $key ); 1458 1459 if ( isset( $user_already_exists ) ) 1460 return new WP_Error( 'user_already_exists', __( 'That username is already activated.' ), $signup ); 1461 1462 $user = array( 'user_id' => $user_id, 'password' => $meta['password'], 'meta' => $meta ); 1459 1463 1460 1464 // Notify the site admin of a new user registration 1461 1465 wp_new_user_notification( $user_id ); 1462 1466 1463 // Remove the activation key meta 1464 delete_user_meta( $user_id, 'activation_key' ); 1467 if ( isset( $user_already_created ) ) { 1468 1469 do_action( 'bp_core_activated_user', $user_id, $key, $user ); 1470 1471 return $user_id; 1472 } 1473 1474 } 1475 1476 // Set any profile data 1477 if ( bp_is_active( 'xprofile' ) ) { 1478 if ( ! empty( $user['meta']['profile_field_ids'] ) ) { 1479 $profile_field_ids = explode( ',', $user['meta']['profile_field_ids'] ); 1480 1481 foreach( (array) $profile_field_ids as $field_id ) { 1482 $current_field = isset( $user['meta']["field_{$field_id}"] ) ? $user['meta']["field_{$field_id}"] : false; 1483 1484 if ( !empty( $current_field ) ) 1485 xprofile_set_field_data( $field_id, $user_id, $current_field ); 1486 1487 // Save the visibility level 1488 $visibility_level = ! empty( $user['meta']['field_' . $field_id . '_visibility'] ) ? $user['meta']['field_' . $field_id . '_visibility'] : 'public'; 1489 xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level ); 1490 } 1491 } 1465 1492 } 1466 1493 1467 1494 // Update the display_name 1468 1495 wp_update_user( array( 'ID' => $user_id, 'display_name' => bp_core_get_user_displayname( $user_id ) ) ); 1469 1496 1470 1497 // Set the password on multisite installs 1471 if ( is_multisite() && !empty( $user['meta']['password'] ) )1498 if ( ! empty( $user['meta']['password'] ) ) 1472 1499 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_pass = %s WHERE ID = %d", $user['meta']['password'], $user_id ) ); 1473 1500 1474 1501 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 d88380b..e1e4762 100644
class BP_Members_Component extends BP_Component { 68 68 if ( !defined( 'BP_MEMBERS_SLUG' ) ) 69 69 define( 'BP_MEMBERS_SLUG', $this->id ); 70 70 71 parent::setup_globals(array(71 $members_globals = array( 72 72 'slug' => BP_MEMBERS_SLUG, 73 73 'root_slug' => isset( $bp->pages->members->slug ) ? $bp->pages->members->slug : BP_MEMBERS_SLUG, 74 74 'has_directory' => true, … … class BP_Members_Component extends BP_Component { 76 76 'table_name_last_activity' => bp_core_get_table_prefix() . 'bp_activity', 77 77 ), 78 78 'search_string' => __( 'Search Members...', 'buddypress' ), 79 ) ); 79 ); 80 81 if ( bp_get_signup_allowed() ) { 82 $members_globals['global_tables']['table_name_signups'] = bp_core_get_table_prefix() . 'signups'; 83 } 84 85 parent::setup_globals( $members_globals ); 80 86 81 87 /** Logged in user ****************************************************/ 82 88 -
bp-members/bp-members-screens.php
diff --git bp-members/bp-members-screens.php bp-members/bp-members-screens.php index 4cb9f40..5cf8b8a 100644
function bp_core_screen_activation() { 251 251 bp_core_redirect( trailingslashit( bp_get_root_domain() . '/' . $bp->pages->activate->slug ) ); 252 252 } 253 253 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'] ); 259 255 260 256 // Check if the avatar folder exists. If it does, move rename it, move 261 257 // it and delete the signup avatar dir