{"id":34,"date":"2012-06-29T18:12:33","date_gmt":"2012-06-29T16:12:33","guid":{"rendered":"https:\/\/wprealm.com\/?p=34"},"modified":"2012-06-29T18:12:33","modified_gmt":"2012-06-29T16:12:33","slug":"writing-plugins-is-it-always-worth-it","status":"publish","type":"post","link":"http:\/\/wprealm.local\/writing-plugins-is-it-always-worth-it\/","title":{"rendered":"Writing Plugins: Is It Always Worth It?"},"content":{"rendered":"
Writing code can be boring sometimes, whether you need some new features, but don’t like them or the process itself has somehow become tedious. You cannot focus and you are at a dead-end. The only thing you want is to get this thing working and finish it already. Sometimes what you need to get done\u00a0is so\u00a0simple\u00a0<\/em>that two lines in your theme’s <\/p>\n We all have used any combination of these at any given moment:<\/p>\n We develop large plugins or small pieces of code. For the small pieces, we just need to add them to the\u00a0 Consider child themes, for instance. As you know, your\u00a0 The code is for this one specific client only. You’re not going to use it again. Never. Ever. You’re absolutely sure.<\/p>\n Right. The truth is that if you have a piece of code that is simple and useful, you are going to use it again. If you have spent a lot of time developing it, you’ll be proud of it and will end up using it again in your next project. Take a look at the examples below; they were all originally developed for a single use-case. Then they were transformed into plugins, and reused in many projects.<\/p>\n When you are developing for clients, your main concern is their needs. At first, you think to yourself “my client is from Spain, and Spanish people only use stuff in Spanish, why bother?”, “I’ll do it in English only, anyone can use it” or even “I’m going to show off my geekiness, I’ll do it in Klingon”. I hope it has become clear that there are benefits in writing plugins instead of using disordered pieces of code. It’s not alway easy to remember in which project you used a piece of code that you need in the new one. If you have everything neatly packaged, it will be good for everyone \u2013 and great for you.\u00a0Your first couple of plugins will be a bit messy and sometimes difficult to get to work. You’ll need to write clean, nicely indented code and prepare a header for your plugin, but \u00a0the Codex makes it easy to get started<\/a>. You could even use another plugin’s code to start your own.<\/p>\n When you write code, you have a community of developers that can help you. If you are working with php there’s\u00a0php.net<\/a> to solve your questions, for instance, or even Stack Overflow<\/a>. If you share your code in \u00a0public repositories such as\u00a0GitHub<\/a>, people can see it, fork it and help you improve it.<\/p>\n Keep in mind that you are coding PHP, a programming language that has one of the biggest developer communities. You are coding for WordPress, too, not only for you, but for the whole community. If you need to write a plugin about anything, you will probably find a plugin that can help you get started, in the repository. They share, you share, all under the GPL. This why you are never alone in your corner, churning out code; there are literally thousands of developers ready to help<\/strong>. Really. Just take a look at\u00a0these archives<\/a>.<\/p>\n When writing code for WordPress, here are your best resources:<\/p>\n One of the greatest features of Free Software and Open Source is security, i.e. if you are the only one using a particular piece of code, you could have a security problem and not realize it until it’s too late. However, if your code is being used by many, they can help you in finding issues (and trust me, they will), much in the same way you sometimes find issues in their<\/strong> code. Also,\u00a0if you are going to release your code to the world, there is a greater probability that you’ll look at it twice, before releasing.<\/p>\n When a client of yours has a problem that can be solved with software, your job is usually to help him identify the problem and look for the right solution. If the solution doesn’t exist already, you will probably develop it for your client. What just happened? Your client is paying the time you need to code the solution. The code itself, however, should be free as it is itself based on Free Software. Why? Because everybody wins. The whole community will see and possibly use your code. It will notice, if you have included the information on the plugin’s credits, that your client is using it, that they’ve helped in its development. Because you are offering it back to the community that helped you to learn and develop it, they can improve it, helping you and your client to reach an even better solution. And finally, because it looks good on your portfolio. Good karma all-around.<\/p>\n You already know the three R’s. They are not only for glass and plastics. You can use them for software, too.<\/p>\nfunctions.php<\/code> file would probably do the trick, and the code for the header of a plugin alone is 10 lines. Why bother coding a plugin at all?<\/p>\n
The usual excuses<\/h3>\n
“It’s just the two lines”<\/h4>\n
functions.php<\/code> file. Pretty easy, why complicate?<\/p>\n
functions.php<\/code> file belongs to a specific theme, not your whole site. \u00a0If someone updates it, your changes will be lost. If you are the only admin or developer and you have a good memory, you can probably risk it, \u00a0but isn’t it just easier to not have to remember<\/strong> and have a plugin that you can activate and deactivate without having to touch anything else?<\/p>\n
“I’m not going to reuse it”<\/h4>\n
“I’m not going to use it in another language, no need to make it translatable”<\/h4>\n
\nI myself have some plugins and code whose HTML on the frontend is in Spanish only. Despite it being very common, however, it doesn’t make it right<\/strong>. \u00a0Internationalization<\/a>\u00a0looks difficult\u00a0at first, even tricky. With little time, you will notice that it is actually quite easy and just another step in your development cycle. Your plugin will be translated by many and will gain a visibility that it wouldn’t have if you hard-coded its strings.<\/p>\nPlugin beats functions.php<\/h3>\n
Community<\/h4>\n
\n
\n
Security<\/h4>\n
Acknowledgement & Reputation<\/h4>\n
The three R’s<\/h4>\n
Reduce<\/h5>\n