A WordPress plugin file structure that doesn’t suck
Inheriting a plugin with 15 classes crammed into one 3,000-line file is a nightmare to change. How PSR-4 and an autoloader give you a WordPress plugin file structure you can actually navigate.
Inheriting a plugin with 15 classes crammed into one 3,000-line file is a nightmare to change. How PSR-4 and an autoloader give you a WordPress plugin file structure you can actually navigate.
A client’s site had the same widget code copy-pasted twelve times. Here is how I use an abstract base class so one edit updates every widget instead of twelve.
A client’s WooCommerce product filter kept timing out. The fix was not a faster query but a custom taxonomy, and the real story is about designing instead of copy-pasting.
A plugin stuffed 2MB of logs into one autoloaded option and dragged every page down. Here is how the Options API autoload flag works and how to split the data properly.
Hooks buried in class constructors made a WooCommerce plugin impossible to follow. Here is how a small PHP interface and a hook manager give every class a clear, testable contract.
A client asked for one small change to a meme shortcode plugin, but its 2,000-line class made every edit risky. Splitting it by responsibility fixed that.
A client’s site kept redirecting to a pharma store no matter how many times they cleaned it. The malware was only the symptom; an outdated plugin left a backdoor open.
A client’s plugin had a 200-line constructor stuffed with add_action and add_filter calls, so the class could not be tested or reused. Keep hooks out of the constructor.
A WooCommerce store’s coupons applied at random because functions kept overwriting shared globals. Wrapping the logic in a class with private data and public methods fixed it.
A walk through using a WordPress abstract class as a shared blueprint for plugin admin pages, so adding a new option means editing one child class instead of six copy-pasted files.