Wordpress的问题添加额外的用户配置文件字段 [英] Issue with Wordpress Adding extra user profile fields

查看:65
本文介绍了Wordpress的问题添加额外的用户配置文件字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在向Wordpress用户配置文件添加自定义字段并使输入的字段显示在网站的前面时遇到问题.使用下面的教程,我以为我可以使用它,但是注意到实际上它仅对一个用户有效,而其他所有用户均无效,这使我感到困惑,因为我习惯了某些正常工作或不正常工作的情况,而这仅适用于我尝试过的第一个用户,但其他用户则不行.

I am having an issue with adding custom fields to the wordpress user profile and having the inputted fields show on the front of the site. Using the below tutorial I thought I had it working, however noticed that actually it only works for ONE user, then all of the others don't work, this is what is confusing me as I am used to things either working, or not working, whereas this works for the first user I tried it for, but no others.

我看上去高低不一,尝试不同的尝试都无济于事.

I have looked high and low trying different things to no avail.

我这样做的目的是允许多个wordpress用户将他们的Google+个人资料添加到该特定作者具有rel属性的帖子的wordpress标题上.

My purpose for this is to allow multiple wordpress users to add their Google+ profile to the wordpress head on posts BY that specific author with the rel attribute.

这是我使用的教程

http://bavotasan.com/2009/将额外字段添加到wordpress用户个人资料/

这是我用于该功能的代码

Here is the code I am using for the function

1-这会将字段添加到用户个人资料

1 - This adds the field to the user profile

/* 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-profs" id="u-profs" value="<?php echo esc_attr( get_the_author_meta( 'u-profs', $user->ID ) ); ?>" class="regular-text" /><br />
                <span class="description">Enter Your Profile Info.</span>
            </td>
            <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' );

foreach($user_ids as $user_id){
    update_user_meta( $user_id, 'u-profs2', $_POST['u-profs2'] );
}

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-profs', $_POST['u-profs'] );
    update_user_meta( $user_id, 'u-profs2', $_POST['u-profs2'] );
}

2-这将获取字段内容并将其添加到wordpress的wp_head

2 - This gets the field content and adds it to the wp_head of wordpress

    /* Google Rel Author */

function google_rel_author_in_document_head() {
echo '<link rel="author" href="' . get_the_author_meta('u-profs2') . '"/>';
}
add_action('wp_head', 'google_rel_author_in_document_head',99);

StackOverflow上的此链接似乎是一个类似的问题,但未解决...

This link on StackOverflow seems to be a similar problem but is unresolved...

Wordpress中有多个update_user_meta

推荐答案

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

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);

这篇关于Wordpress的问题添加额外的用户配置文件字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆