Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Register Helper field type example shows an example of every possible field in Register Helper
<?php
/**
* This example is to show you the 'niche' options each Paid Memberships Pro - Register Helper Add-on field can take and how to use it.
* For more information on the Register Helper Add-on please visit https://www.paidmembershipspro.com/add-ons/free-add-ons/pmpro-register-helper-add-checkout-and-profile-fields/
**/
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();
// TEXT FIELD
$fields[] = new PMProRH_Field(
"text_example", // input name, will also be used as meta key
"text", // type of field
array(
"size" => 20 // size attribute of text field
)
);
// TEXTAREA
$fields[] = new PMProRH_Field(
"textarea_example", // input name, will also be used as meta key
"textarea", // type of field
array(
"rows" => 10, // row attribute of textarea (height)
"cols" => 50, // cols attribute of textarea (width)
)
);
// SELECT
$fields[] = new PMProRH_Field(
"select_example", // input name, will also be used as meta key
"select", // type of field
array(
"multiple" => true, //allow multiple selections for select
"options" => array(
"" => "", // blank option to be displayed first, followed by options
"option_1" => "Option 1",
"option_2" => "Option 2",
"option_3" => "Option 3",
)
)
);
// SELECT2
$fields[] = new PMProRH_Field(
"select_2_example", // input name, will also be used as meta key
"select2", // type of field
array(
"options" => array(
"" => "", // blank option to be displayed first, followed by options
"option_1" => "Option 1",
"option_2" => "Option 2",
"option_3" => "Option 3",
)
)
);
// CHECKBOX
$fields[] = new PMProRH_Field(
"checkbox_example", // input name, will also be used as meta key
"checkbox", // type of field
array(
"text" => "Check this" // string for <label></label>
)
);
// RADIO
$fields[] = new PMProRH_Field(
"radio_example", // input name, will also be used as meta key
"radio", // type of field
array(
"options" => array( // display the different options, no need for a "blank" option
"option_1" => "Option 1",
"option_2" => "Option 2",
"option_3" => "Option 3",
)
)
);
// FILE
$fields[] = new PMProRH_Field(
"file_example", // input name, will also be used as meta key
"file", // type of field
array(
"accept" => "image/*" // accept all image types for file upload (http://www.w3schools.com/TAGs/att_input_accept.asp)
)
);
// HTML
$fields[] = new PMProRH_Field(
"html_example", // input name, will also be used as meta key
"html", // type of field
array(
"html" => "<p><u>Add a paragraph into your checkout.php for Paid Memberships Pro. You may also use normal HTML code to generate fields.</u></p>" // accepts HTML code
)
);
// HTML
$fields[] = new PMProRH_Field(
"hidden_example", // input name, will also be used as meta key
"hidden" // type of field - creates a field that is hidden. (Great for creating a honeypot for your checkout form)
);
/**
* Conditional field example. Display a textfield depending on checkbox value
**/
$fields[] = new PMProRH_Field(
"conditional_example_depends_on", // input name, will also be used as meta key
"checkbox", // type of field
array(
"text" => "Check this to display a text field" // string for <label></label>
)
);
$fields[] = new PMProRH_Field(
"conditional_example_show", // input name, will also be used as meta key
"text", // type of field
array(
"depends" => array(
array(
"id" => "conditional_example_depends_on", //depends on this field
"value" => true //if checkbox is checked show this field
)
)
)
);
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