BuddyDev

Search

[Resolved] Make Buddypress profile completion to Redirect to specific "profile field group"

  • Participant
    Level: Master
    Posts: 285
    evillizard on #22722

    About this plugin:

    https://wordpress.org/plugins/buddypress-profile-completion/

    Is there a way to make it redirect the user to ONLY! a particular “PROFILE FIELD GROUP” ? … Or Perhaps maybe there should be a “profile field group” selector ..incase the admin wants ONLY a specific “profile field group” completed

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #22723

    Hi ,
    Thank you for the suggestion. At the moment, we are unable to add this. We do not feel it will add much value to the plugin in normal cases. It can be a lot confusing instead.

    If you need custom code for redirection, Please do let me know.

    Regards
    Brajesh

  • Participant
    Level: Master
    Posts: 285
    evillizard on #22726

    Yes please, I need a custom code for redirection… Because its just showing the user the first part of the profile fields.. “which have ALREADY been completed.. I need to redirect them to the part that has’nt been completed

  • Participant
    Level: Master
    Posts: 285
    evillizard on #22743

    Any update on the custom code?

  • Participant
    Level: Master
    Posts: 285
    evillizard on #22774

    Good morning

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #22787

    Hi,
    I will post today or Monday.

    Thank you
    Brajesh

  • Participant
    Level: Master
    Posts: 285
    evillizard on #22795

    Ok boss, no problem

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #22817

    Hi,

    Please download the latest version of plugin from github repo. You can download from the following url:

    https://github.com/buddydev/bp-profile-completion

    and use the following code in your bp-custom.php file.

    
    
    add_filter( 'buddypress_profile_completion_redirect', function( $redirect_url, $has_fields, $has_photo,    $has_cover ) {
    	if ( ! $has_fields ) {
    		$user_id  = get_current_user_id();
    		$group_id = buddydev_get_first_empty_required_group_id( $user_id );
    
    		$redirect_url = bp_core_get_user_domain( $user_id ) . bp_get_profile_slug() . '/edit/group/' . $group_id;
    	}
    
    	return $redirect_url;
    }, 10, 4 );
    
    function buddydev_get_first_empty_required_group_id( $user_id ) {
    	global $wpdb;
    
    	$table = buddypress()->profile->table_name_data;
    
    	$required_fields = BP_Profile_Completion\Core\BP_Profile_Completion_Helper::get_required_field_details();
    
    	// No required field, so profile should be considered complete.
    	if ( empty( $required_fields ) ) {
    		return null;
    	}
    
    	$required_field_ids = wp_list_pluck( $required_fields, 'id' );
    	$fields_list        = '(' . join( ',', $required_field_ids ) . ')';
    
    	$query = $wpdb->prepare( "SELECT field_id, value  FROM {$table} WHERE user_id = %d AND field_id IN {$fields_list}", $user_id );
    
    	$profile_entries = $wpdb->get_results( $query );
    
    	$fields = array();
    	foreach ( $profile_entries as $profile_entry ) {
    		$value = maybe_unserialize( $profile_entry->value );
    
    		if ( empty( $value ) ) {
    			continue;
    		}
    
    		$fields[ $profile_entry->field_id ] = $profile_entry->value;
    	}
    
    	$not_found_groups = array();
    
    	foreach ( $required_fields as $required_field ) {
    		if ( isset( $fields[ $required_field->id ] ) ) {
    			continue;
    		}
    		$not_found_groups[] = $required_field->group_id;
    	}
    
    	$grp_table = $wpdb->prefix . 'bp_xprofile_groups';
    	// Now, query, order by soredr
    	$grplist = '(' . join( ',', $not_found_groups ) . ')';
    
    	return $wpdb->get_var( "SELECT id FROM {$grp_table} WHERE id IN {$grplist} ORDER BY group_order ASC limit 0, 1" );
    }
    
    

    Thank You
    Ravi

  • Participant
    Level: Master
    Posts: 285
    evillizard on #22822

    Ok thank you ravi..ild give you feedback as soon as i try it out

  • Participant
    Level: Master
    Posts: 285
    evillizard on #22944

    Thank you so much, it worked

The topic ‘ [Resolved] Make Buddypress profile completion to Redirect to specific "profile field group"’ is closed to new replies.

This topic is: resolved