pmpro-buddypress field sync support in GUI#3118
pmpro-buddypress field sync support in GUI#3118DarkLotus wants to merge 2 commits intostrangerstudios:v3.2from
Conversation
… fields added via GUI and not register helper
There was a problem hiding this comment.
Pull request overview
This PR adds GUI support for syncing Paid Memberships Pro user fields to BuddyPress XProfile fields. Previously, this functionality was only available through register helper code-defined fields. The new feature is conditionally displayed in the user field settings when the pmpro-buddypress plugin is enabled.
Key Changes
- Added
buddypressproperty to user field objects to store the BuddyPress XProfile field name - Introduced a new GUI input field that allows admins to configure BP sync directly from the admin interface
- Updated JavaScript to capture and save the buddypress field value when user fields are saved
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| js/pmpro-admin.js | Added extraction of the buddypress field value from the form input and includes it in the field object when saving user field settings |
| includes/fields.php | Added handling for the buddypress property throughout the field lifecycle: retrieval from field objects, display in the GUI (conditionally when PMPROBP_DIR is defined), and loading from settings into field instances |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| <input type="text" placeholder="The Name of the Xprofile Field, or blank to not sync" name="pmpro_userfields_field_buddypress" value="<?php echo esc_attr( $field_buddypress );?>" /> | ||
| </label> | ||
| </div> <!-- end pmpro_userfield-field-setting --> | ||
| <?php endif; ?> |
There was a problem hiding this comment.
The closing PHP tag should be on the same indentation level as the opening <?php tag. This line should have 3 fewer spaces of indentation to align properly with line 1486.
| <?php endif; ?> | |
| <?php endif; ?> |
| $field_element_class = $field->element_class; | ||
| $field_hint = $field->hint; | ||
| $field_options = $field->options; | ||
| $field_buddypress = $field->buddypress; |
There was a problem hiding this comment.
Accessing $field->buddypress directly without checking if the property exists could cause a PHP notice for fields saved before this feature was added. For backward compatibility, consider using the null coalescing operator or isset check, such as $field_buddypress = $field->buddypress ?? ''; to safely handle fields that don't have this property.
| $field_buddypress = $field->buddypress; | |
| $field_buddypress = $field->buddypress ?? ''; |
| 'options' => $options, | ||
| 'levels' => $levels, | ||
| 'memberslistcsv' => true, | ||
| 'buddypress' => $settings_field->buddypress, |
There was a problem hiding this comment.
Accessing $settings_field->buddypress directly without checking if the property exists could cause a PHP notice for fields saved before this feature was added. For backward compatibility, consider using the null coalescing operator or isset check, such as $settings_field->buddypress ?? '' to safely handle fields that don't have this property.
| 'buddypress' => $settings_field->buddypress, | |
| 'buddypress' => $settings_field->buddypress ?? '', |
| </div> <!-- end pmpro_userfield-field-setting --> | ||
| </div> <!-- end pmpro_userfield-field-setting-dual --> | ||
|
|
||
| <?php if(defined('PMPROBP_DIR')) : ?> |
There was a problem hiding this comment.
The conditional check should have a space after if and before the opening parenthesis to follow WordPress coding standards. It should be if ( defined( 'PMPROBP_DIR' ) ) instead of if(defined('PMPROBP_DIR')).
| <?php if(defined('PMPROBP_DIR')) : ?> | |
| <?php if ( defined( 'PMPROBP_DIR' ) ) : ?> |
All Submissions:
Changes proposed in this Pull Request:
Brings across the abilty to enable Syncing PMPRO Fields to BP XProfile fields via the GUI instead of just via register helper code defined fields.
Adds a new input thats only visible in the user field settings if pmpro-buddypress is enabled, that lets you set the $field->buddypress value via GUI.
Other information:
Changelog entry