Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andrewlimaza/398ff7c19f5834c661f1dd85a18415e4 to your computer and use it in GitHub Desktop.
Save andrewlimaza/398ff7c19f5834c661f1dd85a18415e4 to your computer and use it in GitHub Desktop.
Modified PMPro Register Helper Example with fields for school, county, job title, race, ethnicity, languages spoken, and gender.
<?php
/*
Plugin Name: Register Helper Example
Plugin URI: http://www.paidmembershipspro.com/wp/pmpro-customizations/
Description: Register Helper Initialization Example
Version: .2
Author: Stranger Studios
Author URI: http://www.strangerstudios.com
*/
//we have to put everything in a function called on init, so we are sure Register Helper is loaded
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();
$fields[] = new PMProRH_Field(
'jobtitle',
'select',
array(
'label' => 'Job Title',
'profile' => true,
'required' => true,
'memberslistcsv' => true,
'options' => array(
'elementarylibrarian' => 'Elementary School Librarian',
'middlelibrarian' => 'Middle School Librarian',
'highlibrarian' => 'High School Librarian',
'districtlibrarian' => 'District Librarian',
'librarysupervisor' => 'Library Supervisor',
'publiclibrarian' => 'Public Librarian',
'professor' => 'Professor',
'student' => 'Student',
'teacher' => 'Teacher',
'retired' => 'Retired',
'msde' => 'MSDE',
'vendor' => 'Vendor',
'author_illustrator' => 'Author/Illustrator',
'other' => 'Other',
)
)
);
$fields[] = new PMProRH_Field(
'school', // input name, will also be used as meta key
'text', // type of field
array(
'label' => 'school', // custom field label
'size' => 40, // input size
'class' => 'school', // custom class
'profile' => true, // show in user profile
'memberslistcsv' => true,
'required' => true, // make this field required
)
);
$fields[] = new PMProRH_Field(
'county_lea', // input name, will also be used as meta key
'select', // type of field
array(
'label' => 'County/LEA', // custom field label
'profile' => true, // show in user profile
'required' => true, // make this field required
'memberslistcsv' => true,
'options' => array( // <option> elements for select field
'allegany' => 'Allegany',
'anne_arundel' => 'Anne Arundel',
'baltimore' => 'Baltimore',
'baltimore_city' => 'Baltimore City',
'calvert' => 'Calvert',
'caroline' => 'Caroline',
'carroll' => 'Carroll',
'cecil' => 'Cecil',
'charles' => 'Charles',
'dorchester' => 'Dorchester',
'frederick' => 'Frederick',
'garrett' => 'Garrett',
'harford' => 'Harford',
'howard' => 'Howard',
'kent' => 'Kent',
'montgomery' => 'Montgomery',
'prince_georges' => "Prince George's",
'queen_annes' => "Queen Anne's",
'st_marys' => "St. Mary's",
'somerset' => 'Somerset',
'talbot' => 'Talbot',
'washington' => 'Washington',
'wicomico' => 'Wicomico',
'worcester' => 'Worcester',
'aims' => 'AIMS',
'othernonpublic' => 'Other Non-Public',
'notinadistrict' => 'Not in a district',
'outofstate' => 'Out of state',
)
)
);
$fields[] = new PMProRH_Field(
'language', // input name, will also be used as meta key
'text', // type of field
array(
'label' => 'Languages spoken other than English', // custom field label
'size' => 40, // input size
'profile' => true, // show in user profile
'memberslistcsv' => true,
)
);
$fields[] = new PMProRH_Field(
'race', // input name, will also be used as meta key
'select2', // type of field
array(
'label' => 'Race', // custom field label
'required' => true, // make this field required
'memberslistcsv' => true,
'hint' => 'Select all options that apply',
'options' => array( // <option> elements for select field
'americanindianoralaskanative' => 'American Indian or Alaska Native',
'asian' => 'Asian',
'blackorafricanamerican' => 'Black or African American',
'nativehawaiianorotherpacificislander' => 'Native Hawaiian or Other Pacific Islander',
'white' => 'White',
)
)
);
$fields[] = new PMProRH_Field(
'ethnicity', // input name, will also be used as meta key
'select', // type of field
array(
'label' => 'Ethnicity', // custom field label
'required' => true, // make this field required
'options' => array( // <option> elements for select field
'hispanicorlatino' => 'Hispanic or Latino',
'nothispanicorlatino' => 'Not Hispanic or Latino',
)
)
);
$fields[] = new PMProRH_Field(
'gender', // input name, will also be used as meta key
'select', // type of field
array(
'label' => 'Gender', // custom field label
'required' => true, // make this field required
'options' => array( // <option> elements for select field
'female' => 'Hispanic or Latino',
'male' => 'Not Hispanic or Latino',
'nonbinary' => 'Non-Binary/Third Gender',
'selfdescribe' => 'Prefer to self describe',
'omit' => 'Prefer not to say',
)
)
);
//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' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment