I add a column to users page, it goes wrong when checkbox is not in correct position. This is my code, can you help me to move checkbox to the correct position?
public static function user_register_columns( $columns ) {
// create a new array with account just after username, then everything else
$new_columns = array();
if ( isset($columns['username']) ) {
$new_columns['username'] = $columns['username'];
unset($columns['username']);
}
$new_columns['account'] = self::__( 'Account' );
$new_columns = array_merge($new_columns, $columns);
return $new_columns;
}
public static function user_column_display( $empty='', $column_name, $id ) {
$account = WP_ABC_Account::get_instance( $id );
if ( !$account )
return; // return for that temp post
switch ( $column_name ) {
case 'account':
$account_id = $account->get_ID();
$user_id = $account->get_user_id_for_account( $account_id );
$user = get_userdata( $user_id );
$get_name = $account->get_name();
$name = ( strlen( $get_name ) <= 1 ) ? '' : $get_name;
//Build row actions
$actions = array(
'edit' => sprintf( '<a href="#">'.self::__( 'Manage' ).'</a>', $account_id ),
'payments' => sprintf( '<a href="#">'.self::__( 'Payments' ).'</a>', $account_id ),
'gifts' => sprintf( '<a href="#">'.self::__( 'Gifts').'</a>', $account_id )
);
//Return the title contents
return sprintf( self::__( '%1$s <span style="color:silver">(account id:%2$s)</span> <span style="color:silver">(user id:%3$s)</span>%4$s' ),
$name,
$account_id,
$user_id,
WP_List_Table::row_actions( $actions )
);
break;
default:
// code...
break;
}
}
Result look like this, checkbox is not in correct position. It must always on left.
Thank you
I assume you have hooked into
manage_users_columns
. Probably your array_merge is causing the problem. Instead of using$new_columns
as the 1st parameter, use it as the 2nd as given below.