Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save itsjusteileen/6dd3e5d590258c9acba7cc6ac5f829e5 to your computer and use it in GitHub Desktop.
Save itsjusteileen/6dd3e5d590258c9acba7cc6ac5f829e5 to your computer and use it in GitHub Desktop.
These examples show the range of possibilities, including the 'niche' options, for fields used in Paid Memberships Pro's Register Helper Add-On.
<?php // Do not include this or the doc block if adding to a Customizations plugin
/**
* Add this to its own folder in your plugins directory or copy the code below this doc block to a Customizations Plugin and customize to suit your needs.
*
* Plugin Name: PMPro Register Helper Examples
* Description: Create a folder name in your plugins' folder with the same name as this filename, but without the .php extension. Save this file in that folder and then you can activate this plugin in your WordPress dashboard,
* Author: pbrocks
* Author URI: https://github.com/pbrocks
*/
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',
'text',
array(
'label' => ucwords( preg_replace( '/_+/', ' ', 'text_example' ) ),
'size' => 40,
'profile' => true,
'memberslistcsv' => true,
'addmember' => true,
'required' => false,
)
);
// TEXTAREA
$fields[] = new PMProRH_Field(
'textarea_example', // input name, will also be used as meta key
'textarea', // type of field
array(
'id' => 'textarea_example',
'label' => 'Textarea Example',
'rows' => 10, // row attribute of textarea (height)
'cols' => 50, // cols attribute of textarea (width)
'profile' => true,
'memberslistcsv' => true,
'addmember' => true,
'required' => false,
)
);
// SELECT
$fields[] = new PMProRH_Field(
'select_example', // input name, will also be used as meta key
'select', // type of field
array(
'label' => ucwords( preg_replace( '/_+/', ' ', 'select_example' ) ),
'options' => array(
'' => '', // blank option to be displayed first, followed by options
'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 name, will also be used as meta key
'select', // type of field
array(
'label' => ucwords( preg_replace( '/_+/', ' ', 'multiselect_example' ) ),
'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',
),
'profile' => true,
'memberslistcsv' => true,
'addmember' => true,
'required' => false,
)
);
// SELECT2
$fields[] = new PMProRH_Field(
'select_2_example', // input name, will also be used as meta key
'select2', // type of field
array(
'label' => ucwords( preg_replace( '/_+/', ' ', 'select_2_example' ) ),
'options' => array(
// '' => '', // blank option to be displayed first, followed by options
'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 name, will also be used as meta key
'checkbox', // type of field
array(
'label' => ucwords( preg_replace( '/_+/', ' ', 'checkbox_example' ) ),
'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 name, will also be used as meta key
'checkbox_grouped', // type of field
array(
'label' => ucwords( preg_replace( '/_+/', ' ', 'checkbox_grouped_example' ) ),
'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 name, will also be used as meta key
'radio', // type of field
array(
'label' => ucwords( preg_replace( '/_+/', ' ', 'radio_example' ) ),
'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 name, will also be used as meta key
'file', // type of field
array(
'label' => ucwords( preg_replace( '/_+/', ' ', 'file_upload_example' ) ),
'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 name, will also be used as meta key
'html', // type of field
array(
'label' => ucwords( preg_replace( '/_+/', ' ', 'html_example' ) ),
'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,
)
);
// HIDDEN
$fields[] = new PMProRH_Field(
'hidden_example',
'hidden',
array(
'label' => ucwords( preg_replace( '/_+/', ' ', 'hidden_example' ) ),
'profile' => true,
)
);
/**
* Conditional field example. Display a textfield depending on checkbox value
*/
$fields[] = new PMProRH_Field(
'conditional_example_depends_on',
'checkbox', // type of field
array(
'label' => ucwords( preg_replace( '/_+/', ' ', 'conditional_example_depends_on' ) ),
'text' => 'Check this to display a text field',
'profile' => true,
)
);
$fields[] = new PMProRH_Field(
'conditional_example_show', // input name, will also be used as meta key
'text', // type of field
array(
'label' => ucwords( preg_replace( '/_+/', ' ', 'conditional_example_show' ) ),
'depends' => array(
array(
'id' => 'conditional_example_depends_on', // depends on this field
'value' => true, // if checkbox is checked show this field
),
),
'profile' => true,
)
);
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