Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ipokkel
Created January 21, 2020 19:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ipokkel/f637d12022ed7c8bc9a73689d2b8c029 to your computer and use it in GitHub Desktop.
Save ipokkel/f637d12022ed7c8bc9a73689d2b8c029 to your computer and use it in GitHub Desktop.
Example Register Helper field that displays as read only to the user on the WordPress profile page.
<?php
/**
* PMPro Customization: Register Helper - Add date of birth date picker to checkout
* Display field as read-only for user but as editable field for administrators
*/
//we have to put everything in a function called on init, so we are sure Register Helper is loaded
function my_pmprorh_init() {
//don't break if Register Helper is not loaded
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) {
return false;
}
$fields = array();
$fields[] = new PMProRH_Field(
'date_of_birth', // input name, will also be used as meta key
'date', // type of field
array(
'label' => 'Date Of Birth', // custom field label
'class' => 'date', // date class
'profile' => 'admin', // show in registration form but only show to administrators in user profile,
'required' => true, // make this field required
'addmember' => true, // show in Add Member
'memberslistcsv' => true, // Include in Member List CSV Export
)
);
// display as readonly in the backend if user not an administrator
if ( is_admin() && ! current_user_can( 'manage_options' ) ) {
$fields[] = new PMProRH_Field(
'date_of_birth', // input name, will also be used as meta key
'readonly', // type of field
array(
'label' => 'Date Of Birth', // custom field label
'class' => 'date', // date class
'profile' => 'only', // show in user profile only
)
);
}
//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