Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Our Register Helper Fields plugin from the August 19th, 2015 Webinar.
<?php
/*
Plugin Name: Register Helper Example
Plugin URI: http://www.paidmembershipspro.com/wp/pmpro-customizations/
Description: Register Helper Initialization Example
Version: .1
Author: Stranger Studios
Author URI: http://www.strangerstudios.com
*/
/*
Included below are a lot of fields making use of various Register Helper field types, properties, and features.
The fields themselves won't make a lot of sense, and we did edit this plugin many times during the webinar.
Still it might be useful as reference for some.
*/
//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 checkout boxes
pmprorh_add_checkout_box("personal_info", "Personal Information");
pmprorh_add_checkout_box("company_info", "Company Information");
//define the fields
$fields = array();
$fields[] = new PMProRH_Field(
"text_example", // input name, will also be used as meta key
"text", // type of field
array(
"profile"=>false, // show in user profile
"label"=>"Text Example",
"required"=>true, // make this field required
"showrequired"=>true,
"levels"=>array(1,2),
"memberslistcsv"=>true,
"class"=>"special-input",
"divclass"=>"input_div",
));
$fields[] = new PMProRH_Field(
"admin_notes", // input name, will also be used as meta key
"textarea", // type of field
array(
"label" => "bio",
"profile"=>"only_admin", // show in user profile
"required"=>true, // make this field required
"hint"=>"Please include information about your work history.",
));
//add the fields into a new checkout_boxes are of the checkout page
foreach($fields as $field)
pmprorh_add_registration_field(
"personal_info", // location on checkout page
$field // PMProRH_Field object
);
$fields = array();
$fields[] = new PMProRH_Field(
"awesome", // input name, will also be used as meta key
"checkbox", // type of field
array(
"label"=>"Are you Awesome?", // custom field label
"profile"=>"only_admin", // only show in profile for admins
"value"=>"yes this person is awesome",
));
/*
Depends Example
*/
$fields[] = new PMProRH_Field(
"interest", // input name, will also be used as meta key
"select", // type of field
array(
"label"=>"What are you most interested in?",
"memberslistcsv"=>true,
"required"=>true,
"profile"=>true, // show in user profile
"options"=>array( // <option> elements for select field
""=>"- Chose One -",
"php"=>"php",
"wordpress"=>"wordpress",
"art"=>"art",
"fun"=>"fun",
"other"=>"other",
)));
$fields[] = new PMProRH_Field(
"interest_other", // input name, will also be used as meta key
"text", // type of field
array(
"profile"=>true, // show in user profile
"label"=>"Other Interest",
"showrequired"=>"*",
"memberslistcsv"=>true,
"depends"=>array(
array('id'=>'interest', 'value'=>'other')
)
));
$fields[] = new PMProRH_Field(
"chooseone", // input name, will also be used as meta key
"radio", // type of field
array(
"options"=>array( // <option> elements for select field
"option 1", "option 2", "option 3",
)));
$fields[] = new PMProRH_Field(
"hrhtml", // input name, will also be used as meta key
"html", // type of field
array(
"html"=>"<hr />",
"label"=>false,
));
$fields[] = new PMProRH_Field(
"resume", // input name, will also be used as meta key
"file", // type of field
array(
"profile"=>true, // show in user profile
"required"=>true // make this field required
));
$fields[] = new PMProRH_Field(
"affiliate_id", // input name, will also be used as meta key
"text", // type of field
array(
"profile"=>true,
"readonly"=>true,
"save_function"=>"my_affiliate_id_save_function",
));
//add the fields into a new checkout_boxes are of the checkout page
foreach($fields as $field)
pmprorh_add_registration_field(
"company_info", // location on checkout page
$field // PMProRH_Field object
);
/*
pmpro_checkout_boxes
pmpro_after_email
pmpro_after_password
pmpro_after_username
pmprorh_add_checkout_box()
*/
//that's it. see the PMPro Register Helper readme for more information and examples.
}
add_action("init", "my_pmprorh_init");
function my_affiliate_id_save_function($user_id, $field_name, $value)
{
$value = pmpro_getDiscountCode();
update_user_meta($user_id, $field_name, $value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment