Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbrocks/b65e6283a39ea0ce6ebbc22bfeb0c1a8 to your computer and use it in GitHub Desktop.
Save pbrocks/b65e6283a39ea0ce6ebbc22bfeb0c1a8 to your computer and use it in GitHub Desktop.
Paid Memberships Pro Register Helper field type examples 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.
*
* Add this to a Customizations Plugin and customize to suit your needs
*/
function initialize_pmprorh_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
$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(
'options' => array(
'' => '', // blank option to be displayed first, followed by options
'option_1' => 'Option 1',
'option_2' => 'Option 2',
'option_3' => 'Option 3',
),
)
);
// MULTISELECT
$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', 'initialize_pmprorh_fields' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment