Every developer has the habit to reinvent the wheel. We search for excuses to do everything ourselves, such as "Ah no, that thing doesn't fully cover what I need" and "I don't trust code I didn't write myself". That's too bad because others might have fixed the same issues you ran into. In this post, I'll discuss some questions I believe you should ask yourself before making your own plugin.
What should my code or plugin do?
When running a website, you might have some particular needs in terms of how it should work. The themes and plugins you've found aren't covering these needs. Sometimes, your requirements are too specific and maybe writing a plugin can solve this issue. That's awesome.
However, I recommend having a clear idea of what your plugin should do. Do you just need to customize little things by adding filters or something like that? Over time, a simple plugin can grow from some simple filters to having implementations for adding tracking code or social behavior.
There's nothing wrong with having your own custom plugin for such things. But before you know it, instead of doing a simple filter, your plugin will end up doing all kinds of stuff. That's a pity because there is a WordPress ecosystem with thousands of plugins and there might be one that does exactly what you want.
Is it bad to do things yourself?
I do believe in 'reinventing the wheel' as a learning school. For example, you'll gain a better understanding of the inner workings of a plugin or a theme when you learn how to make one from scratch.
Outside the WordPress context you can, for example, write your own PHP framework. This gives you the opportunity to see most common code patterns, to learn how a framework works and how difficult it can be to write a framework. When you're done writing your own framework, just throw it away. Not because it is rubbish, but because it's only useful as a learning experience.
Beware of doing things for their own sake!
A couple of years ago, just before I became a WordPress developer, I thought it might be a good idea to write my own CMS. Just because I love to code and I wanted to have the power to make changes to something that was mine. After a while, most of the work was done and I started looking for new features to add.
Instead of having a CMS that was ready to use for a blog I was just maintaining a CMS. Besides that, I was thinking of new functionalities that I might want to use in the future, instead of using the current functionality.
Change your mindset
For most situations you might not need to write your own plugin. Search for plugins that add the type of functionality you need. If you find a plugin, just dive into its codebase and see if you like the code you see. Maybe you see some ways to extend the plugin by using hooks and you can consider whether you want to contribute if you think some things need improvement. This way, you can actually make other people happy. Instead of doing new things yourself, you'll make existing things better for more people.