Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save pbrocks/4a61cfd78bca2db8d53021ef7705f94d to your computer and use it in GitHub Desktop.
Save pbrocks/4a61cfd78bca2db8d53021ef7705f94d to your computer and use it in GitHub Desktop.
Example of defining PMPro Register Helper Fields Synchronized to BuddyPress XProfile Fields
<?php
/**
* Based on the Register Helper example.
* We've added a "buddypress" option for each field
* set to the XProfile name we used when setting up
* the fields in the BuddyPress extended profile.
* If the PMPro BuddyPress Add On is activated
* then the fields will be synchronized.
* Register Helper: https://www.paidmembershipspro.com/add-ons/pmpro-register-helper-add-checkout-and-profile-fields/
* PMPro BuddyPress: https://www.paidmembershipspro.com/add-ons/buddypress-integration/
*/
function my_pmprorh_init() {
// don't break if Register Helper is not loaded
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) {
return false;
}
// define the fields
$fields = array();
$fields[] = new PMProRH_Field(
'company', // input name, will also be used as meta key
'text', // type of field
array(
'buddypress' => 'Company', // XProfile Field Name <-- !!!
'label' => 'Company', // custom field label
'size' => 40, // input size
'class' => 'company', // custom class
'profile' => true, // show in user profile
'required' => true, // make this field required
'levels' => array( 1, 2 ), // only levels 1 and 2 should have the company field
)
);
$fields[] = new PMProRH_Field(
'referral', // input name, will also be used as meta key
'text', // type of field
array(
'buddypress' => 'Referral' // XProfile Field Name <-- !!!
'label' => 'Referral Code', // custom field label
'profile' => 'only_admin', // only show in profile for admins
)
);
// add the fields into a new checkout_boxes are of the checkout page
foreach ( $fields as $field ) {
pmprorh_add_registration_field(
'checkout_boxes', // location on checkout page
$field // PMProRH_Field object
);
}
// that's it. see the PMPro Register Helper readme for more information and examples.
}
add_action( 'init', 'my_pmprorh_init' );
@grifini
Copy link

grifini commented May 3, 2019

Hi there,
I used a similar code. However, if you set the porfile as true it generates extended profile field besides generating a field in profile. So, it duplicates itself. Besides, using profile=> 'only_admin' or 'only' somehow brakes the code. I tried 'profile=>false which solved the duplicated field in profile and changed profile field option from everyone to me within the buddypress profile field itself. Yet it does not work. Profile fields are visible to all. Any oslution?

@kimwhite
Copy link

comma needed in line 37 after 'referral'
'buddypress' => 'Referral' // XProfile Field Name <-- !!!

@andrewlimaza
Copy link

For support, please reach out to www.paidmembershipspro.com/support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment