How to add columns to WordPress tables using filters
| By Matt Dunlap on March 17th, 2010 |
When you manage WPMU websites, you’ll quickly realize many of your subscribers will be spammers. There are tons of plugins that try to help manage the problem. Recently instead of just trying to remove them, I’ve tried to understand where they come from, how they signup, and what their purposes are. While trying to figure out spammers, I made a cool tutorial about filters and actions.
![]()
When I first started with WPMU, it was easy to see a spammer, but lately I’ve noticed they can sign up, and reply to the activation email. I started to monitor this activity and I started to monitor log in times to see if they every log in. The purpose of the log in time is to purge the database of users if they either never log in or stop logging in.
This plugin simply adds an action to the wordpress login action and adds the last login time to the usermeta table for the current user. Along with the database entry, I needed to add a column to the user table for system admin that shows the last login time. Luckily, you can add to the columns using a filter so you don’t have to edit the wp-admin/wpmu-user.php file.
First, grab the last login time plugin here.
It is the bones of a plugin, meaning it only logs the last login time. There are no flags or activities. Feel free to add your own depending on what you need to do. Unzip and upload to the mu-plugin folder. There are 4 functions in the file. I’ve added a function to log the ip number of the user also. Eventually I’m going to map it using an IP location service, but in the current plugin it just logs the IP number.
I’m often asked, how do you find actions and filters to connect to… the answer is, you have to find them. You have to look at the wordpress code and see if any exists for whatever function you are trying to extend. In this case, I’m trying to add a column to the user table for the system admin.
Here the WordPress page for Actions and plugins
That page is very good at explaining the uses of both actions and filters
Don’t forget you can also use add_action() and apply_filter() to plugins you make, allowing other plugin developers to extend your plugins





Post a Comment