Skip to content

Instantly share code, notes, and snippets.

@MaryOJob
Last active July 23, 2021 17:51
Show Gist options
  • Save MaryOJob/cae7b4f284234a714be1a6aaceb05c70 to your computer and use it in GitHub Desktop.
Save MaryOJob/cae7b4f284234a714be1a6aaceb05c70 to your computer and use it in GitHub Desktop.
Sync BuddyPress Dropdown Select Box Profile Fields with PMPro using Register Helper
<?php // Do Not Copy This Line
/*
* Based on Register Helper PMPro Extension, 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/
* The options on the left for this select RH fields must match the labels used in BP extended profile
*/
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(
'have_a_girl', // input name, will also be used as meta key
'select', // type of field
array(
'buddypress' => 'Have A Girl?', // XProfile Field Name <-- !!!
'label' => 'Have A Girl?',
'profile' => true, // display on user profile and at checkout
'required' => true, // optional field
'options' => array(
'Yes'=> 'Yes',
'No'=> 'No',
'Maybe'=> 'Maybe',
'Never'=> 'Never',
)
)
);
$fields[] = new PMProRH_Field(
'your_girls_name', // input name, will also be used as meta key
'select', // type of field
array(
'buddypress' => 'Your Girls Name', // XProfile Field Name <-- !!!
'label' => 'Your Girls Name', // custom field label
'profile' => true, // show in user profile
'required' => true, // make this field required
'options' => array(
'Maggi'=> 'Maggi',
'Mary'=> 'Mary',
'Moe'=> 'Moe',
)
)
);
$fields[] = new PMProRH_Field(
'boy_or_girl', // input name, will also be used as meta key
'select', // type of field
array(
'buddypress' => 'Boy Or Girl', // XProfile Field Name <-- !!!
'label' => 'Boy Or Girl', // custom field label
'profile' => true, // show in user profile
'required' => true, // make this field required
'options' => array(
'Boy'=> 'Boy',
'Girl'=> 'Girl',
'GirlBoy'=>'GirlBoy',
)
)
);
// 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' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment