BuddyPress: Remind Members to Complete Their Profile
Shows a friendly notice on BuddyPress pages to members who have not filled in important profile fields or uploaded a profile photo, with a link to edit their profile.
Opens WPIDE on
Code
if ( ! function_exists( 'buddypress' ) ) {
return;
}
// Profile field names that should be filled in.
$wpide_bp_required_fields = array( 'Location', 'About me' );
add_action( 'bp_before_member_header', function () use ( $wpide_bp_required_fields ) {
$user_id = bp_loggedin_user_id();
if ( ! $user_id || ! bp_is_my_profile() || ! bp_is_active( 'xprofile' ) || bp_is_user_profile_edit() ) {
return;
}
$missing = get_transient( 'wpide_bp_missing_' . $user_id );
if ( false === $missing ) {
$missing = array();
foreach ( $wpide_bp_required_fields as $field ) {
if ( '' === trim( (string) xprofile_get_field_data( $field, $user_id, 'comma' ) ) ) {
$missing[] = $field;
}
}
if ( ! bp_get_user_has_avatar( $user_id ) ) {
$missing[] = 'profile photo';
}
set_transient( 'wpide_bp_missing_' . $user_id, $missing, HOUR_IN_SECONDS );
}
if ( $missing ) {
printf(
'<div class="bp-feedback info wpide-bp-complete"><span class="bp-icon" aria-hidden="true"></span><p>%1$s <a href="%2$s">Complete your profile</a></p></div>',
esc_html( sprintf( 'Your profile is missing: %s.', implode( ', ', $missing ) ) ),
esc_url( trailingslashit( function_exists( 'bp_members_get_user_url' ) ? bp_members_get_user_url( $user_id ) : bp_core_get_user_domain( $user_id ) ) . 'profile/edit/' )
);
}
} );
add_action( 'xprofile_updated_profile', function ( $user_id ) {
delete_transient( 'wpide_bp_missing_' . (int) $user_id );
} );
add_action( 'bp_members_avatar_uploaded', function ( $item_id ) {
delete_transient( 'wpide_bp_missing_' . (int) $item_id );
} );
Notes
List the field names to check in $wpide_bp_required_fields. The result is cached per member for an hour.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.