Created
February 12, 2018 14:14
-
-
Save Waller74/09d46f7852babc91fa0660c25e8f7feb to your computer and use it in GitHub Desktop.
This file contains 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 | |
/* | |
Plugin Name: PMPro Customizations | |
Plugin URI: https://www.paidmembershipspro.com/wp/pmpro-customizations/ | |
Description: Customizations for my Paid Memberships Pro Setup | |
Version: .1 | |
Author: Paid Memberships Pro | |
Author URI: https://www.paidmembershipspro.com | |
*/ | |
//Now start placing your customization code below this line | |
/* | |
/* | |
Define the global array below for your main accounts and sponsored levels. | |
Array keys should be the main account level. | |
*/ | |
global $pmprosm_sponsored_account_levels; | |
$pmprosm_sponsored_account_levels = array( | |
//set 5 seats at checkout | |
1 => array( | |
'main_level_id' => 2, //redundant but useful | |
'sponsored_level_id' => 2, //array or single id | |
'seats' => 5 | |
), | |
//seats based on field at checkout | |
3 => array( | |
'main_level_id' => 2, //redundant but useful | |
'sponsored_level_id' => 2, | |
'seat_cost' => 0, | |
'max_seats' => 5 | |
) | |
); | |
/** | |
* Add this code below to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function pmpro_change_text_example_group_members( $translated_text, $text, $domain ) { | |
switch ( $translated_text ) { | |
case 'Number of Seats' : | |
$translated_text = __( 'Number of Family Members', 'pmpro_sponsored_members' ); | |
break; | |
} | |
return $translated_text; | |
} | |
add_filter( 'gettext', 'pmpro_change_text_example_group_members', 20, 3 ); | |
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( | |
'date_of_birth', // input name, will also be used as meta key | |
'date', // type of field | |
array( | |
'label' => 'Date Of Birth' , // custom field label | |
'size' => 40, // input size | |
'profile' => true, // show in user profile | |
'required' => true, // make this field required | |
) | |
); | |
//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' ); | |
/** | |
* 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( '2' != $_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