Skip to:
Content

BuddyPress.org

Opened 4 years ago

Last modified 4 years ago

#6757 new defect (bug)

Empty Groups appear in Extended Profile on WP Admin causing error during save

Reported by: garrett-eclipse Owned by:
Milestone: Awaiting Contributions Priority: normal
Severity: normal Version: 2.4.0
Component: Extended Profile Keywords: needs-patch
Cc:

Description

Hello,

While working with Buddypress Admin Only Profile fields I ran into an issue with the Extended Profile within the WP Admin. If you have an XProfile Group containing all Admin fields it appears empty on the Extended Profile and causes an issue during save.

On save we get an error;
"There was a problem updating some of your profile information. Please try again."

This isn't an issue on the front end edit screen as the group is hidden from tabs when it doesn't have any fields.

Would appreciate if a check for if the group has fields (available to the user) be introduced into the bp_profile_groups loop within register_metaboxes on line 788 of bp-xprofile-admin.php, in this code;

<?php
// Loop through field groups and add a metabox for each one.
while ( bp_profile_groups() ) : bp_the_profile_group();
        add_meta_box(
                'bp_xprofile_user_admin_fields_' . sanitize_key( bp_get_the_profile_group_slug() ),
                esc_html( bp_get_the_profile_group_name() ),
                array( $this, 'user_admin_profile_metaboxes' ),
                $screen_id,
                'normal',
                'core',
                array( 'profile_group_id' => absint( bp_get_the_profile_group_id() ) )
        );                                      
endwhile;

I presume this issue would affect other plugins and custom code which excludes access to certain fields potentially leaving fields groups with no accessible fields.

Plugin Reference: https://wordpress.org/plugins/buddypress-admin-only-profile-fields/
Plugin Github: https://github.com/A5hleyRich/buddypress-admin-only-profile-fields/
Github Issue: https://github.com/A5hleyRich/buddypress-admin-only-profile-fields/issues/13

Thank you

Change History (4)

#1 @garrett-eclipse
4 years ago

Note: I attempted to correct my Buddypress instance by wrapping the add_meta_box in a check using bp_profile_group_has_fields:

<?php
if ( bp_profile_group_has_fields() ) {

However this returned false always so hide all field groups in the WP Admin, seems to only function while on the front-end.

#2 @garrett-eclipse
4 years ago

WORKAROUND UPDATE

The metabox can be removed through the same bp_members_admin_xprofile_metabox action hook as follows;

<?php
add_action( 'bp_members_admin_xprofile_metabox', array( $this, 'remove_empty_groups_metaboxes' ), 20, 3 );
public function remove_empty_groups_metaboxes($user_id, $screen_id, $stats_metabox) {
        // Get all users xprofile groups
        $groups = bp_xprofile_get_groups( array(
                'fetch_fields' => true,
                'user_id'      => $user_id
        ) );

        foreach( $groups as $group ) {
                if ( empty( $group->fields ) ) {
                        // Remove empty groups metabox
                        remove_meta_box('bp_xprofile_user_admin_fields_' . sanitize_key( sanitize_title( $group->name ) ), $screen_id, 'normal');
                }
        }
}

#3 @DJPaul
4 years ago

  • Milestone changed from Awaiting Review to Under Consideration

This needs investigating

#4 @DJPaul
4 years ago

  • Keywords needs-patch added
  • Milestone changed from Under Consideration to Future Release

Haven't tested but I can see how this could be an issue. Probably bp_profile_group_has_fields is the right fix, need to step through and figure out why it didn't work.

Note: See TracTickets for help on using tickets.