admin管理员组文章数量:1122832
I'm trying to add two columns to the users.php file. I'm not sure how to add both $total_time_display and $logged_in_amount_display. How could I return both values?
Here is my code:
add_filter('manage_users_columns', 'freeman_add_user_minutes_column');
function freeman_add_user_minutes_column($columns) {
$columns['total_time'] = 'Total Minutes';
$columns['logged_in_amount'] = 'Number of Logins';
return $columns;
}
add_action('manage_users_custom_column', 'freeman_show_user_minutes_column_content', 10, 3);
function freeman_show_user_minutes_column_content($value, $column_name, $user_id) {
$user = get_userdata( $user_id );
if ( 'total_time' == $column_name )
$total_time_display = ($user->total_time);
return $total_time_display;
if ( 'logged_in_amount' == $column_name )
$logged_in_amount_display = ($user->logged_in_amount);
return $logged_in_amount_display;
return $value;
}
I'm trying to add two columns to the users.php file. I'm not sure how to add both $total_time_display and $logged_in_amount_display. How could I return both values?
Here is my code:
add_filter('manage_users_columns', 'freeman_add_user_minutes_column');
function freeman_add_user_minutes_column($columns) {
$columns['total_time'] = 'Total Minutes';
$columns['logged_in_amount'] = 'Number of Logins';
return $columns;
}
add_action('manage_users_custom_column', 'freeman_show_user_minutes_column_content', 10, 3);
function freeman_show_user_minutes_column_content($value, $column_name, $user_id) {
$user = get_userdata( $user_id );
if ( 'total_time' == $column_name )
$total_time_display = ($user->total_time);
return $total_time_display;
if ( 'logged_in_amount' == $column_name )
$logged_in_amount_display = ($user->logged_in_amount);
return $logged_in_amount_display;
return $value;
}
Share
Improve this question
asked Nov 7, 2013 at 5:41
graphical_forcegraphical_force
1941 gold badge3 silver badges18 bronze badges
1
|
3 Answers
Reset to default 2Thanks for the help buys but I ended up figuring it out. Just echoing the code did not give me the results I wanted but returning it did.
Here is the code:
add_filter('manage_users_columns', 'freeman_add_user_minutes_column');
function freeman_add_user_minutes_column($columns) {
$columns['total_time'] = 'Total Minutes';
$columns['logged_in_amount'] = 'Number of Logins';
return $columns;
}
add_filter('manage_users_custom_column', 'freeman_show_user_minutes_column_content', 10, 3);
function freeman_show_user_minutes_column_content($value, $column_name, $user_id) {
$user = get_userdata( $user_id );
if ( 'total_time' == $column_name )
$output .= ($user->total_time);
if ( 'logged_in_amount' == $column_name )
$output .= ($user->logged_in_amount);
return $output;
}
Guessing at what your meta fields are calling, implementing Oleg's suggestions would mean updating your freeman_show_user_minutes_column_content()
function like so:
add_action('manage_users_custom_column', 'freeman_show_user_minutes_column_content', 10, 3);
function freeman_show_user_minutes_column_content($value, $column_name, $user_id) {
$user = get_userdata( $user_id );
if ( 'total_time' == $column_name )
echo get_user_meta( $user_id, 'total_time', true );
if ( 'logged_in_amount' == $column_name )
echo get_user_meta( $user_id, 'logged_in_amount' );
}
Your custom meta isn't part of the $user
object, so instead, you have to use get_user_meta()
.
Correct to use echo
not return
. This is action, not the filter. And you can delete return $value;
from your callback.
本文标签: customizationadding multiple custom columns to usersphp
版权声明:本文标题:customization - adding multiple custom columns to users.php 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736296573a1929827.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
total_time
or thelogged_in_amount
. Neither of these are valid objects of theget_userdata()
method. You will need to create the function for each of the values you are trying to ascertain. – josh Commented Nov 7, 2013 at 6:23