BP_Xprofile_Profile_Completion_Widget::get_user_progress( type $group_ids, type $photo_types )
Function returns logged in user progress based on options selected in the widget form.
Description
Parameters
- $group_ids
-
(Required)
- $photo_types
-
(Required)
Return
(int)
Source
File: bp-xprofile/classes/class-bp-xprofile-profile-completion-widget.php
function get_user_progress( $group_ids, $photo_types ) { /* User Progress specific VARS. */ $user_id = get_current_user_id(); $progress_details = array(); $grand_total_fields = 0; $grand_completed_fields = 0; /* Profile Photo */ // check if profile photo option still enabled. $is_profile_photo_disabled = bp_disable_avatar_uploads(); if ( ! $is_profile_photo_disabled && in_array( 'profile_photo', $photo_types ) ) { ++ $grand_total_fields; $is_profile_photo_uploaded = ( bp_get_user_has_avatar( $user_id ) ) ? 1 : 0; if ( $is_profile_photo_uploaded ) { ++ $grand_completed_fields; } $progress_details['photo_type']['profile_photo'] = array( 'is_uploaded' => $is_profile_photo_uploaded, 'name' => __( 'Profile Photo', 'buddyboss' ), ); } /* Cover Photo */ // check if cover photo option still enabled. $is_cover_photo_disabled = bp_disable_cover_image_uploads(); if ( ! $is_cover_photo_disabled && in_array( 'cover_photo', $photo_types ) ) { ++ $grand_total_fields; $is_cover_photo_uploaded = ( bp_attachments_get_user_has_cover_image( $user_id ) ) ? 1 : 0; if ( $is_cover_photo_uploaded ) { ++ $grand_completed_fields; } $progress_details['photo_type']['cover_photo'] = array( 'is_uploaded' => $is_cover_photo_uploaded, 'name' => __( 'Cover Photo', 'buddyboss' ), ); } /* Groups Fields */ // Get Groups and Group fields with Loggedin user data. $profile_groups = bp_xprofile_get_groups( array( 'fetch_fields' => true, 'fetch_field_data' => true, 'user_id' => $user_id, ) ); foreach ( $profile_groups as $single_group_details ) { if ( empty( $single_group_details->fields ) ) { continue; } /* Single Group Specific VARS */ $group_id = $single_group_details->id; $single_group_progress = array(); // Consider only selected Groups ids from the widget form settings, skip all others. if ( ! in_array( $group_id, $group_ids ) ) { continue; } // Check if Current Group is repeater if YES then get number of fields inside current group. $is_group_repeater_str = bp_xprofile_get_meta( $group_id, 'group', 'is_repeater_enabled', true ); $is_group_repeater = ( 'on' === $is_group_repeater_str ) ? true : false; /* Loop through all the fields and check if fields completed or not. */ $group_total_fields = 0; $group_completed_fields = 0; foreach ( $single_group_details->fields as $group_single_field ) { // If current group is repeater then only consider first set of fields. if ( $is_group_repeater ) { // If field not a "clone number 1" then stop. That means proceed with the first set of fields and restrict others. $field_id = $group_single_field->id; $clone_number = bp_xprofile_get_meta( $field_id, 'field', '_clone_number', true ); if ( $clone_number > 1 ) { continue; } } $field_data_value = maybe_unserialize( $group_single_field->data->value ); if ( ! empty( $field_data_value ) ) { ++ $group_completed_fields; } ++ $group_total_fields; } /* Prepare array to return group specific progress details */ $single_group_progress['group_name'] = $single_group_details->name; $single_group_progress['group_total_fields'] = $group_total_fields; $single_group_progress['group_completed_fields'] = $group_completed_fields; $grand_total_fields += $group_total_fields; $grand_completed_fields += $group_completed_fields; $progress_details['groups'][ $group_id ] = $single_group_progress; } /* Total Fields vs completed fields to calculate progress percentage. */ $progress_details['total_fields'] = $grand_total_fields; $progress_details['completed_fields'] = $grand_completed_fields; /** * Filter returns User Progress array. * * @since BuddyBoss 1.2.5 */ return apply_filters( 'xprofile_pc_user_progress', $progress_details ); }
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.