Ticket #7565: 7565.01.patch
| File 7565.01.patch, 2.0 KB (added by , 9 years ago) |
|---|
-
src/bp-members/bp-members-functions.php
2007 2007 2008 2008 bp_delete_user_meta( $user_id, 'activation_key' ); 2009 2009 2010 $member = get_userdata( $user_id );2011 $member->set_role( get_option('default_role') );2012 2013 2010 $user_already_created = true; 2014 2011 2015 2012 } else { … … 2124 2121 } 2125 2122 2126 2123 /** 2124 * Add default WordPress role for new signups on the BP root blog. 2125 * 2126 * @since 3.0.0 2127 * 2128 * @param int $user_id The user ID to add the default role for. 2129 */ 2130 function bp_members_add_role_after_activation( $user_id ) { 2131 if ( ! is_numeric( $user_id ) ) { 2132 return; 2133 } 2134 2135 $is_root_blog = bp_is_root_blog(); 2136 if ( ! $is_root_blog ) { 2137 switch_to_blog( bp_get_root_blog_id() ); 2138 } 2139 2140 $member = get_userdata( $user_id ); 2141 $member->set_role( get_option( 'default_role' ) ); 2142 2143 if ( ! $is_root_blog ) { 2144 restore_current_blog(); 2145 } 2146 } 2147 add_action( 'bp_core_activated_user', 'bp_members_add_role_after_activation', 1 ); 2148 2149 /** 2127 2150 * Migrate signups from pre-2.0 configuration to wp_signups. 2128 2151 * 2129 2152 * @since 2.0.1 -
tests/phpunit/testcases/members/functions.php
637 637 638 638 $wpdb->suppress_errors( $suppress ); 639 639 } 640 641 /** 642 * @group bp_core_activate_signup 643 */ 644 public function test_bp_core_activate_signup_should_add_user_role() { 645 $key = 'test'; 646 647 // Create the signup. 648 $this->factory->signup->create( array( 649 'user_login' => 'test', 650 'user_email' => 'test@example.com', 651 'activation_key' => $key, 652 'meta' => array( 653 'field_1' => 'Foo Bar', 654 'password' => 'foobar', 655 ), 656 ) ); 657 658 // Activate user. 659 $user_id = bp_core_activate_signup( $key ); 660 661 // Assert that user has a role. 662 $user = get_userdata( $user_id ); 663 $this->assertNotEmpty( $user->roles ); 664 } 640 665 }