Skip to content

Instantly share code, notes, and snippets.

@femiyb
Created February 12, 2020 13:21
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 femiyb/197045d7f3979c3dc9e2c049eae13a9c to your computer and use it in GitHub Desktop.
Save femiyb/197045d7f3979c3dc9e2c049eae13a9c to your computer and use it in GitHub Desktop.
<?php
/**
* add Register Helper
*/
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(
"check_age", // input name, will also be used as meta key
"text", // type of field
array(
"label" => "Age",
"size" => 3, // size attribute of text field
'profile' => true, // show in user profile
'required' => true, // make this field required
'memberslistcsv' => true,
)
);
//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' );
function pmpro_check_age( $pmpro_continue_registration ) {
//only bother if things are okay so far
if(!$pmpro_continue_registration)
return $pmpro_continue_registration;
$check_age = $_REQUEST['check_age'];
if ( !is_user_logged_in() ) {
$onlyNumeric = filter_var($check_age, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
if ( $onlyNumeric < 18 ) {
pmpro_setMessage( esc_html__( 'Must be 18+.' ), 'pmpro_error' );
return false;
}
}
return $pmpro_continue_registration;
}
add_filter( 'pmpro_registration_checks', 'pmpro_check_age' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment