admin - Add a custom column in users list page

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

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.

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.

Share Improve this question edited Jun 1, 2017 at 17:22 Johansson 15.4k11 gold badges43 silver badges79 bronze badges asked Jun 1, 2017 at 16:22 jhoannajhoanna 211 silver badge2 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 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 );

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 );

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/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744955676a4603179.html

相关推荐

  • admin - Add a custom column in users list page

    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

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信