Añadimos la siguiente función al functions. php del tema hijo.
//Añadir campo cif registro usuario //FRONTEND //Displaying the field add_action( 'register_form', 'crf_registration_form' ); function crf_registration_form() { $cif = ! empty( $_POST['cif'] ) ? intval( $_POST['cif'] ) : ''; ?> <p> <label for="cif"><?php esc_html_e( 'CIF', 'crf' ) ?><br/> <input type="text" id="cif" name="cif" value="<?php echo esc_attr( $cif ); ?>" class="input" required /> </label> </p> <style> #cif.fallo{ border-color: red; } label[for="cif"]::after{ color: red; } label[for="cif"].vacio::after{ content: 'Por favor introduce el CIF.'; } label[for="cif"].caracteres::after{ content: 'El CIF debe contener 9 caracteres.'; } </style> <script> function validar(){ var cif = jQuery('#cif'); var ciflabel = jQuery('label[for="cif"]'); if(cif.val() == ''){ cif.addClass('fallo'); ciflabel.removeClass('caracteres'); ciflabel.addClass('vacio'); return false; }else if(cif.val().length > 9 || cif.val().length < 9){ cif.addClass('vacio'); ciflabel.removeClass('vacio'); ciflabel.addClass('caracteres'); return false; } } jQuery('#registerform').attr('onsubmit','return validar()'); </script> <?php } //Validating the field /*add_filter( 'registration_errors', 'crf_registration_errors', 10, 3 ); function crf_registration_errors( $errors, $sanitized_user_login, $user_email ) { if ( empty( $_POST['cif'] ) ) { $errors->add( 'cif_error', __( '<strong>Error</strong>: Por favor introduce el CIF.', 'crf' ) ); } if(strlen($_POST['cif']) > 9 || strlen($_POST['cif']) < 9){ $errors->add( 'cif_error', __( '<strong>Error</strong>: El CIF debe contener 9 caracteres.', 'crf' ) ); } return $errors; }*/ //Sanitizing and saving the field add_action( 'user_register', 'crf_user_register' ); function crf_user_register( $user_id ) { if ( ! empty( $_POST['cif'] ) ) { update_user_meta( $user_id, 'cif', intval( $_POST['cif'] ) ); } } //BACKEND //Displaying the field add_action( 'user_new_form', 'crf_admin_registration_form' ); function crf_admin_registration_form( $operation ) { if ( 'add-new-user' !== $operation ) { // $operation may also be 'add-existing-user' return; } $cif = ! empty( $_POST['cif'] ) ? intval( $_POST['cif'] ) : ''; ?> <h3><?php esc_html_e( 'Información personal', 'crf' ); ?></h3> <table class="form-table"> <tr> <th><label for="cif"><?php esc_html_e( 'CIF', 'crf' ); ?></label> <span class="description"><?php esc_html_e( '(required)', 'crf' ); ?></span></th> <td> <input type="text" id="cif" name="cif" value="<?php echo esc_attr( $cif ); ?>" class="regular-text" required /> </td> </tr> </table> <?php } //Validating the field add_action( 'user_profile_update_errors', 'crf_user_profile_update_errors', 10, 3 ); function crf_user_profile_update_errors( $errors, $update, $user ) { if ( $update ) { return; } if ( empty( $_POST['cif'] ) ) { $errors->add( 'cif_error', __( '<strong>Error</strong>: Por favor introduce el CIF.', 'crf' ) ); } if(strlen($_POST['cif']) > 9 || strlen($_POST['cif']) < 9){ $errors->add( 'cif_error', __( '<strong>Error</strong>: El CIF debe contener 9 caracteres.', 'crf' ) ); } } //Sanitizing and saving the field add_action( 'edit_user_created_user', 'crf_user_register' ); //Profile display add_action( 'show_user_profile', 'crf_show_extra_profile_fields' ); add_action( 'edit_user_profile', 'crf_show_extra_profile_fields' ); function crf_show_extra_profile_fields( $user ) { ?> <h3><?php esc_html_e( 'Información personal', 'crf' ); ?></h3> <table class="form-table"> <tr> <th><label for="cif"><?php esc_html_e( 'CIF', 'crf' ); ?></label></th> <td><?php echo esc_html( get_the_author_meta( 'cif', $user->ID ) ); ?></td> </tr> </table> <?php }