2

I need to hook to the users list page.

I Need to add a checkbox column for each user to remember if they have paid or not.

Thanks for help because can’t find snippet to hook to this admin page.

2

One thing you should remember is that function, which will be hooked into manage_users_custom_column action must have 3 parameters, the first of which (i.e. $val) should be the returned value:

// Add custom column using 'manage_users_columns' filter
if(!function_exists('bm_utm_column')){
function bm_utm_column($columns) {
    return array_merge( $columns, 
        array('utm_source' => __('UTM source'),
            'utm_medium' => __('UTM medium')
            ) 
        );
    }
}

// Add the content from usermeta's table by using 'manage_users_custom_column' hook
if(!function_exists('bm_utm_column_value')){
   function bm_utm_column_value($val, $column_name, $user_id) {
    if ( 'utm_source' == $column_name ) {
        //Custom value
        $val = get_user_meta($user_id, 'utm_source', true);
    }
    if ( 'utm_medium' == $column_name ) {
        //Custom value
        $val = get_user_meta($user_id, 'utm_medium', true);
    }
    return $val;
   }
}
// Hook into filter
add_filter( 'manage_users_columns', 'bm_utm_column' );
add_action( 'manage_users_custom_column', 'bm_utm_column_value', 10, 3 );
1

The users list column is filtered by manage_users_columns. Take a look into this simple example of how to hook into this filter:

// We add another column using 'manage_users_columns' filter
function my_payment_column($columns) {
    return array_merge( $columns, 
              array('payment' => __('Payment')) 
            );
}
// Now we add some content to each row by using 'manage_users_custom_column' hook
function my_payment_column_value($column_name, $user_id) {
        if ( 'payment' == $column_name ) {
            // Place to add checkbox, text field, etc.

            // If the user has paid, show it. Else, show N/A.
            if ( isset($paid) && $paid ) {
                echo __('Paid','text-domain');
            } else {
                echo __('N/A','text-domain');
            }
        }
}
// Hook into filter
add_filter( 'manage_users_columns', 'my_payment_column' );
add_action( 'manage_users_custom_column', 'my_payment_column_value', 10, 2 );
0

You can use this

function modify_user_table( $column ) {
   $column['comments'] = 'Comments';
   return $column;
}
add_filter( 'manage_users_columns', 'modify_user_table' );

function modify_user_table_row( $val, $column_name, $user_id ) { 
   global $wpdb;
   if ($column_name == 'comments') {
       $comment_count = $wpdb->get_var( wpdb->prepare( "SELECT COUNT(*) S total FROM $wpdb->comments WHERE comment_approved = 1 AND user_id = %s", $user_id ) );
       return $comment_count; 
   }
   return $val;
}
add_filter( 'manage_users_custom_column', 'modify_user_table_row', 10, 3 );

For detailed explanation visit http://tekina.info/add-extra-column-user-listing-page-wordpress-admin-panel/

1
  • 1
    Please, explain what the code does in the answer itself; use external links only as reference.
    – cybmeta
    Sep 13 '17 at 7:25

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.