且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Wordpress的问题添加额外的用户配置文件字段

更新时间:2022-03-31 07:23:52

对,我终于找到了工作代码...

Right I found the working code in the end...

/* Add Additional Fields to Author Profile */

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="u-profs">Profile Info</label></th>
            <td>
                <input type="text" name="u-profs2" id="u-profs2" value="<?php echo esc_attr( get_the_author_meta( 'u-profs2', $user->ID ) ); ?>" class="regular-text" /><br />
                <span class="description">Enter Your Google+ Url.</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 'u-profs' to the field ID. */
    update_user_meta( $user_id, 'u-profs2', $_POST['u-profs2'] );
}

/* Google Rel Author */

function google_rel_author_in_document_head() {
global $post;
$author_id=$post->post_author;
?>
<link rel="author" href="<?echo get_user_meta($author_id, 'u-profs2', true);?>"/>
<?
}
add_action('wp_head', 'google_rel_author_in_document_head',99);