Erhan Yakut Software Developer @Binalyze | Founder @Passwall | Golang Enthusiast | Open Sorcerer

WordPress Kullanıcı Hesabına Ek Bilgi Ekleme

57 sec read

WordPress’in ne kadar esnek ve geliştirilebilir bir kod yapısı olduğunu artık söylemeye gerek yok sanırım. Bu esneklik sayesinde wordpress kullanıcı hesaplarına ek alan girebiliyoruz. Örnek vermek gerekirse normal bir WordPress kullanıcısı profilinde E-posta ve İnternet Sitesi alanları mevcutken biz buna Telefon alanı da ekleyebiliriz. Bu söylediğimi gerçekleştirmek için de tek yapmanız gereken aşağıdaki kodu temanızın functions.php dosyasına eklemek, hepsi bu kadar.

[php]<?php

function alan_ekle( $user ) {
?>
<h3><?php _e(‘Ek Bilgiler’, ‘your_textdomain’); ?></h3>

<table class="form-table">
<tr>
<th>
<label for="telefon"><?php _e(‘Telefon’, ‘your_textdomain’); ?></label>
</th>
<td>
<input type="text" name="telefon" id="telefon" value="<?php echo esc_attr( get_the_author_meta( ‘telefon’, $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description"><?php _e(‘Lütfen telefon numaranızı giriniz.’, ‘your_textdomain’); ?></span>
</td>
</tr>
</table>
<?php }

function alan_kaydet( $user_id ) {

if ( !current_user_can( ‘edit_user’, $user_id ) )
return FALSE;

update_usermeta( $user_id, ‘telefon’, $_POST[‘telefon’] );
}

add_action( ‘show_user_profile’, ‘alan_ekle’ );
add_action( ‘edit_user_profile’, ‘alan_ekle’ );

add_action( ‘personal_options_update’, ‘alan_kaydet’ );
add_action( ‘edit_user_profile_update’, ‘alan_kaydet’ );

?>[/php]

Erhan Yakut Software Developer @Binalyze | Founder @Passwall | Golang Enthusiast | Open Sorcerer