Ticket #5374: 5374.diff
File 5374.diff, 70.2 KB (added by , 11 years ago) |
---|
-
bp-core/admin/bp-core-functions.php
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. … … 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
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() { … … 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
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 $signups_table = buddypress()->members->table_name_signups; 2503 2504 $r = bp_parse_args( $args, 2505 array( 2506 'domain' => '', 2507 'path' => '', 2508 'title' => '', 2509 'user_login' => '', 2510 'user_email' => '', 2511 'registered' => current_time( 'mysql', true ), 2512 'activation_key' => '', 2513 'meta' => '' 2514 ), 2515 'bp_core_signups_add_args' 2516 ); 2517 2518 $inserted = $wpdb->insert( 2519 $signups_table, 2520 $r, 2521 array( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) 2522 ); 2523 2524 return apply_filters( 'bp_core_signups_add', $inserted ); 2525 } 2526 2527 /** 2528 * "Activate" a signup 2529 * 2530 * @access public 2531 * @since BuddyPress (2.0.0) 2532 * 2533 * @global $wpdb 2534 * @param string $key 2535 * @return boolean 2536 * @static 2537 */ 2538 public static function validate( $key = '' ) { 2539 global $wpdb; 2540 2541 if ( empty( $key ) ) 2542 return; 2543 2544 $signups_table = buddypress()->members->table_name_signups; 2545 2546 $activated = $wpdb->update( 2547 $signups_table, 2548 array( 2549 'active' => 1, 2550 'activated' => current_time('mysql', true) 2551 ), 2552 array( 2553 'activation_key' => $key 2554 ), 2555 // Data sanitization format 2556 array( 2557 '%d', 2558 '%s' 2559 ), 2560 // WHERE sanitization format 2561 array( 2562 '%s', 2563 ) 2564 ); 2565 2566 return apply_filters( 'bp_core_signups_activate', $activated ); 2567 } 2568 2569 /** 2570 * How many signups ? 2571 * 2572 * @access public 2573 * @since BuddyPress (2.0.0) 2574 * 2575 * @global $wpdb 2576 * @return int the number of signups 2577 * @static 2578 */ 2579 public static function count_signups() { 2580 global $wpdb; 2581 2582 $signups_table = buddypress()->members->table_name_signups; 2583 $count_signups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) AS total FROM {$signups_table} WHERE active = %d", 0 ) ); 2584 2585 return apply_filters( 'bp_core_signups_count', (int) $count_signups ); 2586 } 2587 2588 /** 2589 * Update the meta for a signup 2590 * 2591 * This is the way we use to "trace" the last date an activation 2592 * email was sent and how many times activation was sent 2593 * 2594 * @access public 2595 * @since BuddyPress (2.0.0) 2596 * 2597 * @global $wpdb 2598 * @param array $args 2599 * @return int the signup id 2600 * @static 2601 */ 2602 public static function update( $args = array() ) { 2603 global $wpdb; 2604 2605 $r = bp_parse_args( $args, 2606 array( 2607 'signup_id' => 0, 2608 'meta' => array(), 2609 ), 2610 'bp_core_signups_update_args' 2611 ); 2612 2613 extract( $r, EXTR_SKIP ); 2614 2615 if ( empty( $signup_id ) || empty( $meta ) ) 2616 return false; 2617 2618 $wpdb->update( 2619 // Signups table 2620 buddypress()->members->table_name_signups, 2621 // Data to update 2622 array( 2623 'meta' => serialize( $meta ), 2624 ), 2625 // WHERE 2626 array( 2627 'signup_id' => $signup_id, 2628 ), 2629 // Data sanitization format 2630 array( 2631 '%s', 2632 ), 2633 // WHERE sanitization format 2634 array( 2635 '%d', 2636 ) 2637 ); 2638 2639 return $signup_id; 2640 } 2641 2642 /** 2643 * Resend an activation link 2644 * 2645 * @access public 2646 * @since BuddyPress (2.0.0) 2647 * 2648 * @param array $signup_ids single id or list of ids to resend 2649 * @return array the results 2650 * @static 2651 */ 2652 public static function resend( $signup_ids = array() ) { 2653 if ( empty( $signup_ids ) || ! is_array( $signup_ids ) ) 2654 return false; 2655 2656 $to_resend = self::get( array( 'include' => $signup_ids ) ); 2657 2658 if ( ! $signups = $to_resend['signups'] ) 2659 return false; 2660 2661 $now = current_time( 'timestamp', true ); 2662 $result = array(); 2663 2664 do_action( 'bp_core_signup_before_resend', $signup_ids ); 2665 2666 foreach ( $signups as $signup ) { 2667 $sent_at = mysql2date('U', $signup->date_sent ); 2668 $diff = $now - $sent_at; 2669 2670 // If a previous resent happened less than a day ago, skip. 2671 if ( $diff < 1 * DAY_IN_SECONDS ) { 2672 $result['errors'][] = $signup->signup_id; 2673 continue; 2674 } 2675 2676 $meta = maybe_unserialize( $signup->meta ); 2677 2678 $meta['sent_date'] = current_time( 'mysql', true ); 2679 $meta['count_sent'] = $signup->count_sent + 1; 2680 2681 // Send activation email 2682 if( is_multisite() ) { 2683 wpmu_signup_user_notification( $signup->user_login, $signup->user_email, $signup->activation_key, serialize( $meta ) ); 2684 } else { 2685 bp_core_signup_send_validation_email( false, $signup->user_email, $signup->activation_key ); 2686 } 2687 2688 // Update metas 2689 $result['resent'][] = self::update( array( 'signup_id' => $signup->signup_id, 'meta' => $meta ) ); 2690 } 2691 2692 do_action( 'bp_core_signup_after_resend', $signup_ids ); 2693 2694 return $result; 2695 } 2696 2697 /** 2698 * Activate a pending account 2699 * 2700 * @access public 2701 * @since BuddyPress (2.0.0) 2702 * 2703 * @param array $signup_ids single id or list of ids to resend 2704 * @return array the results 2705 * @static 2706 */ 2707 public static function activate( $signup_ids = array() ) { 2708 if ( empty( $signup_ids ) || ! is_array( $signup_ids ) ) 2709 return false; 2710 2711 $to_activate = self::get( array( 'include' => $signup_ids ) ); 2712 2713 if ( ! $signups = $to_activate['signups'] ) 2714 return false; 2715 2716 $result = array(); 2717 2718 do_action( 'bp_core_signup_before_activate', $signup_ids ); 2719 2720 foreach ( $signups as $signup ) { 2721 2722 $user = bp_core_activate_signup( $signup->activation_key ); 2723 2724 if ( ! empty( $user->errors ) ) { 2725 $result['errors'][ $signup->signup_id ] = array( $signup->user_login, $user->get_error_message() ); 2726 } else { 2727 $result['activated'][] = $user; 2728 } 2729 2730 } 2731 2732 do_action( 'bp_core_signup_after_activate', $result ); 2733 2734 return $result; 2735 } 2736 2737 /** 2738 * Delete a pending account 2739 * 2740 * @access public 2741 * @since BuddyPress (2.0.0) 2742 * 2743 * @param array $signup_ids single id or list of ids to resend 2744 * @return array the results 2745 * @static 2746 */ 2747 public static function delete( $signup_ids = array() ) { 2748 global $wpdb; 2749 2750 if ( empty( $signup_ids ) || ! is_array( $signup_ids ) ) 2751 return false; 2752 2753 $to_delete = self::get( array( 'include' => $signup_ids ) ); 2754 2755 if ( ! $signups = $to_delete['signups'] ) 2756 return false; 2757 2758 $deleted = array(); 2759 2760 do_action( 'bp_core_signup_before_delete', $signup_ids ); 2761 2762 foreach ( $signups as $signup ) { 2763 2764 $user_id = username_exists( $signup->user_login ); 2765 2766 // If we have a user id, let's delete it 2767 if ( ! empty( $user_id ) && $signup->activation_key == wp_hash( $user_id ) ) 2768 bp_core_delete_account( $user_id ); 2769 2770 $wpdb->delete( 2771 // Signups table 2772 buddypress()->members->table_name_signups, 2773 // Where 2774 array( 'signup_id' => $signup->signup_id ), 2775 // WHERE sanitization format 2776 array( '%d' ) 2777 ); 2778 2779 $deleted[] = $signup->signup_id; 2780 2781 } 2782 2783 do_action( 'bp_core_signup_after_delete', $signup_ids, $deleted ); 2784 2785 return $deleted; 2786 } 2787 2788 } -
bp-core/bp-core-update.php
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! *************************************************************/ … … 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 'domain' => '', 374 'path' => '', 375 'title' => '', 376 'user_login' => $user_login, 377 'user_email' => $user_email, 378 'registered' => $signup->user_registered, 379 'activation_key' => $signup->activation_key, 380 'meta' => $meta 381 ); 382 383 $wpdb->insert( buddypress()->members->table_name_signups, $args ); 384 385 // Deleting these options will remove signups from users count 386 delete_user_option( $signup->ID, 'capabilities' ); 387 delete_user_option( $signup->ID, 'user_level' ); 388 } 389 } 390 } 391 392 /** 331 393 * Redirect user to BP's What's New page on first page load after activation. 332 394 * 333 395 * @since BuddyPress (1.7.0) -
bp-loader.php
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
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
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() ) … … 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 /** … … 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 ); … … 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) … … 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', … … 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 } 181 212 182 213 } 183 214 184 215 /** 216 * Highlight the Users menu if on Edit Profile or Signups pages. 217 * 218 * @access public 219 * @since BuddyPress (2.0.0) 220 */ 221 public function modify_admin_menu_highlight() { 222 global $plugin_page, $submenu_file; 223 224 // Only Show the All users menu 225 if ( in_array( $plugin_page, array( 'bp-profile-edit', 'bp-signups' ) ) ) { 226 $submenu_file = 'users.php'; 227 } 228 } 229 230 /** 231 * Remove the Edit Profile & Signups submenu page. 232 * 233 * @access public 234 * @since BuddyPress (2.0.0) 235 */ 236 public function admin_head() { 237 // Remove submenu to force using Profile Navigation 238 remove_submenu_page( 'users.php', 'bp-profile-edit' ); 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 … … 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 … … 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 ( $this->users_page != get_current_screen()->id ) 772 return; 773 774 if ( ! empty( $query->query_vars['role'] ) ) 775 return; 776 777 $query->query_where .= " AND {$wpdb->users}.user_status != 2"; 778 } 779 780 /** 781 * Filter the WP Users List Table views to include the signup one 782 * 783 * @access public 784 * @since BuddyPress (2.0.0) 785 * 786 * @param array $views the WP List Table views 787 * @return array the views with the signup one 788 */ 789 public function signup_filter_view( $views = array() ) { 790 $class = ''; 791 792 $signups = BP_Core_Signup::count_signups(); 793 794 if ( $this->signups_page == get_current_screen()->id ) { 795 $views['all'] = str_replace( 'class="current"', '', $views['all'] ); 796 $class = ' class="current"'; 797 } 798 799 $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>'; 800 801 return $views; 802 } 803 804 /** 805 * Load the Signup WP Users List table 806 * 807 * @access public 808 * @since BuddyPress (2.0.0) 809 * 810 * @param string $class the name of the class to use 811 * @param string $required the parent class 812 * @return WP_List_Table the List table 813 * @static 814 */ 815 public static function get_list_table_class( $class = '', $required = '' ) { 816 if( empty( $class ) ) 817 return; 818 819 if( ! empty( $required ) ) { 820 require_once( ABSPATH . 'wp-admin/includes/class-wp-' . $required . '-list-table.php' ); 821 require_once( buddypress()->members->admin->admin_dir . 'bp-members-classes.php' ); 822 } 823 824 return new $class(); 825 } 826 827 /** 828 * Set up the signups admin page. 829 * 830 * Loaded before the page is rendered, this function does all initial 831 * setup, including: processing form requests, registering contextual 832 * help, and setting up screen options. 833 * 834 * @access public 835 * @since BuddyPress (2.0.0) 836 * 837 * @global $bp_members_signup_list_table 838 */ 839 public function signups_admin_load() { 840 global $bp_members_signup_list_table; 841 842 // Build redirection URL 843 $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'] ); 844 $doaction = bp_admin_list_table_current_bulk_action(); 845 846 // Call an action for plugins to hook in early 847 do_action_ref_array( 'bp_signups_admin_load', array( $doaction, $_REQUEST ) ); 848 849 // Allowed actions 850 $allowed_actions = apply_filters( 'bp_signups_admin_allowed_actions', array( 'do_delete', 'do_activate', 'do_resend' ) ); 851 852 // Prepare the display of the Community Profile screen 853 if ( ! in_array( $doaction, $allowed_actions ) || -1 == $doaction ) { 854 855 if ( bp_core_do_network_admin() ) { 856 $bp_members_signup_list_table = self::get_list_table_class( 'BP_Members_MS_List_Table', 'ms-users' ); 857 } else { 858 $bp_members_signup_list_table = self::get_list_table_class( 'BP_Members_List_Table', 'users' ); 859 } 860 861 // per_page screen option 862 add_screen_option( 'per_page', array( 'label' => _x( 'Pending Accounts', 'Pending Accounts per page (screen options)', 'buddypress' ) ) ); 863 864 get_current_screen()->add_help_tab( array( 865 'id' => 'bp-signups-overview', 866 'title' => __( 'Overview', 'buddypress' ), 867 'content' => 868 '<p>' . __( 'This is the admininistration screen of the pending accounts of your site.', 'buddypress' ) . '</p>' . 869 '<p>' . __( 'From the screen options, you can customize the displayed columns and the pagination of this screen.', 'buddypress' ) . '</p>' . 870 '<p>' . __( 'You can reorder the list of your pending accounts by clicking on the Username, E-mail or Registered column headers.', 'buddypress' ) . '</p>' . 871 '<p>' . __( 'Using the search form, you can find pending accounts more easily: Username and E-mail fields will be looked at.', 'buddypress' ) . '</p>' 872 ) ); 873 874 get_current_screen()->add_help_tab( array( 875 'id' => 'bp-signups-actions', 876 'title' => __( 'Actions', 'buddypress' ), 877 'content' => 878 '<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>' . 879 '<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>' . 880 '<li>' . __( 'Delete allows you to delete a pending account from your site, once you confirmed your choice from the confirmation screen.', 'buddypress' ) . '</li></ul>' . 881 '<p>' . __( 'By clicking on a Username you will be able to activate a pending account from the confirmation screen.', 'buddypress' ) . '</p>' . 882 '<p>' . __( 'Bulk actions allow you to perform these 3 actions for the selected rows.', 'buddypress' ) . '</p>' 883 ) ); 884 885 // Help panel - sidebar links 886 get_current_screen()->set_help_sidebar( 887 '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' . 888 '<p>' . __( '<a href="http://codex.buddypress.org/buddypress-site-administration/managing-signups/">Managing Sign-ups</a>', 'buddypress' ) . '</p>' . 889 '<p>' . __( '<a href="http://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>' 890 ); 891 } else { 892 if ( ! empty( $_REQUEST['signup_ids' ] ) ) 893 $signups = wp_parse_id_list( $_REQUEST['signup_ids' ] ); 894 895 // Handle resent activation links 896 if ( 'do_resend' == $doaction ) { 897 // nonce check 898 check_admin_referer( 'signups_resend' ); 899 900 $resent = BP_Core_SignUp::resend( $signups ); 901 902 if ( empty( $resent ) ) { 903 $redirect_to = add_query_arg( 'error', $doaction, $redirect_to ); 904 // resent messages 905 } else { 906 $query_arg = array( 'updated' => 'resent' ); 907 908 if ( ! empty( $resent['resent'] ) ) 909 $query_arg['resent'] = count( $resent['resent'] ); 910 911 if ( ! empty( $resent['errors'] ) ) 912 $query_arg['notsent'] = count( $resent['errors'] ); 913 914 $redirect_to = add_query_arg( $query_arg, $redirect_to ); 915 } 916 917 bp_core_redirect( $redirect_to ); 918 919 // Handle activated accounts 920 } else if ( 'do_activate' == $doaction ) { 921 // nonce check 922 check_admin_referer( 'signups_activate' ); 923 924 $activated = BP_Core_SignUp::activate( $signups ); 925 926 if ( empty( $activated ) ) { 927 $redirect_to = add_query_arg( 'error', $doaction, $redirect_to ); 928 // resent messages 929 } else { 930 $query_arg = array( 'updated' => 'activated' ); 931 932 if ( ! empty( $activated['activated'] ) ) 933 $query_arg['activated'] = count( $activated['activated'] ); 934 935 if ( ! empty( $activated['errors'] ) ) { 936 $query_arg['notactivated'] = count( $activated['errors'] ); 937 set_transient( '_bp_account_activation_errors', $activated['errors'], 30 ); 938 } 939 940 $redirect_to = add_query_arg( $query_arg, $redirect_to ); 941 } 942 943 bp_core_redirect( $redirect_to ); 944 945 // Handle sign-ups delete 946 } else if ( 'do_delete' == $doaction ) { 947 // nonce check 948 check_admin_referer( 'signups_delete' ); 949 950 $deleted = BP_Core_SignUp::delete( $signups ); 951 952 if ( empty( $deleted ) ) { 953 $redirect_to = add_query_arg( 'error', $doaction, $redirect_to ); 954 // resent messages 955 } else { 956 $query_arg = array( 957 'updated' => 'deleted', 958 'deleted' => count( $deleted ) 959 ); 960 961 $redirect_to = add_query_arg( $query_arg, $redirect_to ); 962 } 963 964 bp_core_redirect( $redirect_to ); 965 966 // Plugins can update other stuff from here 967 } else { 968 $this->redirect = $redirect_to; 969 970 do_action_ref_array( 'bp_members_admin_update_signups', array( $doaction, $_REQUEST, $this->redirect ) ); 971 972 bp_core_redirect( $this->redirect ); 973 } 974 } 975 } 976 977 /** 978 * Display the activation errors 979 * 980 * @access public 981 * @since BuddyPress (2.0.0) 982 */ 983 public function display_activate_errors() { 984 // Bail if no activation errors 985 if ( ! $errors = get_transient( '_bp_account_activation_errors' ) ) 986 return; 987 988 foreach ( $errors as $error ) { 989 ?> 990 <li><?php echo esc_html( $error[0] );?>: <?php echo esc_html( $error[1] );?></li> 991 <?php 992 } 993 994 // Delete the redirect transient 995 delete_transient( '_bp_account_activation_errors' ); 996 } 997 998 /** 999 * Choose the best signups admin page 1000 * 1001 * Depending on the context, display 1002 * - the list of signups 1003 * - or the delete confirmation screen 1004 * - or the activate confirmation screen 1005 * - or the "resend" email confirmation screen 1006 * 1007 * Also prepare the admin notices 1008 * 1009 * @access public 1010 * @since BuddyPress (2.0.0) 1011 */ 1012 public function signups_admin() { 1013 $doaction = bp_admin_list_table_current_bulk_action(); 1014 1015 // Prepare notices for admin 1016 $notice = array(); 1017 1018 if ( ! empty( $_REQUEST['updated'] ) ) { 1019 switch ( $_REQUEST['updated'] ) { 1020 case 'resent': 1021 $notice = array( 1022 'class' => 'updated', 1023 'message' => '' 1024 ); 1025 1026 if ( ! empty( $_REQUEST['resent'] ) ) { 1027 $notice['message'] .= sprintf( 1028 _nx( '%s activation email successfully sent! ', '%s activation emails successfully sent! ', 1029 absint( $_REQUEST['resent'] ), 1030 'signup resent', 1031 'buddypress' 1032 ), 1033 number_format_i18n( absint( $_REQUEST['resent'] ) ) 1034 ); 1035 } 1036 1037 if ( ! empty( $_REQUEST['notsent'] ) ) { 1038 $notice['message'] .= sprintf( 1039 _nx( '%s activation email was not sent: user already received one today.', '%s activation emails were not sent: users already received one today.', 1040 absint( $_REQUEST['notsent'] ), 1041 'signup notsent', 1042 'buddypress' 1043 ), 1044 number_format_i18n( absint( $_REQUEST['notsent'] ) ) 1045 ); 1046 1047 if ( empty( $_REQUEST['resent'] ) ) 1048 $notice['class'] = 'error'; 1049 } 1050 1051 break; 1052 1053 case 'activated': 1054 $notice = array( 1055 'class' => 'updated', 1056 'message' => '' 1057 ); 1058 1059 if ( ! empty( $_REQUEST['activated'] ) ) { 1060 $notice['message'] .= sprintf( 1061 _nx( '%s account successfully activated! ', '%s accounts successfully activated! ', 1062 absint( $_REQUEST['activated'] ), 1063 'signup resent', 1064 'buddypress' 1065 ), 1066 number_format_i18n( absint( $_REQUEST['activated'] ) ) 1067 ); 1068 } 1069 1070 if ( ! empty( $_REQUEST['notactivated'] ) ) { 1071 $notice['message'] .= sprintf( 1072 _nx( '%s account was not activated.', '%s accounts were not activated.', 1073 absint( $_REQUEST['notactivated'] ), 1074 'signup notsent', 1075 'buddypress' 1076 ), 1077 number_format_i18n( absint( $_REQUEST['notactivated'] ) ) 1078 ); 1079 1080 if ( empty( $_REQUEST['activated'] ) ) 1081 $notice['class'] = 'error'; 1082 } 1083 1084 break; 1085 1086 case 'deleted': 1087 $notice = array( 1088 'class' => 'updated', 1089 'message' => sprintf( 1090 _nx( '%s sign-up successfully deleted!', '%s sign-ups successfully deleted!', 1091 absint( $_REQUEST['deleted'] ), 1092 'signup deleted', 1093 'buddypress' 1094 ), 1095 number_format_i18n( absint( $_REQUEST['deleted'] ) ) ) 1096 ); 1097 1098 break; 1099 } 1100 } 1101 1102 if ( ! empty( $_REQUEST['error'] ) ) { 1103 switch ( $_REQUEST['error'] ) { 1104 case 'do_resend': 1105 $notice = array( 1106 'class' => 'error', 1107 'message' => esc_html__( 'There was a problem sending the activation emails, please try again.', 'buddypress' ) 1108 ); 1109 break; 1110 case 'do_activate': 1111 $notice = array( 1112 'class' => 'error', 1113 'message' => esc_html__( 'There was a problem activating accounts, please try again.', 'buddypress' ) 1114 ); 1115 break; 1116 case 'do_delete': 1117 $notice = array( 1118 'class' => 'error', 1119 'message' => esc_html__( 'There was a problem deleting sign-ups, please try again.', 'buddypress' ) 1120 ); 1121 break; 1122 } 1123 } 1124 1125 if ( ! empty( $notice ) ) : 1126 if ( 'updated' === $notice['class'] ) : ?> 1127 <div id="message" class="<?php echo esc_attr( $notice['class'] ); ?>"> 1128 <?php else: ?> 1129 <div class="<?php echo esc_attr( $notice['class'] ); ?>"> 1130 <?php endif; ?> 1131 <p><?php echo $notice['message']; ?></p> 1132 <?php if ( ! empty( $_REQUEST['notactivated'] ) ) :?> 1133 <ul><?php $this->display_activate_errors();?></ul> 1134 <?php endif ;?> 1135 </div> 1136 <?php endif; 1137 1138 switch( $doaction ) { 1139 case 'activate' : 1140 case 'delete' : 1141 case 'resend' : 1142 $this->signups_admin_manage( $doaction ); 1143 break; 1144 1145 default: 1146 $this->signups_admin_index(); 1147 break; 1148 1149 } 1150 } 1151 1152 /** 1153 * This is the list of the Pending accounts (signups) 1154 * 1155 * @access public 1156 * @since BuddyPress (2.0.0) 1157 * 1158 * @global $plugin_page 1159 * @global $bp_members_signup_list_table 1160 */ 1161 public function signups_admin_index() { 1162 global $plugin_page, $bp_members_signup_list_table; 1163 1164 $usersearch = ! empty( $_REQUEST['s'] ) ? $_REQUEST['s'] : ''; 1165 // Prepare the group items for display 1166 $bp_members_signup_list_table->prepare_items(); 1167 1168 $form_url = add_query_arg( array( 1169 'page' => 'bp-signups' 1170 ), 1171 bp_get_admin_url( 'users.php' ) 1172 ); 1173 $search_form_url = remove_query_arg( 1174 array( 1175 'action', 1176 'deleted', 1177 'error', 1178 'updated', 1179 'delete', 1180 'activate', 1181 'activated', 1182 'notactivated', 1183 'resend', 1184 'resent', 1185 'notresent', 1186 'do_delete', 1187 'do_activate', 1188 'do_resend', 1189 'action2', 1190 '_wpnonce', 1191 'signup_ids' 1192 ), $_SERVER['REQUEST_URI'] 1193 ); 1194 ?> 1195 1196 <div class="wrap"> 1197 <?php screen_icon( 'users' ); ?> 1198 <h2> 1199 <?php 1200 _e( 'Users', 'buddypress' ); 1201 if ( current_user_can( 'create_users' ) ) { ?> 1202 <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'user' ); ?></a> 1203 <?php } elseif ( is_multisite() && current_user_can( 'promote_users' ) ) { ?> 1204 <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add Existing', 'user' ); ?></a> 1205 <?php } 1206 1207 if ( $usersearch ) 1208 printf( '<span class="subtitle">' . __('Search results for “%s”') . '</span>', esc_html( $usersearch ) ); ?> 1209 </h2> 1210 1211 <?php // Display each signups on its own row ?> 1212 <?php $bp_members_signup_list_table->views(); ?> 1213 1214 <form id="bp-signups-search-form" action="<?php echo $search_form_url ;?>"> 1215 <input type="hidden" name="page" value="<?php echo esc_attr( $plugin_page ); ?>" /> 1216 <?php $bp_members_signup_list_table->search_box( __( 'Search Pending accounts', 'buddypress' ), 'bp-signups' ); ?> 1217 </form> 1218 1219 <form id="bp-signups-form" action="<?php echo $form_url;?>" method="post"> 1220 <?php $bp_members_signup_list_table->display(); ?> 1221 </form> 1222 1223 </div> 1224 <?php 1225 } 1226 1227 /** 1228 * This is the confirmation screen for actions 1229 * 1230 * @access public 1231 * @since BuddyPress (2.0.0) 1232 * 1233 * @param string $action delete/activate or resend activation link 1234 */ 1235 public function signups_admin_manage( $action = '' ) { 1236 if ( ! is_super_admin() || empty( $action ) ) 1237 die( '-1' ); 1238 1239 $ids = false; 1240 1241 1242 if ( ! empty( $_REQUEST['allsignups'] ) ) { 1243 $ids = wp_parse_id_list( $_REQUEST['allsignups'] ); 1244 } else if ( ! empty( $_REQUEST['signup_id'] ) ) { 1245 $ids = absint( $_REQUEST['signup_id'] ); 1246 } 1247 1248 if( empty( $ids ) ) 1249 return false; 1250 1251 $signups_query = BP_Core_SignUp::get( array( 'include' => $ids ) ); 1252 $signups = $signups_query['signups']; 1253 1254 // Create a new list of signup ids, based on those that actually exist 1255 $signup_ids = array(); 1256 foreach ( $signups as $signup ) { 1257 $signup_ids[] = $signup->signup_id; 1258 } 1259 1260 switch ( $action ) { 1261 case 'delete' : 1262 $caption = __( 'delete', 'buddypress' ); 1263 break; 1264 case 'activate' : 1265 $caption = __( 'activate', 'buddypress' ); 1266 break; 1267 case 'resend' : 1268 $caption = __( 'resend activation email to', 'buddypress' ) ; 1269 } 1270 1271 1272 $url_args = array( 'page' => 'bp-signups' ); 1273 $action_args = array( 1274 'action' => 'do_' . $action, 1275 'signup_ids' => implode( ',', $signup_ids ) 1276 ); 1277 1278 $cancel_url = add_query_arg( $url_args, bp_get_admin_url( 'users.php' ) ); 1279 $action_url = wp_nonce_url( 1280 add_query_arg( 1281 array_merge( $url_args, $action_args ), 1282 bp_get_admin_url( 'users.php' ) 1283 ), 1284 'signups_' . $action ); 1285 ?> 1286 1287 <div class="wrap"> 1288 <?php screen_icon( 'users' ); ?> 1289 <h2><?php printf( __( '%s Pending accounts', 'buddypress' ), ucfirst( $caption ) ); ?></h2> 1290 <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> 1291 1292 <ol class="bp-signups-list"> 1293 <?php foreach ( $signups as $signup ) : ?> 1294 <li><?php echo esc_html( $signup->user_name ) ?> - <?php echo sanitize_email( $signup->user_email );?></li> 1295 <?php endforeach; ?> 1296 </ol> 1297 1298 <?php if ( 'resend' != $action ) : ?> 1299 <p><strong><?php esc_html_e( 'This action cannot be undone.', 'buddypress' ) ?></strong></p> 1300 <?php endif ; ?> 1301 1302 <a class="button-primary" href="<?php echo $action_url; ?>"><?php esc_html_e( 'Confirm', 'buddypress' ); ?></a> 1303 <a class="button" href="<?php echo esc_attr( $cancel_url ); ?>"><?php esc_html_e( 'Cancel', 'buddypress' ) ?></a> 1304 </div> 1305 1306 <?php 1307 } 1308 694 1309 } 695 1310 endif; // class_exists check 696 1311 -
bp-members/bp-members-functions.php
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 … … 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; 1268 1271 1272 // We need to cast $user_id to pass to the filters 1273 $user_id = false; 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 1280 $user_id = wp_insert_user( array( 1281 'user_login' => $user_login, 1282 'user_pass' => $user_password, 1283 'display_name' => sanitize_title( $user_login ), 1284 'user_email' => $user_email 1285 ) ); 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 1286 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; 1290 } 1287 $args = array( 1288 'user_login' => $user_login, 1289 'user_email' => $user_email, 1290 'activation_key' => $activation_key, 1291 'meta' => $meta 1292 ); 1291 1293 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 BP_Core_SignUp::add( $args ); 1294 1295 1295 // Set any profile data1296 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 level1308 $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;1315 1316 /***1317 * Now generate an activation key and send an email to the user so they can activate their1318 * account and validate their email address. Multisite installs send their own email, so1319 * this is only for single blog installs.1320 *1321 * To disable sending activation emails you can user the filter1322 * 'bp_core_signup_send_activation_key' and return false. Note that this will only disable1323 * the email - a key will still be generated, and the account must still be activated1324 * before use.1325 */1326 if ( !is_multisite() ) {1327 $activation_key = wp_hash( $user_id );1328 update_user_meta( $user_id, 'activation_key', $activation_key );1329 1330 1296 if ( apply_filters( 'bp_core_signup_send_activation_key', true ) ) { 1331 1297 bp_core_signup_send_validation_email( $user_id, $user_email, $activation_key ); 1332 1298 } 1333 1299 } 1334 1300 1301 $bp->signup->username = $user_login; 1302 1335 1303 do_action( 'bp_core_signup_user', $user_id, $user_login, $user_password, $user_email, $usermeta ); 1336 1304 1337 1305 return $user_id; … … 1354 1322 $user = wpmu_activate_signup( $key ); 1355 1323 1356 1324 // If there were errors, add a message and redirect 1357 if ( ! empty( $user->errors ) ) {1325 if ( ! empty( $user->errors ) ) { 1358 1326 return $user; 1359 1327 } 1360 1328 1361 1329 $user_id = $user['user_id']; 1362 1330 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'] ); 1331 } else { 1367 1332 1368 foreach( (array) $profile_field_ids as $field_id ) { 1369 $current_field = isset( $user['meta']["field_{$field_id}"] ) ? $user['meta']["field_{$field_id}"] : false; 1333 $signup = BP_Core_SignUp::get_by_key( $key ); 1370 1334 1371 if ( !empty( $current_field) )1372 xprofile_set_field_data( $field_id, $user_id, $current_field);1335 if ( empty( $signup ) ) 1336 return new WP_Error( 'invalid_key', __( 'Invalid activation key.', 'buddypress' ) ); 1373 1337 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 }1338 if ( $signup->active ) { 1339 if ( empty( $signup->domain ) ) 1340 return new WP_Error( 'already_active', __( 'The user is already active.', 'buddypress' ), $signup ); 1341 else 1342 return new WP_Error( 'already_active', __( 'The site is already active.', 'buddypress' ), $signup ); 1379 1343 } 1380 } else {1381 1344 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 ) ); 1345 $meta = maybe_unserialize( $signup->meta ); 1346 // password is hashed again in wp_insert_user 1347 $password = wp_generate_password( 12, false ); 1384 1348 1385 if ( empty( $user_id ) ) 1386 return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) ); 1349 $user_id = username_exists( $signup->user_login ); 1387 1350 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' ) ); 1351 if ( ! $user_id ) { 1352 $user_id = wp_create_user( $signup->user_login, $password, $signup->user_email ); 1353 // It might be a signup set in previous versions let's check against previous way of setting activation key 1354 } else if ( $key == wp_hash( $user_id ) ) { 1355 // Change the user's status so they become active 1356 if ( ! $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_status = 0 WHERE ID = %d", $user_id ) ) ) 1357 return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) ); 1358 1359 bp_delete_user_meta( $user_id, 'activation_key' ); 1391 1360 1361 $member = get_userdata( $user_id ); 1362 $member->set_role( get_option('default_role') ); 1363 1364 $user_already_created = true; 1365 1366 } else { 1367 $user_already_exists = true; 1368 } 1369 1370 if ( ! $user_id ) 1371 return new WP_Error( 'create_user', __( 'Could not create user', 'buddypress' ), $signup ); 1372 1373 BP_Core_SignUp::validate( $key ); 1374 1375 if ( isset( $user_already_exists ) ) 1376 return new WP_Error( 'user_already_exists', __( 'That username is already activated.' ), $signup ); 1377 1378 $user = array( 'user_id' => $user_id, 'password' => $meta['password'], 'meta' => $meta ); 1379 1380 if ( isset( $user_already_created ) ) { 1381 1382 do_action( 'bp_core_activated_user', $user_id, $key, $user ); 1383 1384 return $user_id; 1385 } 1386 1392 1387 // Notify the site admin of a new user registration 1393 1388 wp_new_user_notification( $user_id ); 1389 } 1394 1390 1395 // Remove the activation key meta 1396 delete_user_meta( $user_id, 'activation_key' ); 1391 // Set any profile data 1392 if ( bp_is_active( 'xprofile' ) ) { 1393 if ( ! empty( $user['meta']['profile_field_ids'] ) ) { 1394 $profile_field_ids = explode( ',', $user['meta']['profile_field_ids'] ); 1395 1396 foreach( (array) $profile_field_ids as $field_id ) { 1397 $current_field = isset( $user['meta']["field_{$field_id}"] ) ? $user['meta']["field_{$field_id}"] : false; 1398 1399 if ( !empty( $current_field ) ) 1400 xprofile_set_field_data( $field_id, $user_id, $current_field ); 1401 1402 // Save the visibility level 1403 $visibility_level = ! empty( $user['meta']['field_' . $field_id . '_visibility'] ) ? $user['meta']['field_' . $field_id . '_visibility'] : 'public'; 1404 xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level ); 1405 } 1406 } 1397 1407 } 1398 1408 1399 1409 // Update the display_name 1400 1410 wp_update_user( array( 'ID' => $user_id, 'display_name' => bp_core_get_user_displayname( $user_id ) ) ); 1401 1411 1402 1412 // Set the password on multisite installs 1403 if ( is_multisite() && !empty( $user['meta']['password'] ) )1413 if ( ! empty( $user['meta']['password'] ) ) 1404 1414 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_pass = %s WHERE ID = %d", $user['meta']['password'], $user_id ) ); 1405 1415 1406 1416 do_action( 'bp_core_activated_user', $user_id, $key, $user ); -
bp-members/bp-members-loader.php
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 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 ); 83 78 84 /** Logged in user ****************************************************/ 79 85 80 86 // Fetch the full name for the logged in user -
bp-members/bp-members-screens.php
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