Custom Code vs. WordPress Plugins: Which Is Better?

Custom Code vs. WordPress Plugins: Which Is Better?

Choosing between writing custom code or using existing WordPress plugins is a common dilemma for developers. Both options have their advantages and drawbacks, and the best choice often depends on the specific needs of the project. In this article, we’ll explore the pros and cons of each approach and offer guidance on making the right decision for your site or your client’s site.

Is it better to use or write custom code instead of using an existing WordPress plugin?

Sometimes plugins and themes come with lots of functionality that is supposed to cover various cases that your site or client’s site may not necessary need.

Custom Code = Higher Efficiency (Usually)

The code you write is specialized to solve exactly the problem that your client is facing and because of that it’s usually efficient. You have to know php in order to evaluate and write the code efficiently.

Plugin are made to solve a set of problems. The trend is usually to add as many features as possible and almost never to remove features. Having a plugin that provides lots features will definitely slow things down and if you have 20-50 plugins that problem will become worse over time.

For example in our plugins (under the Orbisius brand which is the parent company of WPSandbox) we have simple checks before doing the complex checks and this improves the performance. There’s no point of calling an resource consuming function when there’s no need for it.

For example before doing a regular expression check e.g. !/users/(\w+)!si we check if the text even contains /users/. Another example if we have a function that is supposed to check a buffer if it’s a html_string or a binary file. Let’s say that the file size can range from 5KB to 5MB. We could take the first 20 characters of the buffer and check for common starting bytes for know file types such as zip, rar, 7z, images, PDF etc. if it’s a binary we return right away and let the other code handle this type of content. Next, we do another check but we take a small buffer e.g. 32kb and then search for common HTML tags and as soon we find them we return html_buffer as a result.

Custom code vs. Existing Plugins

Several years ago we had a client that was using a really nice newsletter plugin. He has a SaaS app and wanted to let his customers compose emails from within WordPress. The plugin’s user interface was good, flexible and full of features. It also created between 10-12 extra database tables. It may not sound too bad but my client had a WordPress Multisite setup. Each subsite in a WordPress Multisite set up is duplicating all tables and this started accumulating over time. So every new site had those extra db tables. We didn’t catch this on time to advice him about the technical issues.

Another reason to use custom code is some (old) plugins in the official plugin repository may collect user data without asking the user permission or may be abandoned at any time.

Another bad habit that plugin authors have is to start adding all kinds of stupid stuff in the WordPress notifications (admin_notices hook)… basically spam or put promotional offers. It may be relatively ok if only the developer/designer sees this but when the site is in your client’s hands it’s not ok for the clients to keep seeing different upsells as this ruins the user experience.

When write custom code follow these simple rules

  • if it’s related to the currently installed theme -> then add it to the functions.php file. Hopefully you have created a child theme otherwise your changes will be lost after an update to the (main) theme. If you are not using a child theme then it’s better to use a custom plugin for your code snippets and custom code.
  • Custom code in a plugin. It’s better to use a custom plugin then to use another plugin that will store php code. You can use our Simple WordPress Plugin Generator to package your snippet(s) into a plugin that you can install.

....

Read the full article Custom Code vs #WordPress Plugins: Which Is Better on WPSandbox Blog



要查看或添加评论,请登录

Svetoslav Marinov的更多文章

社区洞察

其他会员也浏览了