Php 向wordpress中的作者信息添加自定义文件

Php 向wordpress中的作者信息添加自定义文件,php,wordpress,custom-fields,add-filter,Php,Wordpress,Custom Fields,Add Filter,我是Wordpress的新手,我正在寻找一种添加自定义字段并显示它们的方法(无需插件)。 我在网上找到了。作者通过向fuctions.php文件中添加以下函数,添加了许多自定义字段 function modify_contact_methods($profile_fields) { // Add new fields $profile_fields['linkedin'] = 'LinkedIn URL'; $profile_fields['telephone'] =

我是Wordpress的新手,我正在寻找一种添加自定义字段并显示它们的方法(无需插件)。 我在网上找到了。作者通过向
fuctions.php
文件中添加以下函数,添加了许多自定义字段

function modify_contact_methods($profile_fields) {

    // Add new fields
    $profile_fields['linkedin'] = 'LinkedIn URL';
    $profile_fields['telephone'] = 'Telephone';        
    return $profile_fields;
}

add_filter('user_contactmethods', 'modify_contact_methods');
我已经能够成功地将这些字段添加到我的用户注册表的联系人信息部分。我一直在尝试向其他部分添加自定义字段,比如作者信息部分(Bio所在的位置),但没有成功。 我想我必须更改
add\u filter(…)
函数中的值
user\u contactmethods
,但我没有找到任何东西


我甚至不知道这是否是正确的方法,但到目前为止它仍然有效-

因为您是wordpress的新手,您不了解
过滤器和
操作。如果您浏览,您将找到
用户\u联系人方法

正如您在作者和用户过滤器中所看到的那样,作者和用户只有4个过滤器。我们不能用它们来实现你想要的输出

但是我们可以通过在下添加另一个关于用户的字段来实现这一点,比如作者信息

    add_action( 'show_user_profile', 'extra_user_profile_fields' );
    add_action( 'edit_user_profile', 'extra_user_profile_fields' );

    function extra_user_profile_fields( $user ) { ?>
    <h3><?php _e("Author Information", "blank"); ?></h3>

    <table class="form-table">
    <tr>
    <th><label for="author"><?php _e("Author Information"); ?></label></th>
    <td>
    <textarea name="author" id="author" rows="5" cols="10" ><?php echo esc_attr( get_the_author_meta( 'author', $user->ID ) ); ?></textarea><br />
    <span class="description"><?php _e("Please enter Author's Information."); ?></span>
    </td>
    </tr>
    </table>
    <?php }

    add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
    add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );

    function save_extra_user_profile_fields( $user_id ) {

    if ( !current_user_can( 'edit_user', $user_id ) ) { return false; }

    update_user_meta( $user_id, 'author', $_POST['author'] );
    }
add_操作('show_user_profile'、'extra_user_profile_fields');
添加操作(“编辑用户配置文件”、“额外用户配置文件”字段);
函数额外用户配置文件字段($user){?>


哇,这肯定解决了我的问题。是时候了解一下文件管理器和操作了!