小编Dis*_*ame的帖子

在wordpress中如何在注释中显示USER ROLE

在我的wordpress网站上,有一个评论模板,我在其中做了一些我想要的更改,但我遇到了问题.

注意:我正在使用用户角色编辑器插件.

我想在每个评论中显示用户旁边的用户角色.

我的代码:

    function get_the_author_role() {
    global $wpdb, $wp_roles, $authordata;

    if ( !isset($wp_roles) )
        $wp_roles = new WP_Roles();

    foreach($wp_roles->role_names as $role => $Role) {
        $caps = $wpdb->prefix . 'capabilities';
        if (array_key_exists($role, $authordata->$caps))
            return $Role;
    }
}

/**
 * Echo the account role of the author of the current post in the Loop.
 * @see get_the_author_role()
 * @return null
 */
function the_author_role() {
    echo get_the_author_role();
}
Run Code Online (Sandbox Code Playgroud)

我将此代码添加到function.php中,但它不起作用.

这是我的comment-template.php部分:

     <?php printf( __( ' <cite …
Run Code Online (Sandbox Code Playgroud)

php wordpress

2
推荐指数
1
解决办法
836
查看次数

标签 统计

php ×1

wordpress ×1