Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
RCP: Require first name and last name during registration
<?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

This comment has been minimized.

Copy link

@lolodi lolodi commented Feb 21, 2017

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?

@ashleyfae

This comment has been minimized.

Copy link
Owner Author

@ashleyfae ashleyfae commented Feb 24, 2017

@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;
}
@lolodi

This comment has been minimized.

Copy link

@lolodi lolodi commented Feb 26, 2017

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
You can’t perform that action at this time.