User Registration

  1. Home
  2. Docs
  3. User Registration
  4. How to?
  5. How to add extra information of the users in admin overview ( users tab)

How to add extra information of the users in admin overview ( users tab)

This example code will add the additional Country field from the registration form and it’s value.
Expected Result:
add_filter( 'manage_users_columns', 'ur_add_column_head' );
add_filter( 'manage_users_custom_column', 'ur_add_column_cell', 10, 3 );


/**
* Add the column header
*
* @param array $columns
*
* @return array
*/
function ur_add_column_head( $columns ) {
    if ( ! current_user_can( 'edit_user' ) ) {
     return $columns;
    }

  $columns['ur_extra'] = __( 'Country', 'user-registration' );
  return $columns;
}

/**
* Set the Column value for each user in the users list
*
* @param string $val
* @param string $column_name
* @param int $user_id
*
* @return string
*/
function ur_add_column_cell( $val, $column_name, $user_id ) {

     if ( ! current_user_can( 'edit_user' ) ) {
        return false;
     }

    $val = '';
    if ( $column_name == 'ur_extra') {
       $val = get_user_meta( $user_id, 'user_registration_country_1543398649', true );
       return isset( $val ) ? $val : '';
    }
   return $val;
}
Note that to get the  value of the field you need to add user_registration_ prefix and the field name of that specific field. For example in the above code. get_user_meta( $user_id, ‘user_registration_country_1528783674′, true );
country.png
Was this article helpful to you? Yes No

How can we help?