Skip to content

Instantly share code, notes, and snippets.

@ashleyfae
Last active August 30, 2017 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashleyfae/1d414c5eac78a7643b9c7faa30a24a73 to your computer and use it in GitHub Desktop.
Save ashleyfae/1d414c5eac78a7643b9c7faa30a24a73 to your computer and use it in GitHub Desktop.
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
Copy link

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
Copy link
Author

@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
Copy link

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