Display registration date for all users on the website.

Hiển thị ngày đăng ký của người dùng vào trang tất cả người dùng

In the event of a spam attack on a website with nearly 50 spam users out of more than 1000 total users, the last 50 users can be deleted without accessing the database by adding a Sign-up Date column to the user page. By sorting the users based on their sign-up date, from newest to oldest, the last 50 spam users can be easily identified and deleted. This can be achieved by creating a new column in the user page using the provided code in the functions.php file of the theme being used. Additionally, the data display section utilizes the get_the_author_meta function to retrieve the registration time of users for sorting purposes. By making the Registration date column sortable, managing users on the site can be done more effectively.

If you’ve been dealing with a spam attack on your website and need to delete the last 50 spam users without diving into the database, fret not! Here’s a nifty solution for you.

In the image above, you’ll see a table displaying user information with a new column called "Sign-up Date." Clicking on this column header allows you to sort users based on their sign-up date, from the newest to the oldest. Pretty handy, right?

If you’re keen on a similar setup but showcasing the user’s last login instead, I’ve got an article tailored just for you. Don’t let that valuable information slip through your fingers.

Now, to spice up your user page and seamlessly manage those users, consider adding the following code snippet to your theme’s functions.php file:

add_filter( 'manage_users_columns', 'hk_modify_user_table' );

function hk_modify_user_table( $columns ) {
    $columns['registration_date'] = 'Ngày đăng ký';
    return $columns;
}

add_filter( 'manage_users_custom_column', 'hk_modify_user_table_row', 10, 3 );

function hk_modify_user_table_row( $row_output, $column_id_attr, $user ) {
    $date_format = "j M, Y H:i";

    switch ( $column_id_attr ) {
        case 'registration_date':
            return date( $date_format, strtotime( get_the_author_meta( 'registered', $user ) );
            break;
        default:
    }

    return $row_output;
}

To ensure your data columns are not only informative but also sortable, simply insert the below code snippet into your functions.php file:

add_filter( 'manage_users_sortable_columns', 'hk_make_registered_column_sortable' );

function hk_make_registered_column_sortable( $columns ) {
    return wp_parse_args( array( 'registration_date' => 'registered' ), $columns );
}

By implementing these steps, you’ll be well on your way to managing your site’s users more efficiently, especially for those focusing on community-driven websites. If you found this article helpful, feel free to drop a comment and share it with others. Stay tuned for more insightful WordPress Tips and follow us on Facebook for a dose of new knowledge.

See also  Easiest ways to change Favicon in WordPress

And don’t forget to rate this article. Your feedback means the world to us!

Rate this post

Related posts