Created
January 11, 2021 12:23
-
-
Save yousufansa/93299066e6e33a99fd04f06c56fd09f7 to your computer and use it in GitHub Desktop.
MAS Videos - Displaying first name and last name fields on registration page.
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
/** | |
* Displaying first name and last name fields on | |
* MAS Video's registration page. | |
*/ | |
function masvideos_customize_register_form() { | |
$fields = array( | |
'first_name' => __('First name', 'masvideos'), | |
'last_name' => __('Last name', 'masvideos') | |
); | |
foreach( $fields as $k => $v ): ?> | |
<p class="form-row form-row-wide"> | |
<label for="<?php echo $k; ?>"><?php echo $v; ?> <span class="required">*</span></label> | |
<input type="text" class="input-text" name="<?php echo $k; ?>" id="<?php echo $k; ?>" value="<?php | |
if ( ! empty( $_POST[$k] ) ) echo esc_attr( $_POST[$k] ); ?>" /> | |
</p> | |
<?php | |
endforeach; | |
} | |
add_action( 'masvideos_register_form_start', 'masvideos_customize_register_form' ); | |
/** | |
* Validate the extra register fields. | |
*/ | |
function masvideos_customize_registration_errors( $validation_error, $username, $password, $email ) | |
{ | |
if( !isset($_POST['first_name']) || empty($_POST['first_name']) ){ | |
$validation_error->add('error', 'Please enter your First name'); | |
} | |
elseif( !isset($_POST['last_name']) || empty($_POST['last_name']) ){ | |
$validation_error->add('error', 'Please enter your Last name'); | |
} | |
return $validation_error; | |
} | |
add_filter( 'masvideos_process_registration_errors', 'masvideos_customize_registration_errors', 10, 4 ); | |
/** | |
* Save the extra register fields. | |
*/ | |
function masvideos_customize_new_user_data( $data ) { | |
/** | |
* WordPress will automatically insert this information's into database, | |
* we just need to include it here | |
**/ | |
$data['first_name'] = masvideos_clean( $_POST['first_name'] ); | |
$data['last_name'] = masvideos_clean( $_POST['last_name'] ); | |
return $data; | |
} | |
add_filter( 'masvideos_new_user_data', 'masvideos_customize_new_user_data' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment