Created
August 4, 2019 18:59
-
-
Save ipokkel/bcd1315d3f85dd06130a3919fc7d1342 to your computer and use it in GitHub Desktop.
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 | |
/* Sample Register Helper fields | |
Register Helper Add On (https://www.paidmembershipspro.com/add-ons/pmpro-register-helper-add-checkout-and-profile-fields/) | |
Add this to your customization plugin for PMPro Customizations: https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
or | |
Add this to your theme's functions file. | |
*/ | |
function my_pmprorh_init_example_fields() { | |
// don't break if Register Helper is not loaded | |
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) { | |
return false; | |
} | |
// define the fields | |
$fields = array(); | |
// TEXT FIELD - Basic Example | |
$fields[] = new PMProRH_Field( | |
'basic_example', // input field name, used as meta key | |
'text', // field type | |
array( | |
'label' => 'Basic Example', // field label | |
'profile' => true, // display on user profile | |
'required' => false, // optional field | |
) | |
); | |
// TEXT FIELD | |
$fields[] = new PMProRH_Field( | |
'text_example', // input field name, used as meta key | |
'text', // field type | |
array( | |
'label' => 'Text', // display custom label, if not used field name will be used | |
'html_attributes' => array( 'placeholder' => 'e.g., Example' ), // add valid html input field attributs | |
'hint' => 'This is a hint', // display a hint under field | |
'levels' => array( 1, 3, 5 ), // levels to display field for | |
'class' => 'css_class_name', // custum class for input field | |
'divclass' => 'css_class_name_for_div', // custom class for container div | |
'size' => 40, // field width | |
'profile' => true, // show on profile | |
'memberslistcsv' => true, // include when using export members to csv | |
'addmember' => true, // include when using add member from admin | |
'required' => true, // make field required | |
) | |
); | |
// TEXTAREA | |
$fields[] = new PMProRH_Field( | |
'textarea_example', // input field name, used as meta key | |
'textarea', // field type | |
array( | |
'id' => 'custom_field_id', // set custom id attribute for field | |
'label' => 'Textarea Example', | |
'rows' => 10, // amount of rows (height) | |
'cols' => 50, // amount of columns (width) | |
'profile' => true, | |
'memberslistcsv' => true, | |
'addmember' => true, | |
'required' => false, | |
) | |
); | |
// SELECT | |
$fields[] = new PMProRH_Field( | |
'select_example', // input field name, used as meta key | |
'select', // field type | |
array( | |
'label' => 'Select', | |
'options' => array( | |
'' => '', // blank option displayed first | |
'option_1' => 'Option 1', | |
'option_2' => 'Option 2', | |
'option_3' => 'Option 3', | |
), | |
'profile' => true, | |
'memberslistcsv' => true, | |
'addmember' => true, | |
'required' => false, | |
) | |
); | |
// MULTISELECT | |
$fields[] = new PMProRH_Field( | |
'multiselect_example', // input field name, used as meta key | |
'select', // field type | |
array( | |
'label' => 'Multi-select', | |
'multiple' => true, // allow multiple selections for select | |
'options' => array( | |
'' => '- select -', // blank option displaying "-select-" | |
'option_1' => 'Option 1', | |
'option_2' => 'Option 2', | |
'option_3' => 'Option 3', | |
), | |
'profile' => true, | |
'memberslistcsv' => true, | |
'addmember' => true, | |
'required' => false, | |
) | |
); | |
// SELECT2 | |
$fields[] = new PMProRH_Field( | |
'select_2_example', // input field name, used as meta key | |
'select2', // field type | |
array( | |
'label' => 'Select 2', | |
'options' => array( | |
'option_1' => 'Option 1', | |
'option_2' => 'Option 2', | |
'option_3' => 'Option 3', | |
), | |
'profile' => true, | |
'memberslistcsv' => true, | |
'addmember' => true, | |
'required' => false, | |
) | |
); | |
// CHECKBOX | |
$fields[] = new PMProRH_Field( | |
'checkbox_example', // input field name, used as meta key | |
'checkbox', // field type | |
array( | |
'label' => 'Checkbox', | |
'text' => 'Check this', // string for <label></label> | |
'profile' => true, | |
'memberslistcsv' => true, | |
'addmember' => true, | |
'required' => false, | |
) | |
); | |
// GROUPED CHECKBOX | |
$fields[] = new PMProRH_Field( | |
'checkbox_grouped_example', // input field name, used as meta key | |
'checkbox_grouped', // field type | |
array( | |
'label' => 'Checkbox Grouped', | |
'required' => false, // Should always include this attribute | |
'addmember' => false, // Should always include this attribute | |
'memberslistcsv' => false, // Should always include this attribute | |
'profile' => true, // Should always include this attribute | |
'options' => array( // <option> elements for select field | |
'option_1' => 'Option 1', // <option value=”option_1”>Option 1</option> | |
'option_2' => 'Option 2', // <option value=”option_2”>Option 2</option> | |
'option_3' => 'Option 3', // <option value=”option_3”>Option 3</option> | |
'option_4' => 'Option 4', // <option value=”option_4”>Option 4</option> | |
), | |
) | |
); | |
// RADIO | |
$fields[] = new PMProRH_Field( | |
'radio_example', // input field name, used as meta key | |
'radio', // field type | |
array( | |
'label' => 'Radio', | |
'options' => array( // display the different options, no need for a "blank" option | |
'option_1' => 'Option 1', | |
'option_2' => 'Option 2', | |
'option_3' => 'Option 3', | |
), | |
'profile' => true, | |
'memberslistcsv' => true, | |
'addmember' => true, | |
'required' => false, | |
) | |
); | |
// FILE | |
$fields[] = new PMProRH_Field( | |
'file_upload_example', // input field name, used as meta key | |
'file', // field type | |
array( | |
'label' => 'File Upload', | |
'accept' => 'image/*', // accept all image types for file upload (http://www.w3schools.com/TAGs/att_input_accept.asp) | |
'profile' => true, | |
) | |
); | |
// HTML | |
$fields[] = new PMProRH_Field( | |
'html_example', // input field name, used as meta key | |
'html', // field type | |
array( | |
'label' => 'HTML', | |
'html' => '<p>Add a paragraph into your <u>profile or checkout.php</u> for <b><em>Paid Memberships Pro</em></b>. You may also use normal HTML code to generate fields.</p>', // accepts HTML code | |
'profile' => true, | |
'showmainlabel' => false, | |
) | |
); | |
// HIDDEN | |
$fields[] = new PMProRH_Field( | |
'hidden_example', | |
'hidden', | |
array( | |
'label' => 'Hidden', | |
'profile' => true, | |
) | |
); | |
// Display a field depending on the value of another field | |
// CHECKBOX - Reference field | |
$fields[] = new PMProRH_Field( | |
'conditional_example_depends_on', // input field name, used as meta key | |
'checkbox', // field type | |
array( | |
'label' => 'Checkbox w. Conditional Depends', | |
'text' => 'Check this to display a text field', | |
'profile' => true, | |
) | |
); | |
// Display field depending on value of another field | |
// TEXT | |
$fields[] = new PMProRH_Field( | |
'conditional_example_show', // input field name, used as meta key | |
'text', // field type | |
array( | |
'label' => 'Text w. Show on Condition', | |
'depends' => array( | |
array( | |
'id' => 'conditional_example_depends_on', // depends on this field | |
'value' => true, // if checkbox is checked show this field | |
), | |
), | |
'profile' => true, | |
) | |
); | |
/* | |
By default, you can place a new field in one of 8 different locations: | |
after_username | |
after_password | |
after_email | |
after_captcha | |
checkout_boxes | |
after_billing_fields | |
before_submit_button | |
just_profile – The field will only be shown on the Edit User/Profile pages. To use this, “profile” must be set to either true or admin. | |
*/ | |
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_example_fields' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment