Kullanıcı Profiline Yeni Alanlar Eklemek

WordPress üyelik sistemiyle gelen kullanıcı profilindeki alanlar çoğu zaman yetersiz kalabilir. Bunları artırmak ve bu kısma özel alanlar eklemek, sonrasında da bu alanları dilediğimiz yerde gösterebilmek için functions.php dosyasına aşağıdaki satırları ekliyoruz:

add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
function my_show_extra_profile_fields( $user ) { ?>
    <h3>Extra profile information</h3>
    <table class="form-table">
        <tr>
            <th><label for="twitter">Twitter</label></th>
            <td>
                <input type="text" name="twitter" id="twitter" value="<?php echo esc_attr( get_the_author_meta( 'twitter', $user->ID ) ); ?>" class="regular-text" /><br />
                <span class="description">Please enter your Twitter username.</span>
            </td>
        </tr>
    </table>
<?php }

add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );
function my_save_extra_profile_fields( $user_id ) {
    if ( !current_user_can( 'edit_user', $user_id ) )
        return false;
    /* Copy and paste this line for additional fields. Make sure to change 'twitter' to the field ID. */
    update_usermeta( $user_id, 'twitter', $_POST['twitter'] );
}

Eğer farklı alanlar eklemek istersek aşağıdaki kısmı çoğaltabiliriz.

<tr>
    <th><label for="twitter">Twitter</label></th>

    <td>
        <input type="text" name="twitter" id="twitter" value="<?php echo esc_attr( get_the_author_meta( 'twitter', $user->ID ) ); ?>" class="regular-text" /><br />
        <span class="description">Please enter your Twitter username.</span>
    </td>
</tr>

Yazar bilgilerini göstermek için başka bir fonksiyon daha yazabiliriz:

function my_author_box() { ?>
    <div class="author-profile vcard">
        <?php echo get_avatar( get_the_author_meta( 'user_email' ), '96' ); ?>

        <h4 class="author-name fn n">Article written by <?php the_author_posts_link(); ?></h4>
        <p class="author-description author-bio">
            <?php the_author_meta( 'description' ); ?>
        </p>
        <?php if ( get_the_author_meta( 'twitter' ) ) { ?>
            <p class="twitter clear">
                <a href="http://twitter.com/<?php the_author_meta( 'twitter' ); ?>" title="Follow <?php the_author_meta( 'display_name' ); ?> on Twitter">Follow <?php the_author_meta( 'display_name' ); ?> on Twitter</a>
            </p>
        <?php } // End check for twitter ?>
    </div><?php
}

bu fonksiyonu kullanmak için de aşağıdaki kodu temamızın herhangi bir yerine yerleştirebiliriz.

<?php my_author_box(); ?>