Wordpress 更改默认显示名称 Publicy 对于所有现有用户 [英] Wordpress Change Default Display Name Publicy As for all existing users

查看:18
本文介绍了Wordpress 更改默认显示名称 Publicy 对于所有现有用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道我可以像所有用户一样公开更改现有显示名称的方法.我想将名字姓氏作为默认值,因为这将反映在论坛中.我已经阅读了所有的论坛并尝试了所有的技巧,任何建议将不胜感激.提前致谢

does anyone know of way I can change the existing display name publicly as for all users. I want to have firstname lastname as the default because this will reflect in the forum. I have read all the forums and have tried all the hacks, any suggestions would be appreciated. Thanks in advance

推荐答案

使用 admin_head 钩子的问题是它对不使用管理系统的用户不起作用.此外,我尝试实施 Marty 发布的解决方案失败了,因为似乎无法通过 update_user_meta() 更新 display_name - 您必须使用 wp_update_user().

Problem with using the admin_head hook is that it doesn't work for users who don't use the admin system. Also, my attempts to implement the solution posted by Marty failed because it doesn't seem that the display_name can be updated by update_user_meta() - you have to use wp_update_user().

我的建议 - 把它放在你的functions.php文件中:

My proposal - put this in your functions.php file:

function force_pretty_displaynames($user_login, $user) {

    $outcome = trim(get_user_meta($user->ID, 'first_name', true) . " " . get_user_meta($user->ID, 'last_name', true));
    if (!empty($outcome) && ($user->data->display_name!=$outcome)) {
        wp_update_user( array ('ID' => $user->ID, 'display_name' => $outcome));    
    }
}
add_action('wp_login','force_pretty_displaynames',10,2); 

对我来说(使用 WP 3.4.1),这工作正常,在他们登录后立即替换显示名称.

For me (using WP 3.4.1), that works OK, replacing the display name as soon as they log in.

这篇关于Wordpress 更改默认显示名称 Publicy 对于所有现有用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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