Plugin Overrides BP-XProfile Exclude Fields
-
Hi Christian,
I hope this finds you well, I wanted to point out a minor conflict I ran into using your plugin and when trying to exclude fields for the Buddypress XProfile using the bp_after_has_profile_parse_args filter.
In my functions.php I had added a filter on bp_after_has_profile_parse_args which excluded specific fields, this seemed to stop working and I finally isolated it to your plugin.
In your plugin file bp-xprofile-wp-user-sync.php there’s a filter hooked onto bp_after_has_profile_parse_args called intercept_profile_query_args which has a priority of 30, which ran after my filter hook.
The intercept_profile_query_args function:
/** * Intercept xProfile query process and manage display of fields * * @param array $args The existing arguments used to query for fields * @return array $args The modified arguments used to query for fields */ public function intercept_profile_query_args( $args ) { // if on profile view screen if ( bp_is_user_profile() AND ! bp_is_user_profile_edit() ) { // get fields to exclude on profile view screen $args['exclude_fields'] = $this->_get_excluded_fields(); } // if on profile edit screen if ( bp_is_user_profile_edit() ) { // exclude name field (bp_xprofile_fullname_field_id is available since BP 2.0) $args['exclude_fields'] = bp_xprofile_fullname_field_id(); } /** * Apply to registration form whichever page it is displayed on, whilst avoiding * splitting the Name field into First Name and Last Name fields in the profile * display loop of the user. Note that we cannot determine if we are in the loop * prior to the query, so we test for an empty user ID instead. */ if ( ! is_user_logged_in() // user must be logged out AND ( ! bp_is_user_profile() OR ( bp_is_user_profile() AND empty( $args['user_id'] ) ) ) ) { // query only group 1 $args['profile_group_id'] = 1; // exclude name field (bp_xprofile_fullname_field_id is available since BP 2.0) $args['exclude_fields'] = bp_xprofile_fullname_field_id(); } // --< return $args; }
As you can see it’s setting the $args[‘exclude_fields’] overwriting any current information for this attribute, which removes any previously set exclude_fields.
I was able to work around this by updating my filter hook to have a priority of 50 and within my function rather than set the exclude_fields from scratch did an empty() check and if not empty appended my additional fields.
I wanted to bring this to your attention as all instructions out there for setting exclude_fields has people set their hook without priority so I presume anyone else with a similar hook that installs your plugin will find their hook becomes useless.
A thought to avoid this with your plugin would be to do a empty check on the $args[‘exclude_fields’] and if it’s not empty append to it with a preceding comma so as to add your fields to the list without overwriting any previously established.Always appreciate your assistance,
Cheers
- The topic ‘Plugin Overrides BP-XProfile Exclude Fields’ is closed to new replies.