Skip to:
Content

BuddyPress.org

Changeset 11829


Ignore:
Timestamp:
01/27/2018 04:39:38 PM (21 months ago)
Author:
r-a-y
Message:

Activation: Add default WordPress role for new signups.

Props r-a-y, needle, espellcaste, DJPaul, boonebgorges.

Fixes #7565.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/bp-members-functions.php

    r11818 r11829  
    18581858            bp_delete_user_meta( $user_id, 'activation_key' );
    18591859
    1860             $member = get_userdata( $user_id );
    1861             $member->set_role( get_option('default_role') );
    1862 
    18631860            $user_already_created = true;
    18641861
     
    19831980
    19841981/**
     1982 * Add default WordPress role for new signups on the BP root blog.
     1983 *
     1984 * @since 3.0.0
     1985 *
     1986 * @param int $user_id The user ID to add the default role for.
     1987 */
     1988function bp_members_add_role_after_activation( $user_id ) {
     1989    // Get default role to add.
     1990    $role = bp_get_option( 'default_role' );
     1991
     1992    // Multisite.
     1993    if ( is_multisite() && ! is_user_member_of_blog( $user_id, bp_get_root_blog_id() ) ) {
     1994        add_user_to_blog( bp_get_root_blog_id(), $user_id, $role );
     1995
     1996    // Single-site.
     1997    } elseif ( ! is_multisite() ) {
     1998        $member = get_userdata( $user_id );
     1999        $member->set_role( $role );
     2000    }
     2001}
     2002add_action( 'bp_core_activated_user', 'bp_members_add_role_after_activation', 1 );
     2003
     2004/**
    19852005 * Migrate signups from pre-2.0 configuration to wp_signups.
    19862006 *
  • trunk/tests/phpunit/testcases/members/functions.php

    r11818 r11829  
    576576        );
    577577    }
     578
     579    /**
     580     * @group bp_core_activate_signup
     581     */
     582    public function test_bp_core_activate_signup_should_add_user_role() {
     583        $key = 'test';
     584
     585        // Create the signup.
     586        $this->factory->signup->create( array(
     587            'user_login'     => 'test',
     588            'user_email'     => 'test@example.com',
     589            'activation_key' => $key,
     590            'meta' => array(
     591                'field_1' => 'Foo Bar',
     592                'password' => 'foobar',
     593            ),
     594        ) );
     595
     596        // Activate user.
     597        $user_id = bp_core_activate_signup( $key );
     598
     599        // Assert that user has a role.
     600        $user = get_userdata( $user_id );
     601        $this->assertNotEmpty( $user->roles );
     602    }
    578603}
Note: See TracChangeset for help on using the changeset viewer.