Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Register Helper Example
<?php
/*
* Example Register Helper fields for Company, Referral Code, and Budget.
*
*/
// 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(
'company', // input name, will also be used as meta key
'text', // type of field
array(
'label' => 'Company', // custom field label
'size' => 40, // input size
'class' => 'company', // custom class
'profile' => true, // show in user profile
'required' => true, // make this field required
'levels' => array(1,2) // only levels 1 and 2 should have the company field
)
);
$fields[] = new PMProRH_Field(
'referral', // input name, will also be used as meta key
'text', // type of field
array(
'label' => 'Referral Code', // custom field label
'profile' => 'only_admin' // only show in profile for admins
)
);
$fields[] = new PMProRH_Field(
'budget', // input name, will also be used as meta key
'select', // type of field
array(
'options' => array( // <option> elements for select field
'' => '', // blank option - cannot be selected if this field is required
'lessthan2000' => '&lt; $2,000', // <option value="lessthan2000">&lt; $2,000</option>
'2000to5000' => '$2,000-$5,000', // <option value="2000to5000">$2,000-$5,000</option>
'5000to10000' => '$5,000-$10,000', // <option value="5000to10000">$5,000-$10,000</option>
'morethan10000' => '&gt; $10,000', // <option value="morethan10000">&gt; $10,000</option>
)
)
);
// 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' );
@ideadude
Copy link
Author

PMPro 2.9 includes user fields and changes some of the functions that would be used to create fields via code. The old Register Helper ones will still work for a while, but will eventually be deprecated.

You can see the new snippet here: https://github.com/strangerstudios/pmpro-snippets-library/blob/dev/user-fields/add-user-fields.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment