• Diablo2

    (@diablo2)


    Hi guys, quick question.
    How would i add a column to show the “Website” field in the main Users admin screen? This way I wont have to click on a username to view their website.

    I found the following code online, but it obviously needs correcting. Could anyone help me modify it accordingly? (assuming this code is remotely the right one). Thanks!

    function new_contact_methods( $contactmethods ) {
    $contactmethods[‘url’] = ‘Pro’;
    return $contactmethods;
    }
    add_filter( ‘user_contactmethods’, ‘new_contact_methods’, 10, 1 );
    
    function new_modify_user_table( $column ) {
    $column[‘url’] = ‘Pro’;
    return $column;
    }
    add_filter( ‘manage_users_columns’, ‘new_modify_user_table’ );
    
    function new_modify_user_table_row( $val, $column_name, $user_id ) {
    switch ($column_name) {
    case ‘url’ :
    return get_the_author_meta( ‘url’, $user_id );
    break;
    default:
    }
    return $val;
    }
    add_filter( ‘manage_users_custom_column’, ‘new_modify_user_table_row’, 10, 3 );

    [Moderator note: code fixed. Please wrap code in the backtick character or use the code button.]

    • This topic was modified 7 years ago by bdbrown.
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Well, you don’t need the contact methods since the user’s site is already in the users table. The manage_users_columns part are just labels, you can change them to anything you like. The array key is like a slug for the column, the value is what appears at the column head. If you want to reorder the columns horizontally, you can recreate the passed array using a new order, placing your column where you want it to appear. The check box and user name should always be first. The rest do not matter. You can remove columns from view by unsetting its respective array element.

    In manage_users_custom_column, the case is the column slug you assigned in manage_users_columns. The return value will be the website URL from the user’s WP_User object. Get the user object with $user = get_user($user_id); The URL will then be $user->user_url.

    Note that all the quotes in your example are the improper “curly” style. They all need to be changed to the “straight” style.

Viewing 1 replies (of 1 total)
  • The topic ‘Adding ‘Website’ field as a Column in the “Users” admin screen’ is closed to new replies.