customization - Add custom column to Users admin panel with Types user custom fields?

admin2025-06-05  1

I added custom columns but now I don't know how to get the date from the fields to show... and I have an error in my code. Can someone help?

Thanks

Here's the code :

function new_modify_user_table( $column ) {
    $column['les-non-specialistes'] = 'Non-spécialiste';
    $column['specialistes'] = 'Spécialiste';
    return $column;
}
add_filter( 'manage_users_columns', 'new_modify_user_table' );

function new_modify_user_table_row( $val, $column_name, $user_id ) {
    $user = get_userdata( $user_id );
    switch ($column_name) {
        case 'les-non-specialistes' :
            return get_the_author_meta( 'les-non-specialistes', $user_id );
            break;
        case 'specialistes' :
            return '';
            break;
        default:
    }
    return $return;
}
add_filter( 'manage_users_custom_column', 'new_modify_user_table_row', 10, 3 );

I added custom columns but now I don't know how to get the date from the fields to show... and I have an error in my code. Can someone help?

Thanks

Here's the code :

function new_modify_user_table( $column ) {
    $column['les-non-specialistes'] = 'Non-spécialiste';
    $column['specialistes'] = 'Spécialiste';
    return $column;
}
add_filter( 'manage_users_columns', 'new_modify_user_table' );

function new_modify_user_table_row( $val, $column_name, $user_id ) {
    $user = get_userdata( $user_id );
    switch ($column_name) {
        case 'les-non-specialistes' :
            return get_the_author_meta( 'les-non-specialistes', $user_id );
            break;
        case 'specialistes' :
            return '';
            break;
        default:
    }
    return $return;
}
add_filter( 'manage_users_custom_column', 'new_modify_user_table_row', 10, 3 );

Share Improve this question edited Jun 26, 2015 at 3:42 JJ Rohrer 14210 bronze badges asked Jun 26, 2015 at 0:32 MelMel 212 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

To fix the error, you can do something like this:

 function new_modify_user_table_row( $val, $column_name, $user_id ) {
    $user = get_userdata( $user_id );
    switch ($column_name) {
        case 'les-non-specialistes' :
            return get_the_author_meta( 'les-non-specialistes', $user_id );
            break;
        case 'specialistes' :
            return '';
            break;
        default:
    }
    return $val; //<-- Changed
  }

Regarding the date, which date are you looking for? Which column should it go into (a new one)?

I'll take a guess - I hope this gets you started. In general, say if you want to add the last modified date, you can do something like this (untested code):

case 'last-modified': //<-- new column that maybe you added above
  global $post;
  $ugly_date = $post->post_modified;
  $pretty_date = date("Y, M, jS",strtotime($ugly_date)); //<-- format as desired.  There are smarter ways of doing this part
  return $pretty_date;
  break;

(reference: http://codex.wordpress/Function_Reference/$post)

Good luck,

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749137456a316677.html

最新回复(0)