Ver Mensaje Individual
  #11 (permalink)  
Antiguo 23/01/2012, 04:49
Fernando_net
 
Fecha de Ingreso: marzo-2010
Mensajes: 191
Antigüedad: 14 años, 1 mes
Puntos: 3
Respuesta: Registro con campos personalizados + Base de datos - No se guardan los dat

Nada, al final sigue sin funcionar.

Os paso el codigo PHP de la función que usa wp-login.php para registrar nuevos usuarios. Solamente tenía el campo user_login y user_email; los demás campos los añadí yo.

A pesar de todo, voy a la base de datos y siguen en blanco. A ver si podéis ver algún detalle que a mi se me escape...

Código PHP:
Ver original
  1. function register_new_user( $user_login, $user_email, $user_centro, $user_especialidad, $user_participantes, $user_telefono ) {
  2.     $errors = new WP_Error();
  3.  
  4.     $sanitized_user_login = sanitize_user( $user_login );
  5.     $user_email = apply_filters( 'user_registration_email', $user_email );
  6.  
  7.     // Check the username
  8.     if ( $sanitized_user_login == '' ) {
  9.         $errors->add( 'empty_username', __( '<strong>ERROR</strong>: Please enter a username.' ) );
  10.     } elseif ( ! validate_username( $user_login ) ) {
  11.         $errors->add( 'invalid_username', __( '<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' ) );
  12.         $sanitized_user_login = '';
  13.     } elseif ( username_exists( $sanitized_user_login ) ) {
  14.         $errors->add( 'username_exists', __( '<strong>ERROR</strong>: This username is already registered, please choose another one.' ) );
  15.     }
  16.  
  17.     // Check the e-mail address
  18.     if ( $user_email == '' ) {
  19.         $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please type your e-mail address.' ) );
  20.     } elseif ( ! is_email( $user_email ) ) {
  21.         $errors->add( 'invalid_email', __( '<strong>ERROR</strong>: The email address isn’t correct.' ) );
  22.         $user_email = '';
  23.     } elseif ( email_exists( $user_email ) ) {
  24.         $errors->add( 'email_exists', __( '<strong>ERROR</strong>: This email is already registered, please choose another one.' ) );
  25.     }
  26.  
  27.     do_action( 'register_post', $sanitized_user_login, $user_email, $errors );
  28.  
  29.     $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email );
  30.  
  31.     if ( $errors->get_error_code() )
  32.         return $errors;
  33.  
  34.     $user_pass = wp_generate_password( 12, false);
  35.     $user_id = wp_create_user( $sanitized_user_login, $user_pass, $user_email, $user_centro, $user_especialidad, $user_participantes, $user_telefono);
  36.     if ( ! $user_id ) {
  37.         $errors->add( 'registerfail', sprintf( __( '<strong>ERROR</strong>: Couldn’t register you... please contact the <a href="mailto:%s">webmaster</a> !' ), get_option( 'admin_email' ) ) );
  38.         return $errors;
  39.     }
  40.  
  41.     update_user_option( $user_id, 'default_password_nag', true, true ); //Set up the Password change nag.
  42.  
  43.     wp_new_user_notification( $user_id, $user_pass );
  44.  
  45.     return $user_id;
  46. }

Y aquí es cuando llama a la función

Código PHP:
Ver original
  1. $user_login = '';
  2.     $user_email = '';
  3.     $user_centro = '';
  4.     $user_especialidad = '';
  5.     $user_participantes = '';
  6.     $user_telefono = '';
  7.     if ( $http_post ) {
  8.         $user_login = $_POST['user_login'];
  9.         $user_email = $_POST['user_email'];
  10.         $user_centro = $_POST['user_centro'];
  11.         $user_especialidad = $_POST['user_especialidad'];
  12.         $user_participantes = $_POST['user_participantes'];
  13.         $user_telefono = $_POST['user_telefono'];
  14.         $errors = register_new_user($user_login, $user_email, $user_centro, $user_especialidad, $user_participantes, $user_telefono);
  15.         if ( !is_wp_error($errors) ) {
  16.             $redirect_to = !empty( $_POST['redirect_to'] ) ? $_POST['redirect_to'] : 'wp-login.php?checkemail=registered';
  17.             wp_safe_redirect( $redirect_to );
  18.             exit();
  19.         }
  20.     }

A ver si alguien puede darme alguna manita...

Un abrazo!