0
votes

I'm using this plugin to create custom registration fields in WordPress http://www.wpexplorer.com/wordpress-user-contact-fields/

I would like to make all custom fields required. I tried the following code, but it doesn't work - the registration can be completed even when the custom fields are left blank:

    function myplugin_registration_errors( $errors, $sanitized_user_login, $user_email ) {

    if ( empty( $_POST[$field[0]] ) || ! empty( $_POST[$field[0]] ) && trim( $_POST[$field[0]]  ) == '' ) {
        $errors->add( 'first_name_error', __( '<strong>ERROR</strong>: You must include a first name.', 'mydomain' ) );
    }

    return $errors;
}

I took it from the codex page http://codex.wordpress.org/Customizing_the_Registration_Form and inserted it straight after the closing of foreach( $extra_fields as $field ) construct.

Any ideas how I could make it work?

1

1 Answers

0
votes

Are you adding the filter hook ? Something like these

add_action( 'register_form', 'myplugin_add_registration_fields' );



add_filter('registration_errors', 'myplugin_registration_errors', 10, 3);