显示用户角色wordpress

时间:2014-06-10 16:33:33

标签: php html wordpress

所以我试图从Wordpress中显示用户角色,似乎有点挣扎。该角色的核心名称仍然是订阅者,但我可以展示除角色之外的所有内容,而且我有点卡住了。

我不确定要获取该信息该怎么办?

 <?php
    $args1 = array(
     'role' => 'committee',
     'orderby' => 'user_nicename',
     'order' => 'ASC'
    );
     $committee = get_users($args1);

    echo '
    <table>
      <tr>
        <th style="padding: 10px;">Title</th>
        <th style="padding: 10px;">Name</th>
        <th style="padding: 10px;">Email Address</th>
        <th style="padding: 10px;">Telephone Number</th>            
      </tr>';

    foreach ($committee as $user) {
    echo '  
      <tr>
        <td style="padding: 10px;">' .$user->job_title .'</td>
        <td style="padding: 10px;">' . $user->display_name .'</td>
        <td style="padding: 10px;">'.$user->user_email . '</td>
        <td style="padding: 10px;">'.$user->tel_number . '</td>
      </tr>';

     }
    echo '</table></ul>';
    ?>

1 个答案:

答案 0 :(得分:0)

    // If you don't already have a WP_User object
    $user = new WP_User( $user_ID );

    // Then you can get the role(s)
    if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
        foreach ( $user->roles as $role )
            echo $role;
    }

一个方便的帮助函数来获取本地化的角色名称:

function get_role_display_name( $role_id ) {
    global $wp_roles;
    if ( !isset( $wp_roles ) ) $wp_roles = new WP_Roles();

    return isset( $wp_roles->role_names[ $role_id ] )
            ? $wp_roles->role_names[ $role_id ]
            : $role_id;
}