$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>customization - Add custom column to Users admin panel with Types user custom fields?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin10PV0评论

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,

Post a comment

comment list (0)

  1. No comments so far