This entry is part 2 of 7 in the Creating a User Follow System Plugin Series
Part 1 of the User Follow System series looked at laying out the main structure of the plugin. For part 2, we’re going to continue that and lay out the main skeleton functions that we need for our plugin. These will include the functions for following a user, unfollowing a user, checking if a user followers another, and other similar functions.
There are several main tasks that happen in a plugin like this, and that’s primarily what I want to walk you through in this part of the series. We won’t write a lot of code here (we will in part 3) because it’s really important that you have a good understanding of how the logic of the system works before you jump into the code.
The Storage Method Used
There are a lot of ways to store data about users (primarily data about who is following who) and it’s important that you think about it before simply choosing one. In this tutorial series we’ll be storing the info in the WordPress user meta table. Now, there are a couple of really important notes that you need to know about this:
1. When storing in the user meta table, it is possible to make user meta global for multi site installs, or localized to individual installs. The add/get/update_user_option() set of functions is (by default) localized to individual sites. The add/get/update_user_meta() set of functions, however, is global for multi site installs, meaning that meta stored for a user on site #4 will also exist for that same user on site #7. We will be using the global option for this series, but in your own applications, this may not work.
2. By storing the data in the user meta tables, our system is persistent, meaning that all data is stored forever. Due to the way the data is stored, it is technically limited in size. All of the user IDs that one particular user is following, will be stored in the same database column and row, which means that at some point, it is possible the space will run out and no more users will be able to be followed (or some other nasty effect). In order for this to happen, a user would have to follow an exorbitant number of other users (thousands and thousands), so it is very unlikely, but still possible. If you are in a scenario where this could cause an issue, you should consider an alternate storage method.
There are three separate meta keys that will be using for storing information. One for the other users that a user is following; one for the other users that are followed by a user; one for the total number of users a user is followed by. The meta IDs will be as follows: