Ticket #5374: 5374.02.diff
File 5374.02.diff, 73.1 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..7c40cf0 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 6001979..d0ba2fa 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 c3d2d66..b9bbec2 100644
class BP_Walker_Nav_Menu_Checklist extends Walker_Nav_Menu { 2221 2221 $output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="'. esc_attr( $item->xfn ) .'" />'; 2222 2222 } 2223 2223 } 2224 2225 /** 2226 * Signups Management class. 2227 * 2228 * @package BuddyPress 2229 * @subpackage coreClasses 2230 * 2231 * @since BuddyPress (2.0.0) 2232 */ 2233 class 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 array $args 2535 * @return boolean 2536 * @static 2537 */ 2538 public static function add_backcompat( $user_login = '', $user_password = '', $user_email='', $usermeta = array() ) { 2539 global $wpdb; 2540 2541 $errors = new WP_Error(); 2542 2543 $user_id = wp_insert_user( array( 2544 'user_login' => $user_login, 2545 'user_pass' => $user_password, 2546 'display_name' => sanitize_title( $user_login ), 2547 'user_email' => $user_email 2548 ) ); 2549 2550 if ( is_wp_error( $user_id ) || empty( $user_id ) ) { 2551 $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' ) ) ); 2552 return $errors; 2553 } 2554 2555 // Update the user status to '2' which we will use as 'not activated' (0 = active, 1 = spam, 2 = not active) 2556 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_status = 2 WHERE ID = %d", $user_id ) ); 2557 2558 // Deleting these options will remove signups from users count 2559 delete_user_option( $user_id, 'capabilities' ); 2560 delete_user_option( $user_id, 'user_level' ); 2561 2562 // Set any profile data 2563 if ( bp_is_active( 'xprofile' ) ) { 2564 if ( !empty( $usermeta['profile_field_ids'] ) ) { 2565 $profile_field_ids = explode( ',', $usermeta['profile_field_ids'] ); 2566 2567 foreach( (array) $profile_field_ids as $field_id ) { 2568 if ( empty( $usermeta["field_{$field_id}"] ) ) 2569 continue; 2570 2571 $current_field = $usermeta["field_{$field_id}"]; 2572 xprofile_set_field_data( $field_id, $user_id, $current_field ); 2573 2574 // Save the visibility level 2575 $visibility_level = !empty( $usermeta['field_' . $field_id . '_visibility'] ) ? $usermeta['field_' . $field_id . '_visibility'] : 'public'; 2576 xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level ); 2577 } 2578 } 2579 } 2580 2581 return apply_filters( 'bp_core_signups_add_backcompat', $user_id ); 2582 } 2583 2584 /** 2585 * "Activate" a signup 2586 * 2587 * @access public 2588 * @since BuddyPress (2.0.0) 2589 * 2590 * @global $wpdb 2591 * @param string $key 2592 * @return boolean 2593 * @static 2594 */ 2595 public static function validate( $key = '' ) { 2596 global $wpdb; 2597 2598 if ( empty( $key ) ) 2599 return; 2600 2601 $activated = $wpdb->update( 2602 // Signups table 2603 buddypress()->members->table_name_signups, 2604 array( 2605 'active' => 1, 2606 'activated' => current_time( 'mysql', true ) 2607 ), 2608 array( 2609 'activation_key' => $key 2610 ), 2611 // Data sanitization format 2612 array( 2613 '%d', 2614 '%s' 2615 ), 2616 // WHERE sanitization format 2617 array( 2618 '%s' 2619 ) 2620 ); 2621 2622 return apply_filters( 'bp_core_signups_validate', $activated ); 2623 } 2624 2625 /** 2626 * How many signups ? 2627 * 2628 * @access public 2629 * @since BuddyPress (2.0.0) 2630 * 2631 * @global $wpdb 2632 * @return int the number of signups 2633 * @static 2634 */ 2635 public static function count_signups() { 2636 global $wpdb; 2637 2638 $signups_table = buddypress()->members->table_name_signups; 2639 $count_signups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) AS total FROM {$signups_table} WHERE active = %d", 0 ) ); 2640 2641 return apply_filters( 'bp_core_signups_count', (int) $count_signups ); 2642 } 2643 2644 /** 2645 * Update the meta for a signup 2646 * 2647 * This is the way we use to "trace" the last date an activation 2648 * email was sent and how many times activation was sent 2649 * 2650 * @access public 2651 * @since BuddyPress (2.0.0) 2652 * 2653 * @global $wpdb 2654 * @param array $args 2655 * @return int the signup id 2656 * @static 2657 */ 2658 public static function update( $args = array() ) { 2659 global $wpdb; 2660 2661 $r = bp_parse_args( $args, 2662 array( 2663 'signup_id' => 0, 2664 'meta' => array(), 2665 ), 2666 'bp_core_signups_update_args' 2667 ); 2668 2669 extract( $r, EXTR_SKIP ); 2670 2671 if ( empty( $signup_id ) || empty( $meta ) ) 2672 return false; 2673 2674 $wpdb->update( 2675 // Signups table 2676 buddypress()->members->table_name_signups, 2677 // Data to update 2678 array( 2679 'meta' => serialize( $meta ) 2680 ), 2681 // WHERE 2682 array( 2683 'signup_id' => $signup_id 2684 ), 2685 // Data sanitization format 2686 array( 2687 '%s' 2688 ), 2689 // WHERE sanitization format 2690 array( 2691 '%d' 2692 ) 2693 ); 2694 2695 return apply_filters( 'bp_core_signups_update', $signup_id ); 2696 } 2697 2698 /** 2699 * Resend an activation link 2700 * 2701 * @access public 2702 * @since BuddyPress (2.0.0) 2703 * 2704 * @param array $signup_ids single id or list of ids to resend 2705 * @return array the results 2706 * @static 2707 */ 2708 public static function resend( $signup_ids = array() ) { 2709 if ( empty( $signup_ids ) || ! is_array( $signup_ids ) ) 2710 return false; 2711 2712 $to_resend = self::get( array( 'include' => $signup_ids ) ); 2713 2714 if ( ! $signups = $to_resend['signups'] ) 2715 return false; 2716 2717 $now = current_time( 'timestamp', true ); 2718 $result = array(); 2719 2720 do_action( 'bp_core_signup_before_resend', $signup_ids ); 2721 2722 foreach ( $signups as $signup ) { 2723 $sent_at = mysql2date('U', $signup->date_sent ); 2724 $diff = $now - $sent_at; 2725 2726 // If a previous resent happened less than a day ago, skip. 2727 if ( $diff < 1 * DAY_IN_SECONDS ) { 2728 $result['errors'][] = $signup->signup_id; 2729 continue; 2730 } 2731 2732 $meta = maybe_unserialize( $signup->meta ); 2733 2734 $meta['sent_date'] = current_time( 'mysql', true ); 2735 $meta['count_sent'] = $signup->count_sent + 1; 2736 2737 // Send activation email 2738 if( is_multisite() ) { 2739 wpmu_signup_user_notification( $signup->user_login, $signup->user_email, $signup->activation_key, serialize( $meta ) ); 2740 } else { 2741 bp_core_signup_send_validation_email( false, $signup->user_email, $signup->activation_key ); 2742 } 2743 2744 // Update metas 2745 $result['resent'][] = self::update( array( 'signup_id' => $signup->signup_id, 'meta' => $meta ) ); 2746 } 2747 2748 do_action( 'bp_core_signup_after_resend', $signup_ids ); 2749 2750 return apply_filters( 'bp_core_signup_resend', $result ); 2751 } 2752 2753 /** 2754 * Activate a pending account 2755 * 2756 * @access public 2757 * @since BuddyPress (2.0.0) 2758 * 2759 * @param array $signup_ids single id or list of ids to resend 2760 * @return array the results 2761 * @static 2762 */ 2763 public static function activate( $signup_ids = array() ) { 2764 if ( empty( $signup_ids ) || ! is_array( $signup_ids ) ) 2765 return false; 2766 2767 $to_activate = self::get( array( 'include' => $signup_ids ) ); 2768 2769 if ( ! $signups = $to_activate['signups'] ) 2770 return false; 2771 2772 $result = array(); 2773 2774 do_action( 'bp_core_signup_before_activate', $signup_ids ); 2775 2776 foreach ( $signups as $signup ) { 2777 2778 $user = bp_core_activate_signup( $signup->activation_key ); 2779 2780 if ( ! empty( $user->errors ) ) { 2781 $result['errors'][ $signup->signup_id ] = array( $signup->user_login, $user->get_error_message() ); 2782 } else { 2783 $result['activated'][] = $user; 2784 } 2785 2786 } 2787 2788 do_action( 'bp_core_signup_after_activate', $result ); 2789 2790 return apply_filters( 'bp_core_signup_activate', $result ); 2791 } 2792 2793 /** 2794 * Delete a pending account 2795 * 2796 * @access public 2797 * @since BuddyPress (2.0.0) 2798 * 2799 * @param array $signup_ids single id or list of ids to resend 2800 * @return array the results 2801 * @static 2802 */ 2803 public static function delete( $signup_ids = array() ) { 2804 global $wpdb; 2805 2806 if ( empty( $signup_ids ) || ! is_array( $signup_ids ) ) 2807 return false; 2808 2809 $to_delete = self::get( array( 'include' => $signup_ids ) ); 2810 2811 if ( ! $signups = $to_delete['signups'] ) 2812 return false; 2813 2814 $deleted = array(); 2815 2816 do_action( 'bp_core_signup_before_delete', $signup_ids ); 2817 2818 foreach ( $signups as $signup ) { 2819 2820 $user_id = username_exists( $signup->user_login ); 2821 2822 // If we have a user id, let's delete it 2823 if ( ! empty( $user_id ) && $signup->activation_key == wp_hash( $user_id ) ) 2824 bp_core_delete_account( $user_id ); 2825 2826 $wpdb->delete( 2827 // Signups table 2828 buddypress()->members->table_name_signups, 2829 // Where 2830 array( 'signup_id' => $signup->signup_id ), 2831 // WHERE sanitization format 2832 array( '%d' ) 2833 ); 2834 2835 $deleted[] = $signup->signup_id; 2836 2837 } 2838 2839 do_action( 'bp_core_signup_after_delete', $signup_ids, $deleted ); 2840 2841 return apply_filters( 'bp_core_signup_delete', $deleted ); 2842 } 2843 2844 } -
bp-core/bp-core-update.php
diff --git bp-core/bp-core-update.php bp-core/bp-core-update.php index 54d9d1e..e21483b 100644
function bp_version_updater() { 230 230 if ( $raw_db_version < 7731 ) { 231 231 bp_update_to_1_9_2(); 232 232 } 233 234 // 2.0.0 235 if ( $raw_db_version < 7820 ) { 236 bp_update_to_2_0(); 237 } 233 238 } 234 239 235 240 /** All done! *************************************************************/ … … function bp_update_to_1_9_2() { 328 333 } 329 334 330 335 /** 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 */ 347 function 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 /** 331 390 * Redirect user to BP's What's New page on first page load after activation. 332 391 * 333 392 * @since BuddyPress (1.7.0) -
bp-loader.php
diff --git bp-loader.php bp-loader.php index e069db5..aedacad 100644
class BuddyPress { 304 304 /** Versions **************************************************/ 305 305 306 306 $this->version = '2.0-alpha-7752'; 307 $this->db_version = 7 731;307 $this->db_version = 7820; 308 308 309 309 /** Loading ***************************************************/ 310 310 -
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..17cf227 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 c9c99e1..3c89087 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', '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 messages 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 917 $redirect_to = add_query_arg( $query_arg, $redirect_to ); 918 } 919 920 bp_core_redirect( $redirect_to ); 921 922 // Handle activated accounts 923 } else if ( 'do_activate' == $doaction ) { 924 // nonce check 925 check_admin_referer( 'signups_activate' ); 926 927 $activated = BP_Core_SignUp::activate( $signups ); 928 929 if ( empty( $activated ) ) { 930 $redirect_to = add_query_arg( 'error', $doaction, $redirect_to ); 931 // resent messages 932 } else { 933 $query_arg = array( 'updated' => 'activated' ); 934 935 if ( ! empty( $activated['activated'] ) ) 936 $query_arg['activated'] = count( $activated['activated'] ); 937 938 if ( ! empty( $activated['errors'] ) ) { 939 $query_arg['notactivated'] = count( $activated['errors'] ); 940 set_transient( '_bp_account_activation_errors', $activated['errors'], 30 ); 941 } 942 943 $redirect_to = add_query_arg( $query_arg, $redirect_to ); 944 } 945 946 bp_core_redirect( $redirect_to ); 947 948 // Handle sign-ups delete 949 } else if ( 'do_delete' == $doaction ) { 950 // nonce check 951 check_admin_referer( 'signups_delete' ); 952 953 $deleted = BP_Core_SignUp::delete( $signups ); 954 955 if ( empty( $deleted ) ) { 956 $redirect_to = add_query_arg( 'error', $doaction, $redirect_to ); 957 // resent messages 958 } else { 959 $query_arg = array( 960 'updated' => 'deleted', 961 'deleted' => count( $deleted ) 962 ); 963 964 $redirect_to = add_query_arg( $query_arg, $redirect_to ); 965 } 966 967 bp_core_redirect( $redirect_to ); 968 969 // Plugins can update other stuff from here 970 } else { 971 $this->redirect = $redirect_to; 972 973 do_action_ref_array( 'bp_members_admin_update_signups', array( $doaction, $_REQUEST, $this->redirect ) ); 974 975 bp_core_redirect( $this->redirect ); 976 } 977 } 978 } 979 980 /** 981 * Display the activation errors 982 * 983 * @access public 984 * @since BuddyPress (2.0.0) 985 */ 986 public function display_activate_errors() { 987 // Bail if no activation errors 988 if ( ! $errors = get_transient( '_bp_account_activation_errors' ) ) 989 return; 990 991 foreach ( $errors as $error ) { 992 ?> 993 <li><?php echo esc_html( $error[0] );?>: <?php echo esc_html( $error[1] );?></li> 994 <?php 995 } 996 997 // Delete the redirect transient 998 delete_transient( '_bp_account_activation_errors' ); 999 } 1000 1001 /** 1002 * Choose the best signups admin page 1003 * 1004 * Depending on the context, display 1005 * - the list of signups 1006 * - or the delete confirmation screen 1007 * - or the activate confirmation screen 1008 * - or the "resend" email confirmation screen 1009 * 1010 * Also prepare the admin notices 1011 * 1012 * @access public 1013 * @since BuddyPress (2.0.0) 1014 */ 1015 public function signups_admin() { 1016 $doaction = bp_admin_list_table_current_bulk_action(); 1017 1018 // Prepare notices for admin 1019 $notice = array(); 1020 1021 if ( ! empty( $_REQUEST['updated'] ) ) { 1022 switch ( $_REQUEST['updated'] ) { 1023 case 'resent': 1024 $notice = array( 1025 'class' => 'updated', 1026 'message' => '' 1027 ); 1028 1029 if ( ! empty( $_REQUEST['resent'] ) ) { 1030 $notice['message'] .= sprintf( 1031 _nx( '%s activation email successfully sent! ', '%s activation emails successfully sent! ', 1032 absint( $_REQUEST['resent'] ), 1033 'signup resent', 1034 'buddypress' 1035 ), 1036 number_format_i18n( absint( $_REQUEST['resent'] ) ) 1037 ); 1038 } 1039 1040 if ( ! empty( $_REQUEST['notsent'] ) ) { 1041 $notice['message'] .= sprintf( 1042 _nx( '%s activation email was not sent: user already received one today.', '%s activation emails were not sent: users already received one today.', 1043 absint( $_REQUEST['notsent'] ), 1044 'signup notsent', 1045 'buddypress' 1046 ), 1047 number_format_i18n( absint( $_REQUEST['notsent'] ) ) 1048 ); 1049 1050 if ( empty( $_REQUEST['resent'] ) ) 1051 $notice['class'] = 'error'; 1052 } 1053 1054 break; 1055 1056 case 'activated': 1057 $notice = array( 1058 'class' => 'updated', 1059 'message' => '' 1060 ); 1061 1062 if ( ! empty( $_REQUEST['activated'] ) ) { 1063 $notice['message'] .= sprintf( 1064 _nx( '%s account successfully activated! ', '%s accounts successfully activated! ', 1065 absint( $_REQUEST['activated'] ), 1066 'signup resent', 1067 'buddypress' 1068 ), 1069 number_format_i18n( absint( $_REQUEST['activated'] ) ) 1070 ); 1071 } 1072 1073 if ( ! empty( $_REQUEST['notactivated'] ) ) { 1074 $notice['message'] .= sprintf( 1075 _nx( '%s account was not activated.', '%s accounts were not activated.', 1076 absint( $_REQUEST['notactivated'] ), 1077 'signup notsent', 1078 'buddypress' 1079 ), 1080 number_format_i18n( absint( $_REQUEST['notactivated'] ) ) 1081 ); 1082 1083 if ( empty( $_REQUEST['activated'] ) ) 1084 $notice['class'] = 'error'; 1085 } 1086 1087 break; 1088 1089 case 'deleted': 1090 $notice = array( 1091 'class' => 'updated', 1092 'message' => sprintf( 1093 _nx( '%s sign-up successfully deleted!', '%s sign-ups successfully deleted!', 1094 absint( $_REQUEST['deleted'] ), 1095 'signup deleted', 1096 'buddypress' 1097 ), 1098 number_format_i18n( absint( $_REQUEST['deleted'] ) ) ) 1099 ); 1100 1101 break; 1102 } 1103 } 1104 1105 if ( ! empty( $_REQUEST['error'] ) ) { 1106 switch ( $_REQUEST['error'] ) { 1107 case 'do_resend': 1108 $notice = array( 1109 'class' => 'error', 1110 'message' => esc_html__( 'There was a problem sending the activation emails, please try again.', 'buddypress' ) 1111 ); 1112 break; 1113 case 'do_activate': 1114 $notice = array( 1115 'class' => 'error', 1116 'message' => esc_html__( 'There was a problem activating accounts, please try again.', 'buddypress' ) 1117 ); 1118 break; 1119 case 'do_delete': 1120 $notice = array( 1121 'class' => 'error', 1122 'message' => esc_html__( 'There was a problem deleting sign-ups, please try again.', 'buddypress' ) 1123 ); 1124 break; 1125 } 1126 } 1127 1128 if ( ! empty( $notice ) ) : 1129 if ( 'updated' === $notice['class'] ) : ?> 1130 <div id="message" class="<?php echo esc_attr( $notice['class'] ); ?>"> 1131 <?php else: ?> 1132 <div class="<?php echo esc_attr( $notice['class'] ); ?>"> 1133 <?php endif; ?> 1134 <p><?php echo $notice['message']; ?></p> 1135 <?php if ( ! empty( $_REQUEST['notactivated'] ) ) :?> 1136 <ul><?php $this->display_activate_errors();?></ul> 1137 <?php endif ;?> 1138 </div> 1139 <?php endif; 1140 1141 switch( $doaction ) { 1142 case 'activate' : 1143 case 'delete' : 1144 case 'resend' : 1145 $this->signups_admin_manage( $doaction ); 1146 break; 1147 1148 default: 1149 $this->signups_admin_index(); 1150 break; 1151 1152 } 1153 } 1154 1155 /** 1156 * This is the list of the Pending accounts (signups) 1157 * 1158 * @access public 1159 * @since BuddyPress (2.0.0) 1160 * 1161 * @global $plugin_page 1162 * @global $bp_members_signup_list_table 1163 */ 1164 public function signups_admin_index() { 1165 global $plugin_page, $bp_members_signup_list_table; 1166 1167 $usersearch = ! empty( $_REQUEST['s'] ) ? $_REQUEST['s'] : ''; 1168 // Prepare the group items for display 1169 $bp_members_signup_list_table->prepare_items(); 1170 1171 $form_url = add_query_arg( array( 1172 'page' => 'bp-signups' 1173 ), 1174 bp_get_admin_url( 'users.php' ) 1175 ); 1176 $search_form_url = remove_query_arg( 1177 array( 1178 'action', 1179 'deleted', 1180 'error', 1181 'updated', 1182 'delete', 1183 'activate', 1184 'activated', 1185 'notactivated', 1186 'resend', 1187 'resent', 1188 'notresent', 1189 'do_delete', 1190 'do_activate', 1191 'do_resend', 1192 'action2', 1193 '_wpnonce', 1194 'signup_ids' 1195 ), $_SERVER['REQUEST_URI'] 1196 ); 1197 ?> 1198 1199 <div class="wrap"> 1200 <?php screen_icon( 'users' ); ?> 1201 <h2> 1202 <?php 1203 _e( 'Users', 'buddypress' ); 1204 if ( current_user_can( 'create_users' ) ) { ?> 1205 <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'user' ); ?></a> 1206 <?php } elseif ( is_multisite() && current_user_can( 'promote_users' ) ) { ?> 1207 <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add Existing', 'user' ); ?></a> 1208 <?php } 1209 1210 if ( $usersearch ) 1211 printf( '<span class="subtitle">' . __('Search results for “%s”') . '</span>', esc_html( $usersearch ) ); ?> 1212 </h2> 1213 1214 <?php // Display each signups on its own row ?> 1215 <?php $bp_members_signup_list_table->views(); ?> 1216 1217 <form id="bp-signups-search-form" action="<?php echo $search_form_url ;?>"> 1218 <input type="hidden" name="page" value="<?php echo esc_attr( $plugin_page ); ?>" /> 1219 <?php $bp_members_signup_list_table->search_box( __( 'Search Pending accounts', 'buddypress' ), 'bp-signups' ); ?> 1220 </form> 1221 1222 <form id="bp-signups-form" action="<?php echo $form_url;?>" method="post"> 1223 <?php $bp_members_signup_list_table->display(); ?> 1224 </form> 1225 1226 </div> 1227 <?php 1228 } 1229 1230 /** 1231 * This is the confirmation screen for actions 1232 * 1233 * @access public 1234 * @since BuddyPress (2.0.0) 1235 * 1236 * @param string $action delete/activate or resend activation link 1237 */ 1238 public function signups_admin_manage( $action = '' ) { 1239 if ( ! is_super_admin() || empty( $action ) ) 1240 die( '-1' ); 1241 1242 $ids = false; 1243 1244 1245 if ( ! empty( $_REQUEST['allsignups'] ) ) { 1246 $ids = wp_parse_id_list( $_REQUEST['allsignups'] ); 1247 } else if ( ! empty( $_REQUEST['signup_id'] ) ) { 1248 $ids = absint( $_REQUEST['signup_id'] ); 1249 } 1250 1251 if( empty( $ids ) ) 1252 return false; 1253 1254 $signups_query = BP_Core_SignUp::get( array( 'include' => $ids ) ); 1255 $signups = $signups_query['signups']; 1256 1257 // Create a new list of signup ids, based on those that actually exist 1258 $signup_ids = array(); 1259 foreach ( $signups as $signup ) { 1260 $signup_ids[] = $signup->signup_id; 1261 } 1262 1263 switch ( $action ) { 1264 case 'delete' : 1265 $caption = __( 'delete', 'buddypress' ); 1266 break; 1267 case 'activate' : 1268 $caption = __( 'activate', 'buddypress' ); 1269 break; 1270 case 'resend' : 1271 $caption = __( 'resend activation email to', 'buddypress' ) ; 1272 } 1273 1274 1275 $url_args = array( 'page' => 'bp-signups' ); 1276 $action_args = array( 1277 'action' => 'do_' . $action, 1278 'signup_ids' => implode( ',', $signup_ids ) 1279 ); 1280 1281 $cancel_url = add_query_arg( $url_args, bp_get_admin_url( 'users.php' ) ); 1282 $action_url = wp_nonce_url( 1283 add_query_arg( 1284 array_merge( $url_args, $action_args ), 1285 bp_get_admin_url( 'users.php' ) 1286 ), 1287 'signups_' . $action ); 1288 ?> 1289 1290 <div class="wrap"> 1291 <?php screen_icon( 'users' ); ?> 1292 <h2><?php printf( __( '%s Pending accounts', 'buddypress' ), ucfirst( $caption ) ); ?></h2> 1293 <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> 1294 1295 <ol class="bp-signups-list"> 1296 <?php foreach ( $signups as $signup ) : ?> 1297 <li><?php echo esc_html( $signup->user_name ) ?> - <?php echo sanitize_email( $signup->user_email );?></li> 1298 <?php endforeach; ?> 1299 </ol> 1300 1301 <?php if ( 'resend' != $action ) : ?> 1302 <p><strong><?php esc_html_e( 'This action cannot be undone.', 'buddypress' ) ?></strong></p> 1303 <?php endif ; ?> 1304 1305 <a class="button-primary" href="<?php echo $action_url; ?>"><?php esc_html_e( 'Confirm', 'buddypress' ); ?></a> 1306 <a class="button" href="<?php echo esc_attr( $cancel_url ); ?>"><?php esc_html_e( 'Cancel', 'buddypress' ) ?></a> 1307 </div> 1308 1309 <?php 1310 } 1311 694 1312 } 695 1313 endif; // class_exists check 696 1314 -
bp-members/bp-members-functions.php
diff --git bp-members/bp-members-functions.php bp-members/bp-members-functions.php index d7744fa..b6bb20f 100644
function bp_core_validate_user_signup( $user_name, $user_email ) { 1232 1232 $errors->add( 'user_name', __( 'Sorry, usernames must have letters too!', 'buddypress' ) ); 1233 1233 } 1234 1234 1235 // Check into signups 1236 $signup = BP_Core_SignUp::get_by_userlogin( $user_name ); 1237 1235 1238 // Check if the username has been used already. 1236 if ( username_exists( $user_name ) ) {1239 if ( username_exists( $user_name ) || ! empty( $signup ) ) { 1237 1240 $errors->add( 'user_name', __( 'Sorry, that username already exists!', 'buddypress' ) ); 1238 1241 } 1239 1242 … … function bp_core_validate_blog_signup( $blog_url, $blog_title ) { 1264 1267 } 1265 1268 1266 1269 function 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; 1268 1274 1269 1275 // Multisite installs have their own install procedure 1270 1276 if ( is_multisite() ) { 1271 1277 wpmu_signup_user( $user_login, $user_email, $usermeta ); 1272 1278 1273 // On multisite, the user id is not created until the user activates the account1274 // but we need to cast $user_id to pass to the filters1275 $user_id = false;1276 1277 1279 } 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_email1285 ) );1286 1280 1287 if ( is_wp_error( $user_id ) || empty( $user_id ) ) { 1288 $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' ) ) ); 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 ); 1290 1301 } 1291 1302 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 ); 1315 1309 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 ); 1329 1311 1330 1312 if ( apply_filters( 'bp_core_signup_send_activation_key', true ) ) { 1331 1313 bp_core_signup_send_validation_email( $user_id, $user_email, $activation_key ); 1332 1314 } 1333 1315 } 1334 1316 1317 $bp->signup->username = $user_login; 1318 1335 1319 do_action( 'bp_core_signup_user', $user_id, $user_login, $user_password, $user_email, $usermeta ); 1336 1320 1337 1321 return $user_id; … … function bp_core_activate_signup( $key ) { 1354 1338 $user = wpmu_activate_signup( $key ); 1355 1339 1356 1340 // If there were errors, add a message and redirect 1357 if ( ! empty( $user->errors ) ) {1341 if ( ! empty( $user->errors ) ) { 1358 1342 return $user; 1359 1343 } 1360 1344 1361 1345 $user_id = $user['user_id']; 1362 1346 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 { 1367 1348 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 ); 1370 1350 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' ) ); 1373 1353 1374 // Save the visibility level1375 $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 ); 1379 1359 } 1380 } else {1381 1360 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') ); 1384 1379 1385 if ( empty( $user_id ) ) 1386 return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) ); 1380 $user_already_created = true; 1387 1381 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 ); 1391 1395 1392 1396 // Notify the site admin of a new user registration 1393 1397 wp_new_user_notification( $user_id ); 1394 1398 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 } 1397 1424 } 1398 1425 1399 1426 // Update the display_name 1400 1427 wp_update_user( array( 'ID' => $user_id, 'display_name' => bp_core_get_user_displayname( $user_id ) ) ); 1401 1428 1402 1429 // Set the password on multisite installs 1403 if ( is_multisite() && !empty( $user['meta']['password'] ) )1430 if ( ! empty( $user['meta']['password'] ) ) 1404 1431 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_pass = %s WHERE ID = %d", $user['meta']['password'], $user_id ) ); 1405 1432 1406 1433 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 { 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, 75 75 '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 ); 77 83 78 84 /** Logged in user ****************************************************/ 79 85 -
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() { 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