Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
WordPress has been through many iterations. There have been a number of different versions. Interestingly enough, they all have code names of jazz musicians, like version 2.7 was code named John Coltrane, and the most recent 3.0 was code named Thelonious Monk. What's great about having these different versions is over the time WordPress contributors are constantly making this a better and better environment to work with. However, because there are always changes to this environment, it's really important that we pay attention to the API and do some certain practices that make sure that we can account for these different versions.
If you go to the WordPress web site, there's a page dedicated specifically to WordPress versions. You can see when the versions were released, and you can read change logs for each of them. Note you can also see their code names. There have been quite a number of versions, and as they go from version to version, they can change the structure of the database. They can change the functions that exist, actions and hooks changes, and there can be all kinds of changes in the user interface. So there are a few things that can go wrong with our code because of this.
One is an old version of WordPress can break when they install your plugin because your plugin doesn't work. Remember, every time you have a plugin, it gets included in every request, which means that code is always going to execute. So if there's a problem in that code, it's literally going to hold production and throw an error. Another thing that can happen is a new version of WordPress is installed, and it breaks because your plugin doesn't have compatibility. It's extremely difficult, and a lot of it is just keeping up with the API, but there are a few things that you can know about.
One is there's a special page dedicated to deprecated functions. These are functions that no longer exist or are no longer popularly used in the WordPress system. If you need to use them, they're located in a number of different files, and this page will tell you where to find them. You can always include them in your script, if it's necessary, and you don't want to rewrite your code. However, it's best to use whatever they are replaced with, and usually there will be some new solution. Another way to get around this is to use the function exists function, to test and see if functions are there.
Let's go into our cc_comment plugin that we worked on earlier. One of the things that we did recently was we registered an uninstall hook. Well, this particular function register_uninstall_hook didn't exist until WordPress 2.7. So if you try to run this in a previous version, it would actually throw an error. We don't have to worry about adding actions and filters. If you try and add an action to a filter that doesn't exist in a version of WordPress that they're running, it'll basically just get ignored.
However, because this is a function that's actually being executed, it will throw an error. So what you want to do in instances like this, if you know you're going to run a function that may not work with the version of WordPress someone's using, you simply wrap it in if function_exists, and then just put the name of the function: register_uninstall_hook. If that exists then it will execute whatever is in this code block, in which case it'll run that function; otherwise it won't happen, which means they won't be able to uninstall prior to 2.7, but that's okay, because it wouldn't have worked.
So long story short, keeping track of WordPress versions becomes of utmost importance as a plugin developer, so you know what exists and what doesn't. The good news is that the Codex provide a lot of information about functions, their availability, and what version they do and don't exist in. The bad news is it's all up to you.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 101058 Viewers
61 Video lessons · 87839 Viewers
71 Video lessons · 71720 Viewers
56 Video lessons · 103597 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.