← WordPress

Registo Wordpress com campo usermeta

Lida 2654 vezes

Offline

Fernando Augusto 
Membro
Mensagens 922 Gostos 0
Feedback +1

Troféus totais: 30
Trófeus: (Ver todos)
Linux User Mobile User Windows User Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3

Olá, estou aqui com um problema, tenho uma página de registo mas não consigo fazer com que os campos usermeta que criei para as redes sociais sejam actualizados.

O Código para a página de registo é :

Código: (php) [Seleccione]
<?php    $err '';
    
$success '';
    global 
$wpdb$PasswordHash$current_user$user_ID;
    if(isset(
$_POST['task']) && $_POST['task'] == 'register' ) {
        
        
$pwd1 $wpdb->escape(trim($_POST['pwd1']));
        
$pwd2 $wpdb->escape(trim($_POST['pwd2']));
        
$first_name $wpdb->escape(trim($_POST['first_name']));
        
$last_name $wpdb->escape(trim($_POST['last_name']));
        
$email $wpdb->escape(trim($_POST['email']));
        
$username $wpdb->escape(trim($_POST['username']));
$description $wpdb->escape(trim($_POST['description']));
       
        if( 
$email == "" || $pwd1 == "" || $pwd2 == "" || $username == "") {
            
$err 'Não preencheu os campos obrigatórios!';
        } else if(!
filter_var($emailFILTER_VALIDATE_EMAIL)) {
            
$err 'Endereço de email inválido.';
        } else if(
email_exists($email) ) {
            
$err 'Este email já estão a ser utilizado.';
        } else if(
$pwd1 <> $pwd2 ){
            
$err 'As passwords inseridas não são iguais';        
        } else {
            
$user_id wp_insert_user( array ('first_name' => apply_filters('pre_user_first_name'$first_name), 'last_name' => apply_filters('pre_user_last_name'$last_name), 'user_pass' => apply_filters('pre_user_user_pass'$pwd1), 'user_login' => apply_filters('pre_user_user_login'$username), 'user_email' => apply_filters('pre_user_user_email'$email), 'user_description' => apply_filters('pre_user_user_description'$description), 'role' => 'contributor' ) );
            if( 
is_wp_error($user_id) ) {
                
$err 'Erro na criação do utilizador.';
            } else {
                
do_action('user_register'$user_id);
                
                
$success 'You\'re successfully register';
            }
            
        }
        
    }

?>

Os campos normais chamo assim

Código: (html4strict) [Seleccione]
       <div class="registarint"><label>Password(**)</label>
<input type="password" value="" name="pwd1" id="pwd1" />
</div>


Para criar os campos das redes socais nos perfis utilizo o seguinte no functions.

Código: (php) [Seleccione]
/* Campos de Perfil */
function show_extra_profile_fields( $user ) { ?>
<h3>Perfis Social Media</h3>
<table class="form-table">
<tr>
<th><label for="google">Google Plus</label></th>
<td><input type="text" name="googlelink" id="googlelink" value="<?php echo esc_attrget_the_author_meta'googlelink'$user->ID ) ); ?>" class="regular-text" /><br /><span class="description">Google Plus Profile ID.</span></td>
<td><input type="text" name="googlename" id="googlename" value="<?php echo esc_attrget_the_author_meta'googlename'$user->ID ) ); ?>" class="regular-text" /><br /><span class="description">Google Plus Profile Name.</span></td>
</tr>
<tr>
<th><label for="twitter">Twitter</label></th>
<td><input type="text" name="twitter" id="twitter" value="<?php echo esc_attrget_the_author_meta'twitter'$user->ID ) ); ?>" class="regular-text" /><br /><span class="description">Twitter username.</span></td>
</tr>
<tr>
<th><label for="facebook">Facebook </label></th>
<td><input type="text" name="facebook" id="twitter" value="<?php echo esc_attrget_the_author_meta'facebook'$user->ID ) ); ?>" class="regular-text" /><br /><span class="description">Facebook URL.</span></td>
</tr>
</table>
<?php }
add_action'show_user_profile''show_extra_profile_fields' );
add_action'edit_user_profile''show_extra_profile_fields' );

/* Campos de Perfil */
function save_extra_profile_fields$user_id ) {
if ( !
current_user_can'edit_user'$user_id ) )
return 
false;

/* Copy and paste this line for additional fields. */
update_usermeta$user_id'googlename'$_POST['googlename'] );
update_usermeta$user_id'googlelink'$_POST['googlelink'] );
update_usermeta$user_id'twitter'$_POST['twitter'] );
update_usermeta$user_id'facebook'$_POST['facebook'] );
}
add_action'personal_options_update''save_extra_profile_fields' );
add_action'edit_user_profile_update''save_extra_profile_fields' );


Como é que eu posso fazer com que esses campos sejam actualizados no registo pelo utilizador?
Offline

Fernando Augusto 
Membro
Mensagens 922 Gostos 0
Feedback +1

Troféus totais: 30
Trófeus: (Ver todos)
Linux User Mobile User Windows User Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3

Alguém?
Offline

STronic 
Elite
Mensagens 546 Gostos 8
Feedback +5

Troféus totais: 30
Trófeus: (Ver todos)
Mobile User Search Apple User Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3

Não consegues gravar os dados através da página de registo, certo? Apenas consegues da pagina de perfil no wp-admin ?
Offline

Fernando Augusto 
Membro
Mensagens 922 Gostos 0
Feedback +1

Troféus totais: 30
Trófeus: (Ver todos)
Linux User Mobile User Windows User Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3

Exactamente STronic
Offline

STronic 
Elite
Mensagens 546 Gostos 8
Feedback +5

Troféus totais: 30
Trófeus: (Ver todos)
Mobile User Search Apple User Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3

Experimenta adicionar isto:

Código: (php) [Seleccione]
update_usermeta( $user_id, 'googlename', $_POST['googlename'] );
update_usermeta( $user_id, 'googlelink', $_POST['googlelink'] );
update_usermeta( $user_id, 'twitter', $_POST['twitter'] );
update_usermeta( $user_id, 'facebook', $_POST['facebook'] );

a seguir a isto:

Código: (php) [Seleccione]
$user_id = wp_insert_user.........

na página do registo
Offline

Fernando Augusto 
Membro
Mensagens 922 Gostos 0
Feedback +1

Troféus totais: 30
Trófeus: (Ver todos)
Linux User Mobile User Windows User Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3

Obrigado pela ajuda extra no face :)