BuddyDev

Search

[Resolved] BuddyPress Profile Completion – User Roles

  • Participant
    Level: Initiated
    Posts: 5
    arnotzon on #26992

    Hi!

    Is it possible to force profile completion based on user roles?
    I would want only “subscribers” to be forced to complete their profile.

    Many thanks in advance!

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #26996

    Hi,
    Welcome to BuddyDev.

    You can use the following code to skip non subscribers from the check.

    
    
    /**
     * Skip non subscribers from the profile completion check.
     */
    add_filter( 'bp_force_profile_completion_skip_check', function ( $skip ) {
    	if ( current_user_can( 'edit_posts' ) ) {
    		$skip = true;
    	}
    
    	return $skip;
    } );
    
    

    Please put it in your theme’s functions.php or if you have bp-custom.php in your wp-content/plugins, you can put it there.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 5
    arnotzon on #27002

    Thank you for you reply Brajesh!

    As I have other roles who can edit posts but would require profile completion, is it possible to get it by role? So that only role=donor can skip profile.

    I tried

    $user = get_userdata( $user_id );
    
    $user_roles = $user->roles;
    
    add_filter( 'bp_force_profile_completion_skip_check', function ( $skip ) {
    	if ( in_array( 'donor', $user_roles, true ) ){
    		$skip = true;
    	}
    
    	return $skip;
    } );

    but without success. Maybe you can help me?

    Thank you 🙂

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #27007

    You are welcome.

    you may want to try something like this instead

    
    
    add_filter( 'bp_force_profile_completion_skip_check', function ( $skip ) {
    
    	$user_roles = wp_get_current_user()->roles;
    	if ( in_array( 'donor', $user_roles, true ) ) {
    		$skip = true;
    	}
    
    	return $skip;
    } );
    

    We need to get the role of current user. So, I have updated the code.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 5
    arnotzon on #27011

    That worked perfectly, thank you so much!

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #27013

    Thank you for confirming. I am glad it worked 🙂

    Regards
    Brajesh

The topic ‘ [Resolved] BuddyPress Profile Completion – User Roles’ is closed to new replies.

This topic is: resolved