Last active
February 19, 2019 23:25
-
-
Save andrewlimaza/3785e168e6916ba55aaab4a979bfbe0b to your computer and use it in GitHub Desktop.
Users need to be 18 or older to register for Paid Memberships Pro Checkout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This will only allow users that are 18 years or older to signup on checkout. | |
* This requires a custom 'date' field using Register Helper. | |
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function custom_pmpro_validate_user_age( $okay ) { | |
if( ! $okay ) { | |
return $okay; //handle other errors first. | |
} | |
if( '1' != $_REQUEST[ 'level' ] ) { //Change 1 to level ID that the CODE MUST APPLY TO, all other levels except 1 will not take the code into consideration. | |
return $okay; | |
} | |
global $pmpro_msg, $pmpro_msgt; | |
$date = $_POST[ 'date_of_birth' ]; | |
$year = intval( $date[ 'y' ] ); | |
$today = intval( date( 'Y' ) ); | |
if( $today - $year < 18 ){ | |
$pmpro_msg = "You must be older than 18 years old."; | |
$pmpro_msgt = "pmpro_error"; | |
return false; | |
} | |
return $okay; | |
} | |
add_filter( 'pmpro_registration_checks', 'custom_pmpro_validate_user_age' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment