As you all know, recently, i started coding “seriously” WordPress plugins. My first one was the “Mini RSS reader” and as you also know i plan on keep going with the coding. Since then, I’ve been looking on stuff about coding plugins, especially on the codex pages. I must admit that the platform is excellent and programmer friendly. You can ridiculously easily write your first “Hello world” plugin and it’s easy enough to code a plugin that will parse the output of a post.
Now, why am i writing this post? Definitely not to substitute any manual pages and especially the codex. It’s a very well documented project and it doesn’t need another how to. What i intend on doing here is point you guys to the right direction. It took me a while to find my way around the help pages and see what goes where and this post is actually a set of pointers on the novice-beginner coder. So, here i go…
First of all, i think that everything you need to start coding is on the codex page of WordPress which is actually the main documentation page to the project. Here are a few pages of interest in there:
- It all starts on the “Plugins” page. This actually says a few stuff on what plugins are in WordPress and why they are so useful. So, if you have no idea what they are (which i seriously doubt) start from there.
- The most important page, the one that says a lot about plugin coding and indexes many links to useful articles is the “Plugin API” page. There you will get the first information on how things work and what make things tick.
- There are some things you need to notice there. In my humble opinion, the most important things to notice there, are the “hooks” and the “filters”. What exactly are they? When you create a plugin, you most probably want to interact with the platform rather than just echo some output. Hooks, are just that. For instance, when a post is published, you might want to do something about it (who knows, send an email or something). So, you create a function doing that “something” (for instance sending the email) and then register that function to the “publish_post” action. So, when the post is published, WordPress will call your function passing as an argument the postID. That way you can bring it up and see what was posted or do something with it.
- Now what is the difference with filters? You must have seen all those plugins that get your post and substitute some meaningless text you entered with something meaningful to you. For instance, the “Smart Youtube” plugin gets any youtube link (not so meaningless but the video itself would be much better) and substitutes it with actual code to show the video. Here is where hooks come in. So, if you would like to do the same you would have to write a function that parses the post text finding the links and substituting them with the actual code. After that, you would register a filter that would call your function every time the post is rendered (the hook is “the_content” if you are wondering). Simple and easy.
- If you grasp the idea of all the above then you have some good knowledge on how WordPress works and you should be OK with your first plugins. If you start doing stuff then you will see that you are going to need to interact more with the platform. For instance do some transactions with the database. You can do that using the “WP_Query” function provided.
I have not listed everything on the topic. It’s actually endless since it’s a pretty big platform. But the basics are covered and i am sure you can start coding in no time. All in all, it’s a great platform to work with and even greater for the documentation that you can find on it.
I hope you all have some good coding time and we see some plugins from you all!