How to add columns to WordPress tables using filters

By Matt Dunlap on March 17th, 2010
Clip to Evernote Tags: , ,

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.

wordpress plugins extend your code

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


My next post is going to be awesome... Subscribe to my feed so you don't miss it

Large RSS Feed Button


Previous Post Next Post

Post a Comment

Name:   
Email:   
Website:   
Comments:   
alert icon Do you need help with your website? I can offer full system admin, website development and Internet marketing services
Domain Name Deals
.COM for $1.99
With any non domain name purchase
Free Private Registration - When you buy or transfer 5 domains at opendls.com
Domain Name Reseller Accounts
Low buy rates - Very Profitable
Matt Dunlap on Why am I getting redirect loop errors with FireFox 3.6.8?
Hi, thanks for the heads up... Have you experienced this problem with any other websites? It's reall[...]
Stacy on Why am I getting redirect loop errors with FireFox 3.6.8?
I was attempting to follow your links to these tutorials from your youtube video, and I was using th[...]
Matt Dunlap on 301 redirects will lower your Google Pagerank
You want 301 redirect on same site redirects mainly to eliminate duplicate content. For example, if [...]
Kate Mag on 301 redirects will lower your Google Pagerank
great info. Does this mean that only affecting 301 redirect to another domain. I have 301 redirect t[...]
Mike Johnson - Real Estate Agent on Why is making extra money a bad habit?
Hey man, this is some great stuff. The only thing I can't figure out is why this sort of thing isn'[...]

Top Guest Bloggers

LoneWolf
View Posts | RSS

Guest Bloggers Welcome!


Powered By: Free Premium WordPress Theme | Copyright 2007 - 2010 mattdunlap.org Sitemap