user rank - points and title

Bainternet User Ranks v1.0

This version was all about speed!
the changed made to the plugin save in calls to the database and points calculations.

The Old Way

Every time the plugin was called it called thr database to see how many posts that user has, and how many comments, then it checks to see how many points each post or comment is worth and calculates the users point count, then it checks to see whats the right rank title and returns it.
So thats atleast 3 calls to the database and some calculation for every call you make to the plugin.

The New Way

The plugin now does everyhing listed above but only once per each user and stores the data at the usermeta table, So next time you call the plugin for that spesific user it will take the data strait from the user metatable saving all calls to posts table , comments table and calculations making at most one call to the database.

The Problem With this method:

Since the data now is saved in the database, the problem that rose up is how to update it every time a user posts a new post or adds comments.

The Solution:

To make sure the user points and rank title gets updated I add a simple function that runs each time a post or a comment is published And what that function does is simply removes that saved user data, so next time you call the plugin with that user's ID it will check if he has data saved in the database, and if not it will calculate it.

How to use and download link

As allway feedback and questions are welcome.

Ohad Raz

WordPress Consultant, a WordPress Developer and a WordPress Freelancer With over 10 years experience in architecting web sites and applications. WordPress Development moderator and somethimes Plugin Developer.