Created
July 12, 2018 17:47
-
-
Save dparker1005/250c765dde5ec4597d9696f3fccb7fd3 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 | |
//Add from here down to the bottom of your PMProcustomizations plugin | |
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. | |
$facebook_email_different = new PMProRH_Field( | |
'facebook_email_different', // input name, will also be used as meta key. | |
'checkbox', // type of field. | |
array( | |
'label' => 'Different Facebook Email ', // custom field label. | |
'text' => '', | |
'hint' => 'Check if the email associated with your Facebook account is different than the email address above', | |
) | |
); | |
$facebook_email = new PMProRH_Field( | |
'facebook_email', // input name, will also be used as meta key. | |
'text', // type of field. | |
array( | |
'label' => 'Email Associated with Facebook Account', // custom field label. | |
'size' => 40, // input size. | |
'profile' => true, // show in user profile. | |
'depends' => array( | |
array( | |
'id' => 'facebook_email_different', | |
'value' => true, | |
), | |
), | |
) | |
); | |
pmprorh_add_registration_field( | |
'after_email', // location on checkout page. | |
$facebook_email_different // PMProRH_Field object. | |
); | |
pmprorh_add_registration_field( | |
'after_email', // location on checkout page. | |
$facebook_email // PMProRH_Field object. | |
); | |
} | |
add_action( 'init', 'my_pmprorh_init' ); | |
function my_pmprorh_validate( $pmpro_continue_registration ) { | |
if ( ! isset( $_REQUEST['facebook_email_different'] ) ) { | |
if ( isset( $_REQUEST['bemail'] ) ) { | |
$_REQUEST['facebook_email'] = sanitize_email( stripslashes( $_REQUEST['bemail'] ) ); | |
} elseif ( is_user_logged_in() ) { | |
$_REQUEST['facebook_email'] = $current_user->user_email; | |
} else { | |
$_REQUEST['facebook_email'] = ''; | |
} | |
} elseif ( isset( $_REQUEST['facebook_email_different'] ) ) { | |
$_REQUEST['facebook_email'] = sanitize_email( stripslashes( $_REQUEST['facebook_email'] ) ); | |
} else { | |
$_REQUEST['facebook_email'] = ''; | |
} | |
return true; | |
} | |
add_filter( 'pmpro_registration_checks', 'my_pmprorh_validate' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment