-
-
Save ashleyfae/1d414c5eac78a7643b9c7faa30a24a73 to your computer and use it in GitHub Desktop.
RCP: Require first name and last name during registration
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 | |
/** | |
* Require first and last names during registration | |
* | |
* @param array $posted Array of information sent to the form. | |
* | |
* @return void | |
*/ | |
function ag_rcp_require_first_and_last_names( $posted ) { | |
if ( is_user_logged_in() ) { | |
return; | |
} | |
if ( empty( $posted['rcp_user_first'] ) ) { | |
rcp_errors()->add( 'first_name_required', __( 'Please enter your first name', 'rcp' ), 'register' ); | |
} | |
if ( empty( $posted['rcp_user_last'] ) ) { | |
rcp_errors()->add( 'last_name_required', __( 'Please enter your last name', 'rcp' ), 'register' ); | |
} | |
} | |
add_action( 'rcp_form_errors', 'ag_rcp_require_first_and_last_names' ); | |
/** | |
* Require first and last names during profile edit | |
* | |
* @param array $posted Array of information sent to the form. | |
* @param int $user_id ID of the user editing their profile. | |
* | |
* @return void | |
*/ | |
function ag_rcp_require_first_and_last_name_profile_edit( $posted, $user_id ) { | |
if ( empty( $posted['rcp_first_name'] ) ) { | |
rcp_errors()->add( 'first_name_required', __( 'Please enter your first name', 'rcp' ) ); | |
} | |
if ( empty( $posted['rcp_last_name'] ) ) { | |
rcp_errors()->add( 'last_name_required', __( 'Please enter your last name', 'rcp' ) ); | |
} | |
} | |
add_action( 'rcp_edit_profile_form_errors', 'ag_rcp_require_first_and_last_name_profile_edit', 10, 2 ); |
@lolodi, I've added a small bit at the top that will skip the check if the user is logged in:
if( is_user_logged_in() ) {
return;
}
Thank you!
Another question: I noticed that both in the list in the rcp-members page, and in the details i the rcp-members&edit_member page, there is no Name and Last Name. Would it be possible to show this information in both the membership list and the meber detail pages?
Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried to add this code but now it checks if First Name and Last Name are not empty even when the user tries to change his subscription and the check fails because there is no First Name or Last Name in $posted.
Suggestions?