Last active
November 21, 2019 12:21
-
-
Save MaryOJob/1af289cde34c6b3d5738030a0176a500 to your computer and use it in GitHub Desktop.
Adding Five Custom Fields to PMPro Accounts Page
This file contains hidden or 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 | |
/** | |
* Register Helper example for five fields. This is a test Register Helper example. | |
* Please add the below code to your custom plugin or Code Snippets Plugin by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
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( | |
"user_photo", // input name, will also be used as meta key | |
"file", // type of field | |
array( | |
"label" => "Member Photo", | |
"required" => true, // make this field required | |
"profile" => true, // show in user profile | |
)); | |
$fields[] = new PMProRH_Field( | |
"gender", // input name, will also be used as meta key | |
"select", // type of field | |
array( | |
"required" => true, // make this field required | |
"options" => array( // <option> elements for select field | |
"" => "Please Select", // blank option - cannot be selected if this field is required | |
"male" =>"Male", | |
"female" => "Female", | |
) | |
)); | |
// add a text field to display if female is selected | |
$fields[] = new PMProRH_Field( | |
"Female", | |
"text", | |
array( | |
"id" => "gender", | |
"value" => "female" | |
) | |
), | |
"label" => "female name Is", | |
)); | |
//add a checkbox with multiple options | |
$fields[] = new PMProRH_Field( | |
"select_fruits", // input name, will also be used as meta key | |
"select", // type of field | |
array( | |
"multiple" => true, //allow multiple selections for select | |
"options" => array( | |
"option_1" => "Apples", | |
"option_2" => "Bananas", | |
"option_3" => "Carrots", | |
"option_4" => "Potatoes", | |
) | |
) | |
); | |
//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","my_pmprorh_depends_fields_init"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Learnt from here, here and here. @andrewlimaza