0

I have added some custom columns to users table using the following function

    public function modify_users_columns( $column_headers ) {
    //Remove email, role, and posts column
    unset( $column_headers['email'], $column_headers['role'], $column_headers['posts'] );
    //Add sponsor id, level1 and level2 columns
    $column_headers['sponsor_id'] = 'Sponsor ID';
    $column_headers['level1'] = 'Level 1';
    $column_headers['level2'] = 'Level 2';
    return $column_headers;
}
add_filter( 'manage_users_columns', $plugin_admin, 'modify_users_columns' );

Then I am trying to populate these columns using custom user meta using following function

    public function display_custom_users_columns_data( $output, $column_name, $user_id ) {
    switch ($column_name) {
        case 'sponsor_id':
            return get_user_meta($user_id, 'sponsor_id', true);
            break;
        case 'level1':
            return get_user_meta($user_id, 'level1', true);
            break;
        case 'level2' :
            return get_user_meta($user_id, 'level2', true);
        default:
    }
    return $output;
} 
add_filter( 'manage_users_custom_columns', $plugin_admin, 'display_custom_users_columns_data', 10, 3 );

The first function works correctly and my custom columns are displayed. However the second function is not working, no matter how I return the $output variable

Someone reported this bug here but it was closed, I don't know? manage_users_custom_column filter not working

  • there is no "s" at the end of the filter "manage_users_custom_column" :) – mmm Sep 27 '17 at 19:08
0

I was using the wrong filter name by adding an 's' in manage_users_custom_columns. The correct filter name is without 's' : manage_users_custom_column. This was pointed out in the comments by @mmm.

-3

Try this....

case 'level1' :
  $level1 = get_user_meta( $user_id, 'level1', true );
  echo $level1;
break;
  • Still not working. I tried returning string values directly without switch statements, but still not working – ShahRukhMlk Sep 27 '17 at 18:56
  • 1
    Abson Reavs, this cannot work. This filter need that the value is returned and not echoed. – mmm Sep 27 '17 at 19:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.