Created
January 21, 2020 19:59
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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