Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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&nbsp;id:%2$s)</span> <span style="color:silver">(user&nbsp;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.

enter image description here

Thank you

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

$new_columns = array_merge ( $columns, $new_columns );
share|improve this answer
    
Thanks for help, but result looks not good too. There is space next to checkbox. Screenshot: i.stack.imgur.com/TLSRv.png –  T Kien Dec 3 '13 at 4:03
    
The space is for name column. Since you do not have any data, it's an empty column. –  Chittaranjan Dec 3 '13 at 4:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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