User Profile Avatars

时间:2013-06-14 作者:Jusherb

我正在使用这个插件

http://wordpress.org/plugins/user-photo/

如何获取通过此插件上传的个人资料照片,以显示在用户名旁边的所有用户列表和管理栏中?我在管理栏中看到下面的代码。php但很困惑

/**
 * Add the "My Account" item.
 *
 * @since 3.3.0
 */
function wp_admin_bar_my_account_item( $wp_admin_bar ) {
$user_id      = get_current_user_id();
$current_user = wp_get_current_user();
$profile_url  = get_edit_profile_url( $user_id );

if ( ! $user_id )
    return;

$user_info  = get_avatar( $user_id, 64 );
$user_info .= "<span class=\'display-name\'>{$current_user->display_name}</span>";

if ( $current_user->display_name !== $current_user->user_email )
    $user_info .= "<span class=\'username\'>&nbsp;-&nbsp;{$current_user->user_email}</span>";


$wp_admin_bar->add_menu( array(
    \'id\'        => \'my-account\',
    \'parent\'    => \'top-secondary\',
    \'title\'     => $user_info,
    \'meta\'      => array(
        \'class\'     => \'ProCorner\',
        \'title\'     => __(\'My FRS ID\'),
    ),
) );
}

1 个回复
SO网友:Adam

您需要向用户列表屏幕添加自定义列,如下所示:

// Add a custom user column called Photo with a column key of user_photo 
// and re-arrange the columns array so our new column appears first.
function add_user_columns( $defaults ) {

    $new_order = array();

    foreach ( $defaults as $key => $title ) {

        if ( \'username\' === $key ) {
            $new_order[\'user_photo\'] = __( \'Photo\', \'your_textdomain\' );
        }

        $new_order[ $key ] = $title;

    }

    return $new_order;
}
add_filter( \'manage_users_columns\', \'add_user_columns\', 15 );

// Add data to our user column, specifically in your case 
// get the photo from user meta
function add_custom_user_columns( $value, $column_name, $id ) {

      if ( \'user_photo\' === $column_name ) {
          // replace `$meta_key` with the relevant key that holds the photo
          return get_user_meta( $id, $meta_key, true ); 
      }

}
add_action( \'manage_users_custom_column\', \'add_custom_user_columns\', 15, 3 );

结束