将链接添加到用户列表(后端)以打开每个用户的前端配置文件

时间:2017-03-10 作者:Learning by doing

默认情况下,后端的用户屏幕允许我添加、更改或删除网站的用户:

enter image description here

现在我需要在用户列表中添加一个url,它会将我重定向到每个用户front-end profile (e.g. www.mysite.com/author/anna/). 我在wordpress codex或在线上找不到任何东西。你知道怎么解决这个问题吗?

1 个回复
最合适的回答,由SO网友:Paul \'Sparrow Hawk\' Biron 整理而成

以下内容将向行操作添加“查看作者配置文件”链接(即,当您将鼠标悬停在用户名上时显示的链接):

add_filter (\'user_row_actions\', \'add_view_author_page\', 10, 2) ;

function
add_view_author_page ($actions, $user)
{
    $href = esc_attr (get_author_posts_url ($user->ID)) ;
    $actions[\'add_view_author_page\'] = "<a href=\'$href\'>View author page</a>" ;

    return ($actions) ;
}

Edit:

或者,如果希望在表的列中有链接,可以执行以下操作:

add_filter (\'manage_users_columns\', \'users_columns\') ;
add_filter (\'manage_users_custom_column\', \'users_custom_column\', 10, 3) ;

function
users_columns ($cols)
{
    $cols[\'author_page\'] = \'Author page\' ;

    return ($cols) ;
}

function
users_custom_column ($default, $column_name, $user_id)
{
    if (\'author_page\' == $column_name) {
        $href = esc_attr (get_author_posts_url ($user_id)) ;
        $default .= "<a href=\'$href\'>View</a>" ;
        }

    return ($default) ;
}

相关推荐

Create small dashboard widget

我一直在尝试在admin中的一个用户的帐户页面中添加一列移动电话号码字段。所以我从https://coderwall.com/p/g72jfg/adding-a-phone-numer-field-to-wordpress-user-profile现在我要做的是,为仪表板构建一个自定义小部件,这样用户也可以直接从那里更改他的手机号码(因此小部件中还必须有一个更新按钮)。你可以看到为这个想法附上的照片-第一幅图是小部件在dashboad中的外观,-第二张图片是您现在可以在用户帐户中看到的。我知道一些使用ec